From f067e55d1fe40234c39b55821abf3a488553fa58 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 10 Oct 2023 00:37:19 +0200 Subject: [PATCH] Refactored PhaseGuis --- .../simulator2/data/SimulatorSetting.java | 12 ------ .../gui/SimulatorRedstonePhaseGui.java | 29 +++++--------- .../simulator2/gui/SimulatorTntPhaseGui.java | 38 ++++++------------- 3 files changed, 20 insertions(+), 59 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java index bcea1058..46d5a151 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/data/SimulatorSetting.java @@ -29,16 +29,4 @@ public abstract class SimulatorSetting { protected int tickOffset; protected int lifetime = 80; protected int order = 1; - - public void changeOffset(int tick){ - tickOffset += tick; - } - - public void changeLifetime(int tick){ - lifetime += tick; - } - - public void changeOrder(int tick){ - order += tick; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java index bb06e7cb..fd8b992a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorRedstonePhaseGui.java @@ -66,6 +66,7 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open(); })); + // Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { redstoneElement.getSettings().remove(redstone); back.open(); @@ -75,40 +76,32 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { //Tick Offset int offset = redstone.getTickOffset(); inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.changeOffset(clickType.isShiftClick() ? 5 : 1); + redstone.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); - offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(20, offsetItem); + inventory.setItem(29, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (offset - (clickType.isShiftClick() ? 5 : 1) < 0) { - redstone.changeOffset(-offset); - } else { - redstone.changeOffset(clickType.isShiftClick() ? -5 : -1); - } + redstone.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Lifetime int lifetime = redstone.getLifetime(); inventory.setItem(12, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - redstone.changeLifetime(clickType.isShiftClick() ? 5 : 1); + redstone.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); - lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(21, lifetimeItem); + inventory.setItem(30, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (lifetime - (clickType.isShiftClick() ? 5 : 1) < 0) { - redstone.changeLifetime(-lifetime); - } else { - redstone.changeLifetime(clickType.isShiftClick() ? -5 : -1); - } + redstone.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -120,15 +113,11 @@ public class SimulatorRedstonePhaseGui extends SimulatorBaseGui { }); SWItem orderItem = new SWItem(Material.COMPASS, "§eOrder§8:§7 " + order, clickType -> {}); - orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); inventory.setItem(23, orderItem); + inventory.setItem(32, SWItem.getDye(order > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (order - (clickType.isShiftClick() ? 5 : 1) < 1) { - redstone.changeOrder(-order); - } else { - redstone.changeOrder(clickType.isShiftClick() ? -5 : -1); - } + redstone.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java index 9d732f03..c8a45d1f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator2/gui/SimulatorTntPhaseGui.java @@ -68,6 +68,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); })); + //Delete inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { tntElement.getSettings().remove(tnt); back.open(); @@ -82,55 +83,43 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ }); SWItem countItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + count, clickType -> {}); - countItem.getItemStack().setAmount(Math.max(1, Math.min(count, 64))); inventory.setItem(19, countItem); + inventory.setItem(28, SWItem.getDye(count > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (count - (clickType.isShiftClick() ? 5 : 1) < 1) { - tnt.setCount(1); - } else { - tnt.setCount(count + (clickType.isShiftClick() ? -5 : -1)); - } + tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Tick Offset int offset = tnt.getTickOffset(); inventory.setItem(10, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.changeOffset(clickType.isShiftClick() ? 5 : 1); + tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem offsetItem = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + offset, clickType -> {}); - offsetItem.getItemStack().setAmount(Math.max(1, Math.min(offset, 64))); inventory.setItem(19, offsetItem); + inventory.setItem(28, SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (offset - (clickType.isShiftClick() ? 5 : 1) < 0) { - tnt.changeOffset(-offset); - } else { - tnt.changeOffset(clickType.isShiftClick() ? -5 : -1); - } + tnt.setTickOffset(Math.max(1, offset - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); //Lifetime int lifetime = tnt.getLifetime(); inventory.setItem(11, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { - tnt.changeLifetime(clickType.isShiftClick() ? 5 : 1); + tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); SimulatorWatcher.update(simulator); }); SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {}); - lifetimeItem.getItemStack().setAmount(Math.max(1, Math.min(lifetime, 64))); inventory.setItem(20, lifetimeItem); + inventory.setItem(29, SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (lifetime - (clickType.isShiftClick() ? 5 : 1) < 0) { - tnt.changeLifetime(-lifetime); - } else { - tnt.changeLifetime(clickType.isShiftClick() ? -5 : -1); - } + tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -146,11 +135,7 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ orderItem.getItemStack().setAmount(Math.max(1, Math.min(order, 64))); inventory.setItem(22, orderItem); inventory.setItem(31, SWItem.getDye(order > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { - if (order - (clickType.isShiftClick() ? 5 : 1) < 1) { - tnt.changeOrder(-order); - } else { - tnt.changeOrder(clickType.isShiftClick() ? -5 : -1); - } + tnt.setOrder(Math.max(1, order - (clickType.isShiftClick() ? -5 : -1))); SimulatorWatcher.update(simulator); }); @@ -177,7 +162,6 @@ public class SimulatorTntPhaseGui extends SimulatorBaseGui{ tnt.setJump(!tnt.hasJump()); SimulatorWatcher.update(simulator); }); - - //inventory.setItem(); + inventory.setItem(25, jumpAll); } }