Fixed inoculator don't need Bacteria Vector to process
Some refactored Inoculator machine class
This commit is contained in:
Alexander Kornilov authored and marcin212 committed 2017-05-09 21:58:47 +02:00
1 parent c3d0da2d0a
commit 5052920d73
5 files changed
+103 -99

No files matched your search

@@ -41,13 +41,13 @@ public class WindowInoculator extends WindowMachine {
int x = 16;
int y = 32;
new ControlLiquidTank(this, x, y + 18 + 16).setTankID(0);
CraftGUIUtil.horizontalGrid(x, y, new ControlSlotArray(this, 0, 0, 2, 1).create(Inoculator.slotSerumReserve), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSlot(this, 0.0f, 0.0f).assign(0), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSlotArray(this, 0, 0, 2, 1).create(Inoculator.slotSerumExpended));
CraftGUIUtil.horizontalGrid(x, y, new ControlSlotArray(this, 0, 0, 2, 1).create(Inoculator.SLOT_SERUM_RESERVE), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSlot(this, 0.0f, 0.0f).assign(0), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSlotArray(this, 0, 0, 2, 1).create(Inoculator.SLOT_SERUM_EXPENDED));
x += 18;
new ControlMachineProgress(this, x, y + 24, WindowInoculator.ProgressBase, WindowInoculator.Progress, Position.Left);
new ControlEnergyBar(this, 91, 118, 60, 16, Position.Left);
new ControlErrorState(this, 161.0f, 118.0f);
x += 142;
CraftGUIUtil.verticalGrid(x, y, TextJustification.MiddleLeft, 8.0f, new ControlSlotArray(this, x, y, 4, 1).create(Inoculator.slotReserve), new ControlSlot(this, x, y + 18 + 8).assign(9), new ControlSlotArray(this, x, y + 18 + 8 + 18 + 8, 4, 1).create(Inoculator.slotFinished));
CraftGUIUtil.verticalGrid(x, y, TextJustification.MiddleLeft, 8.0f, new ControlSlotArray(this, x, y, 4, 1).create(Inoculator.SLOT_RESERVE), new ControlSlot(this, x, y + 18 + 8).assign(9), new ControlSlotArray(this, x, y + 18 + 8 + 18 + 8, 4, 1).create(Inoculator.SLOT_FINISHED));
new ControlIconDisplay(this, x + 18, y + 18 + 2, GUIIcon.ArrowUpLeft.getIcon());
new ControlIconDisplay(this, x + 18, y + 18 + 18, GUIIcon.ArrowLeftDown.getIcon());
new ControlPlayerInventory(this);
@@ -53,7 +53,7 @@ public class WindowSequencer extends WindowMachine {
setTitle("Sequencer");
int x = 16;
int y = 32;
CraftGUIUtil.horizontalGrid(x, y, TextJustification.MiddleCenter, 2.0f, new ControlSlotArray(this, 0, 0, 2, 2).create(Sequencer.slotReserve), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSequencerProgress(this, 0, 0), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSlot(this, 0.0f, 0.0f).assign(6));
CraftGUIUtil.horizontalGrid(x, y, TextJustification.MiddleCenter, 2.0f, new ControlSlotArray(this, 0, 0, 2, 2).create(Sequencer.SLOT_RESERVE), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSequencerProgress(this, 0, 0), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowRight.getIcon()), new ControlSlot(this, 0.0f, 0.0f).assign(6));
ControlSlot slotTarget = new ControlSlot(this, x + 96, y + 16);
slotTarget.assign(5);
x = 34;
@@ -44,7 +44,7 @@ public class WindowSplicer extends WindowMachine {
new ControlIconDisplay(this, x + 12 + 36 + 4, 86.0f, GUIIcon.ArrowUpLeft.getIcon());
new ControlEnergyBar(this, 196, 64, 60, 16, Position.Left);
new ControlErrorState(this, 218.0f, 86.0f);
CraftGUIUtil.verticalGrid((w() - 72.0f) / 2.0f, 32.0f, TextJustification.MiddleCenter, 4.0f, new ControlSlotArray(this, 0, 0, 4, 1).create(Inoculator.slotReserve), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowDown.getIcon()), new ControlSlot(this, 0.0f, 0.0f).assign(9), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowDown.getIcon()), new ControlSlotArray(this, 0, 0, 4, 1).create(Inoculator.slotFinished));
CraftGUIUtil.verticalGrid((w() - 72.0f) / 2.0f, 32.0f, TextJustification.MiddleCenter, 4.0f, new ControlSlotArray(this, 0, 0, 4, 1).create(Inoculator.SLOT_RESERVE), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowDown.getIcon()), new ControlSlot(this, 0.0f, 0.0f).assign(9), new ControlIconDisplay(this, 0.0f, 0.0f, GUIIcon.ArrowDown.getIcon()), new ControlSlotArray(this, 0, 0, 4, 1).create(Inoculator.SLOT_FINISHED));
new ControlPlayerInventory(this);
}
@@ -38,7 +38,6 @@ import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -50,20 +49,14 @@ import org.lwjgl.opengl.GL11;
import java.util.Random;
public class Inoculator {
public static int slotSerumVial = 0;
public static int[] slotSerumReserve;
public static int[] slotSerumExpended;
public static int[] slotReserve;
public static int slotTarget = 9;
public static int[] slotFinished;
public static int tankVector = 0;
static {
slotSerumReserve = new int[]{1, 2};
slotSerumExpended = new int[]{3, 4};
slotReserve = new int[]{5, 6, 7, 8};
slotFinished = new int[]{10, 11, 12, 13};
}
public static final int SLOT_SERUM_VIAL = 0;
public static final int[] SLOT_SERUM_RESERVE = new int[]{1, 2};
public static final int[] SLOT_SERUM_EXPENDED = new int[]{3, 4};
public static final int[] SLOT_RESERVE = new int[]{5, 6, 7, 8};
public static final int SLOT_TARGET = 9;
public static final int[] SLOT_FINISHED = new int[]{10, 11, 12, 13};
public static final int TANK_VECTOR = 0;
public static final int TANK_CAPACITY = 1000;
public static void setGene(IGene gene, ItemStack target, int chromoN) {
int chromosomeID = gene.getChromosome().ordinal();
@@ -86,16 +79,17 @@ public class Inoculator {
public static class PackageInoculator extends GeneticMachine.PackageGeneticBase implements IMachineInformation {
public PackageInoculator() {
super("inoculator", GeneticsTexture.Inoculator, 14819893, true);
super("inoculator", GeneticsTexture.Inoculator, 0xe22235, true);
}
@Override
public void createMachine(Machine machine) {
new ComponentGeneticGUI(machine, GeneticsGUI.Inoculator);
ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
inventory.addSlot(0, "serum.active");
inventory.getSlot(0).forbidInteraction();
inventory.getSlot(0).setReadOnly();
InventorySlot slotSerumVial = inventory.addSlot(SLOT_SERUM_VIAL, "serum.active");
slotSerumVial.forbidInteraction();
slotSerumVial.setReadOnly();
SlotValidator serumValid = new SlotValidator(ModuleMachine.IconSerum) {
@Override
public boolean isValid(ItemStack itemStack) {
@@ -108,51 +102,52 @@ public class Inoculator {
}
};
inventory.getSlot(0).setValidator(serumValid);
inventory.addSlotArray(Inoculator.slotSerumReserve, "serum.input");
for (InventorySlot slot : inventory.getSlots(Inoculator.slotSerumReserve)) {
slotSerumVial.setValidator(serumValid);
inventory.addSlotArray(SLOT_SERUM_RESERVE, "serum.input");
for (InventorySlot slot : inventory.getSlots(SLOT_SERUM_RESERVE)) {
slot.setValidator(serumValid);
slot.forbidExtraction();
}
inventory.addSlotArray(Inoculator.slotSerumExpended, "serum.output");
for (InventorySlot slot : inventory.getSlots(Inoculator.slotSerumExpended)) {
inventory.addSlotArray(SLOT_SERUM_EXPENDED, "serum.output");
for (InventorySlot slot : inventory.getSlots(SLOT_SERUM_EXPENDED)) {
slot.setValidator(serumValid);
slot.setReadOnly();
}
inventory.addSlotArray(Inoculator.slotReserve, "input");
for (InventorySlot slot : inventory.getSlots(Inoculator.slotReserve)) {
inventory.addSlotArray(SLOT_RESERVE, "input");
for (InventorySlot slot : inventory.getSlots(SLOT_RESERVE)) {
slot.forbidExtraction();
slot.setValidator(new ValidatorIndividualInoculate());
}
inventory.addSlot(9, "process");
inventory.getSlot(9).setValidator(new ValidatorIndividualInoculate());
inventory.getSlot(9).setReadOnly();
inventory.getSlot(9).forbidInteraction();
inventory.addSlotArray(Inoculator.slotFinished, "output");
for (InventorySlot slot : inventory.getSlots(Inoculator.slotFinished)) {
inventory.addSlot(SLOT_TARGET, "process");
inventory.getSlot(SLOT_TARGET).setValidator(new ValidatorIndividualInoculate());
inventory.getSlot(SLOT_TARGET).setReadOnly();
inventory.getSlot(SLOT_TARGET).forbidInteraction();
inventory.addSlotArray(SLOT_FINISHED, "output");
for (InventorySlot slot : inventory.getSlots(SLOT_FINISHED)) {
slot.setReadOnly();
slot.forbidInsertion();
slot.setValidator(new ValidatorIndividualInoculate());
}
ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
transfer.addRestock(Inoculator.slotReserve, 9, 1);
transfer.addRestock(Inoculator.slotSerumReserve, 0);
transfer.addStorage(0, Inoculator.slotSerumExpended, new ComponentInventoryTransfer.Condition() {
transfer.addRestock(SLOT_RESERVE, SLOT_TARGET, 1);
transfer.addRestock(SLOT_SERUM_RESERVE, SLOT_SERUM_VIAL);
transfer.addStorage(0, SLOT_SERUM_EXPENDED, new ComponentInventoryTransfer.Condition() {
@Override
public boolean fufilled(ItemStack stack) {
return Engineering.getCharges(stack) == 0;
}
});
transfer.addStorage(9, Inoculator.slotFinished, new ComponentInventoryTransfer.Condition() {
transfer.addStorage(9, SLOT_FINISHED, new ComponentInventoryTransfer.Condition() {
@Override
public boolean fufilled(ItemStack stack) {
return stack != null
&& transfer.getMachine().getMachineUtil().getStack(0) != null
&& transfer.getMachine().getMachineUtil().getStack(SLOT_SERUM_VIAL) != null
&& transfer.getMachine().getInterface(ComponentInoculatorLogic.class).isValidSerum() != null;
}
});
@@ -160,17 +155,19 @@ public class Inoculator {
new ComponentPowerReceptor(machine, 15000);
new ComponentInoculatorLogic(machine);
new ComponentInoculatorFX(machine);
new ComponentTankContainer(machine).addTank(0, "input", 1000).setValidator(new Validator<FluidStack>() {
@Override
public boolean isValid(FluidStack object) {
return GeneticLiquid.BacteriaVector.get(1).isFluidEqual(object);
}
@Override
public String getTooltip() {
return GeneticLiquid.BacteriaVector.getName();
}
});
new ComponentTankContainer(machine)
.addTank(TANK_VECTOR, "input", TANK_CAPACITY)
.setValidator(new Validator<FluidStack>() {
@Override
public boolean isValid(FluidStack object) {
return GeneticLiquid.BacteriaVector.get(1).isFluidEqual(object);
}
@Override
public String getTooltip() {
return GeneticLiquid.BacteriaVector.getName();
}
});
}
@Override
@@ -198,7 +195,7 @@ public class Inoculator {
}
private int getNumberOfGenes() {
ItemStack serum = getUtil().getStack(0);
ItemStack serum = getUtil().getStack(SLOT_SERUM_VIAL);
if (serum == null) {
return 1;
}
@@ -213,25 +210,32 @@ public class Inoculator {
@Override
public ErrorState canWork() {
if (getUtil().isSlotEmpty(9)) {
return new ErrorState.NoItem("No Individual to Inoculate", 9);
if (getUtil().isSlotEmpty(SLOT_TARGET)) {
return new ErrorState.NoItem("No Individual to Inoculate", SLOT_TARGET);
}
if (getUtil().isSlotEmpty(0)) {
return new ErrorState.NoItem("No Serum", 0);
if (getUtil().isSlotEmpty(SLOT_SERUM_VIAL)) {
return new ErrorState.NoItem("No Serum", SLOT_SERUM_VIAL);
}
System.out.println("EMPTY = " + getUtil().isTankEmpty(TANK_VECTOR));
if (getUtil().isTankEmpty(TANK_VECTOR)) {
return new ErrorState.InsufficientLiquid("Not enough liquid", TANK_VECTOR);
}
ErrorState state = isValidSerum();
if (state != null) {
return state;
}
if (getUtil().getStack(0) != null && Engineering.getCharges(getUtil().getStack(0)) == 0) {
ItemStack stack = getUtil().getStack(SLOT_SERUM_VIAL);
if (stack != null && Engineering.getCharges(stack) == 0) {
return new ErrorState("Empty Serum", "Serum is empty");
}
return super.canWork();
}
public ErrorState isValidSerum() {
ItemStack serum = getUtil().getStack(0);
ItemStack target = getUtil().getStack(9);
ItemStack serum = getUtil().getStack(SLOT_SERUM_VIAL);
ItemStack target = getUtil().getStack(SLOT_TARGET);
IGene[] genes = Engineering.getGenes(serum);
if (genes.length == 0) {
return new ErrorState("Invalid Serum", "Serum does not hold any genes");
@@ -268,8 +272,8 @@ public class Inoculator {
@Override
protected void onFinishTask() {
super.onFinishTask();
ItemStack serum = getUtil().getStack(0);
ItemStack target = getUtil().getStack(9);
ItemStack serum = getUtil().getStack(SLOT_SERUM_VIAL);
ItemStack target = getUtil().getStack(SLOT_TARGET);
IIndividual ind = AlleleManager.alleleRegistry.getIndividual(target);
if (!ind.isAnalyzed()) {
ind.analyze();
@@ -280,8 +284,8 @@ public class Inoculator {
IGene[] genes = ((IItemSerum) serum.getItem()).getGenes(serum);
for (IGene gene : genes) {
Inoculator.setGene(gene, target, 0);
Inoculator.setGene(gene, target, 1);
setGene(gene, target, 0);
setGene(gene, target, 1);
}
getUtil().damageItem(0, 1);
}
@@ -296,7 +300,11 @@ public class Inoculator {
}
}
public static class ComponentInoculatorFX extends MachineComponent implements IRender.RandomDisplayTick, IRender.DisplayTick, IRender.Render, INetwork.TilePacketSync {
public static class ComponentInoculatorFX extends MachineComponent implements
IRender.RandomDisplayTick,
IRender.DisplayTick,
IRender.Render,
INetwork.TilePacketSync {
private EntityItem dummyEntityItem;
public ComponentInoculatorFX(IMachine machine) {
@@ -360,7 +368,6 @@ public class Inoculator {
@SideOnly(Side.CLIENT)
@Override
public void renderInWorld(RenderItem renderItem, double x, double y, double z) {
// TODO fix duplicate code
if (!getUtil().getProcess().isInProgress()) {
return;
}
@@ -375,10 +382,6 @@ public class Inoculator {
return;
}
EntityPlayer player = BinnieCore.proxy.getPlayer();
double dx = x + 0.5 - player.lastTickPosX;
double dz = z + 0.5 - player.lastTickPosZ;
double t = Math.atan2(dz, dx) * 180.0 / 3.1415;
GL11.glPushMatrix();
GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
GL11.glTranslatef(0.0f, -0.25f, 0.0f);
@@ -389,7 +392,7 @@ public class Inoculator {
@Override
public void syncToNBT(NBTTagCompound nbt) {
NBTTagCompound item = new NBTTagCompound();
ItemStack stack = getUtil().getStack(9);
ItemStack stack = getUtil().getStack(SLOT_TARGET);
if (stack != null) {
stack.writeToNBT(item);
nbt.setTag("item", item);
@@ -399,9 +402,9 @@ public class Inoculator {
@Override
public void syncFromNBT(NBTTagCompound nbt) {
if (nbt.hasKey("item")) {
getUtil().setStack(9, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("item")));
getUtil().setStack(SLOT_TARGET, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("item")));
} else {
getUtil().setStack(9, null);
getUtil().setStack(SLOT_TARGET, null);
}
}
@@ -34,10 +34,11 @@ import net.minecraft.world.World;
import java.util.Random;
public class Sequencer {
public static int[] slotReserve = new int[]{1, 2, 3, 4};
public static int slotDyeIndex = 0;
public static int slotTargetIndex = 5;
public static int slotDoneIndex = 6;
public static final int[] SLOT_RESERVE = new int[]{1, 2, 3, 4};
public static final int SLOT_DYE_INDEX = 0;
public static final int SLOT_TARGET_INDEX = 5;
public static final int SLOT_DONE_INDEX = 6;
public static BinnieIcon fxSeqA;
public static BinnieIcon fxSeqG;
public static BinnieIcon fxSeqT;
@@ -59,28 +60,28 @@ public class Sequencer {
new ComponentGeneticGUI(machine, GeneticsGUI.Sequencer);
ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
InventorySlot slotDye = inventory.addSlot(slotDyeIndex, "dye");
InventorySlot slotDye = inventory.addSlot(SLOT_DYE_INDEX, "dye");
slotDye.setValidator(new SlotValidator.Item(GeneticsItems.FluorescentDye.get(1), ModuleMachine.IconDye));
slotDye.forbidExtraction();
inventory.addSlotArray(slotReserve, "input");
for (InventorySlot slot : inventory.getSlots(slotReserve)) {
inventory.addSlotArray(SLOT_RESERVE, "input");
for (InventorySlot slot : inventory.getSlots(SLOT_RESERVE)) {
slot.setValidator(new SlotValidatorUnsequenced());
slot.forbidExtraction();
}
InventorySlot slotTarget = inventory.addSlot(slotTargetIndex, "process");
InventorySlot slotTarget = inventory.addSlot(SLOT_TARGET_INDEX, "process");
slotTarget.setValidator(new SlotValidatorUnsequenced());
slotTarget.setReadOnly();
slotTarget.forbidInteraction();
InventorySlot slotDone = inventory.addSlot(slotDoneIndex, "output");
InventorySlot slotDone = inventory.addSlot(SLOT_DONE_INDEX, "output");
slotDone.setReadOnly();
ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
transfer.addRestock(slotReserve, slotTargetIndex, 1);
transfer.addRestock(SLOT_RESERVE, SLOT_TARGET_INDEX, 1);
new ComponentChargedSlots(machine).addCharge(slotDyeIndex);
new ComponentChargedSlots(machine).addCharge(SLOT_DYE_INDEX);
new ComponentPowerReceptor(machine, 10000);
logic = new ComponentSequencerLogic(machine);
new ComponentSequencerFX(machine);
@@ -100,7 +101,7 @@ public class Sequencer {
}
public float getSequenceStrength() {
ItemStack stack = getUtil().getStack(slotTargetIndex);
ItemStack stack = getUtil().getStack(SLOT_TARGET_INDEX);
if (stack == null) {
return 1.0f;
}
@@ -121,8 +122,8 @@ public class Sequencer {
@Override
public ErrorState canWork() {
if (getUtil().isSlotEmpty(slotTargetIndex)) {
return new ErrorState.NoItem("No DNA sequence", slotTargetIndex);
if (getUtil().isSlotEmpty(SLOT_TARGET_INDEX)) {
return new ErrorState.NoItem("No DNA sequence", SLOT_TARGET_INDEX);
}
return super.canWork();
}
@@ -132,13 +133,13 @@ public class Sequencer {
if (getMachine().getOwner() == null) {
return new ErrorState("No Owner", "Replace this block to claim this machine");
}
if (getUtil().getSlotCharge(slotDyeIndex) == 0.0f) {
return new ErrorState.NoItem("Insufficient Dye", slotDyeIndex);
if (getUtil().getSlotCharge(SLOT_DYE_INDEX) == 0.0f) {
return new ErrorState.NoItem("Insufficient Dye", SLOT_DYE_INDEX);
}
ItemStack stack = getUtil().getStack(slotDoneIndex);
ItemStack stack = getUtil().getStack(SLOT_DONE_INDEX);
if (stack != null && stack.stackSize >= 64) {
return new ErrorState.NoSpace("No space for empty sequences", new int[]{slotDoneIndex});
return new ErrorState.NoSpace("No space for empty sequences", new int[]{SLOT_DONE_INDEX});
}
return super.canProgress();
}
@@ -151,7 +152,7 @@ public class Sequencer {
@Override
protected void onStartTask() {
super.onStartTask();
ItemStack item = getUtil().getStack(slotTargetIndex);
ItemStack item = getUtil().getStack(SLOT_TARGET_INDEX);
SequencerItem seqItem = new SequencerItem(item);
int seq = seqItem.sequenced;
if (seq != 0) {
@@ -163,26 +164,26 @@ public class Sequencer {
protected void onFinishTask() {
super.onFinishTask();
updateSequence();
SequencerItem seqItem = new SequencerItem(getUtil().getStack(slotTargetIndex));
SequencerItem seqItem = new SequencerItem(getUtil().getStack(SLOT_TARGET_INDEX));
GeneTracker.getTracker(getMachine().getWorld(), getMachine().getOwner()).registerGene(seqItem.getGene());
getUtil().decreaseStack(slotTargetIndex, 1);
getUtil().decreaseStack(SLOT_TARGET_INDEX, 1);
if (getUtil().getStack(slotDoneIndex) == null) {
getUtil().setStack(slotDoneIndex, GeneticsItems.EmptySequencer.get(1));
if (getUtil().getStack(SLOT_DONE_INDEX) == null) {
getUtil().setStack(SLOT_DONE_INDEX, GeneticsItems.EmptySequencer.get(1));
} else {
getUtil().decreaseStack(slotDoneIndex, -1);
getUtil().decreaseStack(SLOT_DONE_INDEX, -1);
}
}
@Override
protected void onTickTask() {
updateSequence();
getUtil().useCharge(slotDyeIndex, 0.4f * getProgressPerTick() / 100.0f);
getUtil().useCharge(SLOT_DYE_INDEX, 0.4f * getProgressPerTick() / 100.0f);
}
private void updateSequence() {
int prog = (int) getProgress();
ItemStack item = getUtil().getStack(slotTargetIndex);
ItemStack item = getUtil().getStack(SLOT_TARGET_INDEX);
SequencerItem seqItem = new SequencerItem(item);
int seq = seqItem.sequenced;
if (prog != seq) {