From c369662a28f89a756e311d1aec9997b3885fa268 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 2 Apr 2024 22:35:27 +0200 Subject: [PATCH] Fixed #227 and made subpixelalignment more user friendly --- .../simulator/data/tnt/TNTElement.java | 33 ++++---- .../gui/SimulatorGroupSettingsGui.java | 76 +++++++++++++------ .../gui/SimulatorTNTSettingsGui.java | 35 +++++---- 3 files changed, 88 insertions(+), 56 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java index 29e90d83..bb3a659d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/data/tnt/TNTElement.java @@ -26,12 +26,17 @@ import de.steamwar.bausystem.features.simulator.gui.SimulatorTNTGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.SWItem; +import lombok.Getter; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.util.Vector; public final class TNTElement extends SimulatorElement { + public static final double SUB_PIXEL = 0.0999999046326; + @Getter + private final Vector alignment = new Vector(); + public TNTElement(Vector position) { super(Material.TNT, position); } @@ -47,26 +52,16 @@ public final class TNTElement extends SimulatorElement { position.setZ(position.getZ() + z); } - public void align(Vector offset) { - if (offset.getX() != 0) { - if (position.getX() - (int) position.getX() == 0.49) { - position.setX(position.getX() + 0.02); - } - if (position.getX() - (int) position.getX() == -0.49) { - position.setX(position.getX() - 0.02); - } - position.setX(position.getBlockX() + offset.getX()); - } + public void alignX(int direction) { + position.setX(position.getX() - SUB_PIXEL * alignment.getX()); + alignment.setX(direction); + position.setX(position.getX() + SUB_PIXEL * alignment.getX()); + } - if (offset.getZ() != 0) { - if (position.getZ() - (int) position.getZ() == 0.49) { - position.setZ(position.getZ() + 0.02); - } - if (position.getZ() - (int) position.getZ() == -0.49) { - position.setZ(position.getZ() - 0.02); - } - position.setZ(position.getBlockZ() + offset.getZ()); - } + public void alignZ(int direction) { + position.setZ(position.getZ() - SUB_PIXEL * alignment.getZ()); + alignment.setZ(direction); + position.setZ(position.getZ() + SUB_PIXEL * alignment.getZ()); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java index e9439ce9..0a66e21d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGroupSettingsGui.java @@ -97,41 +97,69 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui { if (allTNT) { // Subpixel Alignment inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { - simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { - tnt.align(new Vector(0.5, 0, 0.5)); - }); + simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .forEach(tntElement -> { + tntElement.alignX(0); + tntElement.alignZ(0); + }); SimulatorWatcher.update(simulator); })); // Z - inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { - simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { - tnt.align(new Vector(0, 0, 0.49)); - }); + SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .forEach(tntElement -> { + if (tntElement.getAlignment().getZ() != -1) tntElement.alignZ(-1); + }); SimulatorWatcher.update(simulator); - })); + }); + negativZItem.setEnchanted(simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .allMatch(tntElement -> tntElement.getAlignment().getZ() == -1)); + inventory.setItem(20, negativZItem); - inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { - simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { - tnt.align(new Vector(0, 0, 0.51)); - }); + SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .forEach(tntElement -> { + if (tntElement.getAlignment().getZ() != 1) tntElement.alignZ(1); + }); SimulatorWatcher.update(simulator); - })); + }); + positivZItem.setEnchanted(simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .allMatch(tntElement -> tntElement.getAlignment().getZ() == 1)); + inventory.setItem(22, positivZItem); // X - inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { - simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { - tnt.align(new Vector(0.49, 0, 0)); - }); - SimulatorWatcher.update(simulator); - })); + SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .forEach(tntElement -> { + if (tntElement.getAlignment().getX() != -1) tntElement.alignX(-1); + }); - inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { - simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> { - tnt.align(new Vector(0.51, 0, 0)); - }); SimulatorWatcher.update(simulator); - })); + }); + negativXItem.setEnchanted(simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .allMatch(tntElement -> tntElement.getAlignment().getX() == -1)); + inventory.setItem(12, negativXItem); + + SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .forEach(tntElement -> { + if (tntElement.getAlignment().getX() != 1) tntElement.alignX(1); + }); + SimulatorWatcher.update(simulator); + }); + positivXItem.setEnchanted(simulatorGroup.getElements().stream() + .map(TNTElement.class::cast) + .allMatch(tntElement -> tntElement.getAlignment().getX() == -1)); + inventory.setItem(30, positivXItem); } //Pos X diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java index 1dcf005c..24dbb22e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorTNTSettingsGui.java @@ -99,31 +99,40 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // Subpixel Alignment inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { - tnt.align(new Vector(0.5, 0, 0.5)); + tnt.alignX(0); + tnt.alignZ(0); SimulatorWatcher.update(simulator); })); // Z - inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { - tnt.align(new Vector(0, 0, 0.49)); + SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { + if (tnt.getAlignment().getZ() != -1) tnt.alignZ(-1); SimulatorWatcher.update(simulator); - })); + }); + negativZItem.setEnchanted(tnt.getAlignment().getZ() == -1); + inventory.setItem(20, negativZItem); - inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { - tnt.align(new Vector(0, 0, 0.51)); + SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { + if (tnt.getAlignment().getZ() != 1) tnt.alignZ(1); SimulatorWatcher.update(simulator); - })); + }); + positivZItem.setEnchanted(tnt.getAlignment().getZ() == 1); + inventory.setItem(22, positivZItem); // X - inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { - tnt.align(new Vector(0.49, 0, 0)); + SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { + if (tnt.getAlignment().getX() != -1) tnt.alignX(-1); SimulatorWatcher.update(simulator); - })); + }); + negativXItem.setEnchanted(tnt.getAlignment().getX() == -1); + inventory.setItem(12, negativXItem); - inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { - tnt.align(new Vector(0.51, 0, 0)); + SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { + if(tnt.getAlignment().getX() != 1) tnt.alignX(1); SimulatorWatcher.update(simulator); - })); + }); + positivXItem.setEnchanted(tnt.getAlignment().getX() == 1); + inventory.setItem(30, positivXItem); // Pos X inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {