Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }))

Expand Down Expand Up @@ -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(", ")))

Expand Down Expand Up @@ -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())
}

Expand All @@ -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())
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,10 +69,13 @@ object CargoRoutes : Listener {
val previous = source.block.block.position
var current = previous.getRelative(source.face)
val routeBlocks = mutableListOf<BlockPosition>(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) {
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Loading