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;