use of com.bergerkiller.bukkit.common.conversion.blockstate.ChunkBlockStateConverter in project BKCommonLib by bergerhealer.
the class BlockUtil method getBlockStates.
public static Collection<BlockState> getBlockStates(org.bukkit.World world, int x, int y, int z, int radiusX, int radiusY, int radiusZ) {
try {
if (radiusX == 0 && radiusY == 0 && radiusZ == 0) {
// find a single BlockState at this position
Object blockPosition = BlockPositionHandle.T.constr_x_y_z.raw.newInstance(x, y, z);
Object tile = WorldHandle.T.getTileEntity.raw.invoke(HandleConversion.toWorldHandle(world), blockPosition);
if (tile != null) {
blockStateBuff.add(WrapperConversion.toBlockState(tile));
}
} else {
// loop through tile entity list
int xMin = x - radiusX;
int yMin = y - radiusY;
int zMin = z - radiusZ;
int xMax = x + radiusX;
int yMax = y + radiusY;
int zMax = z + radiusZ;
// find range of chunk coordinates to look in
int chunk_xMin = MathUtil.toChunk(xMin);
int chunk_zMin = MathUtil.toChunk(zMin);
int chunk_xMax = MathUtil.toChunk(xMax);
int chunk_zMax = MathUtil.toChunk(zMax);
for (int cx = chunk_xMin; cx <= chunk_xMax; cx++) {
for (int cz = chunk_zMin; cz <= chunk_zMax; cz++) {
// Find chunk if loaded
org.bukkit.Chunk chunk = WorldUtil.getChunk(world, cx, cz);
if (chunk == null) {
continue;
}
// Check tile entities held inside
ChunkBlockStateConverter converter = null;
Collection<?> rawTiles = ChunkHandle.T.getRawTileEntities.invoke(HandleConversion.toChunkHandle(chunk));
for (Object tile : rawTiles) {
BlockPositionHandle blockPosition;
blockPosition = BlockPositionHandle.createHandle(TileEntityHandle.T.position_field.raw.get(tile));
if (blockPosition.isPositionInBox(xMin, yMin, zMin, xMax, yMax, zMax)) {
if (converter == null) {
converter = new ChunkBlockStateConverter(chunk);
}
blockStateBuff.add(converter.convert(tile));
}
}
}
}
}
return new ArrayList<BlockState>(blockStateBuff);
} finally {
blockStateBuff.clear();
}
}
Aggregations