From fce5b9c4934c42c2cfc3069c53edd0b67b09ad54 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 21:39:00 +0100 Subject: [PATCH] Hotfix some more stuff Signed-off-by: yoyosource --- .../features/simulator/tnt/TNTElement.java | 23 +++++++++++-------- .../features/simulator/tnt/TNTGroup.java | 7 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) 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 df762600..fadffe21 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 @@ -50,7 +50,8 @@ public class TNTElement implements SimulatorElement { private static final World WORLD = Bukkit.getWorlds().get(0); - private final RFallingBlockEntity entity; + private final REntityServer entityServer; + private RFallingBlockEntity entity; TNTGroup tntGroup = null; private final Vector position; @@ -71,12 +72,14 @@ public class TNTElement implements SimulatorElement { private boolean disabled = false; public TNTElement(Vector position, REntityServer entityServer) { + this.entityServer = entityServer; this.position = position; this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); this.entity.setNoGravity(true); } public TNTElement(YAPIONObject yapionObject, REntityServer entityServer) { + this.entityServer = entityServer; this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0))); this.disabled = yapionObject.getBooleanOrDefault("disabled", false); this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); @@ -119,7 +122,7 @@ public class TNTElement implements SimulatorElement { @Override public void getEntity(List elements, REntity entity) { if (disabled) return; - if (this.entity.getEntityId() == entity.getEntityId() || getPosition().equals(new Vector(entity.getX(), entity.getY(), entity.getZ()))) { + if (this.entity.getEntityId() == entity.getEntityId() || getPosition().distanceSquared(new Vector(entity.getX(), entity.getY(), entity.getZ())) < 0.01) { elements.add(this); } } @@ -141,8 +144,12 @@ public class TNTElement implements SimulatorElement { } void _updatePosition() { - Vector position = getPosition(); - entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0); + if (disabled || (getParent() != null && getParent().isDisabled())) { + entity.move(-200000, 0, -200000, 0F, 0F, (byte) 0); + } else { + Vector position = getPosition(); + entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0); + } } public int getTickOffset() { @@ -172,7 +179,7 @@ public class TNTElement implements SimulatorElement { lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); } SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, disabled, null); - if (!disabled) swItem.getItemStack().setAmount(tntCount()); + if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1)); return swItem; } @@ -271,10 +278,6 @@ public class TNTElement implements SimulatorElement { public void setDisabled(boolean disabled) { this.disabled = disabled; - entity.setInvisible(disabled); - } - - void _setDisabled(boolean disabled) { - entity.setInvisible(disabled); + _updatePosition(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java index 3ab48778..9485cefa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java @@ -62,6 +62,7 @@ public class TNTGroup implements SimulatorElement { TNTElement tntElement = new TNTElement(element, entityServer); tntElement.tntGroup = this; this.elements.add(tntElement); + tntElement._updatePosition(); } } @@ -135,7 +136,7 @@ public class TNTGroup implements SimulatorElement { lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); } SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, disabled, null); - if (!disabled) swItem.getItemStack().setAmount(tntCount()); + if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1)); return swItem; } @@ -181,8 +182,6 @@ public class TNTGroup implements SimulatorElement { public void setDisabled(boolean disabled) { this.disabled = disabled; - elements.forEach(tntElement -> { - tntElement._setDisabled(disabled); - }); + elements.forEach(TNTElement::_updatePosition); } }