3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

Fix tile copying (#2922)

Dieser Commit ist enthalten in:
Hannes Greule 2024-09-18 23:04:56 +02:00 committet von GitHub
Ursprung d9d5b7b488
Commit 7e75ce78ec
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 22 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -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<String, LockHolder> LOCK_HOLDER_CACHE = new ConcurrentHashMap<>();
private final HashMap<IntTriple, CompoundTag> nbtMap;
private final HashMap<IntTriple, FaweCompoundTag> nbtMap2;
private final HashMap<IntTriple, FaweCompoundTag> 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<CompoundTag> 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<CompoundTag> 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<IntTriple, CompoundTag> entry : nbtMap.entrySet()) {
for (Map.Entry<IntTriple, FaweCompoundTag> 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;
}

Datei anzeigen

@ -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<CompoundTag> getTileEntities();
@Override