Skip to content

Instantly share code, notes, and snippets.

@RainWarrior
Last active August 29, 2015 14:09
Show Gist options
  • Save RainWarrior/018d3206ae8b8a4556db to your computer and use it in GitHub Desktop.
Save RainWarrior/018d3206ae8b8a4556db to your computer and use it in GitHub Desktop.
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
class Test {
void checkBlock(World world, int x, int y, int z) {
int[] xOffsets = {-8, -8, 8, 8};
int[] zOffsets = {-8, 8, -8, 8};
int[] yOffsets = {-8, 8};
ExtendedBlockStorage[][][] esbs = new ExtendedBlockStorage[2][2][2];
for (int i = 0; i < 4; i++) {
if(world.chunkExists((x + xOffsets[i]) >> 4, (z + zOffsets[i]) >> 4))
{
Chunk chunk = world.getChunkFromChunkCoords((x + xOffsets[i]) >> 4, (z + zOffsets[i]) >> 4);
for(int j = 0; i < 2; j++) {
esbs[i >> 1][i & 1][j] = chunk.getBlockStorageArrays[(y + yOffsets[j]) >> 4];
}
} else {
for(int j = 0; i < 2; j++) {
esbs[i >> 1][i & 1][j] = null;
}
}
}
for(int ix = x - 8; ix < x + 8; ix++) {
for(int iy = y; iy < y + 9; iy++) {
for(int iz = z - 8; iz < z + 8; iz++) {
ExtendedBlockStorage esb =
esbs[((x >> 3) & 1) + (ix >> 4) - (x >> 4)]
[((z >> 3) & 1) + (iz >> 4) - (z >> 4)]
[((y >> 3) & 1) + (iy >> 4) - (y >> 4)];
int id = esb.getBlockLSBArray()[(iy & 0xF) << 8 | (iz & 0xF) << 4 | (ix & 0xF)];
if(esb.getBlockMSBArray() != null) {
id |= esb.getBlockMSBArray().get(ix & 0xF, iy & 0xF, iz & 0xF) << 8;
}
// do stuff with id
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment