From 497b5ab882ad32c65acee8c1f4d82fc4d6afaf53 Mon Sep 17 00:00:00 2001 From: rasmus123d <59487370+RasmusKD@users.noreply.github.com> Date: Sun, 16 Aug 2026 15:18:32 +0200 Subject: [PATCH] Probe only the six direct faces when diagonal pipes are disabled With allow-diagonal off (the default), every pipe block still walked all 27 neighbour offsets and skipped 21 of them one comparison at a time. The six cardinal faces are now probed directly, in the same order the full scan visited them, and the neighbour expansion is extracted into a method shared with the diagonal path. No behaviour change, just less work per pipe block. --- .../sk89q/craftbook/mechanics/pipe/Pipes.java | 126 ++++++++++-------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java b/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java index 3b6c9f4aa..55c05d20b 100644 --- a/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java +++ b/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java @@ -241,6 +241,17 @@ private void searchNearbyPipes(Block block, Set visitedPipes, List visitedPipes, List visitedPipes, List visitedPipes, Deque searchQueue) { + Block off = bl.getRelative(x, y, z); + Material offType = off.getType(); + + if (!isValidPipeBlock(offType)) return; + + if (visitedPipes.contains(off.getLocation().toVector())) return; + visitedPipes.add(off.getLocation().toVector()); + + if(ItemUtil.isStainedGlass(blType) && ItemUtil.isStainedGlass(offType) && blType != offType) return; + + if(offType == Material.GLASS || ItemUtil.isStainedGlass(offType)) { + searchQueue.add(off); + } else if (offType == Material.GLASS_PANE || ItemUtil.isStainedGlassPane(offType)) { + Block offsetBlock = off.getRelative(x, y, z); + Material offsetBlockType = offsetBlock.getType(); + if (!isValidPipeBlock(offsetBlockType)) return; + if (visitedPipes.contains(offsetBlock.getLocation().toVector())) return; + if(ItemUtil.isStainedGlassPane(offType)) { + if((ItemUtil.isStainedGlass(blType) + || ItemUtil.isStainedGlassPane(blType)) && ItemUtil.getStainedColor(offType) != ItemUtil + .getStainedColor(offsetBlockType) + || (ItemUtil.isStainedGlass(offsetBlockType) + || ItemUtil.isStainedGlassPane(offsetBlockType)) && ItemUtil.getStainedColor(offType) != ItemUtil + .getStainedColor(offsetBlockType)) return; + } + visitedPipes.add(offsetBlock.getLocation().toVector()); + searchQueue.add(off.getRelative(x, y, z)); + } else if(offType == Material.PISTON) + searchQueue.addFirst(off); //Pistons are treated with higher priority. + } + private static boolean isValidPipeBlock(Material type) { return switch (type) { case GLASS, PISTON, STICKY_PISTON, DROPPER, GLASS_PANE -> true;