Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/binnie/core/machines/power/IProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ public interface IProcess extends IErrorStateSource {
boolean isInProgress();

ProcessInfo getInfo();

/***
* Returns true if the current target got worked on at least once.
*/
default boolean workedOnTarget() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

public class SplicerComponentLogic extends ComponentProcessSetCost implements IProcess {

// Needed to keep stack. If user takes out target slot and it gets automatically refilled, this happens in the same
// tick
private ItemStack workedOnStack = null;

public int nOfGenes;

public SplicerComponentLogic(Machine machine) {
Expand Down Expand Up @@ -50,6 +54,11 @@ public int getProcessEnergy() {
public void onInventoryUpdate() {
super.onInventoryUpdate();
nOfGenes = getGenesToUse();
ItemStack newTarget = getUtil().getStack(Splicer.SLOT_TARGET);

if (newTarget == null || !ItemStack.areItemStacksEqual(workedOnStack, newTarget)) {
workedOnStack = null;
}
}

protected int getGenesToUse() {
Expand Down Expand Up @@ -190,5 +199,31 @@ protected void onFinishTask() {
Splicer.setGene(gene, target, 1);
}
getUtil().damageItem(Splicer.SLOT_SERUM_VIAL, 1);
workedOnStack = getUtil().getStack(Splicer.SLOT_TARGET).copy();
}

@Override
public boolean workedOnTarget() {
return ItemStack.areItemStacksEqual(workedOnStack, getUtil().getStack(Splicer.SLOT_TARGET));
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagCompound tagWorkedOnStack = (NBTTagCompound) nbt.getTag("workedOnStack");
if (tagWorkedOnStack != null) {
workedOnStack = ItemStack.loadItemStackFromNBT(tagWorkedOnStack);
}
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
if (workedOnStack != null) {
NBTTagCompound tagWorkedOnStack = new NBTTagCompound();
workedOnStack.writeToNBT(tagWorkedOnStack);
// Need to save, in case inventory is full it might need to get moved out way later.
nbt.setTag("workedOnStack", tagWorkedOnStack);
}
}
}
17 changes: 15 additions & 2 deletions src/main/java/binnie/genetics/machine/splicer/SplicerPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.item.ItemStack;

import binnie.core.craftgui.minecraft.IMachineInformation;
import binnie.core.machines.IMachine;
import binnie.core.machines.Machine;
import binnie.core.machines.inventory.ComponentInventorySlots;
import binnie.core.machines.inventory.ComponentInventoryTransfer;
Expand Down Expand Up @@ -79,8 +80,20 @@ public boolean fufilled(ItemStack stack) {

@Override
public boolean fufilled(ItemStack stack) {
return stack != null && transfer.getMachine().getMachineUtil().getStack(Splicer.SLOT_SERUM_VIAL) != null
&& transfer.getMachine().getInterface(SplicerComponentLogic.class).isValidSerum() != null;
if (stack == null) {
return false;
}
IMachine machine = transfer.getMachine();
boolean hasSerum = machine.getMachineUtil().getStack(Splicer.SLOT_SERUM_VIAL) != null;

if (hasSerum) {
// Move item if it can't be processed anymore with current serum.
boolean validSerum = machine.getInterface(SplicerComponentLogic.class).isValidSerum() == null;
return !validSerum;
} else {
// Move item if there is no serum and item got processed already
return machine.getMachineUtil().getProcess().workedOnTarget();
}
}
});

Expand Down