From 3d585074fdcc49e61395d51e60a6ee23217ca188 Mon Sep 17 00:00:00 2001 From: LordIdra Date: Wed, 15 Apr 2026 04:52:30 +0100 Subject: [PATCH 1/3] fix pylon#569 --- .../pylonmc/rebar/logistics/CargoRoutes.kt | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt index 55c323193..c9680714c 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt @@ -7,6 +7,8 @@ import io.github.pylonmc.rebar.event.RebarBlockBreakEvent import io.github.pylonmc.rebar.event.RebarBlockLoadEvent import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent +import io.github.pylonmc.rebar.event.RebarCargoConnectEvent +import io.github.pylonmc.rebar.event.RebarCargoDisconnectEvent import io.github.pylonmc.rebar.logistics.CargoRoutes.blockRoutesCache import io.github.pylonmc.rebar.util.IMMEDIATE_FACES import io.github.pylonmc.rebar.util.position.BlockPosition @@ -67,10 +69,13 @@ object CargoRoutes : Listener { val previous = source.block.block.position var current = previous.getRelative(source.face) val routeBlocks = mutableListOf(source.block.block.position) - var endpoint: CargoRouteEndpoint? = null // 42 70 -37 + var endpoint: CargoRouteEndpoint? = null while (current.chunk.isLoaded) { routeBlocks.add(current) + for (face in IMMEDIATE_FACES) { + routeBlocks.add(current.getRelative(face)) + } val currentBlock = BlockStorage.get(current.block) if (currentBlock is CargoDuct) { @@ -117,19 +122,16 @@ object CargoRoutes : Listener { val blocks = routeBlocksCache.remove(source) if (blocks != null) { for (block in blocks) { - blockRoutesCache.remove(block) + blockRoutesCache[block]!!.remove(source) } } routeCache.remove(source) } - private fun invalidateRouteCachesForBlock(block: Block) { - val routes = blockRoutesCache[block.position] - if (routes == null) { - return - } + internal fun invalidateRouteCachesForBlock(block: Block) { + val routes = blockRoutesCache[block.position] ?: return - for (routeSource in routes) { + for (routeSource in routes.toList()) { invalidateRouteCache(routeSource) } } @@ -153,4 +155,17 @@ object CargoRoutes : Listener { private fun onBlockUnloaded(event: RebarBlockUnloadEvent) { invalidateRouteCachesForBlock(event.block) } + + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockLoaded(event: RebarCargoConnectEvent) { + invalidateRouteCachesForBlock(event.block1.block) + invalidateRouteCachesForBlock(event.block2.block) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockUnloaded(event: RebarCargoDisconnectEvent) { + invalidateRouteCachesForBlock(event.block1.block) + invalidateRouteCachesForBlock(event.block2.block) + } } \ No newline at end of file From fce3a9d4a158abf84b78cb4c42b4a0a5bb2ccff7 Mon Sep 17 00:00:00 2001 From: LordIdra Date: Wed, 15 Apr 2026 05:25:53 +0100 Subject: [PATCH 2/3] Add error message if multiblock returns no chunks --- .../kotlin/io/github/pylonmc/rebar/block/MultiblockCache.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/MultiblockCache.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/MultiblockCache.kt index 7d57fbd4e..0ba350a01 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/MultiblockCache.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/MultiblockCache.kt @@ -113,7 +113,9 @@ internal object MultiblockCache : Listener { } private fun onMultiblockAdded(multiblock: RebarMultiblock) { - for (chunk in multiblock.chunksOccupied) { + val chunks = multiblock.chunksOccupied + check(!chunks.isEmpty()) { "Your multiblock must occupy at least one chunk" } + for (chunk in chunks) { multiblocksWithComponentsInChunk.getOrPut(chunk) { mutableSetOf() }.add(multiblock.block.position) } From 7056c7c809b22b1e3cb690e07378828ddf9270ab Mon Sep 17 00:00:00 2001 From: LordIdra Date: Wed, 15 Apr 2026 17:15:00 +0100 Subject: [PATCH 3/3] fix pylon#803 --- .../rebar/block/base/RebarSimpleMultiblock.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt index d0284c7fe..df7d46297 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt @@ -166,9 +166,10 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar val display = BlockDisplayBuilder() .material(materials.first()) .glow(Color.WHITE) - .transformation(TransformBuilder().scale(0.5)) - .displayWidth(0.5f) - .displayHeight(0.5f) + // .51 instead of .5 to prevent z-fighting for half-sized blocks + .transformation(TransformBuilder().scale(0.51)) + .displayWidth(0.51f) + .displayHeight(0.51f) .build(block.location.toCenterLocation()) EntityStorage.add(MultiblockGhostBlock(display, materials.joinToString(", ") { it.key.toString() })) @@ -240,7 +241,8 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar val display = BlockDisplayBuilder() .material(blockDatas.first().material) .glow(Color.WHITE) - .transformation(TransformBuilder().scale(0.5)) + // .51 instead of .5 to prevent z-fighting for half-sized blocks + .transformation(TransformBuilder().scale(0.51)) .build(block.location.toCenterLocation()) EntityStorage.add(MultiblockGhostBlock(display, stringDatas.joinToString(", "))) @@ -302,7 +304,8 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar blockDisplay = BlockDisplayBuilder() .material(blockDatas.first().material) .glow(Color.WHITE) - .transformation(TransformBuilder().scale(0.5)) + // .51 instead of .5 to prevent z-fighting for half-sized blocks + .transformation(TransformBuilder().scale(0.51)) .build(block.location.toCenterLocation()) } @@ -323,7 +326,8 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar itemDisplay = ItemDisplayBuilder() .itemStack(itemBuilder) .glow(Color.WHITE) - .transformation(TransformBuilder().scale(0.5)) + // .51 instead of .5 to prevent z-fighting for half-sized blocks + .transformation(TransformBuilder().scale(0.51)) .build(block.location.toCenterLocation()) } @@ -388,7 +392,8 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar val display = ItemDisplayBuilder() .itemStack(ItemStackBuilder.of(schema.material).addCustomModelDataString(key.toString())) .glow(Color.WHITE) - .transformation(TransformBuilder().scale(0.5)) + // .51 instead of .5 to prevent z-fighting for half-sized blocks + .transformation(TransformBuilder().scale(0.51)) .build(block.location.toCenterLocation()) EntityStorage.add(MultiblockGhostBlock(display, key.toString())) return display.uniqueId