Add automatic migration API to BlockDummyable

This commit is contained in:
abel1502 2025-06-29 01:02:43 +03:00
parent 41d62c49db
commit 4a869ae2ea
No known key found for this signature in database
GPG Key ID: 076926596A536338

View File

@ -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) {