3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-17 00:20:09 +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.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;
} }

Datei anzeigen

@ -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