use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileCentrifuge method hasWork.
@Override
public boolean hasWork() {
if (!pendingProducts.isEmpty()) {
return true;
}
checkRecipe();
boolean hasResource = !getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE).isEmpty();
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE);
return hasResource;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileFermenter method hasWork.
@Override
public boolean hasWork() {
checkRecipe();
checkFuel();
int fermented = Math.min(fermentationTime, fuelCurrentFerment);
boolean hasRecipe = currentRecipe != null;
boolean hasFuel = fuelBurnTime > 0;
boolean hasResource = fermentationTime > 0 || !getStackInSlot(InventoryFermenter.SLOT_RESOURCE).isEmpty();
FluidStack drained = resourceTank.drain(fermented, false);
boolean hasFluidResource = drained != null && drained.amount == fermented;
boolean hasFluidSpace = true;
if (hasRecipe) {
int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier);
Fluid output = currentRecipe.getOutput();
FluidStack fluidStack = new FluidStack(output, productAmount);
hasFluidSpace = productTank.fillInternal(fluidStack, false) == fluidStack.amount;
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL);
errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE);
errorLogic.setCondition(!hasFluidResource, EnumErrorCode.NO_RESOURCE_LIQUID);
errorLogic.setCondition(!hasFluidSpace, EnumErrorCode.NO_SPACE_TANK);
return hasRecipe && hasFuel && hasResource && hasFluidResource && hasFluidSpace;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileMoistener method rotateWorkingSlot.
private boolean rotateWorkingSlot() {
IErrorLogic errorLogic = getErrorLogic();
// Put working slot contents into inventory if space is available
if (!getStackInSlot(InventoryMoistener.SLOT_WORKING).isEmpty()) {
// Get the result of the consumed item in the working slot
ItemStack deposit;
if (FuelManager.moistenerResource.containsKey(getStackInSlot(InventoryMoistener.SLOT_WORKING))) {
MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(InventoryMoistener.SLOT_WORKING));
deposit = res.getProduct().copy();
} else {
deposit = getStackInSlot(InventoryMoistener.SLOT_WORKING).copy();
}
int targetSlot = getFreeReservoirSlot(deposit);
// We stop the whole thing, if we don't have any room anymore.
if (errorLogic.setCondition(targetSlot < 0, EnumErrorCode.NO_SPACE_INVENTORY)) {
return false;
}
if (getStackInSlot(targetSlot).isEmpty()) {
setInventorySlotContents(targetSlot, deposit);
} else {
getStackInSlot(targetSlot).grow(1);
}
decrStackSize(InventoryMoistener.SLOT_WORKING, 1);
}
if (!getStackInSlot(InventoryMoistener.SLOT_WORKING).isEmpty()) {
return true;
}
// Let's look for a new resource to put into the working slot.
int resourceSlot = getNextResourceSlot(InventoryMoistener.SLOT_RESERVOIR_1, InventoryMoistener.SLOT_RESERVOIR_1 + InventoryMoistener.SLOT_RESERVOIR_COUNT);
// Nothing found, stop.
if (errorLogic.setCondition(resourceSlot < 0, EnumErrorCode.NO_RESOURCE)) {
return false;
}
setInventorySlotContents(InventoryMoistener.SLOT_WORKING, decrStackSize(resourceSlot, 1));
return true;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileBottler method hasWork.
@Override
public boolean hasWork() {
FluidHelper.FillStatus emptyStatus;
FluidHelper.FillStatus fillStatus;
IErrorLogic errorLogic = getErrorLogic();
errorLogic.clearErrors();
checkEmptyRecipe();
if (currentRecipe != null) {
IFluidTankProperties properties = tankManager.getTankProperties()[0];
if (properties != null) {
emptyStatus = FluidHelper.drainContainers(tankManager, this, InventoryBottler.SLOT_EMPTYING_PROCESSING, InventoryBottler.SLOT_OUTPUT_EMPTY_CONTAINER, false);
} else {
emptyStatus = FillStatus.SUCCESS;
}
} else {
emptyStatus = null;
}
if (emptyStatus == null || emptyStatus != FillStatus.SUCCESS) {
checkFillRecipe();
if (currentRecipe == null) {
return false;
} else {
fillStatus = FluidHelper.fillContainers(tankManager, this, InventoryBottler.SLOT_FILLING_PROCESSING, InventoryBottler.SLOT_OUTPUT_FULL_CONTAINER, currentRecipe.fluid.getFluid(), false);
}
} else {
return true;
}
if (fillStatus == FillStatus.SUCCESS) {
return true;
}
errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_FLUID, EnumErrorCode.NO_RESOURCE_LIQUID);
errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_SPACE, EnumErrorCode.NO_SPACE_INVENTORY);
errorLogic.setCondition(emptyStatus == FluidHelper.FillStatus.NO_SPACE_FLUID, EnumErrorCode.NO_SPACE_TANK);
if (emptyStatus == FillStatus.INVALID_INPUT || fillStatus == FillStatus.INVALID_INPUT || errorLogic.hasErrors()) {
currentRecipe = null;
return false;
}
return true;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileTrader method updateServerSide.
/* UPDATING */
/**
* The trade station should show errors for missing stamps and paper first.
* Once it is able to send letters, it should display other error states.
*/
@Override
public void updateServerSide() {
if (!isLinked() || !updateOnInterval(10)) {
return;
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasPostageMin(3), EnumErrorCode.NO_STAMPS);
errorLogic.setCondition(!hasPaperMin(2), EnumErrorCode.NO_PAPER);
IInventory inventory = getInternalInventory();
ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD);
errorLogic.setCondition(tradeGood.isEmpty(), EnumErrorCode.NO_TRADE);
boolean hasRequest = hasItemCount(TradeStation.SLOT_EXCHANGE_1, TradeStation.SLOT_EXCHANGE_COUNT, ItemStack.EMPTY, 1);
errorLogic.setCondition(!hasRequest, EnumErrorCode.NO_TRADE);
if (!tradeGood.isEmpty()) {
boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.getCount());
errorLogic.setCondition(!hasSupplies, EnumErrorCode.NO_SUPPLIES);
}
if (inventory instanceof TradeStation && updateOnInterval(200)) {
boolean canReceivePayment = ((TradeStation) inventory).canReceivePayment();
errorLogic.setCondition(!canReceivePayment, EnumErrorCode.NO_SPACE_INVENTORY);
}
}
Aggregations