Search in sources :

Example 11 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileMoistener method updateServerSide.

@Override
public void updateServerSide() {
    if (updateOnInterval(20)) {
        // Check if we have suitable water container waiting in the item slot
        FluidHelper.drainContainers(tankManager, this, InventoryMoistener.SLOT_PRODUCT);
    }
    // Let's get to work
    int lightvalue = world.getLightFromNeighbors(getPos().up());
    IErrorLogic errorLogic = getErrorLogic();
    // Not working in broad daylight
    boolean gloomy = lightvalue <= 11;
    if (errorLogic.setCondition(!gloomy, EnumErrorCode.NOT_DARK)) {
        return;
    }
    // The darker, the better
    int speed;
    if (lightvalue >= 9) {
        speed = 1;
    } else if (lightvalue >= 7) {
        speed = 2;
    } else if (lightvalue >= 5) {
        speed = 3;
    } else {
        speed = 4;
    }
    // Already running
    if (burnTime > 0 && pendingProduct == null) {
        // Not working if there is no water available.
        boolean hasLiquid = resourceTank.getFluidAmount() > 0;
        if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_RESOURCE_LIQUID)) {
            return;
        }
        checkRecipe();
        if (currentRecipe == null) {
            return;
        }
        resourceTank.drain(1, true);
        burnTime -= speed;
        productionTime -= speed;
        if (productionTime <= 0) {
            pendingProduct = currentProduct;
            decrStackSize(InventoryMoistener.SLOT_RESOURCE, 1);
            resetRecipe();
            tryAddPending();
        }
    } else if (pendingProduct != null) {
        tryAddPending();
    } else // Try to start process
    {
        // Make sure we have a new item in the working slot.
        if (rotateWorkingSlot()) {
            checkRecipe();
            // Let's see if we have a valid resource in the working slot
            if (getStackInSlot(InventoryMoistener.SLOT_WORKING).isEmpty()) {
                return;
            }
            if (FuelManager.moistenerResource.containsKey(getStackInSlot(InventoryMoistener.SLOT_WORKING))) {
                MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(InventoryMoistener.SLOT_WORKING));
                burnTime = totalTime = res.getMoistenerValue();
            }
        } else {
            rotateReservoir();
        }
    }
    errorLogic.setCondition(currentRecipe == null, EnumErrorCode.NO_RECIPE);
}
Also used : MoistenerFuel(forestry.api.fuels.MoistenerFuel) IErrorLogic(forestry.api.core.IErrorLogic)

Example 12 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileRaintank method updateServerSide.

@Override
public void updateServerSide() {
    if (updateOnInterval(20)) {
        IErrorLogic errorLogic = getErrorLogic();
        BlockPos pos = getPos();
        Biome biome = world.getBiome(pos);
        errorLogic.setCondition(!biome.canRain(), EnumErrorCode.NO_RAIN_BIOME);
        BlockPos posAbove = pos.up();
        boolean hasSky = world.canBlockSeeSky(posAbove);
        errorLogic.setCondition(!hasSky, EnumErrorCode.NO_SKY_RAIN_TANK);
        errorLogic.setCondition(!world.isRainingAt(posAbove), EnumErrorCode.NOT_RAINING);
        if (!errorLogic.hasErrors()) {
            resourceTank.fillInternal(WATER_PER_UPDATE, true);
        }
        containerFiller.updateServerSide();
    }
    if (canDumpBelow == null) {
        canDumpBelow = FluidHelper.canAcceptFluid(world, getPos().down(), EnumFacing.UP, STACK_WATER);
    }
    if (canDumpBelow) {
        if (dumpingFluid || updateOnInterval(20)) {
            dumpingFluid = dumpFluidBelow();
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) IErrorLogic(forestry.api.core.IErrorLogic)

Example 13 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileSqueezer method hasWork.

@Override
public boolean hasWork() {
    checkRecipe();
    boolean hasResources = inventory.hasResources();
    boolean hasRecipe = true;
    boolean canFill = true;
    boolean canAdd = true;
    if (hasResources) {
        hasRecipe = currentRecipe != null;
        if (hasRecipe) {
            FluidStack resultFluid = currentRecipe.getFluidOutput();
            canFill = productTank.fillInternal(resultFluid, false) == resultFluid.amount;
            if (!currentRecipe.getRemnants().isEmpty()) {
                canAdd = inventory.addRemnant(currentRecipe.getRemnants(), false);
            }
        }
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE);
    errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
    errorLogic.setCondition(!canFill, EnumErrorCode.NO_SPACE_TANK);
    errorLogic.setCondition(!canAdd, EnumErrorCode.NO_SPACE_INVENTORY);
    return hasResources && hasRecipe && canFill && canAdd;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IErrorLogic(forestry.api.core.IErrorLogic)

Example 14 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileStill method hasWork.

@Override
public boolean hasWork() {
    checkRecipe();
    boolean hasRecipe = currentRecipe != null;
    boolean hasTankSpace = true;
    boolean hasLiquidResource = true;
    if (hasRecipe) {
        FluidStack fluidStack = currentRecipe.getOutput();
        hasTankSpace = productTank.fillInternal(fluidStack, false) == fluidStack.amount;
        if (bufferedLiquid == null) {
            int cycles = currentRecipe.getCyclesPerUnit();
            FluidStack input = currentRecipe.getInput();
            int drainAmount = cycles * input.amount;
            FluidStack drained = resourceTank.drain(drainAmount, false);
            hasLiquidResource = drained != null && drained.amount == drainAmount;
            if (hasLiquidResource) {
                bufferedLiquid = new FluidStack(input, drainAmount);
                resourceTank.drain(drainAmount, true);
            }
        }
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
    errorLogic.setCondition(!hasTankSpace, EnumErrorCode.NO_SPACE_TANK);
    errorLogic.setCondition(!hasLiquidResource, EnumErrorCode.NO_RESOURCE_LIQUID);
    return hasRecipe && hasLiquidResource && hasTankSpace;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IErrorLogic(forestry.api.core.IErrorLogic)

Example 15 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileCarpenter method hasWork.

/* STATE INFORMATION */
@Override
public boolean hasWork() {
    if (updateOnInterval(20)) {
        checkRecipe();
    }
    boolean hasRecipe = currentRecipe != null;
    boolean hasLiquidResources = true;
    boolean hasItemResources = true;
    boolean canAdd = true;
    if (hasRecipe) {
        hasLiquidResources = removeLiquidResources(false);
        hasItemResources = removeItemResources(false);
        ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getOutput();
        canAdd = InventoryUtil.tryAddStack(this, pendingProduct, InventoryCarpenter.SLOT_PRODUCT, InventoryCarpenter.SLOT_PRODUCT_COUNT, true, false);
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
    errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID);
    errorLogic.setCondition(!hasItemResources, EnumErrorCode.NO_RESOURCE_INVENTORY);
    errorLogic.setCondition(!canAdd, EnumErrorCode.NO_SPACE_INVENTORY);
    return hasRecipe && hasItemResources && hasLiquidResources && canAdd;
}
Also used : ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic)

Aggregations

IErrorLogic (forestry.api.core.IErrorLogic)25 ItemStack (net.minecraft.item.ItemStack)7 FluidStack (net.minecraftforge.fluids.FluidStack)6 IErrorState (forestry.api.core.IErrorState)2 FarmDirection (forestry.api.farming.FarmDirection)2 ICrop (forestry.api.farming.ICrop)2 IFarmLogic (forestry.api.farming.IFarmLogic)2 MoistenerFuel (forestry.api.fuels.MoistenerFuel)2 FarmWorkStatus (forestry.farming.FarmHelper.FarmWorkStatus)2 FarmTarget (forestry.farming.FarmTarget)2 BlockPos (net.minecraft.util.math.BlockPos)2 EnumBeeType (forestry.api.apiculture.EnumBeeType)1 IBee (forestry.api.apiculture.IBee)1 IBeeHousingInventory (forestry.api.apiculture.IBeeHousingInventory)1 IFarmListener (forestry.api.farming.IFarmListener)1 GeneratorFuel (forestry.api.fuels.GeneratorFuel)1 IClimateHousing (forestry.api.greenhouse.IClimateHousing)1 IGreenhouseController (forestry.api.multiblock.IGreenhouseController)1 IFabricatorRecipe (forestry.api.recipes.IFabricatorRecipe)1 FilteredTank (forestry.core.fluids.FilteredTank)1