From 7e75ce78ec2b2383659cb6a1ac1eb0eb6193a8cc Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Wed, 18 Sep 2024 23:04:56 +0200 Subject: [PATCH] Fix tile copying (#2922) --- .../clipboard/DiskOptimizedClipboard.java | 36 +++++++++---------- .../extent/clipboard/LinearClipboard.java | 4 +++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/DiskOptimizedClipboard.java index c81059ccb..dc2ba4505 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/DiskOptimizedClipboard.java @@ -10,6 +10,7 @@ import com.fastasyncworldedit.core.nbt.FaweCompoundTag; import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.NbtUtils; import com.fastasyncworldedit.core.util.ReflectionUtils; +import com.google.common.collect.Collections2; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.ListTag; @@ -30,6 +31,8 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; import org.apache.logging.log4j.Logger; +import org.enginehub.linbus.tree.LinCompoundTag; +import org.enginehub.linbus.tree.LinTagType; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -66,8 +69,7 @@ public class DiskOptimizedClipboard extends LinearClipboard { private static final int VERSION_2_HEADER_SIZE = 27; // Header size of "version 2" i.e. when NBT/entities could be saved private static final Map LOCK_HOLDER_CACHE = new ConcurrentHashMap<>(); - private final HashMap nbtMap; - private final HashMap nbtMap2; + private final HashMap nbtMap; private final File file; private final int headerSize; @@ -127,7 +129,6 @@ public class DiskOptimizedClipboard extends LinearClipboard { canHaveBiomes = false; } nbtMap = new HashMap<>(); - nbtMap2 = new HashMap<>(); try { this.file = file; try { @@ -184,7 +185,6 @@ public class DiskOptimizedClipboard extends LinearClipboard { super(readSize(file, versionOverride), BlockVector3.ZERO); headerSize = getHeaderSizeOverrideFromVersion(versionOverride); nbtMap = new HashMap<>(); - nbtMap2 = new HashMap<>(); try { this.file = file; this.braf = new RandomAccessFile(file, "rw"); @@ -253,12 +253,12 @@ public class DiskOptimizedClipboard extends LinearClipboard { try (NBTInputStream nbtIS = new NBTInputStream(MainUtil.getCompressedIS(new ByteBufferInputStream(tmp)))) { Iterator iter = nbtIS.toIterator(); while (nbtCount > 0 && iter.hasNext()) { // TileEntities are stored "before" entities - CompoundTag tag = iter.next(); - int x = tag.getInt("x"); - int y = tag.getInt("y"); - int z = tag.getInt("z"); + LinCompoundTag tag = iter.next().toLinTag(); + int x = tag.getTag("x", LinTagType.intTag()).valueAsInt(); + int y = tag.getTag("y", LinTagType.intTag()).valueAsInt(); + int z = tag.getTag("z", LinTagType.intTag()).valueAsInt(); IntTriple pos = new IntTriple(x, y, z); - nbtMap.put(pos, tag); + nbtMap.put(pos, FaweCompoundTag.of(tag)); nbtCount--; } while (entitiesCount > 0 && iter.hasNext()) { @@ -564,8 +564,8 @@ public class DiskOptimizedClipboard extends LinearClipboard { ))) { if (!nbtMap.isEmpty()) { try { - for (CompoundTag tag : nbtMap.values()) { - nbtOS.writeTag(tag); + for (FaweCompoundTag tag : nbtMap.values()) { + nbtOS.writeTag(new CompoundTag(tag.linTag())); } } catch (IOException e) { e.printStackTrace(); @@ -643,7 +643,7 @@ public class DiskOptimizedClipboard extends LinearClipboard { @Override public Collection getTileEntities() { - return nbtMap.values(); + return Collections2.transform(nbtMap.values(), fct -> new CompoundTag(fct.linTag())); } public int getIndex(int x, int y, int z) { @@ -661,10 +661,10 @@ public class DiskOptimizedClipboard extends LinearClipboard { private BaseBlock toBaseBlock(BlockState state, int i) { if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) { - CompoundTag nbt; + FaweCompoundTag nbt; if (nbtMap.size() < 4) { nbt = null; - for (Map.Entry entry : nbtMap.entrySet()) { + for (Map.Entry entry : nbtMap.entrySet()) { IntTriple key = entry.getKey(); int index = getIndex(key.x(), key.y(), key.z()); if (index == i) { @@ -679,15 +679,15 @@ public class DiskOptimizedClipboard extends LinearClipboard { int x = newI - z * getWidth(); nbt = nbtMap.get(new IntTriple(x, y, z)); } - return state.toBaseBlock(nbt); + return state.toBaseBlock(nbt == null ? null : nbt.linTag()); } return state.toBaseBlock(); } private BaseBlock toBaseBlock(BlockState state, int x, int y, int z) { if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) { - CompoundTag nbt = nbtMap.get(new IntTriple(x, y, z)); - return state.toBaseBlock(nbt); + FaweCompoundTag nbt = nbtMap.get(new IntTriple(x, y, z)); + return state.toBaseBlock(nbt == null ? null : nbt.linTag()); } return state.toBaseBlock(); } @@ -715,7 +715,7 @@ public class DiskOptimizedClipboard extends LinearClipboard { @Override public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException { - nbtMap2.put(new IntTriple(x, y, z), NbtUtils.withPosition(tile, x, y, z)); + nbtMap.put(new IntTriple(x, y, z), NbtUtils.withPosition(tile, x, y, z)); return true; } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java index 2e65f59ca..cc0bb07f6 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java @@ -57,6 +57,10 @@ public abstract class LinearClipboard extends SimpleClipboard { */ public abstract void streamBiomes(IntValueReader task); + /** + * @deprecated will be removed as it is unused and uses outdated types + */ + @Deprecated(forRemoval = true, since = "TODO") public abstract Collection getTileEntities(); @Override