From 607dbbfb90c60c39506120cb5f0cfce5dbde310c Mon Sep 17 00:00:00 2001 From: Snownee Date: Mon, 8 Feb 2021 22:40:55 +0800 Subject: [PATCH] Fix PSI item dupe --- .../actors/PortableFluidInterfaceTileEntity.java | 5 +++-- .../actors/PortableItemInterfaceTileEntity.java | 5 +++-- .../actors/PortableStorageInterfaceTileEntity.java | 13 ++++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java index 981213c94..4c27df6f1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java @@ -37,6 +37,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi LazyOptional oldcap = capability; capability = createEmptyHandler(); oldcap.invalidate(); + super.stopTransferring(); } private LazyOptional createEmptyHandler() { @@ -90,7 +91,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi @Override public FluidStack drain(FluidStack resource, FluidAction action) { - if (!isConnected()) + if (!canTransfer()) return FluidStack.EMPTY; FluidStack drain = wrapped.drain(resource, action); if (!drain.isEmpty() && action.execute()) @@ -100,7 +101,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi @Override public FluidStack drain(int maxDrain, FluidAction action) { - if (!isConnected()) + if (!canTransfer()) return FluidStack.EMPTY; FluidStack drain = wrapped.drain(maxDrain, action); if (!drain.isEmpty() && (action.execute() || drain.getAmount() == 1)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableItemInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableItemInterfaceTileEntity.java index 1642a30ed..227c42dee 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableItemInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableItemInterfaceTileEntity.java @@ -33,6 +33,7 @@ public class PortableItemInterfaceTileEntity extends PortableStorageInterfaceTil LazyOptional oldCap = capability; capability = LazyOptional.of(() -> new InterfaceItemHandler(new ItemStackHandler(0))); oldCap.invalidate(); + super.stopTransferring(); } @Override @@ -55,7 +56,7 @@ public class PortableItemInterfaceTileEntity extends PortableStorageInterfaceTil @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (!isConnected()) + if (!canTransfer()) return ItemStack.EMPTY; ItemStack extractItem = super.extractItem(slot, amount, simulate); if (!simulate && !extractItem.isEmpty()) @@ -65,7 +66,7 @@ public class PortableItemInterfaceTileEntity extends PortableStorageInterfaceTil @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (!isConnected()) + if (!canTransfer()) return stack; ItemStack insertItem = super.insertItem(slot, stack, simulate); if (!simulate && !insertItem.equals(stack, false)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java index de4043458..2fd42b5ab 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java @@ -8,6 +8,7 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.LerpedFloat; +import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.AxisAlignedBB; @@ -21,6 +22,7 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity protected float distance; protected LerpedFloat connectionAnimation; protected boolean powered; + protected Entity connectedEntity; public PortableStorageInterfaceTileEntity(TileEntityType tileEntityTypeIn) { super(tileEntityTypeIn); @@ -32,11 +34,20 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity public void startTransferringTo(Contraption contraption, float distance) { this.distance = distance; + connectedEntity = contraption.entity; startConnecting(); notifyUpdate(); } - protected abstract void stopTransferring(); + protected void stopTransferring() { + connectedEntity = null; + } + + public boolean canTransfer() { + if (connectedEntity != null && !connectedEntity.isAlive()) + stopTransferring(); + return connectedEntity != null && isConnected(); + } protected abstract void invalidateCapability();