use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class BeekeepingLogic method canWork.
/* UPDATING */
@Override
public boolean canWork() {
IErrorLogic errorLogic = housing.getErrorLogic();
errorLogic.clearErrors();
IBeeHousingInventory beeInventory = housing.getBeeInventory();
boolean hasSpace = addPendingProducts(beeInventory, spawn);
errorLogic.setCondition(!hasSpace, EnumErrorCode.NO_SPACE_INVENTORY);
ItemStack queenStack = beeInventory.getQueen();
EnumBeeType beeType = BeeManager.beeRoot.getType(queenStack);
// check if we're breeding
if (beeType == EnumBeeType.PRINCESS) {
boolean hasDrone = BeeManager.beeRoot.isDrone(beeInventory.getDrone());
errorLogic.setCondition(!hasDrone, EnumErrorCode.NO_DRONE);
// not active (no bee FX) when we are breeding
setActive(false);
return !errorLogic.hasErrors();
}
if (beeType == EnumBeeType.QUEEN) {
if (!isQueenAlive(queenStack)) {
IBee dyingQueen = BeeManager.beeRoot.getMember(queenStack);
Collection<ItemStack> spawned = killQueen(dyingQueen, housing, beeListener);
spawn.addAll(spawned);
queenStack = ItemStack.EMPTY;
}
} else {
queenStack = ItemStack.EMPTY;
}
if (this.queenStack != queenStack) {
if (!queenStack.isEmpty()) {
this.queen = BeeManager.beeRoot.getMember(queenStack);
if (this.queen != null) {
hasFlowersCache.onNewQueen(queen, housing);
}
} else {
this.queen = null;
}
this.queenStack = queenStack;
queenCanWorkCache.clear();
}
if (errorLogic.setCondition(queen == null, EnumErrorCode.NO_QUEEN)) {
setActive(false);
beeProgress = 0;
return false;
}
Set<IErrorState> queenErrors = queenCanWorkCache.queenCanWork(queen, housing);
for (IErrorState errorState : queenErrors) {
errorLogic.setCondition(true, errorState);
}
hasFlowersCache.update(queen, housing);
boolean hasFlowers = hasFlowersCache.hasFlowers();
boolean flowerCacheNeedsSync = hasFlowersCache.needsSync();
errorLogic.setCondition(!hasFlowers, EnumErrorCode.NO_FLOWER);
boolean canWork = !errorLogic.hasErrors();
if (active != canWork) {
setActive(canWork);
} else if (flowerCacheNeedsSync) {
syncToClient();
}
return canWork;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TilePowered method updateServerSide.
@Override
protected void updateServerSide() {
super.updateServerSide();
if (!updateOnInterval(WORK_TICK_INTERVAL)) {
return;
}
IErrorLogic errorLogic = getErrorLogic();
boolean disabled = isRedstoneActivated();
errorLogic.setCondition(disabled, EnumErrorCode.DISABLED_BY_REDSTONE);
if (disabled) {
return;
}
if (!hasWork()) {
return;
}
int ticksPerWorkCycle = getTicksPerWorkCycle();
if (workCounter < ticksPerWorkCycle) {
int energyPerWorkCycle = getEnergyPerWorkCycle();
boolean consumedEnergy = EnergyHelper.consumeEnergyToDoWork(energyManager, ticksPerWorkCycle, energyPerWorkCycle);
if (consumedEnergy) {
errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
workCounter++;
noPowerTime = 0;
} else {
noPowerTime++;
if (noPowerTime > 4) {
errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
}
}
}
if (workCounter >= ticksPerWorkCycle) {
if (workCycle()) {
workCounter = 0;
}
}
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class ClimateSourceClimatiser method canWork.
@Override
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
IClimateHousing region = container.getParent();
if (region instanceof IGreenhouseControllerInternal) {
IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
IErrorLogic errorLogic = owner.getErrorLogic();
EnergyManager energyManager = controller.getEnergyManager();
if (energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), true) > 0) {
owner.setActive(true);
errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
return true;
} else {
owner.setActive(false);
errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
return false;
}
}
if (owner.isActive()) {
owner.setActive(false);
}
return false;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class ClimateSourceHygroregulator method canWork.
@Override
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
createRecipe();
FilteredTank liquidTank = owner.getLiquidTank();
IErrorLogic errorLogic = owner.getErrorLogic();
if (currentRecipe != null && liquidTank.drainInternal(currentRecipe.liquid.amount, false) != null) {
errorLogic.setCondition(false, EnumErrorCode.NO_RESOURCE_LIQUID);
return true;
}
errorLogic.setCondition(true, EnumErrorCode.NO_RESOURCE_LIQUID);
return false;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileFabricator method hasWork.
@Override
public boolean hasWork() {
boolean hasRecipe = true;
boolean hasLiquidResources = true;
boolean hasResources = true;
ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
if (!recipePair.isEmpty()) {
IFabricatorRecipe recipe = recipePair.getRecipe();
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
hasResources = removeFromInventory(crafting, recipePair, false);
FluidStack toDrain = recipe.getLiquid();
FluidStack drained = moltenTank.drainInternal(toDrain, false);
hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
} else {
hasRecipe = false;
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID);
errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE_INVENTORY);
return hasRecipe;
}
Aggregations