Search in sources :

Example 6 with EngineChunk

use of thpmc.engine.api.world.cache.EngineChunk in project THP-Engine by TheHollowPlanetMC.

the class EngineEntity method setPosition.

public void setPosition(double x, double y, double z) {
    int previousBlockX = NumberConversions.floor(this.x);
    int previousBlockY = NumberConversions.floor(this.y);
    int previousBlockZ = NumberConversions.floor(this.z);
    int nextBlockX = NumberConversions.floor(x);
    int nextBlockY = NumberConversions.floor(y);
    int nextBlockZ = NumberConversions.floor(z);
    int previousChunkX = previousBlockX >> 4;
    int previousChunkZ = previousBlockZ >> 4;
    int nextChunkX = nextBlockX >> 4;
    int nextChunkZ = nextBlockZ >> 4;
    int previousSectionIndex = ChunkUtil.getSectionIndex(previousBlockY);
    int nextSectionIndex = ChunkUtil.getSectionIndex(nextBlockY);
    // Moving between chunks
    if (!(previousChunkX == nextChunkX && previousChunkZ == nextChunkZ) || previousSectionIndex != nextSectionIndex) {
        if (chunk == null) {
            chunk = world.getChunkAt(previousChunkX, previousChunkZ);
            // unload chunk teleport cancel
            if (chunk == null)
                return;
        }
        Set<EngineEntity> previousEntityList = chunk.getEntitiesInSection(previousSectionIndex);
        EngineChunk nextChunk;
        if (previousChunkX != nextChunkX || previousChunkZ != nextChunkZ) {
            nextChunk = world.getChunkAt(nextBlockX >> 4, nextBlockZ >> 4);
        } else {
            nextChunk = chunk;
        }
        // unload chunk teleport cancel
        if (nextChunk == null)
            return;
        Set<EngineEntity> nextEntityList = nextChunk.getEntitiesInSection(nextSectionIndex);
        nextEntityList.add(this);
        previousEntityList.remove(this);
    }
    this.x = x;
    this.y = y;
    this.z = z;
    nmsEntity.setPositionRaw(x, y, z);
}
Also used : EngineChunk(thpmc.engine.api.world.cache.EngineChunk)

Aggregations

EngineChunk (thpmc.engine.api.world.cache.EngineChunk)6 INMSHandler (thpmc.engine.api.nms.INMSHandler)4 EngineBlock (thpmc.engine.api.world.block.EngineBlock)4 Vector (org.bukkit.util.Vector)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Location (org.bukkit.Location)1 NotNull (org.jetbrains.annotations.NotNull)1 BlockPosition (thpmc.engine.api.entity.ai.pathfinding.BlockPosition)1 EngineWorld (thpmc.engine.api.world.cache.EngineWorld)1