From 4a869ae2ea3a5926508b5f8936aa93e9cff2479d Mon Sep 17 00:00:00 2001 From: abel1502 Date: Sun, 29 Jun 2025 01:02:43 +0300 Subject: [PATCH] Add automatic migration API to BlockDummyable --- .../java/com/hbm/blocks/BlockDummyable.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/hbm/blocks/BlockDummyable.java b/src/main/java/com/hbm/blocks/BlockDummyable.java index 9508350b5..0d7fa08b4 100644 --- a/src/main/java/com/hbm/blocks/BlockDummyable.java +++ b/src/main/java/com/hbm/blocks/BlockDummyable.java @@ -77,27 +77,20 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl super.onNeighborBlockChange(world, x, y, z, block); - if(world.isRemote || safeRem) + if(safeRem) return; - int metadata = world.getBlockMetadata(x, y, z); - - // if it's an extra, remove the extra-ness - if(metadata >= extra) - metadata -= extra; - - ForgeDirection dir = ForgeDirection.getOrientation(metadata).getOpposite(); - Block b = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ); - - if(b != this) { - world.setBlockToAir(x, y, z); - } + destroyIfOrphan(world, x, y, z); } public void updateTick(World world, int x, int y, int z, Random rand) { super.updateTick(world, x, y, z, rand); + destroyIfOrphan(world, x, y, z); + } + + private void destroyIfOrphan(World world, int x, int y, int z) { if(world.isRemote) return; @@ -111,9 +104,26 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl Block b = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ); if(b != this) { - world.setBlockToAir(x, y, z); + if (isLegacyMonoblock(world, x, y, z)) { + fixLegacyMonoblock(world, x, y, z); + } else { + world.setBlockToAir(x, y, z); + } } + } + // Override this when turning a single block into a pseudo-multiblock. + // If this returns true, instead of being deleted as an orphan, the block + // will be promoted to a core of a dummyable, however without any dummies. + // This is only called if the block is presumed an orphan, so you don't + // need to check that here. + protected boolean isLegacyMonoblock(World world, int x, int y, int z) { + return false; + } + + protected void fixLegacyMonoblock(World world, int x, int y, int z) { + // Promote to a lone core block with the same effective rotation as before the change + world.setBlockMetadataWithNotify(x, y, z, offset + world.getBlockMetadata(x, y, z), 3); } public int[] findCore(World world, int x, int y, int z) {