diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ForwardSeekableInputStream.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ForwardSeekableInputStream.java index 47f17781f4..939cdafcc0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ForwardSeekableInputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ForwardSeekableInputStream.java @@ -91,7 +91,6 @@ public long skip(long n) throws IOException { public void seek(long n) throws IOException { long diff = n - position; - LOGGER.error("Seek to {} from {} using {}", n, position, diff); if (diff < 0) { throw new IOException("Can't seek backwards"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk17.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk17.java index fbddb66f08..06d5b41597 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk17.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk17.java @@ -294,7 +294,11 @@ public List getEntities() throws DataException { */ private void populateEntities() { entities = new ArrayList<>(); - LinListTag tags = rootTag.findListTag( + LinCompoundTag entityTag; + if (entityTagSupplier == null || (entityTag = entityTagSupplier.get()) == null) { + return; + } + LinListTag tags = entityTag.findListTag( "Entities", LinTagType.compoundTag() ); if (tags == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk18.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk18.java index c5736bfd5f..af367c936e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk18.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk18.java @@ -25,20 +25,28 @@ import com.sk89q.jnbt.LongArrayTag; import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; +import com.sk89q.worldedit.util.concurrency.LazyReference; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.storage.InvalidFormatException; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import org.enginehub.linbus.tree.LinCompoundTag; +import org.enginehub.linbus.tree.LinListTag; +import org.enginehub.linbus.tree.LinTagType; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Supplier; /** * The chunk format for Minecraft 1.18 and newer @@ -46,11 +54,13 @@ public class AnvilChunk18 implements Chunk { private final CompoundTag rootTag; + private final Supplier entityTagSupplier; private final Int2ObjectOpenHashMap blocks; private final int rootX; private final int rootZ; private Map>> tileEntities; + private List entities; /** * Construct the chunk with a compound tag. @@ -58,8 +68,9 @@ public class AnvilChunk18 implements Chunk { * @param tag the tag to read * @throws DataException on a data error */ - public AnvilChunk18(CompoundTag tag) throws DataException { + public AnvilChunk18(CompoundTag tag, Supplier entityTag) throws DataException { rootTag = tag; + entityTagSupplier = entityTag; rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue(); rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue(); @@ -105,7 +116,7 @@ public AnvilChunk18(CompoundTag tag) throws DataException { try { blockState = getBlockStateWith(blockState, property, value); } catch (IllegalArgumentException e) { - throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().getId() + ", " + property.getName() + ": " + value); + throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().id() + ", " + property.getName() + ": " + value); } } } @@ -197,9 +208,9 @@ private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataExcepti @Override public BaseBlock getBlock(BlockVector3 position) throws DataException { - int x = position.getX() - rootX * 16; - int y = position.getY(); - int z = position.getZ() - rootZ * 16; + int x = position.x() - rootX * 16; + int y = position.y(); + int z = position.z() - rootZ * 16; int section = y >> 4; int yIndex = y & 0x0F; @@ -219,4 +230,37 @@ public BaseBlock getBlock(BlockVector3 position) throws DataException { return state.toBaseBlock(); } + @Override + public List getEntities() throws DataException { + if (entities == null) { + populateEntities(); + } + return entities; + } + + /** + * Used to load the biomes. + */ + private void populateEntities() { + entities = new ArrayList<>(); + LinCompoundTag entityTag; + if (entityTagSupplier == null || (entityTag = entityTagSupplier.get()) == null) { + return; + } + LinListTag tags = entityTag.findListTag( + "Entities", LinTagType.compoundTag() + ); + if (tags == null) { + return; + } + + for (LinCompoundTag tag : tags.value()) { + entities.add(new BaseEntity( + EntityTypes.get(tag.getTag("id", LinTagType.stringTag()).value()), + LazyReference.computed(tag) + )); + } + + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStoreHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStoreHelper.java index c8788a9ce8..c9c2d27437 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStoreHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStoreHelper.java @@ -104,7 +104,15 @@ public static Chunk getChunk(CompoundTag rootTag, Supplier entities } if (dataVersion >= Constants.DATA_VERSION_MC_1_18) { - return new AnvilChunk18(rootTag); + return new AnvilChunk18( + rootTag, () -> { + CompoundTag compoundTag = entitiesTag.get(); + if (compoundTag == null) { + return null; + } + return compoundTag.toLinTag(); + } + ); } Map> children = rootTag.getValue();