diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index d006469e6..0b4a77756 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -185,12 +185,17 @@ public class KineticTileEntity extends SmartTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { if (!level.isClientSide) { if (hasNetwork()) getOrCreateNetwork().remove(this); detachKinetics(); } - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java index 2c3fe1237..0a2667f2e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java @@ -86,10 +86,15 @@ public class EngineTileEntity extends SmartTileEntity implements IInstanceRender @Override public void setRemoved() { - detachWheel(); super.setRemoved(); } + @Override + protected void setRemovedNotDueToChunkUnload() { + detachWheel(); + super.setRemovedNotDueToChunkUnload(); + } + protected void refreshWheelSpeed() { if (poweredWheel == null) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java index fdefd03d9..a5cde2099 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java @@ -362,9 +362,14 @@ public class ClockworkBearingTileEntity extends KineticTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { if (!level.isClientSide) disassemble(); - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java index 2245c6ad5..aa3c8bdac 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java @@ -59,9 +59,14 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { if (!level.isClientSide) disassemble(); - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java index 2a8789677..40c32d11d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java @@ -107,7 +107,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity boolean contraptionPresent = movedContraption != null; if (needsContraption && !contraptionPresent) return; - + float movementSpeed = getMovementSpeed(); float newOffset = offset + movementSpeed; if ((int) newOffset != (int) offset) @@ -122,7 +122,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity return; } } - + if (!contraptionPresent || !movedContraption.isStalled()) offset = newOffset; @@ -173,10 +173,15 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { this.remove = true; if (!level.isClientSide) disassemble(); - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override @@ -261,13 +266,13 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity movedContraption.setContraptionMotion(Vec3.ZERO); return false; } - + Vec3 motion = getMotionVector(); movedContraption.setContraptionMotion(getMotionVector()); movedContraption.move(motion.x, motion.y, motion.z); return ContraptionCollider.collideBlocks(movedContraption); } - + protected void collided() { if (level.isClientSide) { waitingForSpeedChange = true; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java index 0f39bcda5..8d762bfc0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java @@ -197,12 +197,17 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor @Override public void setRemoved() { - onEmptied(); itemCapability.invalidate(); fluidCapability.invalidate(); super.setRemoved(); } + @Override + protected void setRemovedNotDueToChunkUnload() { + onEmptied(); + super.setRemovedNotDueToChunkUnload(); + } + @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, Direction side) { @@ -288,7 +293,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor tryClearingSpoutputOverflow(); if (!contentsChanged) return; - + contentsChanged = false; getOperator().ifPresent(te -> te.basinChecker.scheduleUpdate()); @@ -312,7 +317,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor Direction direction = blockState.getValue(BasinBlock.FACING); BlockEntity te = level.getBlockEntity(worldPosition.below() .relative(direction)); - + FilteringBehaviour filter = null; InvManipulationBehaviour inserter = null; if (te != null) { @@ -362,7 +367,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor update = true; continue; } - + if (targetTank == null) break; @@ -459,7 +464,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor Direction direction = blockState.getValue(BasinBlock.FACING); if (direction != Direction.DOWN) { - + BlockEntity te = level.getBlockEntity(worldPosition.below() .relative(direction)); @@ -472,7 +477,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()) .orElse(null); boolean externalTankNotPresent = targetTank == null; - + if (!outputItems.isEmpty() && targetInv == null) return false; if (!outputFluids.isEmpty() && externalTankNotPresent) { @@ -484,7 +489,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor if (!acceptFluidOutputsIntoBasin(outputFluids, simulate, targetTank)) return false; } - + if (simulate) return true; for (ItemStack itemStack : outputItems) { diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java index 0059fec11..b2861416a 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java @@ -146,10 +146,30 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements IParti .reduce(ItemRequirement.NONE, (a, b) -> a.with(b.getRequiredItems()), (a, b) -> a.with(b)); } + /* TODO: Remove this hack once this issue is resolved: https://github.com/MinecraftForge/MinecraftForge/issues/8302 + Once the PR linked in the issue is accepted, we should use the new method for determining whether setRemoved was + called due to a chunk unload or not, and remove this volatile workaround + */ + private boolean unloaded; + + @Override + public void onChunkUnloaded() { + super.onChunkUnloaded(); + unloaded = true; + } + + protected void setRemovedNotDueToChunkUnload() { + + } + @Override public void setRemoved() { forEachBehaviour(TileEntityBehaviour::remove); super.setRemoved(); + + if (!unloaded) { + setRemovedNotDueToChunkUnload(); + } } public void setLazyTickRate(int slowTickRate) {