Fix tile copying (#2922)

This commit is contained in:
Hannes Greule 2024-09-18 23:04:56 +02:00 committed by GitHub
parent d9d5b7b488
commit 7e75ce78ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.NbtUtils; import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.ReflectionUtils; import com.fastasyncworldedit.core.util.ReflectionUtils;
import com.google.common.collect.Collections2;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.ListTag; 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.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.apache.logging.log4j.Logger; 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.ByteArrayOutputStream;
import java.io.DataInputStream; 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 int VERSION_2_HEADER_SIZE = 27; // Header size of "version 2" i.e. when NBT/entities could be saved
private static final Map<String, LockHolder> LOCK_HOLDER_CACHE = new ConcurrentHashMap<>(); private static final Map<String, LockHolder> LOCK_HOLDER_CACHE = new ConcurrentHashMap<>();
private final HashMap<IntTriple, CompoundTag> nbtMap; private final HashMap<IntTriple, FaweCompoundTag> nbtMap;
private final HashMap<IntTriple, FaweCompoundTag> nbtMap2;
private final File file; private final File file;
private final int headerSize; private final int headerSize;
@ -127,7 +129,6 @@ public class DiskOptimizedClipboard extends LinearClipboard {
canHaveBiomes = false; canHaveBiomes = false;
} }
nbtMap = new HashMap<>(); nbtMap = new HashMap<>();
nbtMap2 = new HashMap<>();
try { try {
this.file = file; this.file = file;
try { try {
@ -184,7 +185,6 @@ public class DiskOptimizedClipboard extends LinearClipboard {
super(readSize(file, versionOverride), BlockVector3.ZERO); super(readSize(file, versionOverride), BlockVector3.ZERO);
headerSize = getHeaderSizeOverrideFromVersion(versionOverride); headerSize = getHeaderSizeOverrideFromVersion(versionOverride);
nbtMap = new HashMap<>(); nbtMap = new HashMap<>();
nbtMap2 = new HashMap<>();
try { try {
this.file = file; this.file = file;
this.braf = new RandomAccessFile(file, "rw"); 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)))) { try (NBTInputStream nbtIS = new NBTInputStream(MainUtil.getCompressedIS(new ByteBufferInputStream(tmp)))) {
Iterator<CompoundTag> iter = nbtIS.toIterator(); Iterator<CompoundTag> iter = nbtIS.toIterator();
while (nbtCount > 0 && iter.hasNext()) { // TileEntities are stored "before" entities while (nbtCount > 0 && iter.hasNext()) { // TileEntities are stored "before" entities
CompoundTag tag = iter.next(); LinCompoundTag tag = iter.next().toLinTag();
int x = tag.getInt("x"); int x = tag.getTag("x", LinTagType.intTag()).valueAsInt();
int y = tag.getInt("y"); int y = tag.getTag("y", LinTagType.intTag()).valueAsInt();
int z = tag.getInt("z"); int z = tag.getTag("z", LinTagType.intTag()).valueAsInt();
IntTriple pos = new IntTriple(x, y, z); IntTriple pos = new IntTriple(x, y, z);
nbtMap.put(pos, tag); nbtMap.put(pos, FaweCompoundTag.of(tag));
nbtCount--; nbtCount--;
} }
while (entitiesCount > 0 && iter.hasNext()) { while (entitiesCount > 0 && iter.hasNext()) {
@ -564,8 +564,8 @@ public class DiskOptimizedClipboard extends LinearClipboard {
))) { ))) {
if (!nbtMap.isEmpty()) { if (!nbtMap.isEmpty()) {
try { try {
for (CompoundTag tag : nbtMap.values()) { for (FaweCompoundTag tag : nbtMap.values()) {
nbtOS.writeTag(tag); nbtOS.writeTag(new CompoundTag(tag.linTag()));
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -643,7 +643,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
@Override @Override
public Collection<CompoundTag> getTileEntities() { public Collection<CompoundTag> getTileEntities() {
return nbtMap.values(); return Collections2.transform(nbtMap.values(), fct -> new CompoundTag(fct.linTag()));
} }
public int getIndex(int x, int y, int z) { 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) { private BaseBlock toBaseBlock(BlockState state, int i) {
if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) { if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
CompoundTag nbt; FaweCompoundTag nbt;
if (nbtMap.size() < 4) { if (nbtMap.size() < 4) {
nbt = null; nbt = null;
for (Map.Entry<IntTriple, CompoundTag> entry : nbtMap.entrySet()) { for (Map.Entry<IntTriple, FaweCompoundTag> entry : nbtMap.entrySet()) {
IntTriple key = entry.getKey(); IntTriple key = entry.getKey();
int index = getIndex(key.x(), key.y(), key.z()); int index = getIndex(key.x(), key.y(), key.z());
if (index == i) { if (index == i) {
@ -679,15 +679,15 @@ public class DiskOptimizedClipboard extends LinearClipboard {
int x = newI - z * getWidth(); int x = newI - z * getWidth();
nbt = nbtMap.get(new IntTriple(x, y, z)); nbt = nbtMap.get(new IntTriple(x, y, z));
} }
return state.toBaseBlock(nbt); return state.toBaseBlock(nbt == null ? null : nbt.linTag());
} }
return state.toBaseBlock(); return state.toBaseBlock();
} }
private BaseBlock toBaseBlock(BlockState state, int x, int y, int z) { private BaseBlock toBaseBlock(BlockState state, int x, int y, int z) {
if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) { if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
CompoundTag nbt = nbtMap.get(new IntTriple(x, y, z)); FaweCompoundTag nbt = nbtMap.get(new IntTriple(x, y, z));
return state.toBaseBlock(nbt); return state.toBaseBlock(nbt == null ? null : nbt.linTag());
} }
return state.toBaseBlock(); return state.toBaseBlock();
} }
@ -715,7 +715,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
@Override @Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException { 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; return true;
} }

View File

@ -57,6 +57,10 @@ public abstract class LinearClipboard extends SimpleClipboard {
*/ */
public abstract void streamBiomes(IntValueReader task); 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<CompoundTag> getTileEntities(); public abstract Collection<CompoundTag> getTileEntities();
@Override @Override