From eabfead5daa6f1c40e25a6cd994e5536b38f5232 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 22:45:06 +0100 Subject: [PATCH] Update TNTSimulator once again Signed-off-by: yoyosource --- .../features/simulator/TNTSimulator.java | 75 +++++++++++++------ 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index eb8d028c..ad07eac8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -54,6 +54,10 @@ public class TNTSimulator { private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); + private static final Vector FX_VECTOR = new Vector(1, 0, 0); + private static final Vector FY_VECTOR = new Vector(0, 1, 0); + private static final Vector FZ_VECTOR = new Vector(0, 0, 1); + private static final World WORLD = Bukkit.getWorlds().get(0); private static final List LORE = Collections.singletonList("§eZum Ändern klicken"); private static final List EMPTY = new ArrayList<>(); @@ -215,7 +219,10 @@ public class TNTSimulator { return new SWListInv.SWListEntry<>(swItem, spawn); }).sorted(Comparator.comparing(SWListInv.SWListEntry::getObject)).collect(Collectors.toList()); - SWListInv swListInv = new SWListInv<>(player, "Kanonensimulator", false, swListEntryList, (clickType, spawn) -> spawn.editTNT()); + SWListInv swListInv = new SWListInv<>(player, "Kanonensimulator", false, swListEntryList, (clickType, spawn) -> { + + spawn.editTNT(); + }); swListInv.setItem(51, new SWItem(Material.BARRIER, "§cTNT löschen", clickType -> { delete(); player.closeInventory(); @@ -307,6 +314,7 @@ public class TNTSimulator { private boolean printed = false; private final Vector position; + private int fuseTicks = 80; private int count = 1; private int tickOffset = 0; private boolean xVelocity = false; @@ -324,6 +332,7 @@ public class TNTSimulator { private TNTSpawn(YAPIONObject yapionObject) { this.position = new Vector(yapionObject.getPlainValueOrDefault("positionX", 0.0), yapionObject.getPlainValueOrDefault("positionY", 0.0), yapionObject.getPlainValueOrDefault("positionZ", 0.0)); this.entity = SimulatorEntityShowMode.createEntity(player, position, false); + this.fuseTicks = yapionObject.getPlainValue("fuseTicks"); this.count = yapionObject.getPlainValue("count"); this.tickOffset = yapionObject.getPlainValue("tickOffset"); this.xVelocity = yapionObject.getPlainValue("xVelocity"); @@ -337,6 +346,7 @@ public class TNTSimulator { yapionObject.add("positionX", position.getX()); yapionObject.add("positionY", position.getY()); yapionObject.add("positionZ", position.getZ()); + yapionObject.add("fuseTicks", fuseTicks); yapionObject.add("count", count); yapionObject.add("tickOffset", tickOffset); yapionObject.add("xVelocity", xVelocity); @@ -362,12 +372,19 @@ public class TNTSimulator { private void spawn() { WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); }); } + private void setFuseTicks(int fuseTicks) { + if (fuseTicks < 0) fuseTicks = 0; + if (fuseTicks > 160) fuseTicks = 160; + this.fuseTicks = fuseTicks; + } + private void setCount(int count) { if (count < 1) count = 1; if (count > 400) count = 400; @@ -396,8 +413,8 @@ public class TNTSimulator { SWInventory swInventory = new SWInventory(player, 54, "TNT konfigurieren"); // Change Count of spawned TNT - swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { - setCount(count + 1); + swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e-10"), false, clickType -> { + setCount(count + (clickType.isShiftClick() ? 10 : 1)); editTNT(); })); SWItem countItem = new SWItem(Material.TNT, "§7TNT-Anzahl §8- §e" + count, LORE, false, clickType -> changeCount(player, "Anzahl TNT", count, c -> { @@ -406,14 +423,14 @@ public class TNTSimulator { }, this::editTNT)); countItem.getItemStack().setAmount(count); swInventory.setItem(10, countItem); - swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { - setCount(count - 1); + swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-10"), false, clickType -> { + setCount(count - (clickType.isShiftClick() ? 10 : 1)); editTNT(); })); // Change TickOffset - swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { - setTickOffset(tickOffset + 1); + swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { + setTickOffset(count + (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), "§7Tick §8- §e" + tickOffset, LORE, false, clickType -> changeCount(player, "Tick Offset", tickOffset, tick -> { @@ -422,8 +439,24 @@ public class TNTSimulator { }, this::editTNT)); tickItem.getItemStack().setAmount(Math.max(tickOffset, 1)); swInventory.setItem(11, tickItem); - swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { - setTickOffset(tickOffset - 1); + swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { + setTickOffset(count - (clickType.isShiftClick() ? 5 : 1)); + editTNT(); + })); + + // Change FuseTicks + swInventory.setItem(3, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { + setFuseTicks(fuseTicks + 1); + editTNT(); + })); + SWItem fuseTickItem = new SWItem(Material.CLOCK, "§7Lebensdauer §8- §e" + fuseTicks, LORE, false, clickType -> changeCount(player, "Fuse-Ticks", fuseTicks, tick -> { + setFuseTicks(tick); + editTNT(); + }, this::editTNT)); + fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1)); + swInventory.setItem(12, fuseTickItem); + swInventory.setItem(21, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { + setFuseTicks(fuseTicks - 1); editTNT(); })); @@ -445,8 +478,8 @@ public class TNTSimulator { // Position Settings // X Position - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { - position.add(X_VECTOR); + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { + position.add(clickType.isShiftClick() ? FX_VECTOR : X_VECTOR); editTNT(); })); swInventory.setItem(14, new SWItem(Material.PAPER, "§7x-Position §8- §e" + position.getX(), LORE, false, clickType -> { @@ -455,14 +488,14 @@ public class TNTSimulator { editTNT(); }, this::editTNT); })); - swInventory.setItem(23, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { - position.subtract(X_VECTOR); + swInventory.setItem(23, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? FX_VECTOR : X_VECTOR); editTNT(); })); // Y Position - swInventory.setItem(6, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { - position.add(Y_VECTOR); + swInventory.setItem(6, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { + position.add(clickType.isShiftClick() ? FY_VECTOR : Y_VECTOR); editTNT(); })); swInventory.setItem(15, new SWItem(Material.PAPER, "§7y-Position §8- §e" + position.getY(), LORE, false, clickType -> { @@ -471,14 +504,14 @@ public class TNTSimulator { editTNT(); }, this::editTNT); })); - swInventory.setItem(24, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { - position.subtract(Y_VECTOR); + swInventory.setItem(24, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? FY_VECTOR : Y_VECTOR); editTNT(); })); // Z Position - swInventory.setItem(7, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { - position.add(Z_VECTOR); + swInventory.setItem(7, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { + position.add(clickType.isShiftClick() ? FZ_VECTOR : Z_VECTOR); editTNT(); })); swInventory.setItem(16, new SWItem(Material.PAPER, "§7z-Position §8- §e" + position.getZ(), LORE, false, clickType -> { @@ -487,8 +520,8 @@ public class TNTSimulator { editTNT(); }, this::editTNT); })); - swInventory.setItem(25, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { - position.subtract(Z_VECTOR); + swInventory.setItem(25, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? FZ_VECTOR : Z_VECTOR); editTNT(); }));