Move out larvae from splicer even when no serum is present anymore (#76)

Co-authored-by: Martin Robertz <dream-master@gmx.net>
This commit is contained in:
DarkShadow44andMartin Robertz authored and GitHub committed 2026-03-20 23:33:14 -04:00
1 parent 63232799bc
commit 355c85598e
3 files changed
+57 -2

No files matched your search

@@ -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;
}
}
@@ -19,6 +19,10 @@ import forestry.api.genetics.IIndividual;
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) {
@@ -50,6 +54,11 @@ public class SplicerComponentLogic extends ComponentProcessSetCost implements IP
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() {
@@ -190,5 +199,31 @@ public class SplicerComponentLogic extends ComponentProcessSetCost implements IP
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);
}
}
}
@@ -3,6 +3,7 @@ package binnie.genetics.machine.splicer;
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;
@@ -79,8 +80,20 @@ public class SplicerPackage extends AdvGeneticMachine.PackageAdvGeneticBase impl
@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();
}
}
});