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);
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations