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 2972a1627..d304af537 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(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java index 26130afe4..acd2b1625 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java @@ -59,6 +59,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit protected Contraption contraption; protected boolean initialized; private boolean prevPosInvalid; + private boolean ticking; public AbstractContraptionEntity(EntityType entityTypeIn, World worldIn) { super(entityTypeIn, worldIn); @@ -246,6 +247,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit if (!world.isRemote) contraption.stalled = false; + ticking = true; for (MutablePair pair : contraption.getActors()) { MovementContext context = pair.right; BlockInfo blockInfo = pair.left; @@ -265,13 +267,25 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit continue; if (newPosVisited && !context.stall) { actor.visitNewPosition(context, gridPosition); + if (!isAlive()) + break; context.firstMovement = false; } - if (!oldMotion.equals(context.motion)) + if (!oldMotion.equals(context.motion)) { actor.onSpeedChanged(context, oldMotion, context.motion); + if (!isAlive()) + break; + } actor.tick(context); + if (!isAlive()) + break; contraption.stalled |= context.stall; } + if (!isAlive()) { + contraption.stop(world); + return; + } + ticking = false; for (Entity entity : getPassengers()) { if (!(entity instanceof OrientedContraptionEntity)) @@ -445,7 +459,8 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit @Override public void remove(boolean keepData) { if (!world.isRemote && !removed && contraption != null) { - contraption.stop(world); + if (!ticking) + contraption.stop(world); } super.remove(keepData); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java index bb8c2ff7e..e64ed67e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java @@ -46,6 +46,8 @@ public class MechanicalPistonTileEntity extends LinearActuatorTileEntity { if (!(world.getBlockState(pos) .getBlock() instanceof MechanicalPistonBlock)) return; + if (getMovementSpeed() == 0) + return; Direction direction = getBlockState().get(BlockStateProperties.FACING); diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java index 1915a3e3b..2411eb091 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItem.java @@ -77,6 +77,8 @@ public class SandPaperItem extends Item { AxisAlignedBB bb = new AxisAlignedBB(hitVec, hitVec).grow(1f); ItemEntity pickUp = null; for (ItemEntity itemEntity : worldIn.getEntitiesWithinAABB(ItemEntity.class, bb)) { + if (!itemEntity.isAlive()) + continue; if (itemEntity.getPositionVec() .distanceTo(playerIn.getPositionVec()) > 3) continue; diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java index 22a225e60..0263c476f 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java @@ -174,7 +174,7 @@ public class ItemHelper { if (!simulate && hasEnoughItems) inv.extractItem(slot, stack.getCount(), false); - if (extracting.getCount() >= maxExtractionCount) { + if (extracting.getCount() >= maxExtractionCount || extracting.getCount() >= extracting.getMaxStackSize()) { if (checkHasEnoughItems) { hasEnoughItems = true; checkHasEnoughItems = false; @@ -234,7 +234,7 @@ public class ItemHelper { if (!simulate) inv.extractItem(slot, stack.getCount(), false); - if (extracting.getCount() == maxExtractionCount) + if (extracting.getCount() >= maxExtractionCount || extracting.getCount() >= extracting.getMaxStackSize()) break; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java index 1524913fb..4cbf86483 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -59,7 +59,7 @@ public final class NBTProcessors { TileEntityType type = tileEntity.getType(); if (survival && survivalProcessors.containsKey(type)) compound = survivalProcessors.get(type).apply(compound); - if (processors.containsKey(type)) + if (compound != null && processors.containsKey(type)) return processors.get(type).apply(compound); if (tileEntity.onlyOpsCanSetNbt()) return null;