use of thpmc.engine.api.world.EngineLocation in project THP-Engine by TheHollowPlanetMC.
the class EntityTracker method tick.
public void tick(Set<EngineEntity> entities) {
tick++;
// Collect tracking entities
if (tick % TRACK_INTERVAL == 0) {
Location pl = enginePlayer.getBukkitPlayer().getLocation();
int playerChunkX = pl.getBlockX() >> 4;
int playerChunkZ = pl.getBlockZ() >> 4;
int drawDistance = enginePlayer.getEntityDrawDistance();
ThreadLocalEngineWorld world = tickRunner.getThreadLocalCache().getWorld(Objects.requireNonNull(pl.getWorld()).getName());
for (EngineEntity entity : entities) {
EngineLocation location = entity.getLocation();
if (location.getWorld() != world) {
continue;
}
int entityChunkX = location.getBlockX() >> 4;
int entityChunkZ = location.getBlockZ() >> 4;
if (Math.abs(entityChunkX - playerChunkX) + Math.abs(entityChunkZ - playerChunkZ) <= drawDistance) {
// in range
if (!trackedEntities.contains(entity) && trackedEntities.size() <= (enginePlayer.getEntityTrackLimit() / THPEngineAPI.getInstance().getTickRunnerPool().getPoolSize())) {
entity.show(enginePlayer);
trackedEntities.add(entity);
}
} else {
// out range
if (trackedEntities.contains(entity)) {
entity.hide(enginePlayer);
trackedEntities.remove(entity);
}
}
}
}
// Show tick result
boolean absolute = tick % ABSOLUTE_PACKET_INTERVAL == 0;
trackedEntities.forEach(engineEntity -> engineEntity.playTickResult(enginePlayer, absolute));
}
Aggregations