Search in sources :

Example 6 with ErrorState

use of binnie.core.machines.errors.ErrorState in project Binnie by ForestryMC.

the class ContainerCraftGUI method createErrorNBT.

private NBTTagCompound createErrorNBT(final IErrorStateSource error) {
    final NBTTagCompound nbt = new NBTTagCompound();
    ErrorState state = null;
    if (error.canWork() != null) {
        nbt.setByte("type", (byte) 0);
        state = error.canWork();
    } else if (error.canProgress() != null) {
        nbt.setByte("type", (byte) 1);
        state = error.canProgress();
    }
    if (state != null) {
        state.writeToNBT(nbt);
    }
    return nbt;
}
Also used : ErrorState(binnie.core.machines.errors.ErrorState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 7 with ErrorState

use of binnie.core.machines.errors.ErrorState in project Binnie by ForestryMC.

the class DistilleryLogic method canProgress.

@Override
public ErrorState canProgress() {
    if (this.currentFluid == null) {
        return new ErrorState(CoreErrorCode.TANK_EMPTY);
    }
    final MachineUtil util = this.getUtil();
    FluidStack fluidInOutputTank = util.getFluid(DistilleryMachine.TANK_OUTPUT);
    if (fluidInOutputTank != null) {
        FluidStack inputFluid = util.getFluid(DistilleryMachine.TANK_INPUT);
        FluidStack recipeOutput = DistilleryRecipeManager.getOutput(inputFluid, this.level);
        if (recipeOutput != null) {
            if (!recipeOutput.isFluidEqual(fluidInOutputTank)) {
                return new ErrorState(CoreErrorCode.TANK_DIFFRENT_FLUID, DistilleryMachine.TANK_OUTPUT);
            } else if (!util.spaceInTank(DistilleryMachine.TANK_OUTPUT, recipeOutput.amount)) {
                return new ErrorState(CoreErrorCode.NO_SPACE_TANK, DistilleryMachine.TANK_OUTPUT);
            }
        }
    }
    return super.canProgress();
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) FluidStack(net.minecraftforge.fluids.FluidStack) ErrorState(binnie.core.machines.errors.ErrorState)

Example 8 with ErrorState

use of binnie.core.machines.errors.ErrorState in project Binnie by ForestryMC.

the class InoculatorLogic method isValidSerum.

@Nullable
public ErrorState isValidSerum() {
    final ItemStack serum = this.getUtil().getStack(Inoculator.SLOT_SERUM_VIAL);
    final ItemStack target = this.getUtil().getStack(Inoculator.SLOT_TARGET);
    final IGene[] genes = Engineering.getGenes(serum);
    if (genes.length == 0) {
        return new ErrorState(GeneticsErrorCode.INVALID_SERUM_NO);
    }
    if (!genes[0].getSpeciesRoot().isMember(target)) {
        return new ErrorState(GeneticsErrorCode.INVALID_SERUM_MISMATCH);
    }
    final IIndividual individual = genes[0].getSpeciesRoot().getMember(target);
    if (individual != null) {
        final IGenome genome = individual.getGenome();
        for (final IGene gene : genes) {
            final IAllele a = genome.getActiveAllele(gene.getChromosome());
            final IAllele b = genome.getInactiveAllele(gene.getChromosome());
            if (!a.getUID().equals(gene.getAllele().getUID()) || !b.getUID().equals(gene.getAllele().getUID())) {
                return null;
            }
        }
    }
    return new ErrorState(GeneticsErrorCode.DEFUNCT_SERUM);
}
Also used : IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) IIndividual(forestry.api.genetics.IIndividual) ErrorState(binnie.core.machines.errors.ErrorState) IGene(binnie.core.api.genetics.IGene) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 9 with ErrorState

use of binnie.core.machines.errors.ErrorState in project Binnie by ForestryMC.

the class SplicerLogic method canWork.

@Override
public ErrorState canWork() {
    if (this.getUtil().isSlotEmpty(Splicer.SLOT_TARGET)) {
        return new ErrorState(GeneticsErrorCode.NO_INDIVIDUAL, Splicer.SLOT_TARGET);
    }
    ItemStack serum = this.getUtil().getStack(Splicer.SLOT_SERUM_VIAL);
    if (serum.isEmpty()) {
        return new ErrorState(GeneticsErrorCode.NO_SERUM, Splicer.SLOT_SERUM_VIAL);
    }
    final ErrorState state = this.isValidSerum();
    if (state != null) {
        return state;
    }
    if (Engineering.getCharges(serum) == 0) {
        return new ErrorState(GeneticsErrorCode.EMPTY_SERUM);
    }
    return super.canWork();
}
Also used : ErrorState(binnie.core.machines.errors.ErrorState) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ErrorState (binnie.core.machines.errors.ErrorState)9 ItemStack (net.minecraft.item.ItemStack)6 MachineUtil (binnie.core.machines.MachineUtil)3 IGene (binnie.core.api.genetics.IGene)2 IAllele (forestry.api.genetics.IAllele)2 IIndividual (forestry.api.genetics.IIndividual)2 Nullable (javax.annotation.Nullable)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 IGenome (forestry.api.genetics.IGenome)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1