mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix some more chunk bugs (maybe there are even more)
This commit is contained in:
parent
0d8e81775c
commit
5824aebc37
@ -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);
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user