mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-14 01:14:21 +00:00
* #19 Fix Sequencer don't reset progress after remove sequence item Some rafactoring Sequencer class * #19 Fixed imports
This commit is contained in:
1 parent
64259e06da
commit
f6186d3cf3
3 files changed
+81
-46
No files matched your search
@@ -59,8 +59,8 @@ public class MachineUtil {
|
||||
setStack(slot, null);
|
||||
}
|
||||
|
||||
public ItemStack decreaseStack(int slotWood, int amount) {
|
||||
return getInventory().decrStackSize(slotWood, amount);
|
||||
public ItemStack decreaseStack(int slot, int amount) {
|
||||
return getInventory().decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.List;
|
||||
|
||||
public class ComponentInventoryTransfer extends MachineComponent {
|
||||
private List<Transfer> transfers = new ArrayList<>();
|
||||
private ITransferRestockListener transferListener;
|
||||
|
||||
public ComponentInventoryTransfer(IMachine machine) {
|
||||
super(machine);
|
||||
@@ -43,6 +44,10 @@ public class ComponentInventoryTransfer extends MachineComponent {
|
||||
transfers.add(new Storage(getMachine(), source, destination).setCondition(condition));
|
||||
}
|
||||
|
||||
public void setTransferListener(ITransferRestockListener transferListener) {
|
||||
this.transferListener = transferListener;
|
||||
}
|
||||
|
||||
public abstract class Transfer {
|
||||
protected Condition condition;
|
||||
protected IMachine machine;
|
||||
@@ -92,17 +97,22 @@ public class ComponentInventoryTransfer extends MachineComponent {
|
||||
|
||||
@Override
|
||||
protected void doTransfer(IInventory inv) {
|
||||
if (inv.getStackInSlot(destination) == null) {
|
||||
for (int i : buffer) {
|
||||
if (inv.getStackInSlot(i) == null) {
|
||||
continue;
|
||||
}
|
||||
if (inv.getStackInSlot(destination) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack newStack = inv.decrStackSize(i, limit);
|
||||
if (newStack != null) {
|
||||
inv.setInventorySlotContents(destination, newStack);
|
||||
return;
|
||||
for (int slot : buffer) {
|
||||
if (inv.getStackInSlot(slot) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack newStack = inv.decrStackSize(slot, limit);
|
||||
if (newStack != null) {
|
||||
inv.setInventorySlotContents(destination, newStack);
|
||||
if (transferListener != null) {
|
||||
transferListener.onRestock(destination);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,4 +151,8 @@ public class ComponentInventoryTransfer extends MachineComponent {
|
||||
|
||||
public abstract boolean fufilled(ItemStack p0);
|
||||
}
|
||||
|
||||
public interface ITransferRestockListener {
|
||||
void onRestock(int target);
|
||||
}
|
||||
}
|
||||
@@ -35,17 +35,19 @@ import java.util.Random;
|
||||
|
||||
public class Sequencer {
|
||||
public static int[] slotReserve = new int[]{1, 2, 3, 4};
|
||||
public static int slotDye = 0;
|
||||
public static int slotTarget = 5;
|
||||
public static int slotDone = 6;
|
||||
public static int slotDyeIndex = 0;
|
||||
public static int slotTargetIndex = 5;
|
||||
public static int slotDoneIndex = 6;
|
||||
public static BinnieIcon fxSeqA;
|
||||
public static BinnieIcon fxSeqG;
|
||||
public static BinnieIcon fxSeqT;
|
||||
public static BinnieIcon fxSeqC;
|
||||
|
||||
private static ComponentSequencerLogic logic;
|
||||
|
||||
public static class PackageSequencer extends GeneticMachine.PackageGeneticBase implements IMachineInformation {
|
||||
public PackageSequencer() {
|
||||
super("sequencer", GeneticsTexture.Sequencer, 12058418, true);
|
||||
super("sequencer", GeneticsTexture.Sequencer, 0xb7ff32, true);
|
||||
Sequencer.fxSeqA = Binnie.Resource.getBlockIcon(Genetics.instance, "fx/sequencer.a");
|
||||
Sequencer.fxSeqG = Binnie.Resource.getBlockIcon(Genetics.instance, "fx/sequencer.g");
|
||||
Sequencer.fxSeqT = Binnie.Resource.getBlockIcon(Genetics.instance, "fx/sequencer.t");
|
||||
@@ -56,30 +58,34 @@ public class Sequencer {
|
||||
public void createMachine(Machine machine) {
|
||||
new ComponentGeneticGUI(machine, GeneticsGUI.Sequencer);
|
||||
ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
|
||||
inventory.addSlot(0, "dye");
|
||||
inventory.getSlot(0).setValidator(new SlotValidator.Item(GeneticsItems.FluorescentDye.get(1), ModuleMachine.IconDye));
|
||||
inventory.getSlot(0).forbidExtraction();
|
||||
inventory.addSlotArray(Sequencer.slotReserve, "input");
|
||||
|
||||
for (InventorySlot slot : inventory.getSlots(Sequencer.slotReserve)) {
|
||||
InventorySlot slotDye = inventory.addSlot(slotDyeIndex, "dye");
|
||||
slotDye.setValidator(new SlotValidator.Item(GeneticsItems.FluorescentDye.get(1), ModuleMachine.IconDye));
|
||||
slotDye.forbidExtraction();
|
||||
|
||||
inventory.addSlotArray(slotReserve, "input");
|
||||
for (InventorySlot slot : inventory.getSlots(slotReserve)) {
|
||||
slot.setValidator(new SlotValidatorUnsequenced());
|
||||
slot.forbidExtraction();
|
||||
}
|
||||
|
||||
inventory.addSlot(5, "process");
|
||||
inventory.getSlot(5).setValidator(new SlotValidatorUnsequenced());
|
||||
inventory.getSlot(5).setReadOnly();
|
||||
inventory.getSlot(5).forbidInteraction();
|
||||
InventorySlot slotTarget = inventory.addSlot(slotTargetIndex, "process");
|
||||
slotTarget.setValidator(new SlotValidatorUnsequenced());
|
||||
slotTarget.setReadOnly();
|
||||
slotTarget.forbidInteraction();
|
||||
|
||||
inventory.addSlot(6, "output");
|
||||
inventory.getSlot(6).setReadOnly();
|
||||
InventorySlot slotDone = inventory.addSlot(slotDoneIndex, "output");
|
||||
slotDone.setReadOnly();
|
||||
|
||||
ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
|
||||
transfer.addRestock(Sequencer.slotReserve, 5, 1);
|
||||
new ComponentChargedSlots(machine).addCharge(0);
|
||||
transfer.addRestock(slotReserve, slotTargetIndex, 1);
|
||||
|
||||
new ComponentChargedSlots(machine).addCharge(slotDyeIndex);
|
||||
new ComponentPowerReceptor(machine, 10000);
|
||||
new ComponentSequencerLogic(machine);
|
||||
logic = new ComponentSequencerLogic(machine);
|
||||
new ComponentSequencerFX(machine);
|
||||
|
||||
transfer.setTransferListener(logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,16 +94,17 @@ public class Sequencer {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComponentSequencerLogic extends ComponentProcess implements IProcess {
|
||||
public static class ComponentSequencerLogic extends ComponentProcess implements IProcess, ComponentInventoryTransfer.ITransferRestockListener {
|
||||
public ComponentSequencerLogic(Machine machine) {
|
||||
super(machine);
|
||||
}
|
||||
|
||||
public float getSequenceStrength() {
|
||||
ItemStack stack = getUtil().getStack(5);
|
||||
ItemStack stack = getUtil().getStack(slotTargetIndex);
|
||||
if (stack == null) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
float mult = 1.0f - stack.getItemDamage() % 6 / 5.0f;
|
||||
return 1.0f - mult * mult * 0.75f;
|
||||
}
|
||||
@@ -114,8 +121,8 @@ public class Sequencer {
|
||||
|
||||
@Override
|
||||
public ErrorState canWork() {
|
||||
if (getUtil().isSlotEmpty(5)) {
|
||||
return new ErrorState.NoItem("No DNA sequence", 5);
|
||||
if (getUtil().isSlotEmpty(slotTargetIndex)) {
|
||||
return new ErrorState.NoItem("No DNA sequence", slotTargetIndex);
|
||||
}
|
||||
return super.canWork();
|
||||
}
|
||||
@@ -125,19 +132,26 @@ public class Sequencer {
|
||||
if (getMachine().getOwner() == null) {
|
||||
return new ErrorState("No Owner", "Replace this block to claim this machine");
|
||||
}
|
||||
if (getUtil().getSlotCharge(0) == 0.0f) {
|
||||
return new ErrorState.NoItem("Insufficient Dye", 0);
|
||||
if (getUtil().getSlotCharge(slotDyeIndex) == 0.0f) {
|
||||
return new ErrorState.NoItem("Insufficient Dye", slotDyeIndex);
|
||||
}
|
||||
if (getUtil().getStack(6) != null && getUtil().getStack(6).stackSize >= 64) {
|
||||
return new ErrorState.NoSpace("No space for empty sequences", new int[]{6});
|
||||
|
||||
ItemStack stack = getUtil().getStack(slotDoneIndex);
|
||||
if (stack != null && stack.stackSize >= 64) {
|
||||
return new ErrorState.NoSpace("No space for empty sequences", new int[]{slotDoneIndex});
|
||||
}
|
||||
return super.canProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestock(int target) {
|
||||
onStartTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartTask() {
|
||||
super.onStartTask();
|
||||
ItemStack item = getUtil().getStack(5);
|
||||
ItemStack item = getUtil().getStack(slotTargetIndex);
|
||||
SequencerItem seqItem = new SequencerItem(item);
|
||||
int seq = seqItem.sequenced;
|
||||
if (seq != 0) {
|
||||
@@ -149,26 +163,26 @@ public class Sequencer {
|
||||
protected void onFinishTask() {
|
||||
super.onFinishTask();
|
||||
updateSequence();
|
||||
SequencerItem seqItem = new SequencerItem(getUtil().getStack(5));
|
||||
SequencerItem seqItem = new SequencerItem(getUtil().getStack(slotTargetIndex));
|
||||
GeneTracker.getTracker(getMachine().getWorld(), getMachine().getOwner()).registerGene(seqItem.getGene());
|
||||
getUtil().decreaseStack(5, 1);
|
||||
getUtil().decreaseStack(slotTargetIndex, 1);
|
||||
|
||||
if (getUtil().getStack(6) == null) {
|
||||
getUtil().setStack(6, GeneticsItems.EmptySequencer.get(1));
|
||||
if (getUtil().getStack(slotDoneIndex) == null) {
|
||||
getUtil().setStack(slotDoneIndex, GeneticsItems.EmptySequencer.get(1));
|
||||
} else {
|
||||
getUtil().decreaseStack(6, -1);
|
||||
getUtil().decreaseStack(slotDoneIndex, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTickTask() {
|
||||
updateSequence();
|
||||
getUtil().useCharge(0, 0.4f * getProgressPerTick() / 100.0f);
|
||||
getUtil().useCharge(slotDyeIndex, 0.4f * getProgressPerTick() / 100.0f);
|
||||
}
|
||||
|
||||
private void updateSequence() {
|
||||
int prog = (int) getProgress();
|
||||
ItemStack item = getUtil().getStack(5);
|
||||
ItemStack item = getUtil().getStack(slotTargetIndex);
|
||||
SequencerItem seqItem = new SequencerItem(item);
|
||||
int seq = seqItem.sequenced;
|
||||
if (prog != seq) {
|
||||
@@ -189,6 +203,7 @@ public class Sequencer {
|
||||
if (!getUtil().getProcess().isInProgress()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BinnieCore.proxy.getMinecraftInstance().effectRenderer.addEffect(new EntityFX(world, x + 0.5, y + 1.2 + rand.nextDouble() * 0.2, z + 0.5, 0.0, 0.0, 0.0) {
|
||||
double axisX = posX;
|
||||
double axisZ = posZ;
|
||||
@@ -237,7 +252,13 @@ public class Sequencer {
|
||||
particleGravity = 0.0f;
|
||||
noClip = true;
|
||||
particleScale = 2.0f;
|
||||
setParticleIcon((new BinnieIcon[]{Sequencer.fxSeqA, Sequencer.fxSeqG, Sequencer.fxSeqC, Sequencer.fxSeqT})[rand.nextInt(4)].getIcon());
|
||||
|
||||
setParticleIcon((new BinnieIcon[]{
|
||||
fxSeqA,
|
||||
fxSeqG,
|
||||
fxSeqC,
|
||||
fxSeqT
|
||||
})[rand.nextInt(4)].getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user