Fix PSI item dupe

This commit is contained in:
Snownee 2021-02-08 22:40:55 +08:00
parent 16991c2ce8
commit 607dbbfb90
3 changed files with 18 additions and 5 deletions

View File

@ -37,6 +37,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi
LazyOptional<IFluidHandler> oldcap = capability; LazyOptional<IFluidHandler> oldcap = capability;
capability = createEmptyHandler(); capability = createEmptyHandler();
oldcap.invalidate(); oldcap.invalidate();
super.stopTransferring();
} }
private LazyOptional<IFluidHandler> createEmptyHandler() { private LazyOptional<IFluidHandler> createEmptyHandler() {
@ -90,7 +91,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi
@Override @Override
public FluidStack drain(FluidStack resource, FluidAction action) { public FluidStack drain(FluidStack resource, FluidAction action) {
if (!isConnected()) if (!canTransfer())
return FluidStack.EMPTY; return FluidStack.EMPTY;
FluidStack drain = wrapped.drain(resource, action); FluidStack drain = wrapped.drain(resource, action);
if (!drain.isEmpty() && action.execute()) if (!drain.isEmpty() && action.execute())
@ -100,7 +101,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi
@Override @Override
public FluidStack drain(int maxDrain, FluidAction action) { public FluidStack drain(int maxDrain, FluidAction action) {
if (!isConnected()) if (!canTransfer())
return FluidStack.EMPTY; return FluidStack.EMPTY;
FluidStack drain = wrapped.drain(maxDrain, action); FluidStack drain = wrapped.drain(maxDrain, action);
if (!drain.isEmpty() && (action.execute() || drain.getAmount() == 1)) if (!drain.isEmpty() && (action.execute() || drain.getAmount() == 1))

View File

@ -33,6 +33,7 @@ public class PortableItemInterfaceTileEntity extends PortableStorageInterfaceTil
LazyOptional<IItemHandlerModifiable> oldCap = capability; LazyOptional<IItemHandlerModifiable> oldCap = capability;
capability = LazyOptional.of(() -> new InterfaceItemHandler(new ItemStackHandler(0))); capability = LazyOptional.of(() -> new InterfaceItemHandler(new ItemStackHandler(0)));
oldCap.invalidate(); oldCap.invalidate();
super.stopTransferring();
} }
@Override @Override
@ -55,7 +56,7 @@ public class PortableItemInterfaceTileEntity extends PortableStorageInterfaceTil
@Override @Override
public ItemStack extractItem(int slot, int amount, boolean simulate) { public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (!isConnected()) if (!canTransfer())
return ItemStack.EMPTY; return ItemStack.EMPTY;
ItemStack extractItem = super.extractItem(slot, amount, simulate); ItemStack extractItem = super.extractItem(slot, amount, simulate);
if (!simulate && !extractItem.isEmpty()) if (!simulate && !extractItem.isEmpty())
@ -65,7 +66,7 @@ public class PortableItemInterfaceTileEntity extends PortableStorageInterfaceTil
@Override @Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (!isConnected()) if (!canTransfer())
return stack; return stack;
ItemStack insertItem = super.insertItem(slot, stack, simulate); ItemStack insertItem = super.insertItem(slot, stack, simulate);
if (!simulate && !insertItem.equals(stack, false)) if (!simulate && !insertItem.equals(stack, false))

View File

@ -8,6 +8,7 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.LerpedFloat; import com.simibubi.create.foundation.utility.LerpedFloat;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
@ -21,6 +22,7 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity
protected float distance; protected float distance;
protected LerpedFloat connectionAnimation; protected LerpedFloat connectionAnimation;
protected boolean powered; protected boolean powered;
protected Entity connectedEntity;
public PortableStorageInterfaceTileEntity(TileEntityType<?> tileEntityTypeIn) { public PortableStorageInterfaceTileEntity(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn); super(tileEntityTypeIn);
@ -32,11 +34,20 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity
public void startTransferringTo(Contraption contraption, float distance) { public void startTransferringTo(Contraption contraption, float distance) {
this.distance = distance; this.distance = distance;
connectedEntity = contraption.entity;
startConnecting(); startConnecting();
notifyUpdate(); 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(); protected abstract void invalidateCapability();