Search in sources :

Example 1 with IErrorState

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) IErrorState(forestry.api.core.IErrorState) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IErrorState

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);
        }
    }
}
Also used : IErrorState(forestry.api.core.IErrorState)

Example 3 with IErrorState

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;
}
Also used : IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies) EnumTemperature(forestry.api.core.EnumTemperature)

Example 4 with IErrorState

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();
}
Also used : EnumCircuitBoardType(forestry.core.circuits.EnumCircuitBoardType) ImmutableSet(com.google.common.collect.ImmutableSet) IErrorState(forestry.api.core.IErrorState) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IErrorState

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;
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) IErrorState(forestry.api.core.IErrorState) IBee(forestry.api.apiculture.IBee) ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic) EnumBeeType(forestry.api.apiculture.EnumBeeType)

Aggregations

IErrorState (forestry.api.core.IErrorState)12 EnumHumidity (forestry.api.core.EnumHumidity)3 EnumTemperature (forestry.api.core.EnumTemperature)3 EnumTolerance (forestry.api.genetics.EnumTolerance)3 HashSet (java.util.HashSet)3 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 IErrorLogic (forestry.api.core.IErrorLogic)2 IErrorLogicSource (forestry.api.core.IErrorLogicSource)2 IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)2 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)2 IGreenhouseBlockHandler (forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler)2 BlockPos (net.minecraft.util.math.BlockPos)2 EnumBeeType (forestry.api.apiculture.EnumBeeType)1 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IBee (forestry.api.apiculture.IBee)1 IBeeHousingInventory (forestry.api.apiculture.IBeeHousingInventory)1 IBeeModifier (forestry.api.apiculture.IBeeModifier)1 IGreenhouseController (forestry.api.multiblock.IGreenhouseController)1