From f465d551bf9c37a38763c6fce91467c2236ac443 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 29 Dec 2023 17:29:47 +0100 Subject: [PATCH] Add option to hide REntities --- .../src/de/steamwar/entity/REntity.java | 15 +++++++++++++++ .../src/de/steamwar/entity/REntityServer.java | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 1868c26..fad5851 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -59,6 +59,8 @@ public class REntity { private byte pitch; private byte headYaw; + @Getter + private boolean hidden; @Getter private boolean invisible; @Getter @@ -104,6 +106,19 @@ public class REntity { this.objectData = objectData; } + public void hide(boolean hide) { + if(hidden == hide) + return; + + if(hide) { + despawn(packet -> server.updateEntity(this, packet)); + hidden = true; + } else { + hidden = false; + spawn(packet -> server.updateEntity(this, packet)); + } + } + public void move(Location location) { move(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), rotToByte(location.getYaw())); } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 721f429..c3b7fb8 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -138,7 +138,8 @@ public class REntityServer implements Listener { if(fromId == toId) return; - onMissing(players.get(fromId), players.get(toId), entity::despawn); + if(!entity.isHidden()) + onMissing(players.get(fromId), players.get(toId), entity::despawn); removeEntityFromChunk(entity); } @@ -149,10 +150,14 @@ public class REntityServer implements Listener { return; addEntityToChunk(entity); - onMissing(players.get(toId), players.get(fromId), entity::spawn); + if(!entity.isHidden()) + onMissing(players.get(toId), players.get(fromId), entity::spawn); } void updateEntity(REntity entity, Object packet) { + if(entity.isHidden()) + return; + for(Player player : players.getOrDefault(entityToId(entity), emptyPlayers)) { TinyProtocol.instance.sendPacket(player, packet); } @@ -260,7 +265,8 @@ public class REntityServer implements Listener { long id = chunkToId(x, z); players.computeIfAbsent(id, i -> new HashSet<>()).add(player); for(REntity entity : entities.getOrDefault(id, emptyEntities)) { - entity.spawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); + if(!entity.isHidden()) + entity.spawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); } } @@ -273,7 +279,8 @@ public class REntityServer implements Listener { players.remove(id); for(REntity entity : entities.getOrDefault(id, emptyEntities)) { - entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); + if(!entity.isHidden()) + entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); } }