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);
}
Aggregations