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();
}
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();
}
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();
}
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());
}
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);
}
Aggregations