From 8b351fe871adb475bd9f7218a56fd16ebf6d25e1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Jun 2022 19:42:11 +0200 Subject: [PATCH] Add seamless changing and showing and hiding Signed-off-by: yoyosource --- .../bausystem/entities/SimulatorEntity15.java | 14 +++-- .../bausystem/entities/SimulatorEntity18.java | 13 ++--- .../bausystem/entities/SimulatorEntity19.java | 13 ++--- BauSystem_Main/src/BauSystem.properties | 11 ++-- .../features/simulatorn/SimulatorCommand.java | 17 +++++-- .../features/simulatorn/SimulatorCursor.java | 6 ++- .../features/simulatorn/SimulatorStorage.java | 4 ++ .../features/simulatorn/TNTSimulator.java | 51 +++++++++++++++++-- .../simulatorn/TNTSimulatorListener.java | 14 ++--- .../simulatorn/gui/SimulatorSelectionGUI.java | 7 ++- .../show/SimulatorEntityShowMode.java | 2 - .../simulatorn/tnt/SimulatorElement.java | 4 +- .../features/simulatorn/tnt/TNTElement.java | 28 +++++++--- .../features/simulatorn/tnt/TNTGroup.java | 14 +++-- 14 files changed, 136 insertions(+), 62 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java index 10354692..5f828a33 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.entities; import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.shared.BaseEntity15; -import de.steamwar.bausystem.shared.ReferenceCounter; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; @@ -29,7 +28,7 @@ import org.bukkit.util.Vector; public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulatorEntity { - private ReferenceCounter referenceCounter = new ReferenceCounter(); + private boolean printed = false; public SimulatorEntity15(World world, Vector position, boolean highlight) { super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT); @@ -40,9 +39,8 @@ public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulator @Override public void display(Player player) { - if (referenceCounter.increment() > 0) { - return; - } + if (printed) return; + printed = true; sendEntity(player); } @@ -55,9 +53,9 @@ public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulator @Override public boolean hide(Player player, boolean force) { - if (!force && referenceCounter.decrement() > 0) { - return false; - } + if (!printed) return false; + printed = false; + sendEntityDestroy(player); die(); diff --git a/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java b/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java index b3165142..58537b7b 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.entities; import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.shared.BaseEntity18; -import de.steamwar.bausystem.shared.ReferenceCounter; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; @@ -29,7 +28,7 @@ import org.bukkit.util.Vector; public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulatorEntity { - private ReferenceCounter referenceCounter = new ReferenceCounter(); + private boolean printed = false; public SimulatorEntity18(World world, Vector position, boolean highlight) { super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT); @@ -45,9 +44,8 @@ public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulator @Override public void display(Player player) { - if (referenceCounter.increment() > 0) { - return; - } + if (printed) return; + printed = true; sendEntity(player); } @@ -60,9 +58,8 @@ public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulator @Override public boolean hide(Player player, boolean force) { - if (!force && referenceCounter.decrement() > 0) { - return false; - } + if (!printed) return false; + printed = false; sendEntityDestroy(player); ag(); diff --git a/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java index a6aaec75..51d3e6eb 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.entities; import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.shared.BaseEntity19; -import de.steamwar.bausystem.shared.ReferenceCounter; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; @@ -29,7 +28,7 @@ import org.bukkit.util.Vector; public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulatorEntity { - private ReferenceCounter referenceCounter = new ReferenceCounter(); + private boolean printed = false; public SimulatorEntity19(World world, Vector position, boolean highlight) { super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT); @@ -45,9 +44,8 @@ public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulator @Override public void display(Player player) { - if (referenceCounter.increment() > 0) { - return; - } + if (printed) return; + printed = true; sendEntity(player); } @@ -60,9 +58,8 @@ public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulator @Override public boolean hide(Player player, boolean force) { - if (!force && referenceCounter.decrement() > 0) { - return false; - } + if (!printed) return false; + printed = false; sendEntityDestroy(player); ag(); diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index f7833bbe..e886313f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -501,12 +501,15 @@ SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eregion type§7 of the current region UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again # Simulator -SIMULATORN_NO_SIM_IN_HAND = §cNo simulator item selected -SIMULATORN_GUI_SELECT_SIM = Simulator selection - +SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand +SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Change your simulator wand selection +SIMULATOR_CREATE_HELP = §8/§esimulator create §8[§7name§8] §8-§7 Create a new simulator +SIMULATOR_NO_SIM_IN_HAND = §cNo simulator item selected +SIMULATOR_GUI_SELECT_SIM = Simulator selection +SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists +SIMULATOR_CREATE = §aSimulator created SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator -SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand SIMULATOR_START_HELP = §8/§esimulator start §8-§7 Starts the simulation SIMULATOR_GUI_HELP = §8/§esimulator gui §8-§7 Opens the simulator's gui SIMULATOR_DELETE_HELP = §8/§esimulator delete §8-§7 Deletes all TNT diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java index 54435365..cfc083de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java @@ -42,19 +42,30 @@ public class SimulatorCommand extends SWCommand { @Register(description = "SIMULATOR_HELP") public void genericCommand(@Guard Player p) { + SimulatorCursor.hide(p, null); SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p)); } - @Register(value = "change", description = "") - public void changeCommand(@Guard Player p) { + @Register(value = "change", description = "SIMULATOR_CHANGE_HELP") + public void change(@Guard Player p) { ItemStack itemStack = p.getInventory().getItemInMainHand(); if (!ItemUtils.isItem(itemStack, "simulator")) { - BauSystem.MESSAGE.send("SIMULATORN_NO_SIM_IN_HAND", p); + BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p); return; } SimulatorSelectionGUI.open(p, itemStack); } + @Register(value = "create", description = "SIMULATOR_CREATE_HELP") + public void create(@Guard Player p, String name) { + if (SimulatorStorage.getSimulatorNames().contains(name)) { + BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p); + return; + } + SimulatorStorage.createNewSimulator(name); + BauSystem.MESSAGE.send("SIMULATOR_CREATE", p); + } + @ClassGuard(value = Player.class, local = true) public GuardChecker guardChecker() { return (commandSender, guardCheckType, strings, s) -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java index 7136e7c3..f5bc1ce6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java @@ -73,11 +73,13 @@ public class SimulatorCursor { if (cursor != null) cursor.hide(player, false); - tntSimulator.hide(player); + if (tntSimulator != null) { + tntSimulator.remove(player); + } cursors.remove(player); } - private Vector getPos(Player player, RayTraceResult result) { + public static Vector getPos(Player player, RayTraceResult result) { Vector pos = result.getHitPosition(); BlockFace face = result.getHitBlockFace(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java index bf54be8a..403cb48f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java @@ -59,6 +59,10 @@ public class SimulatorStorage implements Enable, Disable { private static Map tntSimulators = new HashMap<>(); + public static void createNewSimulator(String name) { + tntSimulators.put(name, new TNTSimulator()); + } + public static Set getSimulatorNames() { return tntSimulators.keySet(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java index 1ab1cbf2..fb4f19c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java @@ -27,15 +27,13 @@ import lombok.Getter; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Getter @@ -84,6 +82,16 @@ public class TNTSimulator { }); } + public void remove(Player player) { + SimulatorEntityShowMode showMode = playerShowMode.remove(player); + if (showMode == null) { + return; + } + tntElementList.forEach(simulatorElement -> { + simulatorElement.hide(showMode); + }); + } + public void hide(Player player, List simulatorElements) { SimulatorEntityShowMode showMode = playerShowMode.get(player); if (showMode == null) { @@ -108,8 +116,41 @@ public class TNTSimulator { public List getEntity(Entity entity) { List tntSpawns = new ArrayList<>(); for (SimulatorElement spawn : tntElementList) { - spawn.getEntity(tntSpawns, new Vector(0, 0, 0), entity); + spawn.getEntity(tntSpawns, entity); } return tntSpawns; } + + public void edit(Player player, RayTraceResult result) { + if (result == null) { + // TODO: Open gui + return; + } + + SimulatorCursor.show(player, this, result); + + if (result.getHitEntity() != null) { + return; + } + + /* + if (result.getHitEntity() != null) { + List tntSpawns = getEntity(result.getHitEntity()); + if (tntSpawns.isEmpty()) { + return; + } + if (tntSpawns.size() == 1) { + tntSpawns.get(0).editTNT(spawns); + } else { + showGUI(new HashSet<>(tntSpawns)); + } + return; + } + */ + + tntElementList.add(new TNTElement(SimulatorCursor.getPos(player, result))); + playerShowMode.forEach((p, simulatorEntityShowMode) -> { + show(p); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java index 060718a3..b31305d3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.ItemUtils; import org.bukkit.FluidCollisionMode; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -54,6 +55,10 @@ public class TNTSimulatorListener implements Listener { } static RayTraceResult trace(Player player, Location to, TNTSimulator simulator) { + if (player.getGameMode() == GameMode.SPECTATOR) { + return null; + } + Location startPos = to.clone().add(0.0, player.getEyeHeight(), 0.0); Vector direction = to.getDirection(); RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true); @@ -89,7 +94,7 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent e) { - simulatorShowHide(e.getPlayer(), ignore -> null, PlayerInventory::getItemInMainHand, e.getTo()); + simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo()); } @EventHandler @@ -99,9 +104,7 @@ public class TNTSimulatorListener implements Listener { private void simulatorShowHide(Player player, Function oldItemFunction, Function newItemFunction, Location location) { TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory())); - if (oldSimulator != null) { - SimulatorCursor.hide(player, oldSimulator); - } + SimulatorCursor.hide(player, oldSimulator); TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory())); if (simulator == null) { @@ -136,9 +139,8 @@ public class TNTSimulatorListener implements Listener { if (simulator == null) { SimulatorSelectionGUI.open(event.getPlayer(), event.getItem()); } else { - + simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator)); } - // get(event.getPlayer()).edit(trace(event.getPlayer(), event.getPlayer().getLocation())); break; default: break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java index 72e1c75e..1ff4a4aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java @@ -43,9 +43,14 @@ public class SimulatorSelectionGUI { swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator)); } - SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATORN_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> { + SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> { + TNTSimulator current = SimulatorStorage.getSimulator(hand); + if (current != null) { + current.remove(player); + } SimulatorStorage.setSimulator(hand, tntSimulator); player.getInventory().setItemInMainHand(hand); + player.closeInventory(); }); // TODO: Add button to create new simulator with AnvilGUI diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java index a88c8bbc..2e73405e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java @@ -25,8 +25,6 @@ import de.steamwar.bausystem.shared.Position; import de.steamwar.bausystem.shared.RoundedPosition; import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.bausystem.utils.NMSWrapper; -import org.bukkit.World; -import org.bukkit.entity.Panda; import org.bukkit.entity.Player; import org.bukkit.util.Vector; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java index 7c3f42cc..8d5ca08a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java @@ -33,7 +33,7 @@ public interface SimulatorElement { YAPIONObject toYAPION(); List getEntities(); - void getEntity(List elements, Vector origin, Entity entity); + void getEntity(List elements, Entity entity); default Vector getPosition() { return new Vector(0, 0, 0); } @@ -42,5 +42,5 @@ public interface SimulatorElement { void hide(SimulatorEntityShowMode showMode); ItemStack menu(); - void locations(Map>> result, Vector origin, int tickOffset); // Ticks to subtick order to spawning runnable to count of activations + void locations(Map>> result); // Ticks to subtick order to spawning runnable to count of activations } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java index c7645c30..57263b68 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java @@ -24,9 +24,9 @@ import de.steamwar.bausystem.features.simulatorn.SimulatorStorage; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Position; +import lombok.Getter; import org.bukkit.Material; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; @@ -37,9 +37,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +@Getter public class TNTElement implements SimulatorElement { private final AbstractSimulatorEntity entity; + TNTGroup tntGroup = null; private final Vector position; private int fuseTicks = 80; @@ -92,25 +94,35 @@ public class TNTElement implements SimulatorElement { } @Override - public void getEntity(List elements, Vector origin, Entity entity) { - if (this.entity.getId() == entity.getEntityId() || position.clone().add(origin).equals(entity.getLocation().toVector())) { + public void getEntity(List elements, Entity entity) { + if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) { elements.add(this); } } @Override public Vector getPosition() { + if (tntGroup != null) { + return tntGroup.getPosition().clone().add(position); + } return position.clone(); } + protected int getTickOffset() { + if (tntGroup != null) { + return tntGroup.getTickOffset() + tickOffset; + } + return tickOffset; + } + @Override public void show(SimulatorEntityShowMode showMode) { - showMode.show(new Position(position)); + showMode.show(new Position(getPosition())); } @Override public void hide(SimulatorEntityShowMode showMode) { - showMode.hide(); + showMode.hide(new Position(getPosition())); } @Override @@ -119,10 +131,10 @@ public class TNTElement implements SimulatorElement { } @Override - public void locations(Map>> result, Vector origin, int tickOffset) { - result.computeIfAbsent(this.tickOffset + tickOffset, ignore -> new HashMap<>()) + public void locations(Map>> result) { + result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) .computeIfAbsent(order, ignore -> new Pair<>(() -> { - SimulatorStorage.WORLD.spawn(position.clone().add(origin).toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> { + SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> { tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java index 1f46be25..b01d8023 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulatorn.tnt; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; +import lombok.Getter; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; @@ -33,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +@Getter public class TNTGroup implements SimulatorElement { private final Vector position; @@ -50,7 +52,9 @@ public class TNTGroup implements SimulatorElement { this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL")); YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray()); for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) { - this.elements.add(new TNTElement(element)); + TNTElement tntElement = new TNTElement(element); + tntElement.tntGroup = this; + this.elements.add(tntElement); } } @@ -76,9 +80,9 @@ public class TNTGroup implements SimulatorElement { } @Override - public void getEntity(List elements, Vector origin, Entity entity) { + public void getEntity(List elements, Entity entity) { for (TNTElement tntElement : this.elements) { - tntElement.getEntity(elements, origin, entity); + tntElement.getEntity(elements, entity); } } @@ -102,9 +106,9 @@ public class TNTGroup implements SimulatorElement { } @Override - public void locations(Map>> result, Vector origin, int tickOffset) { + public void locations(Map>> result) { elements.forEach(tntElement -> { - tntElement.locations(result, origin.clone().add(position), this.tickOffset + tickOffset); + tntElement.locations(result); }); } }