From 9c3560a3ff792a135fff456d4b4f3c896561aa83 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 6 Feb 2022 13:29:25 +0100 Subject: [PATCH] Update blast resistance mode Signed-off-by: yoyosource --- .../slaves/laufbau/BlockBoundingBox.java | 4 +++ .../features/slaves/laufbau/Cuboid.java | 8 ++++- .../features/slaves/laufbau/Laufbau.java | 19 ++++------- .../states/CreatingInnerBlocksState.java | 32 ++++++++----------- .../laufbau/states/ExpandingTracesState.java | 5 ++- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/BlockBoundingBox.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/BlockBoundingBox.java index 9ce54018..db8514ef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/BlockBoundingBox.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/BlockBoundingBox.java @@ -40,6 +40,10 @@ public class BlockBoundingBox { public BlockData blockData; public Cuboid cuboid; + public double volume() { + return cuboid.getDx() * cuboid.getDy() * cuboid.getDz(); + } + static { addPixel(Material.AIR.createBlockData(), 0, 0, 0, 0, 0, 0); addPixel(Material.END_STONE.createBlockData(), 0, 0, 0, 16, 16, 16); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java index 862c3af5..0a039c98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Cuboid.java @@ -34,7 +34,13 @@ public class Cuboid { private double dz; public boolean intersects(Cuboid cuboid) { - return expand(cuboid).hasInside(cuboid); + double minx = x - cuboid.dx; + double miny = y - cuboid.dy; + double minz = z - cuboid.dz; + double maxx = minx + dx + cuboid.dx; + double maxy = miny + dy + cuboid.dy; + double maxz = minz + dz + cuboid.dz; + return maxx > cuboid.x && maxy > cuboid.y && maxz > cuboid.z && minx < cuboid.x && miny < cuboid.y && minz < cuboid.z; } public Cuboid add(Point point) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java index 4f957289..2ce9c527 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java @@ -65,20 +65,13 @@ public class Laufbau { editSession = WorldEditUtils.getEditSession(world); if (preferingBlastResistance) { - elements.sort(Comparator.comparing(blockBoundingBox -> { - double element = 1; - if (blockBoundingBox.cuboid.getDx() != 0) { - element *= blockBoundingBox.cuboid.getDx(); + elements.sort((o1, o2) -> { + int compared = Double.compare(o1.blockData.getMaterial().getBlastResistance(), o2.blockData.getMaterial().getBlastResistance()); + if (compared != 0) { + return -compared; } - if (blockBoundingBox.cuboid.getDy() != 0) { - element *= blockBoundingBox.cuboid.getDy(); - } - if (blockBoundingBox.cuboid.getDz() != 0) { - element *= blockBoundingBox.cuboid.getDz(); - } - element *= blockBoundingBox.blockData.getMaterial().getBlastResistance(); - return -element; - })); + return -Double.compare(o1.volume(), o2.volume()); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java index 33ea8410..050534f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java @@ -95,23 +95,19 @@ public class CreatingInnerBlocksState implements LaufbauState { return; } - Cuboid currentHighest = blockDataWithBoundingBoxList.get(0).cuboid; - BlockData highestBlockData = blockDataWithBoundingBoxList.get(0).blockData; + BlockBoundingBox highest = blockDataWithBoundingBoxList.get(0); - for (BlockBoundingBox blockDataWithBoundingBox : blockDataWithBoundingBoxList) { - if (currentHighest.getDx() < blockDataWithBoundingBox.cuboid.getDx() && - currentHighest.getDy() < blockDataWithBoundingBox.cuboid.getDy() && - currentHighest.getDz() < blockDataWithBoundingBox.cuboid.getDz()) { - currentHighest = blockDataWithBoundingBox.cuboid; - highestBlockData = blockDataWithBoundingBox.blockData; - } - if (preferingBlastResistance) { - if (highestBlockData.getMaterial().getBlastResistance() < blockDataWithBoundingBox.blockData.getMaterial().getBlastResistance() && - (currentHighest.getDx() >= blockDataWithBoundingBox.cuboid.getDx() || - currentHighest.getDy() >= blockDataWithBoundingBox.cuboid.getDy() || - currentHighest.getDz() >= blockDataWithBoundingBox.cuboid.getDz())) { - currentHighest = blockDataWithBoundingBox.cuboid; - highestBlockData = blockDataWithBoundingBox.blockData; + if (!preferingBlastResistance) { + for (BlockBoundingBox blockDataWithBoundingBox : blockDataWithBoundingBoxList) { + if (highest.volume() < blockDataWithBoundingBox.volume()) { + highest = blockDataWithBoundingBox; + } + if (preferingBlastResistance) { + if (highest.blockData.getMaterial().getBlastResistance() < blockDataWithBoundingBox.blockData.getMaterial().getBlastResistance()) { + if (highest.volume() > blockDataWithBoundingBox.volume()) { + highest = blockDataWithBoundingBox; + } + } } } } @@ -120,8 +116,8 @@ public class CreatingInnerBlocksState implements LaufbauState { return; } try { - editSession.setBlock(BukkitAdapter.asBlockVector(location), BukkitAdapter.adapt(highestBlockData)); - location.getBlock().setBlockData(highestBlockData, false); + editSession.setBlock(BukkitAdapter.asBlockVector(location), BukkitAdapter.adapt(highest.blockData)); + location.getBlock().setBlockData(highest.blockData, false); } catch (MaxChangedBlocksException e) { e.printStackTrace(); // ignored diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java index 073965ba..595b828b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java @@ -28,7 +28,10 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.function.BiPredicate; public class ExpandingTracesState implements LaufbauState {