diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java index aa54f395b..fcecf28d0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.advancement.AdvancementBehaviour; +import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.item.ItemDescription.Palette; import net.minecraft.core.BlockPos; @@ -44,6 +45,11 @@ public abstract class KineticBlock extends Block implements IRotate { kineticTileEntity.preventSpeedUpdate = 2; } } + + @Override + public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) { + ITE.onRemove(pState, pLevel, pPos, pNewState); + } @Override public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) { 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 3996a5ab3..548e80d3e 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 @@ -184,18 +184,13 @@ public class KineticTileEntity extends SmartTileEntity implements IHaveGoggleInf } @Override - public void setRemoved() { - super.setRemoved(); - } - - @Override - protected void setRemovedNotDueToChunkUnload() { + public void remove() { if (!level.isClientSide) { if (hasNetwork()) getOrCreateNetwork().remove(this); detachKinetics(); } - super.setRemovedNotDueToChunkUnload(); + super.remove(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingKineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingKineticTileEntity.java index 1162e9835..5e1fb49f2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingKineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingKineticTileEntity.java @@ -73,10 +73,10 @@ public abstract class BlockBreakingKineticTileEntity extends KineticTileEntity { } @Override - public void setRemoved() { + public void invalidate() { + super.invalidate(); if (!level.isClientSide && destroyProgress != 0) level.destroyBlockProgress(breakerId, breakingPos, -1); - super.setRemoved(); } @Override 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 17c41d628..f2125015d 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 @@ -112,8 +112,8 @@ public abstract class PortableStorageInterfaceTileEntity extends SmartTileEntity } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); invalidateCapability(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java index 8668795c7..65c3c894d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterBlock.java @@ -95,7 +95,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock } } - if (state.hasBlockEntity() && state.getBlock() != newState.getBlock()) { + if (state.hasBlockEntity() && !state.is(newState.getBlock())) { MechanicalCrafterTileEntity crafter = CrafterHelper.getCrafter(worldIn, pos); if (crafter != null) { if (crafter.covered) @@ -121,9 +121,9 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock ConnectedInputHandler.toggleConnection(worldIn, pos, otherPos); } - - worldIn.removeBlockEntity(pos); } + + super.onRemove(state, worldIn, pos, newState, isMoving); } public static Pointing pointingFromFacing(Direction pointingFace, Direction blockFacing) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java index bc6be652a..a38066091 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java @@ -215,9 +215,9 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { } @Override - public void setRemoved() { + public void invalidate() { + super.invalidate(); invSupplier.invalidate(); - super.setRemoved(); } public int getCountDownSpeed() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelBlock.java index 911391a56..fdcef77ef 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelBlock.java @@ -47,17 +47,14 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock implements ITE @Override public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - for (Direction d : Iterate.directions) { if (d.getAxis() == state.getValue(AXIS)) continue; if (AllBlocks.CRUSHING_WHEEL_CONTROLLER.has(worldIn.getBlockState(pos.relative(d)))) - worldIn.setBlockAndUpdate(pos.relative(d), Blocks.AIR.defaultBlockState()); + worldIn.removeBlock(pos.relative(d), isMoving); } - if (state.hasBlockEntity() && state.getBlock() != newState.getBlock()) { - worldIn.removeBlockEntity(pos); - } + super.onRemove(state, worldIn, pos, newState, isMoving); } public void updateControllers(BlockState state, Level world, BlockPos pos, Direction side) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java index 24d2ee65b..673789b4d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java @@ -8,8 +8,6 @@ import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; import com.simibubi.create.content.contraptions.components.AssemblyOperatorUseContext; import com.simibubi.create.foundation.block.ITE; -import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; @@ -61,20 +59,9 @@ public class DeployerBlock extends DirectionalAxisKineticBlock implements ITE { - if (te.player != null && !isMoving) { - te.player.getInventory() - .dropAll(); - te.overflowItems.forEach(itemstack -> te.player.drop(itemstack, true, false)); - te.player.discard(); - te.player = null; - } - }); - - TileEntityBehaviour.destroy(worldIn, pos, FilteringBehaviour.TYPE); - worldIn.removeBlockEntity(pos); - } + if (!isMoving && !state.is(newState.getBlock())) + withTileEntityDo(worldIn, pos, DeployerTileEntity::discardPlayer); + super.onRemove(state, worldIn, pos, newState, isMoving); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java index fb5c28da8..31d8dfc6f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerTileEntity.java @@ -434,9 +434,19 @@ public class DeployerTileEntity extends KineticTileEntity { return super.createRenderBoundingBox().inflate(3); } + public void discardPlayer() { + if (player == null) + return; + player.getInventory() + .dropAll(); + overflowItems.forEach(itemstack -> player.drop(itemstack, true, false)); + player.discard(); + player = null; + } + @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); if (invHandler != null) invHandler.invalidate(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanBlock.java index 06c3a4edd..445be9ef4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanBlock.java @@ -36,14 +36,6 @@ public class EncasedFanBlock extends DirectionalKineticBlock implements ITE 0 ? facing : facing.getOpposite(); } + @Override + public void remove() { + super.remove(); + updateChute(); + } + @Override public boolean isSourceRemoved() { return remove; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneBlock.java index 1260b4697..dbb38aaf4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneBlock.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.KineticBlock; import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel; import com.simibubi.create.foundation.block.ITE; -import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.core.BlockPos; @@ -118,18 +117,6 @@ public class MillstoneBlock extends KineticBlock implements ITE { - ItemHelper.dropContents(worldIn, pos, te.inputInv); - ItemHelper.dropContents(worldIn, pos, te.outputInv); - }); - - worldIn.removeBlockEntity(pos); - } - } - @Override public Axis getRotationAxis(BlockState state) { return Axis.Y; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java index 65527e345..91a1fa51b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneTileEntity.java @@ -6,6 +6,7 @@ import java.util.Optional; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.advancement.AllAdvancements; +import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.sound.SoundScapes; import com.simibubi.create.foundation.sound.SoundScapes.AmbienceGroup; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -116,10 +117,17 @@ public class MillstoneTileEntity extends KineticTileEntity { } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); capability.invalidate(); } + + @Override + public void destroy() { + super.destroy(); + ItemHelper.dropContents(level, worldPosition, inputInv); + ItemHelper.dropContents(level, worldPosition, outputInv); + } private void process() { RecipeWrapper inventoryIn = new RecipeWrapper(inputInv); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java index 4054b8d86..c444caa2e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java @@ -7,9 +7,6 @@ import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; import com.simibubi.create.content.contraptions.components.actors.DrillBlock; import com.simibubi.create.foundation.block.ITE; -import com.simibubi.create.foundation.item.ItemHelper; -import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; @@ -102,16 +99,6 @@ public class SawBlock extends DirectionalAxisKineticBlock implements ITE ItemHelper.dropContents(worldIn, pos, te.inventory)); - TileEntityBehaviour.destroy(worldIn, pos, FilteringBehaviour.TYPE); - worldIn.removeBlockEntity(pos); - } - @Override public Class getTileEntityClass() { return SawTileEntity.class; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java index bcabe61e0..ce5a2bff7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntity.java @@ -255,9 +255,15 @@ public class SawTileEntity extends BlockBreakingKineticTileEntity { } @Override - public void setRemoved() { + public void invalidate() { + super.invalidate(); invProvider.invalidate(); - super.setRemoved(); + } + + @Override + public void destroy() { + super.destroy(); + ItemHelper.dropContents(level, worldPosition, inventory); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineTileEntity.java index be6589a00..e2fe33f67 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineTileEntity.java @@ -134,11 +134,11 @@ public class SteamEngineTileEntity extends SmartTileEntity implements IHaveGoggl } @Override - protected void setRemovedNotDueToChunkUnload() { + public void remove() { PoweredShaftTileEntity shaft = getShaft(); if (shaft != null) shaft.remove(worldPosition); - super.setRemovedNotDueToChunkUnload(); + super.remove(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleBlock.java index 15b2225e4..96802b57f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/steam/whistle/WhistleBlock.java @@ -193,8 +193,7 @@ public class WhistleBlock extends Block implements ITE, IWren @Override public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) { - if (pState.hasBlockEntity() && (!pState.is(pNewState.getBlock()) || !pNewState.hasBlockEntity())) - pLevel.removeBlockEntity(pPos); + ITE.onRemove(pState, pLevel, pPos, pNewState); FluidTankBlock.updateBoilerState(pState, pLevel, pPos.relative(getAttachedDirection(pState))); } 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 c1faf28d4..424020c75 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 @@ -372,15 +372,10 @@ public class ClockworkBearingTileEntity extends KineticTileEntity } @Override - public void setRemoved() { - super.setRemoved(); - } - - @Override - protected void setRemovedNotDueToChunkUnload() { + public void remove() { if (!level.isClientSide) disassemble(); - super.setRemovedNotDueToChunkUnload(); + super.remove(); } @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 b02f94773..716912d1e 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,15 +59,10 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity } @Override - public void setRemoved() { - super.setRemoved(); - } - - @Override - protected void setRemovedNotDueToChunkUnload() { + public void remove() { if (!level.isClientSide) disassemble(); - super.setRemovedNotDueToChunkUnload(); + super.remove(); } @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 39e54a86e..1090f204d 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 @@ -174,16 +174,11 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity } @Override - public void setRemoved() { - super.setRemoved(); - } - - @Override - protected void setRemovedNotDueToChunkUnload() { + public void remove() { this.remove = true; if (!level.isClientSide) disassemble(); - super.setRemovedNotDueToChunkUnload(); + super.remove(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyBlock.java index 0031780ac..85e1bd250 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyBlock.java @@ -47,18 +47,17 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE getTileEntityClass() { return HosePulleyTileEntity.class; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java index 35a1b105e..30e6c2282 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java @@ -166,8 +166,8 @@ public class HosePulleyTileEntity extends KineticTileEntity { } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); capability.invalidate(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/ItemDrainTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/ItemDrainTileEntity.java index 2206c65dd..2e9414ebf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/ItemDrainTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/ItemDrainTileEntity.java @@ -252,8 +252,8 @@ public class ItemDrainTileEntity extends SmartTileEntity implements IHaveGoggleI } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); for (LazyOptional lazyOptional : itemHandlers.values()) lazyOptional.invalidate(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java index 0c92e55ff..d1ca9c1b8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java @@ -90,11 +90,10 @@ public class FluidValveBlock extends DirectionalAxisKineticBlock @Override public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) { - boolean blockTypeChanged = state.getBlock() != newState.getBlock(); + boolean blockTypeChanged = !state.is(newState.getBlock()); if (blockTypeChanged && !world.isClientSide) FluidPropagator.propagateChangedPipe(world, pos, state); - if (state.hasBlockEntity() && (blockTypeChanged || !newState.hasBlockEntity())) - world.removeBlockEntity(pos); + super.onRemove(state, world, pos, newState, isMoving); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java index 0ed668384..b32c8c11f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java @@ -485,8 +485,8 @@ public class FluidTankTileEntity extends SmartTileEntity implements IHaveGoggleI } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java index c23c6c19c..cbae94b8f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinBlock.java @@ -13,7 +13,6 @@ import com.simibubi.create.foundation.fluid.FluidHelper; import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; -import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -170,15 +169,7 @@ public class BasinBlock extends Block implements ITE, IWrenchab @Override public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - if (!state.hasBlockEntity() || state.getBlock() == newState.getBlock()) - return; - TileEntityBehaviour.destroy(worldIn, pos, FilteringBehaviour.TYPE); - withTileEntityDo(worldIn, pos, te -> { - ItemHelper.dropContents(worldIn, pos, te.inputInventory); - ItemHelper.dropContents(worldIn, pos, te.outputInventory); - te.spoutputBuffer.forEach(is -> Block.popResource(worldIn, pos, is)); - }); - worldIn.removeBlockEntity(pos); + ITE.onRemove(state, worldIn, pos, newState); } @Override 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 af01c8da1..e51ed4df6 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 @@ -19,6 +19,7 @@ import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.foundation.fluid.CombinedTankWrapper; +import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -193,22 +194,30 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor visualizedOutputItems.clear(); visualizedOutputFluids.clear(); } + + @Override + public void destroy() { + super.destroy(); + ItemHelper.dropContents(level, worldPosition, inputInventory); + ItemHelper.dropContents(level, worldPosition, outputInventory); + spoutputBuffer.forEach(is -> Block.popResource(level, worldPosition, is)); + } + + @Override + public void remove() { + super.remove(); + onEmptied(); + } public void onEmptied() { getOperator().ifPresent(te -> te.basinRemoved = true); } - + @Override - public void setRemoved() { + public void invalidate() { + super.invalidate(); itemCapability.invalidate(); fluidCapability.invalidate(); - super.setRemoved(); - } - - @Override - protected void setRemovedNotDueToChunkUnload() { - onEmptied(); - super.setRemovedNotDueToChunkUnload(); } @Nonnull diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java index 679965e2a..f884f62af 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java @@ -455,6 +455,8 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE Block.popResource(world, pos, stack)); diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java index a44225964..489ad92b4 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java @@ -87,8 +87,8 @@ public class ToolboxTileEntity extends SmartTileEntity implements MenuProvider, } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); ToolboxHandler.onUnload(this); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java index 46c96baab..449c7d8f8 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileRenderMode.java @@ -1,7 +1,5 @@ package com.simibubi.create.content.curiosities.weapons; -import static com.simibubi.create.content.curiosities.weapons.PotatoProjectileRenderMode.entityRandom; - import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.utility.AngleHelper; diff --git a/src/main/java/com/simibubi/create/content/logistics/RedstoneLinkNetworkHandler.java b/src/main/java/com/simibubi/create/content/logistics/RedstoneLinkNetworkHandler.java index 019b6de47..687bc8845 100644 --- a/src/main/java/com/simibubi/create/content/logistics/RedstoneLinkNetworkHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/RedstoneLinkNetworkHandler.java @@ -17,7 +17,6 @@ import com.simibubi.create.foundation.utility.WorldHelper; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; public class RedstoneLinkNetworkHandler { @@ -112,10 +111,7 @@ public class RedstoneLinkNetworkHandler { iterator.remove(); continue; } - if (!(world instanceof Level level) || !level.isLoaded(other.getLocation())) { - iterator.remove(); - continue; - } + if (!withinRange(actor, other)) continue; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java index b0f3f605a..f6b2e5b90 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java @@ -56,8 +56,8 @@ public class BeltTunnelTileEntity extends SmartTileEntity { } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); cap.invalidate(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelBlock.java index dece4a44e..7c9629055 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelBlock.java @@ -3,8 +3,7 @@ package com.simibubi.create.content.logistics.block.belts.tunnel; import java.util.List; import com.simibubi.create.AllTileEntities; -import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; +import com.simibubi.create.foundation.block.ITE; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -16,7 +15,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; @@ -61,16 +59,7 @@ public class BrassTunnelBlock extends BeltTunnelBlock { @Override public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) { - if (state.hasBlockEntity() && (state.getBlock() != newState.getBlock() || !newState.hasBlockEntity())) { - TileEntityBehaviour.destroy(level, pos, FilteringBehaviour.TYPE); - withTileEntityDo(level, pos, te -> { - if (!(te instanceof BrassTunnelTileEntity btte)) - return; - Block.popResource(level, pos, btte.stackToDistribute); - btte.stackEnteredFrom = null; - }); - level.removeBlockEntity(pos); - } + ITE.onRemove(state, level, pos, newState); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java index 0d6399094..c45ceff6b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BrassTunnelTileEntity.java @@ -46,6 +46,7 @@ import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -714,9 +715,16 @@ public class BrassTunnelTileEntity extends BeltTunnelTileEntity implements IHave } @Override - public void setRemoved() { + public void invalidate() { + super.invalidate(); tunnelCapability.invalidate(); - super.setRemoved(); + } + + @Override + public void destroy() { + super.destroy(); + Block.popResource(level, worldPosition, stackToDistribute); + stackEnteredFrom = null; } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java index 9bf371d8c..b53d3581d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/AbstractChuteBlock.java @@ -10,7 +10,6 @@ import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.block.render.ReducedDestroyEffects; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; -import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.core.BlockPos; @@ -132,14 +131,10 @@ public abstract class AbstractChuteBlock extends Block implements IWrenchable, I } @Override - public void onRemove(BlockState state, Level world, BlockPos pos, BlockState p_196243_4_, boolean p_196243_5_) { - boolean differentBlock = state.getBlock() != p_196243_4_.getBlock(); - if (state.hasBlockEntity() && (differentBlock || !p_196243_4_.hasBlockEntity())) { - TileEntityBehaviour.destroy(world, pos, FilteringBehaviour.TYPE); - withTileEntityDo(world, pos, c -> c.onRemoved(state)); - world.removeBlockEntity(pos); - } - if (p_196243_5_ || !differentBlock) + public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) { + ITE.onRemove(state, world, pos, newState); + + if (isMoving || state.is(newState.getBlock())) return; updateDiagonalNeighbour(state, world, pos); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java index 7f3f4728e..5a854dc9c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java @@ -509,10 +509,10 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { if (lazyHandler != null) lazyHandler.invalidate(); + super.invalidate(); } @Override @@ -557,8 +557,10 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor return (Mth.clamp(motion, -maxItemSpeed, maxItemSpeed) + (motion <= 0 ? -gravity : 0)) / 20f; } - public void onRemoved(BlockState chuteState) { - ChuteTileEntity targetChute = getTargetChute(chuteState); + @Override + public void destroy() { + super.destroy(); + ChuteTileEntity targetChute = getTargetChute(getBlockState()); List inputChutes = getInputChutes(); if (!item.isEmpty() && level != null) Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), item); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java index 84a16e8d5..8e31cce1b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBehaviour.java @@ -32,6 +32,7 @@ import net.minecraft.nbt.Tag; import net.minecraft.world.Containers; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.capabilities.Capability; @@ -199,7 +200,19 @@ public class DepotBehaviour extends TileEntityBehaviour { } @Override - public void remove() { + public void destroy() { + super.destroy(); + Level level = getWorld(); + BlockPos pos = getPos(); + ItemHelper.dropContents(level, pos, processingOutputBuffer); + for (TransportedItemStack transportedItemStack : incoming) + Block.popResource(level, pos, transportedItemStack.stack); + if (!getHeldItemStack().isEmpty()) + Block.popResource(level, pos, getHeldItemStack()); + } + + @Override + public void unload() { if (lazyItemHandler != null) lazyItemHandler.invalidate(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBlock.java index b6b42b325..2defa56e8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/DepotBlock.java @@ -55,7 +55,7 @@ public class DepotBlock extends Block implements ITE, IWrenchab @Override public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - SharedDepotBlockMethods.onReplaced(state, worldIn, pos, newState, isMoving); + ITE.onRemove(state, worldIn, pos, newState); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java index 875d6462c..349963a33 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorBlock.java @@ -125,12 +125,6 @@ public class EjectorBlock extends HorizontalKineticBlock implements ITE intAttached : launchedItems) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/SharedDepotBlockMethods.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/SharedDepotBlockMethods.java index 1cce72cbf..9f16c24c8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/SharedDepotBlockMethods.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/SharedDepotBlockMethods.java @@ -4,7 +4,6 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; -import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; @@ -13,7 +12,6 @@ import net.minecraft.core.Direction; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; -import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; @@ -76,22 +74,6 @@ public class SharedDepotBlockMethods { return InteractionResult.SUCCESS; } - public static void onReplaced(BlockState state, Level worldIn, BlockPos pos, BlockState newState, - boolean isMoving) { - if (!state.hasBlockEntity() || state.getBlock() == newState.getBlock()) - return; - DepotBehaviour behaviour = get(worldIn, pos); - if (behaviour == null) - return; - ItemHelper.dropContents(worldIn, pos, behaviour.processingOutputBuffer); - for (TransportedItemStack transportedItemStack : behaviour.incoming) - Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), transportedItemStack.stack); - if (!behaviour.getHeldItemStack() - .isEmpty()) - Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), behaviour.getHeldItemStack()); - worldIn.removeBlockEntity(pos); - } - public static void onLanded(BlockGetter worldIn, Entity entityIn) { if (!(entityIn instanceof ItemEntity)) return; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/AbstractFunnelBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/AbstractFunnelBlock.java index 4726ef2b7..3468dd507 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/AbstractFunnelBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/AbstractFunnelBlock.java @@ -128,13 +128,8 @@ public abstract class AbstractFunnelBlock extends Block implements ITE, ICogWh return AllTileEntities.MECHANICAL_ARM.get(); } - @Override - public void onRemove(BlockState p_196243_1_, Level world, BlockPos pos, BlockState p_196243_4_, - boolean p_196243_5_) { - if (p_196243_1_.hasBlockEntity() - && (p_196243_1_.getBlock() != p_196243_4_.getBlock() || !p_196243_4_.hasBlockEntity())) { - withTileEntityDo(world, pos, te -> { - if (!te.heldItem.isEmpty()) - Containers.dropItemStack(world, pos.getX(), pos.getY(), pos.getZ(), te.heldItem); - }); - world.removeBlockEntity(pos); - } - } - @Override public InteractionResult use(BlockState p_225533_1_, Level world, BlockPos pos, Player player, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index 77eefd030..872ba0ff7 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -37,6 +37,7 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.JukeboxBlock; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -215,6 +216,13 @@ public class ArmTileEntity extends KineticTileEntity implements ITransformableTE return hasLevel() && state.getOptionalValue(ArmBlock.CEILING) .orElse(false); } + + @Override + public void destroy() { + super.destroy(); + if (!heldItem.isEmpty()) + Block.popResource(level, worldPosition, heldItem); + } @Nullable private ArmInteractionPoint getTargetedInteractionPoint() { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/ContentObserverBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/ContentObserverBlock.java index 17dd8134a..61ff5c7fe 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/ContentObserverBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/ContentObserverBlock.java @@ -126,10 +126,7 @@ public class ContentObserverBlock extends HorizontalDirectionalBlock implements @Override public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - if (state.hasBlockEntity() && state.getBlock() != newState.getBlock()) { - TileEntityBehaviour.destroy(worldIn, pos, FilteringBehaviour.TYPE); - worldIn.removeBlockEntity(pos); - } + ITE.onRemove(state, worldIn, pos, newState); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayBlock.java index d1b065ffa..5a809b2df 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayBlock.java @@ -308,8 +308,7 @@ public class FlapDisplayBlock extends HorizontalKineticBlock @Override public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) { - if (pState.hasBlockEntity() && (!pState.is(pNewState.getBlock()) || !pNewState.hasBlockEntity())) - pLevel.removeBlockEntity(pPos); + super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving); if (pIsMoving || pNewState.getBlock() == this) return; for (Direction d : Iterate.directionsInAxis(getConnectionAxis(pState))) { diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/TrackTargetingBehaviour.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/TrackTargetingBehaviour.java index ed921d730..6771084d8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/TrackTargetingBehaviour.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/TrackTargetingBehaviour.java @@ -234,10 +234,10 @@ public class TrackTargetingBehaviour extends TileEntit } @Override - public void remove() { + public void destroy() { + super.destroy(); if (edgePoint != null && !getWorld().isClientSide) edgePoint.tileRemoved(getPos(), getTargetDirection() == AxisDirection.POSITIVE); - super.remove(); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlock.java index 59c5c8932..0fa1f184e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/observer/TrackObserverBlock.java @@ -3,8 +3,6 @@ package com.simibubi.create.content.logistics.trains.management.edgePoint.observ import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.foundation.block.ITE; -import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -57,11 +55,8 @@ public class TrackObserverBlock extends Block implements ITE, IWren @Override public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { - SharedDepotBlockMethods.onReplaced(state, worldIn, pos, newState, isMoving); + ITE.onRemove(state, worldIn, pos, newState); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java index 1c9edc2bd..9fdb9a96b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java @@ -438,11 +438,10 @@ public class StationTileEntity extends SmartTileEntity implements ITransformable } @Override - protected void setRemovedNotDueToChunkUnload() { + public void remove() { assemblyAreas.get(level) .remove(worldPosition); - - super.setRemovedNotDueToChunkUnload(); + super.remove(); } public void assemble(UUID playerUUID) { diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationUnloadedCondition.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationUnloadedCondition.java index 4b09cba39..e0c723949 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationUnloadedCondition.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationUnloadedCondition.java @@ -9,13 +9,12 @@ import com.simibubi.create.foundation.utility.Pair; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraft.core.BlockPos; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; public class StationUnloadedCondition extends ScheduleWaitCondition { @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackTileEntity.java index 9e164e5bb..05431e8fd 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackTileEntity.java @@ -269,15 +269,15 @@ public class TrackTileEntity extends SmartTileEntity implements ITransformableTE } @Override - public void setRemoved() { - super.setRemoved(); + public void invalidate() { + super.invalidate(); if (level.isClientSide) removeFromCurveInteraction(); } @Override - protected void setRemovedNotDueToChunkUnload() { - super.setRemovedNotDueToChunkUnload(); + public void remove() { + super.remove(); for (BezierConnection connection : connections.values()) manageFakeTracksAlong(connection, true); diff --git a/src/main/java/com/simibubi/create/foundation/block/ITE.java b/src/main/java/com/simibubi/create/foundation/block/ITE.java index e6debdd82..c79d96ee0 100644 --- a/src/main/java/com/simibubi/create/foundation/block/ITE.java +++ b/src/main/java/com/simibubi/create/foundation/block/ITE.java @@ -34,6 +34,21 @@ public interface ITE extends EntityBlock { .orElse(InteractionResult.PASS); } + /** + * if the ITE is bound to a SmartTileEntity, which implements destroy(),
+ * call this method in BlockBehaviour::onRemove (replace super call) + */ + public static void onRemove(BlockState blockState, Level level, BlockPos pos, BlockState newBlockState) { + if (!blockState.hasBlockEntity()) + return; + if (blockState.is(newBlockState.getBlock()) && newBlockState.hasBlockEntity()) + return; + BlockEntity blockEntity = level.getBlockEntity(pos); + if (blockEntity instanceof SmartTileEntity ste) + ste.destroy(); + level.removeBlockEntity(pos); + } + default Optional getTileEntityOptional(BlockGetter world, BlockPos pos) { return Optional.ofNullable(getTileEntity(world, pos)); } diff --git a/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java b/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java index a88966147..9e8e1fba0 100644 --- a/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java +++ b/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java @@ -3,14 +3,10 @@ package com.simibubi.create.foundation.data; import com.google.common.base.Supplier; import com.google.gson.JsonElement; import com.simibubi.create.AllSoundEvents; -import com.simibubi.create.Create; import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.ponder.PonderLocalization; -import com.simibubi.create.foundation.utility.FilesHelper; import com.simibubi.create.foundation.utility.Lang; -import java.util.List; - public enum AllLangPartials implements ILangPartial { ADVANCEMENTS("Advancements", AllAdvancements::provideLangEntries), diff --git a/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java b/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java index f74d44fe8..0bbf4dd6a 100644 --- a/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java +++ b/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java @@ -5,8 +5,6 @@ import com.google.gson.JsonElement; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.FilesHelper; -import java.util.List; - public interface ILangPartial { String getDisplay(); 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 817b785d7..fb5e886ec 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java @@ -33,6 +33,7 @@ public abstract class SmartTileEntity extends CachedRenderBBTileEntity implement private boolean firstNbtRead = true; protected int lazyTickRate; protected int lazyTickCounter; + private boolean chunkUnloaded; // Used for simulating this TE in a client-only setting private boolean virtualMode; @@ -118,32 +119,37 @@ public abstract class SmartTileEntity extends CachedRenderBBTileEntity implement read(tag, false); } - /* - * 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() { - forEachBehaviour(TileEntityBehaviour::remove); + chunkUnloaded = true; } @Override - public void setRemoved() { + public final void setRemoved() { super.setRemoved(); + if (!chunkUnloaded) + remove(); + invalidate(); + } - if (!unloaded) { - setRemovedNotDueToChunkUnload(); - } + /** + * Block destroyed or Chunk unloaded. Usually invalidates capabilities + */ + public void invalidate() { + forEachBehaviour(TileEntityBehaviour::unload); + } + + /** + * Block destroyed or picked up by a contraption. Usually detaches kinetics + */ + public void remove() {} + + /** + * Block destroyed or replaced. Requires Block to call ITE::onRemove + */ + public void destroy() { + forEachBehaviour(TileEntityBehaviour::destroy); } @Override @@ -186,7 +192,7 @@ public abstract class SmartTileEntity extends CachedRenderBBTileEntity implement protected void removeBehaviour(BehaviourType type) { TileEntityBehaviour remove = behaviours.remove(type); if (remove != null) { - remove.remove(); + remove.unload(); } } @@ -202,6 +208,10 @@ public abstract class SmartTileEntity extends CachedRenderBBTileEntity implement public boolean isVirtual() { return virtualMode; } + + public boolean isChunkUnloaded() { + return chunkUnloaded; + } @Override public boolean canPlayerUse(Player player) { diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/TileEntityBehaviour.java b/src/main/java/com/simibubi/create/foundation/tileEntity/TileEntityBehaviour.java index a0a1cec8e..4bfe34160 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/TileEntityBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/TileEntityBehaviour.java @@ -61,13 +61,15 @@ public abstract class TileEntityBehaviour { } - public void remove() { + /** + * Block destroyed or Chunk unloaded. Usually invalidates capabilities + */ + public void unload() {} - } - - public void destroy() { - - } + /** + * Block destroyed or removed. Requires block to call ITE::onRemove + */ + public void destroy() {} public void setLazyTickRate(int slowTickRate) { this.lazyTickRate = slowTickRate; @@ -96,13 +98,6 @@ public abstract class TileEntityBehaviour { return get(te, type); } - public static void destroy(BlockGetter reader, BlockPos pos, - BehaviourType type) { - T behaviour = get(reader.getBlockEntity(pos), type); - if (behaviour != null) - behaviour.destroy(); - } - public static T get(BlockEntity te, BehaviourType type) { if (te == null) return null; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java index 565518ec4..72410381a 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java @@ -136,8 +136,8 @@ public class SmartFluidTankBehaviour extends TileEntityBehaviour { } @Override - public void remove() { - super.remove(); + public void unload() { + super.unload(); capability.invalidate(); } diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/linked/LinkBehaviour.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/linked/LinkBehaviour.java index 320e2a805..bd189938c 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/linked/LinkBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/linked/LinkBehaviour.java @@ -19,6 +19,7 @@ import com.simibubi.create.foundation.utility.Couple; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; @@ -115,8 +116,8 @@ public class LinkBehaviour extends TileEntityBehaviour implements IRedstoneLinka } @Override - public void remove() { - super.remove(); + public void unload() { + super.unload(); if (getWorld().isClientSide) return; getHandler().removeFromNetwork(getWorld(), this); @@ -208,7 +209,15 @@ public class LinkBehaviour extends TileEntityBehaviour implements IRedstoneLinka @Override public boolean isAlive() { - return !tileEntity.isRemoved() && getWorld().getBlockEntity(getPos()) == tileEntity; + Level level = getWorld(); + BlockPos pos = getPos(); + if (tileEntity.isChunkUnloaded()) + return false; + if (tileEntity.isRemoved()) + return false; + if (!level.isLoaded(pos)) + return false; + return level.getBlockEntity(pos) == tileEntity; } @Override