Search in sources :

Example 1 with ThreadLocalEngineWorld

use of thpmc.engine.api.world.cache.local.ThreadLocalEngineWorld 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));
}
Also used : EngineLocation(thpmc.engine.api.world.EngineLocation) ThreadLocalEngineWorld(thpmc.engine.api.world.cache.local.ThreadLocalEngineWorld) EngineEntity(thpmc.engine.api.entity.EngineEntity) Location(org.bukkit.Location) EngineLocation(thpmc.engine.api.world.EngineLocation)

Aggregations

Location (org.bukkit.Location)1 EngineEntity (thpmc.engine.api.entity.EngineEntity)1 EngineLocation (thpmc.engine.api.world.EngineLocation)1 ThreadLocalEngineWorld (thpmc.engine.api.world.cache.local.ThreadLocalEngineWorld)1