use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.
the class ItemInventoryHabitatLocator method getErrorStates.
/* IErrorSource */
@Override
public ImmutableSet<IErrorState> getErrorStates() {
if (!getStackInSlot(SLOT_ANALYZED).isEmpty()) {
return ImmutableSet.of();
}
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
if (!BeeManager.beeRoot.isMember(specimen)) {
errorStates.add(EnumErrorCode.NO_SPECIMEN);
}
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
errorStates.add(EnumErrorCode.NO_HONEY);
}
return errorStates.build();
}
use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.
the class ErrorLogic method readData.
@Override
public void readData(PacketBuffer data) {
clearErrors();
short errorStateCount = data.readShort();
for (int i = 0; i < errorStateCount; i++) {
short errorStateId = data.readShort();
IErrorState errorState = ForestryAPI.errorStateRegistry.getErrorState(errorStateId);
if (errorState != null) {
errorStates.add(errorState);
}
}
}
use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.
the class Butterfly method getCanGrow.
@Override
public Set<IErrorState> getCanGrow(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
World world = nursery.getWorldObj();
Set<IErrorState> errorStates = new HashSet<>();
// / And finally climate check
IAlleleButterflySpecies species = genome.getPrimary();
EnumTemperature actualTemperature = nursery.getTemperature();
EnumTemperature baseTemperature = species.getTemperature();
EnumTolerance toleranceTemperature = genome.getToleranceTemp();
EnumHumidity actualHumidity = nursery.getHumidity();
EnumHumidity baseHumidity = species.getHumidity();
EnumTolerance toleranceHumidity = genome.getToleranceHumid();
ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
return errorStates;
}
use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.
the class ItemInventorySolderingIron method getErrorStates.
@Override
public ImmutableSet<IErrorState> getErrorStates() {
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) {
errorStates.add(EnumErrorCode.NO_CIRCUIT_LAYOUT);
}
ItemStack blankCircuitBoard = getStackInSlot(inputCircuitBoardSlot);
if (blankCircuitBoard.isEmpty()) {
errorStates.add(EnumErrorCode.NO_CIRCUIT_BOARD);
} else {
EnumCircuitBoardType type = EnumCircuitBoardType.values()[blankCircuitBoard.getItemDamage()];
int circuitCount = 0;
for (short i = 0; i < type.getSockets(); i++) {
if (!getStackInSlot(ingredientSlot1 + i).isEmpty()) {
circuitCount++;
}
}
if (circuitCount != type.getSockets()) {
errorStates.add(EnumErrorCode.CIRCUIT_MISMATCH);
} else {
int count = getCircuitCount();
if (count != type.getSockets()) {
errorStates.add(EnumErrorCode.NO_CIRCUIT_LAYOUT);
}
}
}
return errorStates.build();
}
use of forestry.api.core.IErrorState 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;
}
Aggregations