From 70b90b467b13459050c9a9c621947c583e046d2d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 27 Oct 2020 15:50:24 +0100 Subject: [PATCH] This should fix the waterlogged waterremover problem Signed-off-by: Lixfel --- .../fightsystem/utils/WaterRemover_14.java | 20 +++++++++++++++++ .../fightsystem/utils/WaterRemover_8.java | 8 +++++++ .../fightsystem/utils/WaterRemover.java | 22 ++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java index 265d2e3..17260c3 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java @@ -37,4 +37,24 @@ class WaterRemover_14 { return ((Waterlogged) data).isWaterlogged(); } + + static boolean removeWater(Block block){ + if(block.getType() == Material.WATER){ + block.setType(Material.AIR); + return true; + } + + BlockData data = block.getBlockData(); + if(!(data instanceof Waterlogged)) + return false; + + Waterlogged waterlogged = (Waterlogged) data; + if(waterlogged.isWaterlogged()){ + waterlogged.setWaterlogged(false); + block.setBlockData(waterlogged); + return true; + } + + return false; + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java index 0a544df..a510557 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java @@ -29,4 +29,12 @@ public class WaterRemover_8 { Material type = block.getType(); return type == Material.WATER || type == Material.STATIONARY_WATER; } + + static boolean removeWater(Block block){ + if(isWater(block)){ + block.setType(Material.AIR); + return true; + } + return false; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index 8506394..fcff47a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -49,14 +49,15 @@ public class WaterRemover { } private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean { - if(!isWater(b)) + if(!removeWater(b)) return; // If distance to original block is greater than 20 - if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20) + if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20){ + b.setType(Material.WATER); throw new IsAnOcean(); + } - b.setType(Material.AIR); try{ checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); @@ -84,4 +85,19 @@ public class WaterRemover { return WaterRemover_14.isWater(block); } } + + public static boolean removeWater(Block block){ + //checks for water and removes it, if present + switch(Core.getVersion()){ + case 8: + case 9: + case 10: + case 12: + return WaterRemover_8.removeWater(block); + case 14: + case 15: + default: + return WaterRemover_14.removeWater(block); + } + } }