diff --git a/docs/migration/DIVERGENCES.md b/docs/migration/DIVERGENCES.md index d8e1888..8dee5d9 100644 --- a/docs/migration/DIVERGENCES.md +++ b/docs/migration/DIVERGENCES.md @@ -19,7 +19,8 @@ of the later upstream rename, not a divergence from the `1.7.12` reference. | Area | Difference and consequence | | --- | --- | -| Raw microblock recipe material lookup | Skips `MissingMicroMaterial`, whose recovery item is stone, so sawing stone selects the real stone material. Existing missing-material microblocks retain their recovery behavior. This fixes a pre-existing Scala bug. | +| Raw microblock recipe material lookup | Skips `MissingMicroMaterial`, whose recovery item is stone, so sawing stone selects the real stone material. Existing missing-material microblocks retain their recovery behavior. This fixes a pre-existing Scala bug, also fixed upstream in PR #61. | +| Client part additions | Reuses an existing multipart tile or creates one without converting the stale client block. Conversion and its outgoing packets remain server-side, avoiding duplicate parts and client disconnects. Matches upstream PR #62. | | `BlockMicroMaterial.createAndRegister(Block, Seq, String)` | Registers every supplied metadata value instead of only zero, including dark-oak logs and leaves and their legacy-name remaps. This fixes a pre-existing Scala bug; material IDs are rebuilt through the existing registry mapping. | | Chunk scheduled-tick restoration | Reactivates chunks with restored scheduled ticks so their callbacks resume at the saved deadlines. The Scala implementation restored entries without activating their chunk. NBT layout and duplicate-scheduling behavior are unchanged. | | World scheduler clock loading | Retains successfully loaded `schedTime` instead of overwriting it with total world time. Missing or unreadable files still fall back to world time. This fixes a pre-existing Scala bug and preserves the clock used by saved absolute tick deadlines; the file format is unchanged. | diff --git a/src/functionalTest/java/codechicken/multipart/test/MultipartGeneratorFunctionalTest.java b/src/functionalTest/java/codechicken/multipart/test/MultipartGeneratorFunctionalTest.java index eefde22..802562f 100644 --- a/src/functionalTest/java/codechicken/multipart/test/MultipartGeneratorFunctionalTest.java +++ b/src/functionalTest/java/codechicken/multipart/test/MultipartGeneratorFunctionalTest.java @@ -28,6 +28,7 @@ import codechicken.multipart.MultipartGenerator; import codechicken.multipart.MultipartGenerator$; import codechicken.multipart.TMultiPart; import codechicken.multipart.TSlottedPart; +import codechicken.multipart.TileCache; import codechicken.multipart.TileMultipart; import codechicken.multipart.TileMultipartClient; import codechicken.multipart.asm.MultipartMixinFactory; @@ -175,6 +176,39 @@ public class MultipartGeneratorFunctionalTest { } } + @Test + void clientAdditionsReplaceStaleConvertibleBlocksWithoutConvertingThem() { + World world = MinecraftServer.getServer().worldServers[0]; + BlockCoord pos = new BlockCoord(51, 200, 48); + world.getChunkFromBlockCoords(pos.x, pos.z); + world.setBlock(pos.x, pos.y - 1, pos.z, Blocks.stone, 0, 0); + world.setBlock(pos.x, pos.y, pos.z, Blocks.torch, 5, 0); + boolean wasRemote = world.isRemote; + TileCache.FlaggedTile cached = TileCache.map().get(pos); + try { + // The server-started test event is synchronous; restore the side before any server tick. + world.isRemote = true; + PlainPart first = new PlainPart(); + TileMultipart tile = MultipartGenerator$.MODULE$.addPart(world, pos, first); + assertTrue(tile instanceof TileMultipartClient); + assertSame(MultipartProxy.block(), world.getBlock(pos.x, pos.y, pos.z)); + assertSame(tile, world.getTileEntity(pos.x, pos.y, pos.z)); + assertEquals(Collections.singletonList(first), tile.jPartList()); + assertSame(tile, first.tile()); + + PlainPart second = new PlainPart(); + assertSame(tile, MultipartGenerator$.MODULE$.addPart(world, pos, second)); + assertEquals(Arrays.asList(first, second), tile.jPartList()); + assertSame(tile, second.tile()); + } finally { + world.isRemote = wasRemote; + world.setBlockToAir(pos.x, pos.y, pos.z); + world.setBlockToAir(pos.x, pos.y - 1, pos.z); + if (cached == null) TileCache.map().remove(pos); + else TileCache.map().put(pos, cached); + } + } + @Test void frozenScalaConsumerLinksCompanionGenerationAndDefaultPassThroughRegistration() throws Exception { byte[] bytes; diff --git a/src/main/scala/codechicken/multipart/MultipartGenerator$.java b/src/main/scala/codechicken/multipart/MultipartGenerator$.java index 12cc568..eefb4c6 100644 --- a/src/main/scala/codechicken/multipart/MultipartGenerator$.java +++ b/src/main/scala/codechicken/multipart/MultipartGenerator$.java @@ -105,14 +105,16 @@ public final class MultipartGenerator$ implements ScratchBitSet { /** Replaces the tile if the new part requires additional interfaces, then adds the part. */ public TileMultipart addPart(World world, BlockCoord pos, TMultiPart part) { - Tuple2 convertedTile = TileMultipart.getOrConvertTile2(world, pos); + Tuple2 convertedTile = world.isRemote + ? new Tuple2<>(TileMultipart.getTile(world, pos), Boolean.FALSE) + : TileMultipart.getOrConvertTile2(world, pos); TileMultipart tile = convertedTile._1(); boolean converted = (Boolean) convertedTile._2(); BitSet bitset = setTraits(part, world.isRemote); TileMultipart next = tile; if (next != null) { - if (converted) { + if (converted) { // Server-side conversion, then tell the clients. next.partList().apply(0).invalidateConvertedTile(); world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block(), 0, 0); silentAddTile(world, pos, next);