forked from SteamWar/SteamWar
Do not hide entities with the BauSystem hullhider
HullHider gets a hideEntities parameter: the fight still hides entities inside hidden hulls, /hullhider only hides blocks. As the TechHider also dropped spawn packets at hidden positions, ForPlayer#canAccessEntitySpawn decides about them now, which the BauTechHider always allows.
This commit is contained in:
@@ -42,10 +42,18 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public class HullHider<K> implements Listener {
|
||||
|
||||
private final boolean hideEntities;
|
||||
private final Map<K, Hull> hullMap = new LinkedHashMap<>();
|
||||
// Read on netty threads, replaced on every change
|
||||
private volatile Hull[] hulls = new Hull[0];
|
||||
|
||||
/**
|
||||
* @param hideEntities whether entities and REntities inside the hidden part of a hull are hidden from non-viewers as well
|
||||
*/
|
||||
public HullHider(boolean hideEntities) {
|
||||
this.hideEntities = hideEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hull hides everything from non-viewers until it is initialised.
|
||||
*/
|
||||
@@ -157,6 +165,8 @@ public class HullHider<K> implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDeath(EntityDeathEvent e) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.removeEntity(e.getEntity());
|
||||
}
|
||||
@@ -166,6 +176,8 @@ public class HullHider<K> implements Listener {
|
||||
* Has to be called every tick for every entity, as entities can move into or out of the hidden part of a hull.
|
||||
*/
|
||||
public void checkEntity(Entity entity) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.checkEntity(entity);
|
||||
}
|
||||
@@ -181,12 +193,16 @@ public class HullHider<K> implements Listener {
|
||||
}
|
||||
|
||||
public void updateREntity(REntity e) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.checkREntity(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void despawnREntity(REntity e) {
|
||||
if (!hideEntities) return;
|
||||
|
||||
for (Hull hull : hulls) {
|
||||
hull.removeREntity(e);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,13 @@ public interface AccessPrivilegeProvider {
|
||||
|
||||
boolean canAccessEntity(int entityId);
|
||||
|
||||
/**
|
||||
* @return whether the player may see the entity spawning at this position
|
||||
*/
|
||||
default boolean canAccessEntitySpawn(int entityId, int blockX, int blockY, int blockZ) {
|
||||
return canAccessEntity(entityId) && canAccessPosition(blockX, blockY, blockZ);
|
||||
}
|
||||
|
||||
boolean canAccessBlockEntity(int blockX, int blockY, int blockZ, BlockEntityType<?> type);
|
||||
|
||||
/**
|
||||
|
||||
@@ -372,7 +372,7 @@ public class TechHider {
|
||||
}
|
||||
|
||||
private Packet<? extends PacketListener> processAddEntityPacket(ForPlayer access, ClientboundAddEntityPacket packet) {
|
||||
if (access.canAccessEntity(packet.getId()) && access.canAccessPosition(Mth.floor(packet.getX()), Mth.floor(packet.getY()), Mth.floor(packet.getZ()))) {
|
||||
if (access.canAccessEntitySpawn(packet.getId(), Mth.floor(packet.getX()), Mth.floor(packet.getY()), Mth.floor(packet.getZ()))) {
|
||||
return packet;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user