mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 09:17:39 +00:00
Fix tile copying (#2922)
This commit is contained in:
parent
d9d5b7b488
commit
7e75ce78ec
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user