ref: switch from adventure NBT to LinBus (#2778)

* Switch from adventure NBT to LinBus

* Cleanup

* Clean

* Reimplement NumberTag behaviour

* Use 0.1.0 release

* Fix build, remove fawe tags

---------

Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
This commit is contained in:
Jordan
2024-06-26 21:55:47 +02:00
committed by GitHub
parent 6dd779f90b
commit ad5739e014
134 changed files with 2258 additions and 2542 deletions

View File

@ -55,20 +55,6 @@ import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -134,9 +120,26 @@ import org.bukkit.craftbukkit.v1_19_R3.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinEndTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinLongArrayTag;
import org.enginehub.linbus.tree.LinLongTag;
import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -158,14 +161,13 @@ import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft.nbt.Tag> {
private final Logger LOGGER = Logger.getLogger(getClass().getCanonicalName());
private final Logger logger = Logger.getLogger(getClass().getCanonicalName());
private final Field serverWorldsField;
private final Method getChunkFutureMethod;
@ -347,7 +349,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) {
net.minecraft.nbt.CompoundTag tag = te.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
return state.toBaseBlock();
@ -427,7 +429,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
readEntityIntoTag(mcEntity, tag);
return new BaseEntity(
com.sk89q.worldedit.world.entity.EntityTypes.get(id),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag))
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag))
);
}
@ -443,9 +445,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
Entity createdEntity = createEntityFromId(state.getType().id(), craftWorld.getHandle());
if (createdEntity != null) {
CompoundBinaryTag nativeTag = state.getNbt();
LinCompoundTag nativeTag = state.getNbt();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeBinary(nativeTag);
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeLin(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
@ -527,13 +529,13 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
}
@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().connection.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity(
new BlockPos(pos.x(), pos.y(), pos.z()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
),
__ -> (net.minecraft.nbt.CompoundTag) fromNativeBinary(nbtData)
__ -> (net.minecraft.nbt.CompoundTag) fromNativeLin(nbtData)
));
}
@ -558,7 +560,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt(((LinCompoundTag) toNativeLin(nmsStack.getTag())));
return weStack;
}
@ -733,7 +735,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
state = state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
extent.setBlock(vec, state.toBaseBlock());
if (options.shouldRegenBiomes()) {
@ -816,51 +818,49 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return native WorldEdit NBT structure
*/
@Override
public BinaryTag toNativeBinary(net.minecraft.nbt.Tag foreign) {
public LinTag<?> toNativeLin(net.minecraft.nbt.Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, BinaryTag> values = new HashMap<>();
Map<String, LinTag<?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();
for (String str : foreignKeys) {
net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str);
values.put(str, toNativeBinary(base));
values.put(str, toNativeLin(base));
}
return CompoundBinaryTag.from(values);
return LinCompoundTag.of(values);
} else if (foreign instanceof net.minecraft.nbt.ByteTag) {
return ByteBinaryTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
return LinByteTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
} else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) {
return ByteArrayBinaryTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
return LinByteArrayTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
} else if (foreign instanceof net.minecraft.nbt.DoubleTag) {
return DoubleBinaryTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
return LinDoubleTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
} else if (foreign instanceof net.minecraft.nbt.FloatTag) {
return FloatBinaryTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
return LinFloatTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
} else if (foreign instanceof net.minecraft.nbt.IntTag) {
return IntBinaryTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
return LinIntTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
} else if (foreign instanceof net.minecraft.nbt.IntArrayTag) {
return IntArrayBinaryTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
return LinIntArrayTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
} else if (foreign instanceof net.minecraft.nbt.LongArrayTag) {
return LongArrayBinaryTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
return LinLongArrayTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
} else if (foreign instanceof net.minecraft.nbt.ListTag) {
try {
return toNativeList((net.minecraft.nbt.ListTag) foreign);
return toNativeLinList((net.minecraft.nbt.ListTag) foreign);
} catch (Throwable e) {
LOGGER.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
return ListBinaryTag.empty();
logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
}
} else if (foreign instanceof net.minecraft.nbt.LongTag) {
return LongBinaryTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
return LinLongTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
} else if (foreign instanceof net.minecraft.nbt.ShortTag) {
return ShortBinaryTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
return LinShortTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
} else if (foreign instanceof net.minecraft.nbt.StringTag) {
return StringBinaryTag.of(foreign.getAsString());
return LinStringTag.of(foreign.getAsString());
} else if (foreign instanceof net.minecraft.nbt.EndTag) {
return EndBinaryTag.get();
} else {
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
return LinEndTag.instance();
}
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
}
/**
@ -871,14 +871,16 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @throws SecurityException on error
* @throws IllegalArgumentException on error
*/
private ListBinaryTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
ListBinaryTag.Builder values = ListBinaryTag.builder();
private LinListTag<?> toNativeLinList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
LinListTag.Builder<LinTag<?>> builder = LinListTag.builder(
LinTagType.fromId(LinTagId.fromId(foreign.getElementType()))
);
for (net.minecraft.nbt.Tag tag : foreign) {
values.add(toNativeBinary(tag));
builder.add(toNativeLin(tag));
}
return values.build();
return builder.build();
}
/**
@ -888,44 +890,43 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return non-native structure
*/
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
public net.minecraft.nbt.Tag fromNativeLin(LinTag<?> foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundBinaryTag) {
if (foreign instanceof LinCompoundTag compoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (String key : ((CompoundBinaryTag) foreign).keySet()) {
tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
for (var entry : compoundTag.value().entrySet()) {
tag.put(entry.getKey(), fromNativeLin(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteBinaryTag) {
return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
} else if (foreign instanceof ByteArrayBinaryTag) {
return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
} else if (foreign instanceof DoubleBinaryTag) {
return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
} else if (foreign instanceof FloatBinaryTag) {
return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
} else if (foreign instanceof IntBinaryTag) {
return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
} else if (foreign instanceof IntArrayBinaryTag) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
} else if (foreign instanceof LongArrayBinaryTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
} else if (foreign instanceof ListBinaryTag) {
} else if (foreign instanceof LinByteTag byteTag) {
return net.minecraft.nbt.ByteTag.valueOf(byteTag.valueAsByte());
} else if (foreign instanceof LinByteArrayTag byteArrayTag) {
return new net.minecraft.nbt.ByteArrayTag(byteArrayTag.value());
} else if (foreign instanceof LinDoubleTag doubleTag) {
return net.minecraft.nbt.DoubleTag.valueOf(doubleTag.valueAsDouble());
} else if (foreign instanceof LinFloatTag floatTag) {
return net.minecraft.nbt.FloatTag.valueOf(floatTag.valueAsFloat());
} else if (foreign instanceof LinIntTag intTag) {
return net.minecraft.nbt.IntTag.valueOf(intTag.valueAsInt());
} else if (foreign instanceof LinIntArrayTag intArrayTag) {
return new net.minecraft.nbt.IntArrayTag(intArrayTag.value());
} else if (foreign instanceof LinLongArrayTag longArrayTag) {
return new net.minecraft.nbt.LongArrayTag(longArrayTag.value());
} else if (foreign instanceof LinListTag<?> listTag) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListBinaryTag foreignList = (ListBinaryTag) foreign;
for (BinaryTag t : foreignList) {
tag.add(fromNativeBinary(t));
for (var t : listTag.value()) {
tag.add(fromNativeLin(t));
}
return tag;
} else if (foreign instanceof LongBinaryTag) {
return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
} else if (foreign instanceof ShortBinaryTag) {
return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
} else if (foreign instanceof StringBinaryTag) {
return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
} else if (foreign instanceof EndBinaryTag) {
} else if (foreign instanceof LinLongTag longTag) {
return net.minecraft.nbt.LongTag.valueOf(longTag.valueAsLong());
} else if (foreign instanceof LinShortTag shortTag) {
return net.minecraft.nbt.ShortTag.valueOf(shortTag.valueAsShort());
} else if (foreign instanceof LinStringTag stringTag) {
return net.minecraft.nbt.StringTag.valueOf(stringTag.value());
} else if (foreign instanceof LinEndTag) {
return net.minecraft.nbt.EndTag.INSTANCE;
} else {
throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());
@ -964,7 +965,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
WatchdogThread.tick();
}
} catch (IllegalAccessException e) {
LOGGER.log(Level.WARNING, "Failed to tick watchdog", e);
logger.log(Level.WARNING, "Failed to tick watchdog", e);
}
}
}

View File

@ -35,7 +35,6 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component;
@ -48,7 +47,9 @@ import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.item.DyeColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.EnumMap;
@ -62,7 +63,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
@ -78,16 +78,15 @@ import javax.annotation.Nullable;
@SuppressWarnings({ "rawtypes", "unchecked" })
class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
//FAWE start - BinaryTag
@SuppressWarnings("unchecked")
@Override
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
if (type == FixTypes.CHUNK) {
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
return (T) fixChunk((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_ENTITY) {
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
return (T) fixBlockEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.ENTITY) {
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
return (T) fixEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_STATE) {
return (T) fixBlockState((String) original, srcVer);
} else if (type == FixTypes.ITEM_TYPE) {
@ -98,24 +97,23 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return original;
}
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
private LinCompoundTag fixChunk(LinCompoundTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(originalChunk);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
private LinCompoundTag fixBlockEntity(LinCompoundTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origTileEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
private LinCompoundTag fixEntity(LinCompoundTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
//FAWE end
private String fixBlockState(String blockState, int srcVer) {
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);

View File

@ -19,25 +19,28 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_19_R3;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1;
@ -101,8 +104,15 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
return false;
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false;
}
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
@Override

View File

@ -35,9 +35,6 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -83,6 +80,9 @@ import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R3.util.CraftNamespacedKey;
import org.bukkit.entity.Player;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -274,7 +274,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
}
@ -302,14 +302,14 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
if (id != null) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
PaperweightPlatformAdapter.readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
tags.put("Id", StringBinaryTag.of(id));
return CompoundBinaryTag.from(tags);
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);
} else {
@ -514,7 +514,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt((LinCompoundTag) toNativeLin(nmsStack.getTag()));
return weStack;
}

View File

@ -9,7 +9,6 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@ -24,6 +23,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -132,14 +132,14 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
@Override
public boolean updateTileEntity(BlockPos blockPos, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos blockPos, LinCompoundTag tag) {
// We will assume that the tile entity was created for us,
// though we do not do this on the other versions
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
if (blockEntity == null) {
return false;
}
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeBinary(tag);
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeLin(tag);
blockEntity.load((CompoundTag) nativeTag);
return true;
}

View File

@ -732,7 +732,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
Iterator<CompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag> entityTagMap = nativeTag.getValue();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
final StringTag idTag = (StringTag) entityTagMap.get("Id");
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");

View File

@ -6,8 +6,8 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.nbt.NumericTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.ArrayList;
import java.util.Collections;
@ -36,7 +36,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
@Override
@SuppressWarnings("unchecked")
public Map<String, Tag> getValue() {
public Map<String, Tag<?, ?>> getValue() {
if (compoundTag == null) {
compoundTag = (CompoundTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(compoundTagSupplier.get());
}
@ -44,9 +44,9 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@Override
public CompoundBinaryTag asBinaryTag() {
public LinCompoundTag toLinTag() {
getValue();
return compoundTag.asBinaryTag();
return compoundTag.toLinTag();
}
public boolean containsKey(String key) {
@ -94,10 +94,10 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public List<Tag> getList(String key) {
public List<? extends Tag<?, ?>> getList(String key) {
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
if (tag instanceof net.minecraft.nbt.ListTag nbtList) {
ArrayList<Tag> list = new ArrayList<>();
ArrayList<Tag<?, ?>> list = new ArrayList<>();
for (net.minecraft.nbt.Tag elem : nbtList) {
if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) {
list.add(new PaperweightLazyCompoundTag(compoundTag));
@ -120,7 +120,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
public <T extends Tag<?, ?>> List<T> getList(String key, Class<T> listType) {
ListTag listTag = getListTag(key);
if (listTag.getType().equals(listType)) {
return (List<T>) listTag.getValue();

View File

@ -55,20 +55,6 @@ import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -135,6 +121,22 @@ import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinEndTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinLongArrayTag;
import org.enginehub.linbus.tree.LinLongTag;
import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;
@ -166,7 +168,7 @@ import static com.google.common.base.Preconditions.checkState;
public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft.nbt.Tag> {
private final Logger LOGGER = Logger.getLogger(getClass().getCanonicalName());
private final Logger logger = Logger.getLogger(getClass().getCanonicalName());
private final Field serverWorldsField;
private final Method getChunkFutureMethod;
@ -348,7 +350,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) {
net.minecraft.nbt.CompoundTag tag = te.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
return state.toBaseBlock();
@ -467,7 +469,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
readEntityIntoTag(mcEntity, tag);
return new BaseEntity(
com.sk89q.worldedit.world.entity.EntityTypes.get(id),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag))
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag))
);
}
@ -483,9 +485,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
Entity createdEntity = createEntityFromId(state.getType().id(), craftWorld.getHandle());
if (createdEntity != null) {
CompoundBinaryTag nativeTag = state.getNbt();
LinCompoundTag nativeTag = state.getNbt();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeBinary(nativeTag);
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeLin(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
@ -567,13 +569,13 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
}
@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().connection.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity(
new BlockPos(pos.x(), pos.y(), pos.z()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
),
__ -> (net.minecraft.nbt.CompoundTag) fromNativeBinary(nbtData)
__ -> (net.minecraft.nbt.CompoundTag) fromNativeLin(nbtData)
));
}
@ -609,7 +611,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt(((LinCompoundTag) toNativeLin(nmsStack.getTag())));
return weStack;
}
@ -785,7 +787,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
state = state.toBaseBlock(((LinCompoundTag) toNativeLin(tag)));
}
extent.setBlock(vec, state.toBaseBlock());
if (options.shouldRegenBiomes()) {
@ -879,51 +881,49 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return native WorldEdit NBT structure
*/
@Override
public BinaryTag toNativeBinary(net.minecraft.nbt.Tag foreign) {
public LinTag<?> toNativeLin(net.minecraft.nbt.Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, BinaryTag> values = new HashMap<>();
Map<String, LinTag<?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();
for (String str : foreignKeys) {
net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str);
values.put(str, toNativeBinary(base));
values.put(str, toNativeLin(base));
}
return CompoundBinaryTag.from(values);
return LinCompoundTag.of(values);
} else if (foreign instanceof net.minecraft.nbt.ByteTag) {
return ByteBinaryTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
return LinByteTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
} else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) {
return ByteArrayBinaryTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
return LinByteArrayTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
} else if (foreign instanceof net.minecraft.nbt.DoubleTag) {
return DoubleBinaryTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
return LinDoubleTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
} else if (foreign instanceof net.minecraft.nbt.FloatTag) {
return FloatBinaryTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
return LinFloatTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
} else if (foreign instanceof net.minecraft.nbt.IntTag) {
return IntBinaryTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
return LinIntTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
} else if (foreign instanceof net.minecraft.nbt.IntArrayTag) {
return IntArrayBinaryTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
return LinIntArrayTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
} else if (foreign instanceof net.minecraft.nbt.LongArrayTag) {
return LongArrayBinaryTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
return LinLongArrayTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
} else if (foreign instanceof net.minecraft.nbt.ListTag) {
try {
return toNativeList((net.minecraft.nbt.ListTag) foreign);
return toNativeLinList((net.minecraft.nbt.ListTag) foreign);
} catch (Throwable e) {
LOGGER.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
return ListBinaryTag.empty();
logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
}
} else if (foreign instanceof net.minecraft.nbt.LongTag) {
return LongBinaryTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
return LinLongTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
} else if (foreign instanceof net.minecraft.nbt.ShortTag) {
return ShortBinaryTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
return LinShortTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
} else if (foreign instanceof net.minecraft.nbt.StringTag) {
return StringBinaryTag.of(foreign.getAsString());
return LinStringTag.of(foreign.getAsString());
} else if (foreign instanceof net.minecraft.nbt.EndTag) {
return EndBinaryTag.get();
} else {
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
return LinEndTag.instance();
}
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
}
/**
@ -934,14 +934,16 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @throws SecurityException on error
* @throws IllegalArgumentException on error
*/
private ListBinaryTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
ListBinaryTag.Builder values = ListBinaryTag.builder();
private LinListTag<?> toNativeLinList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
LinListTag.Builder<LinTag<?>> builder = LinListTag.builder(
LinTagType.fromId(LinTagId.fromId(foreign.getElementType()))
);
for (net.minecraft.nbt.Tag tag : foreign) {
values.add(toNativeBinary(tag));
builder.add(toNativeLin(tag));
}
return values.build();
return builder.build();
}
/**
@ -951,44 +953,43 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return non-native structure
*/
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
public net.minecraft.nbt.Tag fromNativeLin(LinTag<?> foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundBinaryTag) {
if (foreign instanceof LinCompoundTag compoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (String key : ((CompoundBinaryTag) foreign).keySet()) {
tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
for (var entry : compoundTag.value().entrySet()) {
tag.put(entry.getKey(), fromNativeLin(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteBinaryTag) {
return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
} else if (foreign instanceof ByteArrayBinaryTag) {
return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
} else if (foreign instanceof DoubleBinaryTag) {
return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
} else if (foreign instanceof FloatBinaryTag) {
return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
} else if (foreign instanceof IntBinaryTag) {
return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
} else if (foreign instanceof IntArrayBinaryTag) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
} else if (foreign instanceof LongArrayBinaryTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
} else if (foreign instanceof ListBinaryTag) {
} else if (foreign instanceof LinByteTag byteTag) {
return net.minecraft.nbt.ByteTag.valueOf(byteTag.valueAsByte());
} else if (foreign instanceof LinByteArrayTag byteArrayTag) {
return new net.minecraft.nbt.ByteArrayTag(byteArrayTag.value());
} else if (foreign instanceof LinDoubleTag doubleTag) {
return net.minecraft.nbt.DoubleTag.valueOf(doubleTag.valueAsDouble());
} else if (foreign instanceof LinFloatTag floatTag) {
return net.minecraft.nbt.FloatTag.valueOf(floatTag.valueAsFloat());
} else if (foreign instanceof LinIntTag intTag) {
return net.minecraft.nbt.IntTag.valueOf(intTag.valueAsInt());
} else if (foreign instanceof LinIntArrayTag intArrayTag) {
return new net.minecraft.nbt.IntArrayTag(intArrayTag.value());
} else if (foreign instanceof LinLongArrayTag longArrayTag) {
return new net.minecraft.nbt.LongArrayTag(longArrayTag.value());
} else if (foreign instanceof LinListTag<?> listTag) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListBinaryTag foreignList = (ListBinaryTag) foreign;
for (BinaryTag t : foreignList) {
tag.add(fromNativeBinary(t));
for (var t : listTag.value()) {
tag.add(fromNativeLin(t));
}
return tag;
} else if (foreign instanceof LongBinaryTag) {
return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
} else if (foreign instanceof ShortBinaryTag) {
return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
} else if (foreign instanceof StringBinaryTag) {
return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
} else if (foreign instanceof EndBinaryTag) {
} else if (foreign instanceof LinLongTag longTag) {
return net.minecraft.nbt.LongTag.valueOf(longTag.valueAsLong());
} else if (foreign instanceof LinShortTag shortTag) {
return net.minecraft.nbt.ShortTag.valueOf(shortTag.valueAsShort());
} else if (foreign instanceof LinStringTag stringTag) {
return net.minecraft.nbt.StringTag.valueOf(stringTag.value());
} else if (foreign instanceof LinEndTag) {
return net.minecraft.nbt.EndTag.INSTANCE;
} else {
throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());
@ -1027,7 +1028,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
WatchdogThread.tick();
}
} catch (IllegalAccessException e) {
LOGGER.log(Level.WARNING, "Failed to tick watchdog", e);
logger.log(Level.WARNING, "Failed to tick watchdog", e);
}
}
}

View File

@ -35,7 +35,6 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component;
@ -48,7 +47,9 @@ import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.item.DyeColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.EnumMap;
@ -62,7 +63,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
@ -78,16 +78,15 @@ import javax.annotation.Nullable;
@SuppressWarnings({ "rawtypes", "unchecked" })
class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
//FAWE start - BinaryTag
@SuppressWarnings("unchecked")
@Override
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
if (type == FixTypes.CHUNK) {
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
return (T) fixChunk((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_ENTITY) {
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
return (T) fixBlockEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.ENTITY) {
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
return (T) fixEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_STATE) {
return (T) fixBlockState((String) original, srcVer);
} else if (type == FixTypes.ITEM_TYPE) {
@ -98,24 +97,23 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return original;
}
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
private LinCompoundTag fixChunk(LinCompoundTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(originalChunk);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
private LinCompoundTag fixBlockEntity(LinCompoundTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origTileEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
private LinCompoundTag fixEntity(LinCompoundTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
//FAWE end
private String fixBlockState(String blockState, int srcVer) {
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R1;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
@ -27,17 +27,20 @@ import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1;
@ -101,8 +104,15 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
return false;
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false;
}
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
@Override

View File

@ -35,9 +35,6 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -83,6 +80,9 @@ import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Player;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -274,7 +274,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
}
@ -302,14 +302,14 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
if (id != null) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
PaperweightPlatformAdapter.readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
tags.put("Id", StringBinaryTag.of(id));
return CompoundBinaryTag.from(tags);
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);
} else {
@ -514,7 +514,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt(((LinCompoundTag) toNativeLin(nmsStack.getTag())));
return weStack;
}

View File

@ -9,15 +9,13 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -25,6 +23,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -133,14 +132,14 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
@Override
public boolean updateTileEntity(BlockPos blockPos, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos blockPos, LinCompoundTag tag) {
// We will assume that the tile entity was created for us,
// though we do not do this on the other versions
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
if (blockEntity == null) {
return false;
}
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeBinary(tag);
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeLin(tag);
blockEntity.load((CompoundTag) nativeTag);
return true;
}

View File

@ -730,7 +730,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
Iterator<CompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag> entityTagMap = nativeTag.getValue();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
final StringTag idTag = (StringTag) entityTagMap.get("Id");
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");

View File

@ -6,8 +6,8 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.nbt.NumericTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.ArrayList;
import java.util.Collections;
@ -36,7 +36,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
@Override
@SuppressWarnings("unchecked")
public Map<String, Tag> getValue() {
public Map<String, Tag<?, ?>> getValue() {
if (compoundTag == null) {
compoundTag = (CompoundTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(compoundTagSupplier.get());
}
@ -44,9 +44,9 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@Override
public CompoundBinaryTag asBinaryTag() {
public LinCompoundTag toLinTag() {
getValue();
return compoundTag.asBinaryTag();
return compoundTag.toLinTag();
}
public boolean containsKey(String key) {
@ -94,10 +94,10 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public List<Tag> getList(String key) {
public List<? extends Tag<?, ?>> getList(String key) {
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
if (tag instanceof net.minecraft.nbt.ListTag nbtList) {
ArrayList<Tag> list = new ArrayList<>();
ArrayList<Tag<?, ?>> list = new ArrayList<>();
for (net.minecraft.nbt.Tag elem : nbtList) {
if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) {
list.add(new PaperweightLazyCompoundTag(compoundTag));
@ -120,7 +120,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
public <T extends Tag<?, ?>> List<T> getList(String key, Class<T> listType) {
ListTag listTag = getListTag(key);
if (listTag.getType().equals(listType)) {
return (List<T>) listTag.getValue();

View File

@ -54,20 +54,6 @@ import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -134,9 +120,26 @@ import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinEndTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinLongArrayTag;
import org.enginehub.linbus.tree.LinLongTag;
import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -158,7 +161,6 @@ import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@ -345,7 +347,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) {
net.minecraft.nbt.CompoundTag tag = te.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
return state.toBaseBlock();
@ -427,7 +429,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
readEntityIntoTag(mcEntity, tag);
return new BaseEntity(
com.sk89q.worldedit.world.entity.EntityTypes.get(id),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag))
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag))
);
}
@ -443,9 +445,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
Entity createdEntity = createEntityFromId(state.getType().id(), craftWorld.getHandle());
if (createdEntity != null) {
CompoundBinaryTag nativeTag = state.getNbt();
LinCompoundTag nativeTag = state.getNbt();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeBinary(nativeTag);
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeLin(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
@ -527,13 +529,13 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
}
@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().connection.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity(
new BlockPos(pos.x(), pos.y(), pos.z()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
),
__ -> (net.minecraft.nbt.CompoundTag) fromNativeBinary(nbtData)
__ -> (net.minecraft.nbt.CompoundTag) fromNativeLin(nbtData)
));
}
@ -558,7 +560,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt((LinCompoundTag) toNativeLin(nmsStack.getTag()));
return weStack;
}
@ -734,7 +736,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
state = state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
extent.setBlock(vec, state.toBaseBlock());
if (options.shouldRegenBiomes()) {
@ -817,51 +819,49 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return native WorldEdit NBT structure
*/
@Override
public BinaryTag toNativeBinary(net.minecraft.nbt.Tag foreign) {
public LinTag<?> toNativeLin(net.minecraft.nbt.Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, BinaryTag> values = new HashMap<>();
Map<String, LinTag<?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();
for (String str : foreignKeys) {
net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str);
values.put(str, toNativeBinary(base));
values.put(str, toNativeLin(base));
}
return CompoundBinaryTag.from(values);
return LinCompoundTag.of(values);
} else if (foreign instanceof net.minecraft.nbt.ByteTag) {
return ByteBinaryTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
return LinByteTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
} else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) {
return ByteArrayBinaryTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
return LinByteArrayTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
} else if (foreign instanceof net.minecraft.nbt.DoubleTag) {
return DoubleBinaryTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
return LinDoubleTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
} else if (foreign instanceof net.minecraft.nbt.FloatTag) {
return FloatBinaryTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
return LinFloatTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
} else if (foreign instanceof net.minecraft.nbt.IntTag) {
return IntBinaryTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
return LinIntTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
} else if (foreign instanceof net.minecraft.nbt.IntArrayTag) {
return IntArrayBinaryTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
return LinIntArrayTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
} else if (foreign instanceof net.minecraft.nbt.LongArrayTag) {
return LongArrayBinaryTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
return LinLongArrayTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
} else if (foreign instanceof net.minecraft.nbt.ListTag) {
try {
return toNativeList((net.minecraft.nbt.ListTag) foreign);
return toNativeLinList((net.minecraft.nbt.ListTag) foreign);
} catch (Throwable e) {
logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
return ListBinaryTag.empty();
}
} else if (foreign instanceof net.minecraft.nbt.LongTag) {
return LongBinaryTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
return LinLongTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
} else if (foreign instanceof net.minecraft.nbt.ShortTag) {
return ShortBinaryTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
return LinShortTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
} else if (foreign instanceof net.minecraft.nbt.StringTag) {
return StringBinaryTag.of(foreign.getAsString());
return LinStringTag.of(foreign.getAsString());
} else if (foreign instanceof net.minecraft.nbt.EndTag) {
return EndBinaryTag.get();
} else {
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
return LinEndTag.instance();
}
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
}
/**
@ -872,14 +872,16 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @throws SecurityException on error
* @throws IllegalArgumentException on error
*/
private ListBinaryTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
ListBinaryTag.Builder values = ListBinaryTag.builder();
private LinListTag<?> toNativeLinList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
LinListTag.Builder<LinTag<?>> builder = LinListTag.builder(
LinTagType.fromId(LinTagId.fromId(foreign.getElementType()))
);
for (net.minecraft.nbt.Tag tag : foreign) {
values.add(toNativeBinary(tag));
builder.add(toNativeLin(tag));
}
return values.build();
return builder.build();
}
/**
@ -889,44 +891,43 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return non-native structure
*/
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
public net.minecraft.nbt.Tag fromNativeLin(LinTag<?> foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundBinaryTag) {
if (foreign instanceof LinCompoundTag compoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (String key : ((CompoundBinaryTag) foreign).keySet()) {
tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
for (var entry : compoundTag.value().entrySet()) {
tag.put(entry.getKey(), fromNativeLin(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteBinaryTag) {
return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
} else if (foreign instanceof ByteArrayBinaryTag) {
return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
} else if (foreign instanceof DoubleBinaryTag) {
return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
} else if (foreign instanceof FloatBinaryTag) {
return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
} else if (foreign instanceof IntBinaryTag) {
return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
} else if (foreign instanceof IntArrayBinaryTag) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
} else if (foreign instanceof LongArrayBinaryTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
} else if (foreign instanceof ListBinaryTag) {
} else if (foreign instanceof LinByteTag byteTag) {
return net.minecraft.nbt.ByteTag.valueOf(byteTag.valueAsByte());
} else if (foreign instanceof LinByteArrayTag byteArrayTag) {
return new net.minecraft.nbt.ByteArrayTag(byteArrayTag.value());
} else if (foreign instanceof LinDoubleTag doubleTag) {
return net.minecraft.nbt.DoubleTag.valueOf(doubleTag.valueAsDouble());
} else if (foreign instanceof LinFloatTag floatTag) {
return net.minecraft.nbt.FloatTag.valueOf(floatTag.valueAsFloat());
} else if (foreign instanceof LinIntTag intTag) {
return net.minecraft.nbt.IntTag.valueOf(intTag.valueAsInt());
} else if (foreign instanceof LinIntArrayTag intArrayTag) {
return new net.minecraft.nbt.IntArrayTag(intArrayTag.value());
} else if (foreign instanceof LinLongArrayTag longArrayTag) {
return new net.minecraft.nbt.LongArrayTag(longArrayTag.value());
} else if (foreign instanceof LinListTag<?> listTag) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListBinaryTag foreignList = (ListBinaryTag) foreign;
for (BinaryTag t : foreignList) {
tag.add(fromNativeBinary(t));
for (var t : listTag.value()) {
tag.add(fromNativeLin(t));
}
return tag;
} else if (foreign instanceof LongBinaryTag) {
return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
} else if (foreign instanceof ShortBinaryTag) {
return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
} else if (foreign instanceof StringBinaryTag) {
return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
} else if (foreign instanceof EndBinaryTag) {
} else if (foreign instanceof LinLongTag longTag) {
return net.minecraft.nbt.LongTag.valueOf(longTag.valueAsLong());
} else if (foreign instanceof LinShortTag shortTag) {
return net.minecraft.nbt.ShortTag.valueOf(shortTag.valueAsShort());
} else if (foreign instanceof LinStringTag stringTag) {
return net.minecraft.nbt.StringTag.valueOf(stringTag.value());
} else if (foreign instanceof LinEndTag) {
return net.minecraft.nbt.EndTag.INSTANCE;
} else {
throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());

View File

@ -35,7 +35,6 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component;
@ -48,7 +47,9 @@ import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.item.DyeColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.EnumMap;
@ -62,7 +63,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
@ -78,16 +78,15 @@ import javax.annotation.Nullable;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
//FAWE start - BinaryTag
@SuppressWarnings("unchecked")
@Override
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
if (type == FixTypes.CHUNK) {
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
return (T) fixChunk((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_ENTITY) {
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
return (T) fixBlockEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.ENTITY) {
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
return (T) fixEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_STATE) {
return (T) fixBlockState((String) original, srcVer);
} else if (type == FixTypes.ITEM_TYPE) {
@ -98,24 +97,23 @@ public class PaperweightDataConverters extends DataFixerBuilder implements com.s
return original;
}
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
private LinCompoundTag fixChunk(LinCompoundTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(originalChunk);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
private LinCompoundTag fixBlockEntity(LinCompoundTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origTileEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
private LinCompoundTag fixEntity(LinCompoundTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
//FAWE end
private String fixBlockState(String blockState, int srcVer) {
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);

View File

@ -24,7 +24,6 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.FullChunkStatus;
@ -34,10 +33,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1;
@ -101,7 +101,7 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
public boolean updateTileEntity(final BlockPos position, final LinCompoundTag tag) {
return false;
}

View File

@ -34,9 +34,6 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -82,6 +79,9 @@ import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
import org.bukkit.entity.Player;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -277,7 +277,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
}
@ -305,14 +305,14 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
if (id != null) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
tags.put("Id", StringBinaryTag.of(id));
return CompoundBinaryTag.from(tags);
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);
} else {
@ -517,7 +517,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt(((LinCompoundTag) toNativeLin(nmsStack.getTag())));
return weStack;
}

View File

@ -9,15 +9,13 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -25,6 +23,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -133,14 +132,14 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
@Override
public boolean updateTileEntity(BlockPos blockPos, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos blockPos, LinCompoundTag tag) {
// We will assume that the tile entity was created for us,
// though we do not do this on the other versions
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
if (blockEntity == null) {
return false;
}
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeBinary(tag);
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeLin(tag);
blockEntity.load((CompoundTag) nativeTag);
return true;
}

View File

@ -738,7 +738,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
Iterator<CompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag> entityTagMap = nativeTag.getValue();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
final StringTag idTag = (StringTag) entityTagMap.get("Id");
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");

View File

@ -6,8 +6,8 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.nbt.NumericTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.ArrayList;
import java.util.Collections;
@ -36,7 +36,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
@Override
@SuppressWarnings("unchecked")
public Map<String, Tag> getValue() {
public Map<String, Tag<?, ?>> getValue() {
if (compoundTag == null) {
compoundTag = (CompoundTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(compoundTagSupplier.get());
}
@ -44,9 +44,9 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@Override
public CompoundBinaryTag asBinaryTag() {
public LinCompoundTag toLinTag() {
getValue();
return compoundTag.asBinaryTag();
return compoundTag.toLinTag();
}
public boolean containsKey(String key) {
@ -94,10 +94,10 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public List<Tag> getList(String key) {
public List<? extends Tag<?, ?>> getList(String key) {
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
if (tag instanceof net.minecraft.nbt.ListTag nbtList) {
ArrayList<Tag> list = new ArrayList<>();
ArrayList<Tag<?, ?>> list = new ArrayList<>();
for (net.minecraft.nbt.Tag elem : nbtList) {
if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) {
list.add(new PaperweightLazyCompoundTag(compoundTag));
@ -120,7 +120,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
public <T extends Tag<?, ?>> List<T> getList(String key, Class<T> listType) {
ListTag listTag = getListTag(key);
if (listTag.getType().equals(listType)) {
return (List<T>) listTag.getValue();

View File

@ -54,20 +54,6 @@ import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -134,9 +120,26 @@ import org.bukkit.craftbukkit.v1_20_R3.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinEndTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinLongArrayTag;
import org.enginehub.linbus.tree.LinLongTag;
import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -158,7 +161,6 @@ import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@ -345,7 +347,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) {
net.minecraft.nbt.CompoundTag tag = te.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
return state.toBaseBlock();
@ -427,7 +429,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
readEntityIntoTag(mcEntity, tag);
return new BaseEntity(
com.sk89q.worldedit.world.entity.EntityTypes.get(id),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag))
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag))
);
}
@ -443,9 +445,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
Entity createdEntity = createEntityFromId(state.getType().id(), craftWorld.getHandle());
if (createdEntity != null) {
CompoundBinaryTag nativeTag = state.getNbt();
LinCompoundTag nativeTag = state.getNbt();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeBinary(nativeTag);
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeLin(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
@ -527,13 +529,13 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
}
@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
((CraftPlayer) player).getHandle().connection.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity(
new BlockPos(pos.x(), pos.y(), pos.z()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
),
__ -> (net.minecraft.nbt.CompoundTag) fromNativeBinary(nbtData)
__ -> (net.minecraft.nbt.CompoundTag) fromNativeLin(nbtData)
));
}
@ -558,7 +560,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt((LinCompoundTag) toNativeLin(nmsStack.getTag()));
return weStack;
}
@ -734,7 +736,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
state = state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
extent.setBlock(vec, state.toBaseBlock());
if (options.shouldRegenBiomes()) {
@ -817,51 +819,49 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return native WorldEdit NBT structure
*/
@Override
public BinaryTag toNativeBinary(net.minecraft.nbt.Tag foreign) {
public LinTag<?> toNativeLin(net.minecraft.nbt.Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, BinaryTag> values = new HashMap<>();
Map<String, LinTag<?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();
for (String str : foreignKeys) {
net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str);
values.put(str, toNativeBinary(base));
values.put(str, toNativeLin(base));
}
return CompoundBinaryTag.from(values);
return LinCompoundTag.of(values);
} else if (foreign instanceof net.minecraft.nbt.ByteTag) {
return ByteBinaryTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
return LinByteTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
} else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) {
return ByteArrayBinaryTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
return LinByteArrayTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
} else if (foreign instanceof net.minecraft.nbt.DoubleTag) {
return DoubleBinaryTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
return LinDoubleTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
} else if (foreign instanceof net.minecraft.nbt.FloatTag) {
return FloatBinaryTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
return LinFloatTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
} else if (foreign instanceof net.minecraft.nbt.IntTag) {
return IntBinaryTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
return LinIntTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
} else if (foreign instanceof net.minecraft.nbt.IntArrayTag) {
return IntArrayBinaryTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
return LinIntArrayTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
} else if (foreign instanceof net.minecraft.nbt.LongArrayTag) {
return LongArrayBinaryTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
return LinLongArrayTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
} else if (foreign instanceof net.minecraft.nbt.ListTag) {
try {
return toNativeList((net.minecraft.nbt.ListTag) foreign);
return toNativeLinList((net.minecraft.nbt.ListTag) foreign);
} catch (Throwable e) {
logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
return ListBinaryTag.empty();
}
} else if (foreign instanceof net.minecraft.nbt.LongTag) {
return LongBinaryTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
return LinLongTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
} else if (foreign instanceof net.minecraft.nbt.ShortTag) {
return ShortBinaryTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
return LinShortTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
} else if (foreign instanceof net.minecraft.nbt.StringTag) {
return StringBinaryTag.of(foreign.getAsString());
return LinStringTag.of(foreign.getAsString());
} else if (foreign instanceof net.minecraft.nbt.EndTag) {
return EndBinaryTag.get();
} else {
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
return LinEndTag.instance();
}
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
}
/**
@ -872,14 +872,16 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @throws SecurityException on error
* @throws IllegalArgumentException on error
*/
private ListBinaryTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
ListBinaryTag.Builder values = ListBinaryTag.builder();
private LinListTag<?> toNativeLinList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
LinListTag.Builder<LinTag<?>> builder = LinListTag.builder(
LinTagType.fromId(LinTagId.fromId(foreign.getElementType()))
);
for (net.minecraft.nbt.Tag tag : foreign) {
values.add(toNativeBinary(tag));
builder.add(toNativeLin(tag));
}
return values.build();
return builder.build();
}
/**
@ -889,44 +891,43 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return non-native structure
*/
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
public net.minecraft.nbt.Tag fromNativeLin(LinTag<?> foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundBinaryTag) {
if (foreign instanceof LinCompoundTag compoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (String key : ((CompoundBinaryTag) foreign).keySet()) {
tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
for (var entry : compoundTag.value().entrySet()) {
tag.put(entry.getKey(), fromNativeLin(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteBinaryTag) {
return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
} else if (foreign instanceof ByteArrayBinaryTag) {
return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
} else if (foreign instanceof DoubleBinaryTag) {
return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
} else if (foreign instanceof FloatBinaryTag) {
return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
} else if (foreign instanceof IntBinaryTag) {
return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
} else if (foreign instanceof IntArrayBinaryTag) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
} else if (foreign instanceof LongArrayBinaryTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
} else if (foreign instanceof ListBinaryTag) {
} else if (foreign instanceof LinByteTag byteTag) {
return net.minecraft.nbt.ByteTag.valueOf(byteTag.valueAsByte());
} else if (foreign instanceof LinByteArrayTag byteArrayTag) {
return new net.minecraft.nbt.ByteArrayTag(byteArrayTag.value());
} else if (foreign instanceof LinDoubleTag doubleTag) {
return net.minecraft.nbt.DoubleTag.valueOf(doubleTag.valueAsDouble());
} else if (foreign instanceof LinFloatTag floatTag) {
return net.minecraft.nbt.FloatTag.valueOf(floatTag.valueAsFloat());
} else if (foreign instanceof LinIntTag intTag) {
return net.minecraft.nbt.IntTag.valueOf(intTag.valueAsInt());
} else if (foreign instanceof LinIntArrayTag intArrayTag) {
return new net.minecraft.nbt.IntArrayTag(intArrayTag.value());
} else if (foreign instanceof LinLongArrayTag longArrayTag) {
return new net.minecraft.nbt.LongArrayTag(longArrayTag.value());
} else if (foreign instanceof LinListTag<?> listTag) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListBinaryTag foreignList = (ListBinaryTag) foreign;
for (BinaryTag t : foreignList) {
tag.add(fromNativeBinary(t));
for (var t : listTag.value()) {
tag.add(fromNativeLin(t));
}
return tag;
} else if (foreign instanceof LongBinaryTag) {
return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
} else if (foreign instanceof ShortBinaryTag) {
return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
} else if (foreign instanceof StringBinaryTag) {
return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
} else if (foreign instanceof EndBinaryTag) {
} else if (foreign instanceof LinLongTag longTag) {
return net.minecraft.nbt.LongTag.valueOf(longTag.valueAsLong());
} else if (foreign instanceof LinShortTag shortTag) {
return net.minecraft.nbt.ShortTag.valueOf(shortTag.valueAsShort());
} else if (foreign instanceof LinStringTag stringTag) {
return net.minecraft.nbt.StringTag.valueOf(stringTag.value());
} else if (foreign instanceof LinEndTag) {
return net.minecraft.nbt.EndTag.INSTANCE;
} else {
throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());

View File

@ -35,8 +35,6 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R3.PaperweightAdapter;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component;
@ -49,7 +47,9 @@ import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.item.DyeColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.EnumMap;
@ -63,7 +63,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
@ -79,16 +78,15 @@ import javax.annotation.Nullable;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
//FAWE start - BinaryTag
@SuppressWarnings("unchecked")
@Override
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
if (type == FixTypes.CHUNK) {
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
return (T) fixChunk((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_ENTITY) {
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
return (T) fixBlockEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.ENTITY) {
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
return (T) fixEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_STATE) {
return (T) fixBlockState((String) original, srcVer);
} else if (type == FixTypes.ITEM_TYPE) {
@ -99,24 +97,23 @@ public class PaperweightDataConverters extends DataFixerBuilder implements com.s
return original;
}
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
private LinCompoundTag fixChunk(LinCompoundTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(originalChunk);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
private LinCompoundTag fixBlockEntity(LinCompoundTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origTileEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
private LinCompoundTag fixEntity(LinCompoundTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
//FAWE end
private String fixBlockState(String blockState, int srcVer) {
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);

View File

@ -19,25 +19,28 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R3;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1;
@ -101,8 +104,15 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
return false;
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false;
}
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
@Override

View File

@ -34,9 +34,6 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -82,6 +79,9 @@ import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey;
import org.bukkit.entity.Player;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -277,7 +277,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
}
@ -305,14 +305,14 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
if (id != null) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
tags.put("Id", StringBinaryTag.of(id));
return CompoundBinaryTag.from(tags);
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);
} else {
@ -517,7 +517,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
weStack.setNbt(((LinCompoundTag) toNativeLin(nmsStack.getTag())));
return weStack;
}

View File

@ -9,14 +9,13 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -24,6 +23,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -132,14 +132,14 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
@Override
public boolean updateTileEntity(BlockPos blockPos, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos blockPos, LinCompoundTag tag) {
// We will assume that the tile entity was created for us,
// though we do not do this on the other versions
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
if (blockEntity == null) {
return false;
}
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeBinary(tag);
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeLin(tag);
blockEntity.load((CompoundTag) nativeTag);
return true;
}

View File

@ -737,7 +737,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
Iterator<CompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag> entityTagMap = nativeTag.getValue();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
final StringTag idTag = (StringTag) entityTagMap.get("Id");
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");

View File

@ -6,8 +6,8 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.nbt.NumericTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.ArrayList;
import java.util.Collections;
@ -36,7 +36,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
@Override
@SuppressWarnings("unchecked")
public Map<String, Tag> getValue() {
public Map<String, Tag<?, ?>> getValue() {
if (compoundTag == null) {
compoundTag = (CompoundTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(compoundTagSupplier.get());
}
@ -44,9 +44,9 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@Override
public CompoundBinaryTag asBinaryTag() {
public LinCompoundTag toLinTag() {
getValue();
return compoundTag.asBinaryTag();
return compoundTag.toLinTag();
}
public boolean containsKey(String key) {
@ -94,10 +94,10 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public List<Tag> getList(String key) {
public List<? extends Tag<?, ?>> getList(String key) {
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
if (tag instanceof net.minecraft.nbt.ListTag nbtList) {
ArrayList<Tag> list = new ArrayList<>();
ArrayList<Tag<?, ?>> list = new ArrayList<>();
for (net.minecraft.nbt.Tag elem : nbtList) {
if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) {
list.add(new PaperweightLazyCompoundTag(compoundTag));
@ -120,7 +120,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
public <T extends Tag<?, ?>> List<T> getList(String key, Class<T> listType) {
ListTag listTag = getListTag(key);
if (listTag.getType().equals(listType)) {
return (List<T>) listTag.getValue();

View File

@ -54,20 +54,6 @@ import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -139,9 +125,26 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.generator.ChunkGenerator;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinEndTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinLongArrayTag;
import org.enginehub.linbus.tree.LinLongTag;
import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -163,7 +166,6 @@ import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@ -375,7 +377,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) {
net.minecraft.nbt.CompoundTag tag = te.saveWithId(MinecraftServer.getServer().registryAccess());
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
return state.toBaseBlock();
@ -457,7 +459,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
readEntityIntoTag(mcEntity, tag);
return new BaseEntity(
com.sk89q.worldedit.world.entity.EntityTypes.get(id),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag))
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag))
);
}
@ -473,9 +475,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
Entity createdEntity = createEntityFromId(state.getType().id(), craftWorld.getHandle());
if (createdEntity != null) {
CompoundBinaryTag nativeTag = state.getNbt();
LinCompoundTag nativeTag = state.getNbt();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeBinary(nativeTag);
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) fromNativeLin(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
@ -575,7 +577,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
}
@Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
public void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
var structureBlock = new StructureBlockEntity(
new BlockPos(pos.x(), pos.y(), pos.z()),
Blocks.STRUCTURE_BLOCK.defaultBlockState()
@ -583,7 +585,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
structureBlock.setLevel(((CraftPlayer) player).getHandle().level());
((CraftPlayer) player).getHandle().connection.send(ClientboundBlockEntityDataPacket.create(
structureBlock,
(blockEntity, registryAccess) -> (net.minecraft.nbt.CompoundTag) fromNativeBinary(nbtData)
(blockEntity, registryAccess) -> (net.minecraft.nbt.CompoundTag) fromNativeLin(nbtData)
));
}
@ -619,7 +621,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
).getOrThrow();
return new BaseItemStack(
BukkitAdapter.asItemType(itemStack.getType()),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag)),
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag)),
itemStack.getAmount()
);
}
@ -811,7 +813,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId(serverWorld.registryAccess());
state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
state = state.toBaseBlock(((LinCompoundTag) toNativeLin(tag)));
}
extent.setBlock(vec, state.toBaseBlock());
if (options.shouldRegenBiomes()) {
@ -894,51 +896,49 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return native WorldEdit NBT structure
*/
@Override
public BinaryTag toNativeBinary(net.minecraft.nbt.Tag foreign) {
public LinTag<?> toNativeLin(net.minecraft.nbt.Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, BinaryTag> values = new HashMap<>();
Map<String, LinTag<?>> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();
for (String str : foreignKeys) {
net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str);
values.put(str, toNativeBinary(base));
values.put(str, toNativeLin(base));
}
return CompoundBinaryTag.from(values);
return LinCompoundTag.of(values);
} else if (foreign instanceof net.minecraft.nbt.ByteTag) {
return ByteBinaryTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
return LinByteTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
} else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) {
return ByteArrayBinaryTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
return LinByteArrayTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
} else if (foreign instanceof net.minecraft.nbt.DoubleTag) {
return DoubleBinaryTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
return LinDoubleTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
} else if (foreign instanceof net.minecraft.nbt.FloatTag) {
return FloatBinaryTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
return LinFloatTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
} else if (foreign instanceof net.minecraft.nbt.IntTag) {
return IntBinaryTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
return LinIntTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
} else if (foreign instanceof net.minecraft.nbt.IntArrayTag) {
return IntArrayBinaryTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
return LinIntArrayTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
} else if (foreign instanceof net.minecraft.nbt.LongArrayTag) {
return LongArrayBinaryTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
return LinLongArrayTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
} else if (foreign instanceof net.minecraft.nbt.ListTag) {
try {
return toNativeList((net.minecraft.nbt.ListTag) foreign);
return toNativeLinList((net.minecraft.nbt.ListTag) foreign);
} catch (Throwable e) {
logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
return ListBinaryTag.empty();
}
} else if (foreign instanceof net.minecraft.nbt.LongTag) {
return LongBinaryTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
return LinLongTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
} else if (foreign instanceof net.minecraft.nbt.ShortTag) {
return ShortBinaryTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
return LinShortTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
} else if (foreign instanceof net.minecraft.nbt.StringTag) {
return StringBinaryTag.of(foreign.getAsString());
return LinStringTag.of(foreign.getAsString());
} else if (foreign instanceof net.minecraft.nbt.EndTag) {
return EndBinaryTag.get();
} else {
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
return LinEndTag.instance();
}
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
}
/**
@ -946,17 +946,19 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
*
* @param foreign the foreign tag
* @return the converted tag
* @throws SecurityException on error
* @throws SecurityException on error
* @throws IllegalArgumentException on error
*/
private ListBinaryTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
ListBinaryTag.Builder values = ListBinaryTag.builder();
private LinListTag<?> toNativeLinList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
LinListTag.Builder<LinTag<?>> builder = LinListTag.builder(
LinTagType.fromId(LinTagId.fromId(foreign.getElementType()))
);
for (net.minecraft.nbt.Tag tag : foreign) {
values.add(toNativeBinary(tag));
builder.add(toNativeLin(tag));
}
return values.build();
return builder.build();
}
/**
@ -966,44 +968,43 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
* @return non-native structure
*/
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
public net.minecraft.nbt.Tag fromNativeLin(LinTag<?> foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundBinaryTag) {
if (foreign instanceof LinCompoundTag compoundTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (String key : ((CompoundBinaryTag) foreign).keySet()) {
tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
for (var entry : compoundTag.value().entrySet()) {
tag.put(entry.getKey(), fromNativeLin(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteBinaryTag) {
return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
} else if (foreign instanceof ByteArrayBinaryTag) {
return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
} else if (foreign instanceof DoubleBinaryTag) {
return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
} else if (foreign instanceof FloatBinaryTag) {
return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
} else if (foreign instanceof IntBinaryTag) {
return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
} else if (foreign instanceof IntArrayBinaryTag) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
} else if (foreign instanceof LongArrayBinaryTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
} else if (foreign instanceof ListBinaryTag) {
} else if (foreign instanceof LinByteTag byteTag) {
return net.minecraft.nbt.ByteTag.valueOf(byteTag.valueAsByte());
} else if (foreign instanceof LinByteArrayTag byteArrayTag) {
return new net.minecraft.nbt.ByteArrayTag(byteArrayTag.value());
} else if (foreign instanceof LinDoubleTag doubleTag) {
return net.minecraft.nbt.DoubleTag.valueOf(doubleTag.valueAsDouble());
} else if (foreign instanceof LinFloatTag floatTag) {
return net.minecraft.nbt.FloatTag.valueOf(floatTag.valueAsFloat());
} else if (foreign instanceof LinIntTag intTag) {
return net.minecraft.nbt.IntTag.valueOf(intTag.valueAsInt());
} else if (foreign instanceof LinIntArrayTag intArrayTag) {
return new net.minecraft.nbt.IntArrayTag(intArrayTag.value());
} else if (foreign instanceof LinLongArrayTag longArrayTag) {
return new net.minecraft.nbt.LongArrayTag(longArrayTag.value());
} else if (foreign instanceof LinListTag<?> listTag) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListBinaryTag foreignList = (ListBinaryTag) foreign;
for (BinaryTag t : foreignList) {
tag.add(fromNativeBinary(t));
for (var t : listTag.value()) {
tag.add(fromNativeLin(t));
}
return tag;
} else if (foreign instanceof LongBinaryTag) {
return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
} else if (foreign instanceof ShortBinaryTag) {
return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
} else if (foreign instanceof StringBinaryTag) {
return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
} else if (foreign instanceof EndBinaryTag) {
} else if (foreign instanceof LinLongTag longTag) {
return net.minecraft.nbt.LongTag.valueOf(longTag.valueAsLong());
} else if (foreign instanceof LinShortTag shortTag) {
return net.minecraft.nbt.ShortTag.valueOf(shortTag.valueAsShort());
} else if (foreign instanceof LinStringTag stringTag) {
return net.minecraft.nbt.StringTag.valueOf(stringTag.value());
} else if (foreign instanceof LinEndTag) {
return net.minecraft.nbt.EndTag.INSTANCE;
} else {
throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());

View File

@ -35,8 +35,6 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R4.PaperweightAdapter;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.StringTag;
@ -51,7 +49,9 @@ import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.item.DyeColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.EnumMap;
@ -65,7 +65,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
@ -81,16 +80,15 @@ import javax.annotation.Nullable;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
//FAWE start - BinaryTag
@SuppressWarnings("unchecked")
@Override
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
if (type == FixTypes.CHUNK) {
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
return (T) fixChunk((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_ENTITY) {
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
return (T) fixBlockEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.ENTITY) {
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
return (T) fixEntity((LinCompoundTag) original, srcVer);
} else if (type == FixTypes.BLOCK_STATE) {
return (T) fixBlockState((String) original, srcVer);
} else if (type == FixTypes.ITEM_TYPE) {
@ -101,24 +99,23 @@ public class PaperweightDataConverters extends DataFixerBuilder implements com.s
return original;
}
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
private LinCompoundTag fixChunk(LinCompoundTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(originalChunk);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
private LinCompoundTag fixBlockEntity(LinCompoundTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origTileEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
private LinCompoundTag fixEntity(LinCompoundTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
return (LinCompoundTag) adapter.toNativeLin(fixed);
}
//FAWE end
private String fixBlockState(String blockState, int srcVer) {
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);

View File

@ -24,7 +24,6 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.FullChunkStatus;
@ -34,10 +33,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1;
@ -101,7 +101,7 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
public boolean updateTileEntity(final BlockPos position, final LinCompoundTag tag) {
return false;
}

View File

@ -36,9 +36,6 @@ import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -88,6 +85,9 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.Player;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -286,7 +286,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId(DedicatedServer.getServer().registryAccess());
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
}
}
@ -314,14 +314,14 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
if (id != null) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
Supplier<LinCompoundTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
tags.put("Id", StringBinaryTag.of(id));
return CompoundBinaryTag.from(tags);
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
tags.put("Id", LinStringTag.of(id));
return LinCompoundTag.of(tags);
};
return new LazyBaseEntity(type, saveTag);
} else {
@ -538,7 +538,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
).getOrThrow();
return new BaseItemStack(
BukkitAdapter.asItemType(itemStack.getType()),
LazyReference.from(() -> (CompoundBinaryTag) toNativeBinary(tag)),
LazyReference.from(() -> (LinCompoundTag) toNativeLin(tag)),
itemStack.getAmount()
);
}

View File

@ -9,15 +9,14 @@ import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -25,6 +24,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
@ -133,14 +133,14 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
@Override
public boolean updateTileEntity(BlockPos blockPos, CompoundBinaryTag tag) {
public boolean updateTileEntity(BlockPos blockPos, LinCompoundTag tag) {
// We will assume that the tile entity was created for us,
// though we do not do this on the other versions
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
if (blockEntity == null) {
return false;
}
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeBinary(tag);
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeLin(tag);
blockEntity.loadWithComponents((CompoundTag) nativeTag, DedicatedServer.getServer().registryAccess());
return true;
}

View File

@ -738,7 +738,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
Iterator<CompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag> entityTagMap = nativeTag.getValue();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
final StringTag idTag = (StringTag) entityTagMap.get("Id");
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");

View File

@ -6,8 +6,8 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.nbt.NumericTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.ArrayList;
import java.util.Collections;
@ -36,7 +36,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
@Override
@SuppressWarnings("unchecked")
public Map<String, Tag> getValue() {
public Map<String, Tag<?, ?>> getValue() {
if (compoundTag == null) {
compoundTag = (CompoundTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(compoundTagSupplier.get());
}
@ -44,9 +44,9 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@Override
public CompoundBinaryTag asBinaryTag() {
public LinCompoundTag toLinTag() {
getValue();
return compoundTag.asBinaryTag();
return compoundTag.toLinTag();
}
public boolean containsKey(String key) {
@ -94,10 +94,10 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public List<Tag> getList(String key) {
public List<? extends Tag<?, ?>> getList(String key) {
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
if (tag instanceof net.minecraft.nbt.ListTag nbtList) {
ArrayList<Tag> list = new ArrayList<>();
ArrayList<Tag<?, ?>> list = new ArrayList<>();
for (net.minecraft.nbt.Tag elem : nbtList) {
if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) {
list.add(new PaperweightLazyCompoundTag(compoundTag));
@ -120,7 +120,7 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
}
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
public <T extends Tag<?, ?>> List<T> getList(String key, Class<T> listType) {
ListTag listTag = getListTag(key);
if (listTag.getType().equals(listType)) {
return (List<T>) listTag.getValue();