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