Support block nbt without handler

This commit is contained in:
TheMode 2021-06-24 16:06:11 +02:00
parent ddba34712e
commit faa7c512af

View File

@ -143,32 +143,30 @@ public class AnvilLoader implements IChunkLoader {
private void loadTileEntities(Chunk loadedChunk, ChunkColumn fileChunk) { private void loadTileEntities(Chunk loadedChunk, ChunkColumn fileChunk) {
for (NBTCompound te : fileChunk.getTileEntities()) { for (NBTCompound te : fileChunk.getTileEntities()) {
final String tileEntityID = te.getString("id");
if (tileEntityID == null) {
LOGGER.warn("Tile entity has failed to load due to invalid namespace");
continue;
}
final var x = te.getInt("x"); final var x = te.getInt("x");
final var y = te.getInt("y"); final var y = te.getInt("y");
final var z = te.getInt("z"); final var z = te.getInt("z");
if (x == null || y == null || z == null) { if (x == null || y == null || z == null) {
LOGGER.warn("Tile entity {} has failed to load due to invalid coordinate", tileEntityID); LOGGER.warn("Tile entity has failed to load due to invalid coordinate");
continue; continue;
} }
final var handler = BLOCK_MANAGER.getHandler(tileEntityID); Block block = loadedChunk.getBlock(x, y, z);
if (handler == null) {
LOGGER.warn("Block {} does not have any corresponding handler, world will load anyway.", tileEntityID); final String tileEntityID = te.getString("id");
continue; if (tileEntityID != null) {
final var handler = BLOCK_MANAGER.getHandler(tileEntityID);
if (handler == null) {
LOGGER.warn("Block {} does not have any corresponding handler, world will load anyway.", tileEntityID);
continue;
}
block = block.withHandler(handler);
} }
// Remove anvil tags // Remove anvil tags
te.removeTag("id") te.removeTag("id")
.removeTag("x").removeTag("y").removeTag("z") .removeTag("x").removeTag("y").removeTag("z")
.removeTag("keepPacked"); .removeTag("keepPacked");
// Place block // Place block
final Block block = loadedChunk.getBlock(x, y, z) loadedChunk.setBlock(x, y, z, block.withNbt(te));
.withHandler(handler)
.withNbt(te);
loadedChunk.setBlock(x, y, z, block);
} }
} }