Search in sources :

Example 1 with MachineUtil

use of binnie.core.machines.MachineUtil in project Binnie by ForestryMC.

the class LumbermillLogic method canWork.

@Override
public ErrorState canWork() {
    MachineUtil util = getUtil();
    ItemStack logStack = util.getStack(LumbermillMachine.SLOT_LOG);
    if (logStack.isEmpty()) {
        return new ErrorState(ExtraTreesErrorCode.LUMBERMILL_NO_WOOD, LumbermillMachine.SLOT_LOG);
    }
    ItemStack plankResult = LumbermillRecipeManager.getPlankProduct(logStack, util.getWorld());
    if (!util.isSlotEmpty(LumbermillMachine.SLOT_PLANKS) && !plankResult.isEmpty()) {
        final ItemStack currentPlank = util.getStack(LumbermillMachine.SLOT_PLANKS);
        if (!plankResult.isItemEqual(currentPlank) || plankResult.getCount() + currentPlank.getCount() > currentPlank.getMaxStackSize()) {
            return new ErrorState(ExtraTreesErrorCode.LUMBERMILL_NO_SPACE_PLANKS, new int[] { LumbermillMachine.SLOT_PLANKS });
        }
    }
    if (!util.isSlotEmpty(LumbermillMachine.SLOT_BARK)) {
        ItemStack itemStack = util.getStack(LumbermillMachine.SLOT_BARK);
        if (itemStack.getCount() + 2 > itemStack.getMaxStackSize()) {
            return new ErrorState(ExtraTreesErrorCode.LUMBERMILL_NO_SPACE_BARK, new int[] { LumbermillMachine.SLOT_BARK });
        }
    }
    if (!util.isSlotEmpty(LumbermillMachine.SLOT_SAWDUST)) {
        ItemStack itemStack = util.getStack(LumbermillMachine.SLOT_SAWDUST);
        if (itemStack.getCount() + 2 > itemStack.getMaxStackSize()) {
            return new ErrorState(ExtraTreesErrorCode.LUMBERMILL_NO_SPACE_SAW_DUST, new int[] { LumbermillMachine.SLOT_SAWDUST });
        }
    }
    return super.canWork();
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) ErrorState(binnie.core.machines.errors.ErrorState) ItemStack(net.minecraft.item.ItemStack)

Example 2 with MachineUtil

use of binnie.core.machines.MachineUtil in project Binnie by ForestryMC.

the class GenepoolLogic method canProgress.

@Override
public ErrorState canProgress() {
    MachineUtil util = getUtil();
    ItemStack individual = util.getStack(Genepool.SLOT_BEE);
    if (!util.spaceInTank(Genepool.TANK_DNA, getDNAAmount(individual))) {
        return new ErrorState(CoreErrorCode.NO_SPACE_TANK, new int[] { Genepool.SLOT_BEE });
    }
    if (!util.liquidInTank(Genepool.TANK_ETHANOL, 1)) {
        return new ErrorState(GeneticsErrorCode.GENEPOOL_INSUFFICIENT_ETHANOL, Genepool.TANK_ETHANOL);
    }
    if (util.getSlotCharge(Genepool.SLOT_ENZYME) == 0.0f) {
        return new ErrorState(GeneticsErrorCode.GENEPOOL_INSUFFICIENT_ENZYME, Genepool.SLOT_ENZYME);
    }
    return super.canProgress();
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) ErrorState(binnie.core.machines.errors.ErrorState) ItemStack(net.minecraft.item.ItemStack)

Example 3 with MachineUtil

use of binnie.core.machines.MachineUtil 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 4 with MachineUtil

use of binnie.core.machines.MachineUtil in project Binnie by ForestryMC.

the class PackageInoculator method createMachine.

@Override
public void createMachine(final Machine machine) {
    new ComponentGeneticGUI(machine, GeneticsGUI.INOCULATOR);
    final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    InventorySlot slotSerumVial = inventory.addSlot(Inoculator.SLOT_SERUM_VIAL, getSlotRL("serum.active"));
    slotSerumVial.forbidInteraction();
    slotSerumVial.setReadOnly();
    final SlotValidator serumValid = new SerumSlotValidator();
    slotSerumVial.setValidator(serumValid);
    for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_SERUM_RESERVE, getSlotRL("serum.input"))) {
        slot.setValidator(serumValid);
        slot.forbidExtraction();
    }
    for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_SERUM_EXPENDED, getSlotRL("serum.output"))) {
        slot.setValidator(serumValid);
        slot.setReadOnly();
    }
    for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_RESERVE, getSlotRL("input"))) {
        slot.forbidExtraction();
        slot.setValidator(new ValidatorIndividualInoculate());
    }
    InventorySlot slotTarget = inventory.addSlot(Inoculator.SLOT_TARGET, getSlotRL("process"));
    slotTarget.setValidator(new ValidatorIndividualInoculate());
    slotTarget.setReadOnly();
    slotTarget.forbidInteraction();
    for (final InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_FINISHED, getSlotRL("output"))) {
        slot.setReadOnly();
        slot.forbidInsertion();
        slot.setValidator(new ValidatorIndividualInoculate());
    }
    final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
    transfer.addRestock(Inoculator.SLOT_RESERVE, 9, 1);
    transfer.addRestock(Inoculator.SLOT_SERUM_RESERVE, 0);
    transfer.addStorage(Inoculator.SLOT_SERUM_VIAL, Inoculator.SLOT_SERUM_EXPENDED, (stack) -> Engineering.getCharges(stack) == 0);
    transfer.addStorage(Inoculator.SLOT_TARGET, Inoculator.SLOT_FINISHED, (stack) -> {
        if (!stack.isEmpty()) {
            IMachine machine1 = transfer.getMachine();
            MachineUtil machineUtil = machine1.getMachineUtil();
            if (!machineUtil.getStack(Inoculator.SLOT_SERUM_VIAL).isEmpty() && machine1.getInterface(InoculatorLogic.class).isValidSerum() != null) {
                return true;
            }
        }
        return false;
    });
    new ComponentPowerReceptor(machine, 15000);
    new InoculatorLogic(machine);
    new InoculatorFX(machine);
    new ComponentTankContainer(machine).addTank(Inoculator.TANK_VEKTOR, "input", 1000).setValidator(new BacteriaVectorTankValidator());
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IMachine(binnie.core.machines.IMachine) ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) InventorySlot(binnie.core.machines.inventory.InventorySlot) ComponentGeneticGUI(binnie.genetics.machine.ComponentGeneticGUI) ComponentInventoryTransfer(binnie.core.machines.inventory.ComponentInventoryTransfer) ComponentTankContainer(binnie.core.machines.inventory.ComponentTankContainer) SlotValidator(binnie.core.machines.inventory.SlotValidator) ComponentPowerReceptor(binnie.core.machines.power.ComponentPowerReceptor)

Example 5 with MachineUtil

use of binnie.core.machines.MachineUtil in project Binnie by ForestryMC.

the class IsolatorLogic method onFinishTask.

@Override
protected void onFinishTask() {
    super.onFinishTask();
    final Random rand = this.getMachine().getWorld().rand;
    MachineUtil util = this.getUtil();
    final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(util.getStack(Isolator.SLOT_TARGET));
    if (root == null) {
        return;
    }
    final IIndividual individual = root.getMember(util.getStack(Isolator.SLOT_TARGET));
    if (individual == null) {
        return;
    }
    IChromosomeType[] karyotype = root.getKaryotype();
    IChromosomeType chromosome = karyotype[rand.nextInt(karyotype.length)];
    IGenome genome = individual.getGenome();
    IAllele allele = rand.nextBoolean() ? genome.getActiveAllele(chromosome) : genome.getInactiveAllele(chromosome);
    Gene gene = Gene.create(allele, chromosome, root);
    final ItemStack serum = ItemSequence.create(gene);
    util.setStack(Isolator.SLOT_RESULUT, serum);
    util.decreaseStack(Isolator.SLOT_SEQUENCER_VIAL, 1);
    if (rand.nextFloat() < TARGET_LOSS_CHANCE) {
        util.decreaseStack(Isolator.SLOT_TARGET, 1);
    }
    util.drainTank(Isolator.TANK_ETHANOL, ETHANOL_PER_PROCESS);
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MachineUtil (binnie.core.machines.MachineUtil)12 ItemStack (net.minecraft.item.ItemStack)9 IMachine (binnie.core.machines.IMachine)3 ErrorState (binnie.core.machines.errors.ErrorState)3 ComponentInventorySlots (binnie.core.machines.inventory.ComponentInventorySlots)2 ComponentInventoryTransfer (binnie.core.machines.inventory.ComponentInventoryTransfer)2 InventorySlot (binnie.core.machines.inventory.InventorySlot)2 SlotValidator (binnie.core.machines.inventory.SlotValidator)2 ComponentPowerReceptor (binnie.core.machines.power.ComponentPowerReceptor)2 ComponentGeneticGUI (binnie.genetics.machine.ComponentGeneticGUI)2 Random (java.util.Random)2 Gene (binnie.core.genetics.Gene)1 ComponentTankContainer (binnie.core.machines.inventory.ComponentTankContainer)1 IChargedSlots (binnie.core.machines.inventory.IChargedSlots)1 IAllele (forestry.api.genetics.IAllele)1 IChromosomeType (forestry.api.genetics.IChromosomeType)1 IGenome (forestry.api.genetics.IGenome)1 IIndividual (forestry.api.genetics.IIndividual)1 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 ArrayList (java.util.ArrayList)1