use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TilePlanter method cullCrop.
private boolean cullCrop(ICrop crop) {
final int fertilizerConsumption = Math.round(logic.getFertilizerConsumption() * Config.fertilizerModifier * 2);
IErrorLogic errorLogic = getErrorLogic();
// Check fertilizer
Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption);
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
return false;
}
// Check water
float hydrationModifier = hydrationManager.getHydrationModifier();
int waterConsumption = logic.getWaterConsumption(hydrationModifier);
FluidStack requiredLiquid = new FluidStack(FluidRegistry.WATER, waterConsumption);
boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid);
if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_LIQUID_FARM)) {
return false;
}
NonNullList<ItemStack> harvested = crop.harvest();
if (harvested != null) {
// Remove fertilizer and water
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
removeLiquid(requiredLiquid);
inventory.stowHarvest(harvested, pendingProduce);
}
return true;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileTrader method setAddress.
private void setAddress(IMailAddress address) {
Preconditions.checkNotNull(address, "address must not be null");
if (this.address.isValid() && this.address.equals(address)) {
return;
}
if (!world.isRemote) {
IErrorLogic errorLogic = getErrorLogic();
boolean hasValidTradeAddress = PostManager.postRegistry.isValidTradeAddress(world, address);
errorLogic.setCondition(!hasValidTradeAddress, EnumErrorCode.NOT_ALPHANUMERIC);
boolean hasUniqueTradeAddress = PostManager.postRegistry.isAvailableTradeAddress(world, address);
errorLogic.setCondition(!hasUniqueTradeAddress, EnumErrorCode.NOT_UNIQUE);
if (hasValidTradeAddress & hasUniqueTradeAddress) {
this.address = address;
PostManager.postRegistry.getOrCreateTradeStation(world, getOwnerHandler().getOwner(), address);
}
} else {
this.address = address;
}
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class TileEngineElectric method updateServerSide.
// / WORK
@Override
public void updateServerSide() {
IErrorLogic errorLogic = getErrorLogic();
// No work to be done if IC2 is unavailable.
if (errorLogic.setCondition(ic2EnergySink == null, EnumErrorCode.NO_ENERGY_NET)) {
return;
}
ic2EnergySink.update();
super.updateServerSide();
if (forceCooldown) {
return;
}
if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) {
replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY);
}
// Updating of gui delayed to prevent it from going crazy
if (!updateOnInterval(80)) {
return;
}
boolean canUseEnergy = ic2EnergySink.canUseEnergy(euConfig.euForCycle);
errorLogic.setCondition(!canUseEnergy, EnumErrorCode.NO_FUEL);
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class FarmController method cullCrop.
private boolean cullCrop(ICrop crop, IFarmLogic provider) {
// Let event handlers handle the harvest first.
for (IFarmListener listener : farmListeners) {
if (listener.beforeCropHarvest(crop)) {
return true;
}
}
final int fertilizerConsumption = Math.round(provider.getFertilizerConsumption() * Config.fertilizerModifier);
IErrorLogic errorLogic = getErrorLogic();
// Check fertilizer
Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption);
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
return false;
}
// Check water
float hydrationModifier = hydrationManager.getHydrationModifier();
int waterConsumption = provider.getWaterConsumption(hydrationModifier);
FluidStack requiredLiquid = new FluidStack(FluidRegistry.WATER, waterConsumption);
boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid);
if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_LIQUID_FARM)) {
return false;
}
NonNullList<ItemStack> harvested = crop.harvest();
if (harvested != null) {
// Remove fertilizer and water
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
removeLiquid(requiredLiquid);
// Let event handlers handle the harvest first.
for (IFarmListener listener : farmListeners) {
listener.afterCropHarvest(harvested, crop);
}
inventory.stowHarvest(harvested, pendingProduce);
}
return true;
}
use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.
the class FarmController method doWork.
@Override
public boolean doWork() {
farmWorkTicks++;
if (targets.isEmpty() || farmWorkTicks % 20 == 0) {
setUpFarmlandTargets();
}
IErrorLogic errorLogic = getErrorLogic();
if (!pendingProduce.isEmpty()) {
boolean added = inventory.tryAddPendingProduce(pendingProduce);
errorLogic.setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY);
return added;
}
boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
return false;
}
// Cull queued crops.
if (!pendingCrops.isEmpty() && harvestProvider != null) {
ICrop first = pendingCrops.get(0);
if (cullCrop(first, harvestProvider)) {
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(logic)) {
farmWorkStatus.didWork = true;
}
List<FarmTarget> farmTargets = targets.get(farmSide);
if (stage == Stage.HARVEST) {
Collection<ICrop> harvested = FarmHelper.harvestTargets(world, farmTargets, logic, farmListeners);
farmWorkStatus.didWork = !harvested.isEmpty();
if (!harvested.isEmpty()) {
pendingCrops.addAll(harvested);
pendingCrops.sort(FarmHelper.TopDownICropComparator.INSTANCE);
harvestProvider = logic;
}
} else if (stage == Stage.CULTIVATE) {
farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic, 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 farmWorkStatus.didWork;
}
Aggregations