обновлен алгоритм для компактных массивов
они используются для хранения данных о SkyLight, BlockLight и BlockMeta
This commit is contained in:
@@ -20,9 +20,7 @@ public class AnvilBlock implements Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLight() {
|
public int getLight() {
|
||||||
final int idx = (location.getY() << 8 | location.getZ() << 4 | location.getX()) >> 1;
|
return chunkSection.getBlockLight().get(location);
|
||||||
final int value = chunkSection.getBlockLight().get(idx);
|
|
||||||
return (idx & 1) == 0 ? value & 15 : value >> 4 & 15;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,8 +30,9 @@ public class AnvilBlock implements Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockType getBlockType() {
|
public BlockType getBlockType() {
|
||||||
byte id = chunkSection.getBlocks().get((location.getY() * 256) + (location.getZ() * 16) + location.getX());
|
final byte id = chunkSection.getBlocks().get((location.getY() * 256) + (location.getZ() * 16) + location.getX());
|
||||||
return BlockType.getByIdMeta(id, 0/*FIXME*/);
|
final int meta = chunkSection.getBlocksMeta().get(location);
|
||||||
|
return BlockType.getByIdMeta(id, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ public class AnvilChunk implements Chunk {
|
|||||||
chunkSection.setParent(this);
|
chunkSection.setParent(this);
|
||||||
chunkSection.setY(((ByteTag) sectionTagValue.get("Y")).getValue());
|
chunkSection.setY(((ByteTag) sectionTagValue.get("Y")).getValue());
|
||||||
|
|
||||||
chunkSection.getBlockLight().add(((ByteArrayTag) sectionTagValue.get("BlockLight")).getValue());
|
chunkSection.setBlockLight(new NibbleArray(((ByteArrayTag) sectionTagValue.get("BlockLight")).getValue()));
|
||||||
chunkSection.getSkyLight().add(((ByteArrayTag) sectionTagValue.get("SkyLight")).getValue());
|
chunkSection.setSkyLight(new NibbleArray(((ByteArrayTag) sectionTagValue.get("SkyLight")).getValue()));
|
||||||
chunkSection.getBlocks().add(((ByteArrayTag) sectionTagValue.get("Blocks")).getValue());
|
chunkSection.getBlocks().add(((ByteArrayTag) sectionTagValue.get("Blocks")).getValue());
|
||||||
|
chunkSection.setBlocksMeta(new NibbleArray(((ByteArrayTag) sectionTagValue.get("Data")).getValue()));
|
||||||
|
|
||||||
this.sections.add(chunkSection);
|
this.sections.add(chunkSection);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,12 @@ public class AnvilChunkSection implements ChunkSection {
|
|||||||
private int y;
|
private int y;
|
||||||
|
|
||||||
private TByteList blocks = new TByteLinkedList();
|
private TByteList blocks = new TByteLinkedList();
|
||||||
private TByteList blockLight = new TByteLinkedList();
|
@Setter
|
||||||
private TByteList skyLight = new TByteLinkedList();
|
private NibbleArray blocksMeta;
|
||||||
|
@Setter
|
||||||
|
private NibbleArray blockLight;
|
||||||
|
@Setter
|
||||||
|
private NibbleArray skyLight;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getX() {
|
public int getX() {
|
||||||
@@ -42,9 +46,7 @@ public class AnvilChunkSection implements ChunkSection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSkyLight(int x, int y, int z) {
|
public int getSkyLight(int x, int y, int z) {
|
||||||
final int idx = (y << 8 | z << 4 | x) >> 1;
|
return skyLight.get(x, y, z);
|
||||||
final int value = skyLight.get(idx);
|
|
||||||
return (idx & 1) == 0 ? value & 15 : value >> 4 & 15;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
32
anvil-loader/src/main/java/mc/world/anvil/NibbleArray.java
Normal file
32
anvil-loader/src/main/java/mc/world/anvil/NibbleArray.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package mc.world.anvil;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import mc.core.world.block.BlockLocation;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class NibbleArray {
|
||||||
|
private final byte[] data;
|
||||||
|
|
||||||
|
private int coordsToIndex(int x, int y, int z) {
|
||||||
|
return y << 8 | z << 4 | x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int nibbleIndex(int index) {
|
||||||
|
return index >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLowerNibble(int index) {
|
||||||
|
return (index & 1) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get(BlockLocation location) {
|
||||||
|
return get(location.getX(), location.getY(), location.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get(int x, int y, int z) {
|
||||||
|
final int idx = coordsToIndex(x, y, z);
|
||||||
|
|
||||||
|
final int ni = nibbleIndex(idx);
|
||||||
|
return isLowerNibble(idx) ? this.data[ni] & 15 : this.data[ni] >> 4 & 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user