From 120d3e23f2b77252e10be0b2defa30b4cd51d4e9 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 4 Sep 2022 14:08:53 -0500 Subject: [PATCH] Fix #545 by creating Tags.WATER --- .../movecraft/async/AsyncManager.java | 2 +- .../movecraft/craft/BaseCraft.java | 8 +++--- .../movecraft/listener/BlockListener.java | 25 ++++++++++--------- .../movecraft/sign/StatusSign.java | 2 +- .../movecraft/craft/type/CraftType.java | 4 +-- .../net/countercraft/movecraft/util/Tags.java | 7 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/AsyncManager.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/AsyncManager.java index fddbe78fa..4d7e1024f 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/AsyncManager.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/AsyncManager.java @@ -624,7 +624,7 @@ public CraftStatus checkCraftStatus(@NotNull Craft craft) { if (type != Material.FIRE && !type.isAir()) { totalNonNegligibleBlocks++; } - if (type != Material.FIRE && !type.isAir() && type != Material.WATER) { + if (type != Material.FIRE && !type.isAir() && !Tags.FLUID.contains(type)) { totalNonNegligibleWaterBlocks++; } diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java index ce630bf88..90266b0b2 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java @@ -480,7 +480,7 @@ public int getWaterLine() { posZ = hitBox.getMinZ() - 1; for (posX = hitBox.getMinX() - 1; posX <= hitBox.getMaxX() + 1; posX++) { Material material = w.getBlockAt(posX, posY, posZ).getType(); - if (material == Material.WATER) + if (Tags.WATER.contains(material)) numWater++; if (material.isAir()) numAir++; @@ -488,7 +488,7 @@ public int getWaterLine() { posZ = hitBox.getMaxZ() + 1; for (posX = hitBox.getMinX() - 1; posX <= hitBox.getMaxX() + 1; posX++) { Material material = w.getBlockAt(posX, posY, posZ).getType(); - if (material == Material.WATER) + if (Tags.WATER.contains(material)) numWater++; if (material.isAir()) numAir++; @@ -496,7 +496,7 @@ public int getWaterLine() { posX = hitBox.getMinX() - 1; for (posZ = hitBox.getMinZ(); posZ <= hitBox.getMaxZ(); posZ++) { Material material = w.getBlockAt(posX, posY, posZ).getType(); - if (material == Material.WATER) + if (Tags.WATER.contains(material)) numWater++; if (material.isAir()) numAir++; @@ -504,7 +504,7 @@ public int getWaterLine() { posX = hitBox.getMaxX() + 1; for (posZ = hitBox.getMinZ(); posZ <= hitBox.getMaxZ(); posZ++) { Material material = w.getBlockAt(posX, posY, posZ).getType(); - if (material == Material.WATER) + if (Tags.WATER.contains(material)) numWater++; if (material.isAir()) numAir++; diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java index 1667a63c9..557838a68 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java @@ -84,15 +84,16 @@ public void onItemSpawn(final ItemSpawnEvent e) { // prevent water and lava from spreading on moving crafts @EventHandler(priority = EventPriority.HIGHEST) public void onBlockFromTo(BlockFromToEvent e) { - if (e.isCancelled()) { + if (e.isCancelled()) return; - } + Block block = e.getToBlock(); - if (block.getType() != Material.WATER && block.getType() != Material.LAVA) { + if (!Tags.FLUID.contains(block.getType())) return; - } + + MovecraftLocation location = MathUtils.bukkit2MovecraftLoc(block.getLocation()); for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) { - if ((!tcraft.isNotProcessing()) && MathUtils.locIsNearCraftFast(tcraft, MathUtils.bukkit2MovecraftLoc(block.getLocation()))) { + if ((!tcraft.isNotProcessing()) && MathUtils.locIsNearCraftFast(tcraft, location)) { e.setCancelled(true); return; } @@ -162,7 +163,7 @@ public void onPhysics(BlockPhysicsEvent event) { if (!MathUtils.locIsNearCraftFast(tcraft, mloc)) { continue; } - if(Tags.FRAGILE_MATERIALS.contains(event.getBlock().getType())) { + if (Tags.FRAGILE_MATERIALS.contains(event.getBlock().getType())) { BlockData m = block.getBlockData(); BlockFace face = BlockFace.DOWN; boolean faceAlwaysDown = block.getType() == Material.COMPARATOR || block.getType() == Material.REPEATER; @@ -191,15 +192,15 @@ public void onBlockDispense(BlockDispenseEvent e) { } @EventHandler - public void onFlow(BlockFromToEvent e){ - if(Settings.DisableSpillProtection) + public void onFlow(BlockFromToEvent e) { + if (Settings.DisableSpillProtection) return; - if(!e.getBlock().isLiquid()) + if (!e.getBlock().isLiquid()) return; MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation()); MovecraftLocation toLoc = MathUtils.bukkit2MovecraftLoc(e.getToBlock().getLocation()); - for(Craft craft : CraftManager.getInstance().getCraftsInWorld(e.getBlock().getWorld())){ - if(craft.getHitBox().contains((loc)) && !craft.getFluidLocations().contains(toLoc)) { + for (Craft craft : CraftManager.getInstance().getCraftsInWorld(e.getBlock().getWorld())) { + if (craft.getHitBox().contains((loc)) && !craft.getFluidLocations().contains(toLoc)) { e.setCancelled(true); break; } @@ -210,7 +211,7 @@ public void onFlow(BlockFromToEvent e){ public void onIceForm(BlockFormEvent e) { if (e.isCancelled() || !Settings.DisableIceForm) return; - if(e.getBlock().getType() != Material.WATER) + if (Tags.WATER.contains(e.getBlock().getType())) return; MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation()); diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/sign/StatusSign.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/sign/StatusSign.java index 3e2cfff90..654e90547 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/sign/StatusSign.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/sign/StatusSign.java @@ -72,7 +72,7 @@ public final void onSignTranslate(SignTranslateEvent event) { } int add = materials.get(material); totalNonNegligibleBlocks += add; - if (!material.equals(Material.WATER)) { + if (!Tags.WATER.contains(material)) { totalNonNegligibleWaterBlocks += add; } } diff --git a/modules/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java b/modules/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java index e2493af21..1fed41645 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java @@ -600,7 +600,7 @@ else if (o instanceof Integer) return data; var passthroughBlocks = data.get(PASSTHROUGH_BLOCKS); - passthroughBlocks.add(Material.WATER); + passthroughBlocks.addAll(Tags.WATER); data.put(PASSTHROUGH_BLOCKS, passthroughBlocks); return data; }); @@ -610,7 +610,7 @@ else if (o instanceof Integer) return data; var forbiddenHoverOverBlocks = data.get(FORBIDDEN_HOVER_OVER_BLOCKS); - forbiddenHoverOverBlocks.add(Material.WATER); + forbiddenHoverOverBlocks.addAll(Tags.WATER); data.put(FORBIDDEN_HOVER_OVER_BLOCKS, forbiddenHoverOverBlocks); return data; }); diff --git a/modules/api/src/main/java/net/countercraft/movecraft/util/Tags.java b/modules/api/src/main/java/net/countercraft/movecraft/util/Tags.java index 11048a092..c19737573 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/util/Tags.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/util/Tags.java @@ -14,8 +14,8 @@ import java.util.Set; public class Tags { - - public static final EnumSet FLUID = EnumSet.of(Material.WATER, Material.LAVA); + public static final EnumSet WATER = EnumSet.of(Material.WATER, Material.BUBBLE_COLUMN); + public static final EnumSet FLUID = EnumSet.of(Material.WATER, Material.BUBBLE_COLUMN, Material.LAVA); public static final EnumSet CHESTS = EnumSet.of(Material.CHEST, Material.TRAPPED_CHEST, Material.BARREL); public static final EnumSet FURNACES = EnumSet.of(Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER); public static final EnumSet SINKING_PASSTHROUGH = EnumSet.of(Material.TALL_GRASS, Material.GRASS); @@ -34,8 +34,6 @@ public class Tags { FRAGILE_MATERIALS.addAll(Tag.WOODEN_PRESSURE_PLATES.getValues()); FALL_THROUGH_BLOCKS.add(Material.AIR); - FALL_THROUGH_BLOCKS.add(Material.WATER); - FALL_THROUGH_BLOCKS.add(Material.LAVA); FALL_THROUGH_BLOCKS.add(Material.DEAD_BUSH); FALL_THROUGH_BLOCKS.addAll(Tag.CORAL_PLANTS.getValues()); FALL_THROUGH_BLOCKS.add(Material.BROWN_MUSHROOM); @@ -51,6 +49,7 @@ public class Tags { FALL_THROUGH_BLOCKS.add(Material.CARROT); FALL_THROUGH_BLOCKS.add(Material.POTATO); FALL_THROUGH_BLOCKS.addAll(Tag.FENCES.getValues()); + FALL_THROUGH_BLOCKS.addAll(FLUID); } @Nullable