mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix chunk position bug (negative coordinates) and loading bug
This commit is contained in:
parent
5d369c6adb
commit
0d8e81775c
@ -60,11 +60,15 @@ public class BlockPosition {
|
||||
return x * y * z;
|
||||
}
|
||||
|
||||
public byte getSectionHeight() {
|
||||
return (byte) (getY() / 16);
|
||||
public InChunkLocation getInChunkLocation() {
|
||||
int x = getX() % 16;
|
||||
if (x < 0) {
|
||||
x = 16 + x;
|
||||
}
|
||||
|
||||
public ChunkNibbleLocation getNibbleLocation() {
|
||||
return new ChunkNibbleLocation(getX() % 16, getY() % 16, getZ() % 16);
|
||||
int z = getZ() % 16;
|
||||
if (z < 0) {
|
||||
z = 16 + z;
|
||||
}
|
||||
return new InChunkLocation(x, getY(), z);
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,13 @@ import java.util.Map;
|
||||
*/
|
||||
public class Chunk {
|
||||
private final HashMap<Byte, ChunkNibble> nibbles;
|
||||
private final HashMap<InChunkLocation, String[]> signs;
|
||||
private final HashMap<InChunkLocation, CompoundTag> blockEntityMeta;
|
||||
|
||||
public Chunk(HashMap<Byte, ChunkNibble> chunks) {
|
||||
this.nibbles = chunks;
|
||||
signs = new HashMap<>();
|
||||
blockEntityMeta = new HashMap<>();
|
||||
}
|
||||
|
||||
public Blocks getBlock(int x, int y, int z) {
|
||||
@ -63,19 +67,18 @@ public class Chunk {
|
||||
}
|
||||
|
||||
public void updateSign(BlockPosition position, String[] lines) {
|
||||
nibbles.get(position.getSectionHeight()).updateSign(position.getNibbleLocation(), lines);
|
||||
signs.put(position.getInChunkLocation(), lines);
|
||||
}
|
||||
|
||||
public String[] getSignText(BlockPosition position) {
|
||||
return nibbles.get(position.getSectionHeight()).getSignText(position.getNibbleLocation());
|
||||
|
||||
return signs.get(position.getInChunkLocation());
|
||||
}
|
||||
|
||||
public void setBlockEntityData(BlockPosition position, CompoundTag nbt) {
|
||||
nibbles.get(position.getSectionHeight()).setBlockEntityData(position.getNibbleLocation(), nbt);
|
||||
blockEntityMeta.put(position.getInChunkLocation(), nbt);
|
||||
}
|
||||
|
||||
public CompoundTag getBlockEntityData(BlockPosition position) {
|
||||
return nibbles.get(position.getSectionHeight()).getBlockEntityData(position.getNibbleLocation());
|
||||
return blockEntityMeta.get(position.getInChunkLocation());
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
package de.bixilon.minosoft.game.datatypes.world;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
|
||||
import de.bixilon.minosoft.nbt.tag.CompoundTag;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -23,20 +22,14 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class ChunkNibble {
|
||||
private final HashMap<ChunkNibbleLocation, Blocks> blocks;
|
||||
private final HashMap<ChunkNibbleLocation, String[]> signs;
|
||||
private final HashMap<ChunkNibbleLocation, CompoundTag> blockEntityMeta;
|
||||
|
||||
public ChunkNibble(HashMap<ChunkNibbleLocation, Blocks> blocks) {
|
||||
this.blocks = blocks;
|
||||
this.signs = new HashMap<>();
|
||||
blockEntityMeta = new HashMap<>();
|
||||
}
|
||||
|
||||
public ChunkNibble() {
|
||||
// empty
|
||||
this.blocks = new HashMap<>();
|
||||
this.signs = new HashMap<>();
|
||||
blockEntityMeta = new HashMap<>();
|
||||
}
|
||||
|
||||
public Blocks getBlock(ChunkNibbleLocation loc) {
|
||||
@ -54,20 +47,4 @@ public class ChunkNibble {
|
||||
public void setBlock(ChunkNibbleLocation location, Blocks block) {
|
||||
blocks.put(location, block);
|
||||
}
|
||||
|
||||
public void updateSign(ChunkNibbleLocation location, String[] lines) {
|
||||
signs.put(location, lines);
|
||||
}
|
||||
|
||||
public String[] getSignText(ChunkNibbleLocation location) {
|
||||
return signs.get(location);
|
||||
}
|
||||
|
||||
public void setBlockEntityData(ChunkNibbleLocation nibbleLocation, CompoundTag nbt) {
|
||||
blockEntityMeta.put(nibbleLocation, nbt);
|
||||
}
|
||||
|
||||
public CompoundTag getBlockEntityData(ChunkNibbleLocation nibbleLocation) {
|
||||
return blockEntityMeta.get(nibbleLocation);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user