Search in sources :

Example 16 with IErrorLogic

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

the class TileEngineBiogas method updateServerSide.

@Override
public void updateServerSide() {
    super.updateServerSide();
    if (!updateOnInterval(20)) {
        return;
    }
    // Check if we have suitable items waiting in the item slot
    FluidHelper.drainContainers(tankManager, this, InventoryEngineBiogas.SLOT_CAN);
    IErrorLogic errorLogic = getErrorLogic();
    boolean hasHeat = getHeatLevel() > 0.2 || heatingTank.getFluidAmount() > 0;
    errorLogic.setCondition(!hasHeat, EnumErrorCode.NO_HEAT);
    boolean hasFuel = burnTank.getFluidAmount() > 0 || fuelTank.getFluidAmount() > 0;
    errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL);
}
Also used : IErrorLogic(forestry.api.core.IErrorLogic)

Example 17 with IErrorLogic

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

the class TileEuGenerator method updateServerSide.

@Override
public void updateServerSide() {
    if (updateOnInterval(20)) {
        FluidHelper.drainContainers(tankManager, this, InventoryGenerator.SLOT_CAN);
    }
    IErrorLogic errorLogic = getErrorLogic();
    // No work to be done if IC2 is unavailable.
    if (errorLogic.setCondition(ic2EnergySource == null, EnumErrorCode.NO_ENERGY_NET)) {
        return;
    }
    ic2EnergySource.update();
    if (resourceTank.getFluidAmount() > 0) {
        GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid());
        if (resourceTank.canDrainFluidType(fuel.getFuelConsumed()) && ic2EnergySource.getFreeCapacity() >= fuel.getEu()) {
            ic2EnergySource.addEnergy(fuel.getEu());
            this.tickCount++;
            if (tickCount >= fuel.getRate()) {
                tickCount = 0;
                resourceTank.drain(fuel.getFuelConsumed().amount, true);
            }
        }
    }
    boolean hasFuel = resourceTank.getFluidAmount() > 0;
    errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL);
}
Also used : GeneratorFuel(forestry.api.fuels.GeneratorFuel) IErrorLogic(forestry.api.core.IErrorLogic)

Example 18 with IErrorLogic

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

the class TileEngine method updateServerSide.

@Override
protected void updateServerSide() {
    TemperatureState energyState = getTemperatureState();
    if (energyState == TemperatureState.MELTING && heat > 0) {
        forceCooldown = true;
    } else if (forceCooldown && heat <= 0) {
        forceCooldown = false;
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(forceCooldown, EnumErrorCode.FORCED_COOLDOWN);
    boolean enabledRedstone = isRedstoneActivated();
    errorLogic.setCondition(!enabledRedstone, EnumErrorCode.NO_REDSTONE);
    // Determine targeted tile
    IBlockState blockState = world.getBlockState(getPos());
    EnumFacing facing = blockState.getValue(BlockBase.FACING);
    TileEntity tile = world.getTileEntity(getPos().offset(facing));
    float newPistonSpeed = getPistonSpeed();
    if (newPistonSpeed != pistonSpeedServer) {
        pistonSpeedServer = newPistonSpeed;
        setNeedsNetworkUpdate();
    }
    if (stagePiston != 0) {
        progress += pistonSpeedServer;
        EnergyHelper.sendEnergy(energyManager, facing, tile);
        if (progress > 0.25 && stagePiston == 1) {
            stagePiston = 2;
        } else if (progress >= 0.5) {
            progress = 0;
            stagePiston = 0;
        }
    } else if (enabledRedstone && EnergyHelper.isEnergyReceiverOrEngine(facing.getOpposite(), tile)) {
        if (EnergyHelper.canSendEnergy(energyManager, facing, tile)) {
            // If we can transfer energy, start running
            stagePiston = 1;
            setActive(true);
            cantSendEnergyCountdown = CANT_SEND_ENERGY_TIME;
        } else {
            if (isActive()) {
                cantSendEnergyCountdown--;
                if (cantSendEnergyCountdown <= 0) {
                    setActive(false);
                }
            }
        }
    } else {
        setActive(false);
    }
    dissipateHeat();
    generateHeat();
    // Now let's fire up the engine:
    if (mayBurn()) {
        burn();
    } else {
        energyManager.drainEnergy(20);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IErrorLogic(forestry.api.core.IErrorLogic)

Example 19 with IErrorLogic

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

the class GreenhouseProviderServer method checkBlocks.

/**
 * Check all internal blocks.
 */
private GreenhouseState checkBlocks(Collection<IGreenhouseBlock> blocks) {
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.clearErrors();
    if (minSize == null || maxSize == null || minSize == Position2D.NULL_POSITION || maxSize == Position2D.NULL_POSITION) {
        Position2D maxCoordinates = limits.getMaximumCoordinates();
        maxSize = maxCoordinates.add(1, 1).add(centerPos.getX(), centerPos.getZ());
        Position2D minCoordinates = limits.getMinimumCoordinates();
        minSize = minCoordinates.add(-1, -1).add(centerPos.getX(), centerPos.getZ());
    }
    int greenhouseHeight = centerPos.getY();
    int greenhouseDepth = centerPos.getY();
    int height = 0;
    int depth = 0;
    int maximalHeight = ((IGreenhouseController) container.getParent()).getCenterCoordinates().getY() + limits.getHeight();
    GreenhouseLimitsBuilder builder = new GreenhouseLimitsBuilder();
    Stack<IGreenhouseBlock> blocksToCheck = new Stack();
    blocksToCheck.addAll(blocks);
    while (!blocksToCheck.isEmpty()) {
        IGreenhouseBlock blockToCheck = blocksToCheck.pop();
        if (blockToCheck != null) {
            BlockPos position = blockToCheck.getPos();
            IGreenhouseBlockHandler handler = blockToCheck.getHandler();
            builder.recalculate(position);
            List<IGreenhouseBlock> newBlocksToCheck = new LinkedList<>();
            IErrorState errorState = handler.checkNeighborBlocks(storage, blockToCheck, newBlocksToCheck);
            if (errorState != null) {
                errorLogic.setCondition(true, errorState);
                break;
            }
            blocksToCheck.addAll(newBlocksToCheck);
            if (blockToCheck instanceof IBlankBlock) {
                int positionHeight = getHeight(position, maximalHeight);
                int positionDepth = getDepth(position);
                if (positionHeight == -1) {
                    errorLogic.setCondition(true, EnumErrorCode.NOT_CLOSED);
                    // throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.roof.notclosed", position.getX(), position.getY(), position.getZ())).setPos(position);
                    break;
                }
                if (positionHeight > greenhouseHeight) {
                    greenhouseHeight = positionHeight;
                }
                height += positionHeight - centerPos.getY();
                if (positionDepth < greenhouseDepth) {
                    greenhouseDepth = positionDepth;
                }
                depth += centerPos.getY() - positionDepth;
            }
        }
    }
    if (!unloadedChunks.isEmpty()) {
        errorLogic.setCondition(true, EnumErrorCode.NOT_LOADED);
        return GreenhouseState.UNLOADED_CHUNK;
    }
    if (errorLogic.hasErrors()) {
        // Remove the state NOT_CLOSED if the logic has the state TOO_LARGE because the state NOT_CLOSED can be caused by the TOO_LARGE state
        if (errorLogic.getErrorStates().contains(EnumErrorCode.TOO_LARGE)) {
            errorLogic.setCondition(false, EnumErrorCode.NOT_CLOSED);
        }
        return GreenhouseState.OPEN;
    }
    this.size = height + depth + storage.getBlockCount();
    usedLimits = builder.build(greenhouseHeight, greenhouseDepth);
    return GreenhouseState.CLOSED;
}
Also used : GreenhouseLimitsBuilder(forestry.greenhouse.multiblock.GreenhouseLimitsBuilder) IGreenhouseController(forestry.api.multiblock.IGreenhouseController) IGreenhouseBlockHandler(forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler) IBlankBlock(forestry.greenhouse.api.greenhouse.IBlankBlock) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock) LinkedList(java.util.LinkedList) Stack(java.util.Stack) IErrorState(forestry.api.core.IErrorState) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos) IErrorLogic(forestry.api.core.IErrorLogic)

Example 20 with IErrorLogic

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

the class TilePlanter method workCycle.

@Override
protected boolean workCycle() {
    if (targets.isEmpty() || updateOnInterval(10)) {
        setUpFarmlandTargets();
    }
    IErrorLogic errorLogic = getErrorLogic();
    boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
    if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
        return false;
    }
    if (!pendingProduce.isEmpty()) {
        boolean added = inventory.tryAddPendingProduce(pendingProduce);
        errorLogic.setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY);
        return added;
    }
    // Cull queued crops.
    if (!pendingCrops.isEmpty()) {
        ICrop first = pendingCrops.get(0);
        if (cullCrop(first)) {
            pendingCrops.remove(0);
            return true;
        } else {
            return false;
        }
    }
    // Cultivation and collection
    FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
    List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
    Collections.shuffle(farmDirections, world.rand);
    for (FarmDirection farmSide : farmDirections) {
        IFarmLogic logic = getFarmLogic(farmSide);
        // Always try to collect windfall.
        if (collectWindfall()) {
            farmWorkStatus.didWork = true;
        }
        List<FarmTarget> farmTargets = targets.get(farmSide);
        if (stage == Stage.HARVEST) {
            Collection<ICrop> harvested = FarmHelper.harvestTargets(world, farmTargets, logic, Collections.emptySet());
            farmWorkStatus.didWork = !harvested.isEmpty();
            if (!harvested.isEmpty()) {
                pendingCrops.addAll(harvested);
                pendingCrops.sort(FarmHelper.TopDownICropComparator.INSTANCE);
            }
        } else if (stage == Stage.CULTIVATE) {
            farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, farmSide);
        }
        if (farmWorkStatus.didWork) {
            break;
        }
    }
    if (stage == Stage.CULTIVATE) {
        errorLogic.setCondition(!farmWorkStatus.hasFarmland, EnumErrorCode.NO_FARMLAND);
        errorLogic.setCondition(!farmWorkStatus.hasFertilizer, EnumErrorCode.NO_FERTILIZER);
        errorLogic.setCondition(!farmWorkStatus.hasLiquid, EnumErrorCode.NO_LIQUID_FARM);
    }
    // alternate between cultivation and harvest.
    stage = stage.next();
    return false;
}
Also used : FarmWorkStatus(forestry.farming.FarmHelper.FarmWorkStatus) FarmTarget(forestry.farming.FarmTarget) FarmDirection(forestry.api.farming.FarmDirection) IFarmLogic(forestry.api.farming.IFarmLogic) ICrop(forestry.api.farming.ICrop) 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