обработка NBT в чанках
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package mc.world.anvil;
|
||||
|
||||
import com.flowpowered.nbt.CompoundTag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.world.block.Block;
|
||||
import mc.core.world.block.BlockLocation;
|
||||
@@ -49,6 +50,20 @@ public class AnvilBlock implements Block {
|
||||
return globalLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNBTData() {
|
||||
CompoundTag compoundTag = chunkSection.getParent().getNbtByGlobalXYZ(
|
||||
(chunkSection.getX() << 4) + location.getX(),
|
||||
(chunkSection.getY() << 4) + location.getY(),
|
||||
(chunkSection.getZ() << 4) + location.getZ()
|
||||
);
|
||||
|
||||
compoundTag.getValue().remove("Items");
|
||||
compoundTag.getValue().remove("Lock");
|
||||
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AnvilBlock{" +
|
||||
|
||||
@@ -20,6 +20,7 @@ public class AnvilChunk implements Chunk {
|
||||
private int z;
|
||||
private TByteList biomes = new TByteArrayList(256);
|
||||
private List<ChunkSection> sections;
|
||||
private ListTag<CompoundTag> tileEntities;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
AnvilChunk(CompoundTag chunkTag) {
|
||||
@@ -29,6 +30,7 @@ public class AnvilChunk implements Chunk {
|
||||
this.z = ((IntTag) levelTagMap.get("zPos")).getValue();
|
||||
|
||||
biomes.add(((ByteArrayTag) levelTagMap.get("Biomes")).getValue());
|
||||
tileEntities = (ListTag<CompoundTag>) levelTagMap.get("TileEntities");
|
||||
|
||||
List<CompoundTag> sections = ((ListTag<CompoundTag>) levelTagMap.get("Sections")).getValue();
|
||||
this.sections = new ArrayList<>(sections.size());
|
||||
@@ -49,6 +51,18 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag getNbtByGlobalXYZ(int x, int y, int z) {
|
||||
for (CompoundTag compoundTag : tileEntities.getValue()) {
|
||||
CompoundMap compoundMap = compoundTag.getValue();
|
||||
if (((IntTag)compoundMap.get("x")).getValue() == x
|
||||
&& ((IntTag)compoundMap.get("y")).getValue() == y
|
||||
&& ((IntTag)compoundMap.get("z")).getValue() == z) {
|
||||
return compoundTag;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkSection getChunkSection(int height) {
|
||||
if (height > sections.size()-1) return null;
|
||||
|
||||
Reference in New Issue
Block a user