fix some more chunk bugs (maybe there are even more)

This commit is contained in:
Bixilon 2020-06-20 15:14:04 +02:00
parent 0d8e81775c
commit 5824aebc37
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 8 additions and 4 deletions

View File

@ -34,13 +34,17 @@ public class Chunk {
} }
public Blocks getBlock(int x, int y, int z) { public Blocks getBlock(int x, int y, int z) {
if (x > 16 || y > 255 || z > 16 || x < 0 || y < 0 || z < 0) { if (x > 15 || y > 255 || z > 15 || x < 0 || y < 0 || z < 0) {
throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z)); throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z));
} }
byte section = (byte) (y / 16); byte section = (byte) (y / 16);
return nibbles.get(section).getBlock(x, y % 16, z); return nibbles.get(section).getBlock(x, y % 16, z);
} }
public Blocks getBlock(InChunkLocation location) {
return getBlock(location.getX(), location.getY(), location.getZ());
}
public void setBlock(int x, int y, int z, Blocks block) { public void setBlock(int x, int y, int z, Blocks block) {
byte section = (byte) (y / 16); byte section = (byte) (y / 16);
createSection(section); createSection(section);

View File

@ -25,7 +25,7 @@ public class InChunkLocation {
// x 0 - 16 // x 0 - 16
// y 0 - 255 // y 0 - 255
// z 0 - 16 // z 0 - 16
if (x > 16 || y > 255 || z > 16 || x < 0 || y < 0 || z < 0) { if (x > 15 || y > 255 || z > 15 || x < 0 || y < 0 || z < 0) {
throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z)); throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z));
} }
this.x = x; this.x = x;

View File

@ -53,14 +53,14 @@ public class World {
public Blocks getBlock(BlockPosition pos) { public Blocks getBlock(BlockPosition pos) {
ChunkLocation loc = pos.getChunkLocation(); ChunkLocation loc = pos.getChunkLocation();
if (getChunk(loc) != null) { if (getChunk(loc) != null) {
return getChunk(loc).getBlock(pos.getX() % 16, pos.getY(), pos.getZ() % 16); return getChunk(loc).getBlock(pos.getInChunkLocation());
} }
return Blocks.AIR; return Blocks.AIR;
} }
public void setBlock(BlockPosition pos, Blocks block) { public void setBlock(BlockPosition pos, Blocks block) {
if (getChunk(pos.getChunkLocation()) != null) { if (getChunk(pos.getChunkLocation()) != null) {
getChunk(pos.getChunkLocation()).setBlock(pos.getX() % 16, pos.getY(), pos.getZ() % 16, block); getChunk(pos.getChunkLocation()).setBlock(pos.getInChunkLocation(), block);
} }
// do nothing if chunk is unloaded // do nothing if chunk is unloaded
} }