SteamWar/SpigotCore
Archiviert
13
0

Add option to hide REntities
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-12-29 17:29:47 +01:00
Ursprung 0051f09409
Commit f465d551bf
2 geänderte Dateien mit 26 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -59,6 +59,8 @@ public class REntity {
private byte pitch; private byte pitch;
private byte headYaw; private byte headYaw;
@Getter
private boolean hidden;
@Getter @Getter
private boolean invisible; private boolean invisible;
@Getter @Getter
@ -104,6 +106,19 @@ public class REntity {
this.objectData = objectData; 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) { public void move(Location location) {
move(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), rotToByte(location.getYaw())); move(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), rotToByte(location.getYaw()));
} }

Datei anzeigen

@ -138,7 +138,8 @@ public class REntityServer implements Listener {
if(fromId == toId) if(fromId == toId)
return; return;
onMissing(players.get(fromId), players.get(toId), entity::despawn); if(!entity.isHidden())
onMissing(players.get(fromId), players.get(toId), entity::despawn);
removeEntityFromChunk(entity); removeEntityFromChunk(entity);
} }
@ -149,10 +150,14 @@ public class REntityServer implements Listener {
return; return;
addEntityToChunk(entity); 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) { void updateEntity(REntity entity, Object packet) {
if(entity.isHidden())
return;
for(Player player : players.getOrDefault(entityToId(entity), emptyPlayers)) { for(Player player : players.getOrDefault(entityToId(entity), emptyPlayers)) {
TinyProtocol.instance.sendPacket(player, packet); TinyProtocol.instance.sendPacket(player, packet);
} }
@ -260,7 +265,8 @@ public class REntityServer implements Listener {
long id = chunkToId(x, z); long id = chunkToId(x, z);
players.computeIfAbsent(id, i -> new HashSet<>()).add(player); players.computeIfAbsent(id, i -> new HashSet<>()).add(player);
for(REntity entity : entities.getOrDefault(id, emptyEntities)) { 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); players.remove(id);
for(REntity entity : entities.getOrDefault(id, emptyEntities)) { 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));
} }
} }