Reorder BuildInClipboardFormat and document changed JNBT classes (#807)

* Get rid of FastSchematicReader/Writer and document changed JNBT classes

This commit includes changes from upstream to the schematic classes
(`com.sk89q.worldedit.extent.clipboard.io`). It also documents the JNBT
classes, specifying what has been changed in FAWE. This was done in preparation
for the upcoming move to adventure-nbt.

The PlotSquared schematic handler classes will now use SpongeSchematicReader/Writer rather than FastSchematicReader/Writer.

This is yet untested and the entire branch is a W.I.P.

* Fix JNBT mutability misuse in FAWE

FAWE previously had mutable compound and list tags. The previous commit changed that, and this commit will fix misuse of the tag API.

I've tried to identify the places where mutability was assumed, but I might have missed something. This needs quite extensive testing.

This is yet another change which increases upstream compatibility in FAWE.

* Fix FAWE_Spigot_<..>#getEntity

* Fix JNBT usage in the AsyncBlockState code

* Readd FastSchematicReader/Writer and add a new schematic format (`FAST`)

* Update dead repository

* Implement missing AsyncChunk#getTileEntities

* handle entities properly and add "brokenentity" format

* Fix fast schematic reader
lazily reading means it's read in order of appearance in the inputstream so we need to read schematic version first (skip past everything) and then reset the stream

* Fix p2 FAWE

* Go back to fast schematics in P2/CompressedSchematicTag (#819)

* Fix compile

Co-authored-by: N0tMyFaultOG <mc.cache@web.de>
Co-authored-by: Alexander Söderberg <Sauilitired@users.noreply.github.com>
Co-authored-by: dordsor21 <dordsor21@gmail.com>
Co-authored-by: Aurora <aurora@relanet.eu>
This commit is contained in:
Alexander Söderberg
2021-01-04 19:18:23 +01:00
committed by GitHub
parent efcca5b66f
commit 3f0b9a2a92
56 changed files with 559 additions and 995 deletions

View File

@ -138,10 +138,8 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
}
if (!tilesTo.isEmpty()) {
for (Map.Entry<BlockVector3, CompoundTag> entry : tilesTo.entrySet()) {
CompoundTag nbt = entry.getValue();
BlockVector3 pos = entry.getKey();
MainUtil.setPosition(nbt, pos.getX() + bx, pos.getY(), pos.getZ() + bz);
addTileCreate(nbt);
addTileCreate(MainUtil.setPosition(entry.getValue(), pos.getX() + bx, pos.getY(), pos.getZ() + bz));
}
}
Set<UUID> entRemoves = set.getEntityRemoves();
@ -259,14 +257,12 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
public void add(EntityCreate change) {
CompoundTag tag = change.state.getNbtData();
MainUtil.setEntityInfo(tag, change.getEntity());
addEntityCreate(tag);
addEntityCreate(MainUtil.setEntityInfo(tag, change.getEntity()));
}
public void add(EntityRemove change) {
CompoundTag tag = change.state.getNbtData();
MainUtil.setEntityInfo(tag, change.getEntity());
addEntityRemove(tag);
addEntityRemove(MainUtil.setEntityInfo(tag, change.getEntity()));
}
@Override
@ -309,14 +305,12 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
if (from.hasNbtData()) {
CompoundTag nbt = from.getNbtData();
assert nbt != null;
MainUtil.setPosition(nbt, x, y, z);
addTileRemove(nbt);
addTileRemove(MainUtil.setPosition(nbt, x, y, z));
}
if (to.hasNbtData()) {
CompoundTag nbt = to.getNbtData();
assert nbt != null;
MainUtil.setPosition(nbt, x, y, z);
addTileCreate(nbt);
addTileCreate(MainUtil.setPosition(nbt, x, y, z));
}
int combinedFrom = from.getOrdinal();
int combinedTo = to.getOrdinal();
@ -332,8 +326,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
if (to.hasNbtData()) {
CompoundTag nbt = to.getNbtData();
assert nbt != null;
MainUtil.setPosition(nbt, x, y, z);
addTileCreate(nbt);
addTileCreate(MainUtil.setPosition(nbt, x, y, z));
}
int combinedTo = to.getInternalId();
add(x, y, z, combinedFrom, combinedTo);

View File

@ -24,6 +24,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
@ -44,7 +45,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
* A clipboard with disk backed storage. (lower memory + loads on crash)
@ -390,11 +390,11 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable
@Override
public boolean setTile(int x, int y, int z, CompoundTag tag) {
nbtMap.put(new IntTriple(x, y, z), tag);
Map<String, Tag> values = tag.getValue();
final Map<String, Tag> values = new HashMap<>(tag.getValue());
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));
nbtMap.put(new IntTriple(x, y, z), new CompoundTag(values));
return true;
}

View File

@ -34,6 +34,9 @@ import net.jpountz.lz4.LZ4InputStream;
import net.jpountz.lz4.LZ4Utils;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
@ -66,6 +69,7 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -83,8 +87,6 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import static java.lang.System.arraycopy;
import static org.slf4j.LoggerFactory.getLogger;
@ -448,24 +450,44 @@ public class MainUtil {
}
}
public static void setPosition(CompoundTag tag, int x, int y, int z) {
Map<String, Tag> value = tag.getValue();
/**
* Create a copy of the tag and modify the (x, y, z) coordinates
*
* @param tag Tag to copy
* @param x New X coordinate
* @param y New Y coordinate
* @param z New Z coordinate
* @return New tag
*/
public static @NotNull CompoundTag setPosition(@Nonnull CompoundTag tag, int x, int y, int z) {
Map<String, Tag> value = new HashMap<>(tag.getValue());
value.put("x", new IntTag(x));
value.put("y", new IntTag(y));
value.put("z", new IntTag(z));
return new CompoundTag(value);
}
public static void setEntityInfo(CompoundTag tag, Entity entity) {
Map<String, Tag> map = tag.getValue();
/**
* Create a copy of the tag and modify the entity inf
*
* @param tag Tag to copy
* @param entity Entity
* @return New tag
*/
public static @NotNull CompoundTag setEntityInfo(@NotNull CompoundTag tag, @NotNull Entity entity) {
Map<String, Tag> map = new HashMap<>(tag.getValue());
map.put("Id", new StringTag(entity.getState().getType().getId()));
ListTag pos = (ListTag) map.get("Pos");
if (pos != null) {
Location loc = entity.getLocation();
List<Tag> posList = ReflectionUtils.getList(pos.getValue());
// Create a copy, because the list is immutable...
List<Tag> posList = new ArrayList<>(pos.getValue());
posList.set(0, new DoubleTag(loc.getX()));
posList.set(1, new DoubleTag(loc.getY()));
posList.set(2, new DoubleTag(loc.getZ()));
map.put("Pos", new ListTag(pos.getType(), posList));
}
return new CompoundTag(map);
}
public static String getText(String url) throws IOException {

View File

@ -67,22 +67,6 @@ public class ReflectionUtils {
blankField(enumClass, "enumConstants"); // IBM JDK
}
public static <T> List<T> getList(List<T> list) {
try {
Class<? extends List<T>> clazz = (Class<? extends List<T>>) Class
.forName("java.util.Collections$UnmodifiableList");
if (!clazz.isInstance(list)) {
return list;
}
Field m = clazz.getDeclaredField("list");
m.setAccessible(true);
return (List<T>) m.get(list);
} catch (Throwable e) {
e.printStackTrace();
return list;
}
}
public static Object getHandle(Object wrapper) {
final Method getHandle = makeMethod(wrapper.getClass(), "getHandle");
return callMethod(getHandle, wrapper);