diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java index 7ea6ac31..e87640d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java @@ -136,37 +136,27 @@ public class TNTElementGUI { // Alignment inv.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_Z", player), clickType -> { // Z negative if (clickType == ClickType.DOUBLE_CLICK) return; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.5, 0, 0.49)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.5, 0, 0.49)); tntElement.change(); })); inv.setItem(25, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_Z", player), clickType -> { // Z positive if (clickType == ClickType.DOUBLE_CLICK) return; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.5, 0, 0.51)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.5, 0, 0.51)); tntElement.change(); })); inv.setItem(15, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_X", player), clickType -> { // X positive if (clickType == ClickType.DOUBLE_CLICK) return; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.51, 0, 0.5)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.51, 0, 0.5)); tntElement.change(); })); inv.setItem(33, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_X", player), clickType -> { // X negative if (clickType == ClickType.DOUBLE_CLICK) return; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.49, 0, 0.5)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.49, 0, 0.5)); tntElement.change(); })); inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER if (clickType == ClickType.DOUBLE_CLICK) return; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.5, 0, 0.5)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.5, 0, 0.5)); tntElement.change(); })); }; @@ -179,25 +169,6 @@ public class TNTElementGUI { inv.open(); } - private void align(Vector vector, Vector offset) { - if (vector.getX() - (int) vector.getX() == 0.49) { - vector.setX(vector.getX() + 0.02); - } - if (vector.getX() - (int) vector.getX() == -0.49) { - vector.setX(vector.getX() - 0.02); - } - if (vector.getZ() - (int) vector.getZ() == 0.49) { - vector.setZ(vector.getZ() + 0.02); - } - if (vector.getZ() - (int) vector.getZ() == -0.49) { - vector.setZ(vector.getZ() - 0.02); - } - - vector.setX(vector.getBlockX() + offset.getX()); - vector.setY(vector.getBlockY() + offset.getY()); - vector.setZ(vector.getBlockZ() + offset.getZ()); - } - private void editProperties(Player player, TNTElement tntElement, Runnable back) { SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_PROPERTIES", player)); if (back != null) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java index e7b358a9..af6e3045 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java @@ -285,4 +285,31 @@ public class TNTElement implements SimulatorElement { this.disabled = disabled; _updatePosition(); } + + public void align(Vector offset) { + Vector vector = getPosition(); + Vector parentVector = new Vector(0, 0, 0); + if (tntGroup != null) { + parentVector = tntGroup.getPosition(); + } + + if (vector.getX() - (int) vector.getX() == 0.49) { + vector.setX(vector.getX() + 0.02); + } + if (vector.getX() - (int) vector.getX() == -0.49) { + vector.setX(vector.getX() - 0.02); + } + if (vector.getZ() - (int) vector.getZ() == 0.49) { + vector.setZ(vector.getZ() + 0.02); + } + if (vector.getZ() - (int) vector.getZ() == -0.49) { + vector.setZ(vector.getZ() - 0.02); + } + + vector.setX(vector.getBlockX() + offset.getX()); + vector.setY(vector.getBlockY() + offset.getY()); + vector.setZ(vector.getBlockZ() + offset.getZ()); + + setPosition(vector.subtract(parentVector)); + } }