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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
134 changed files with 2258 additions and 2542 deletions

View File

@ -40,8 +40,7 @@ fun Project.applyLibrariesConfiguration() {
val relocations = mapOf(
"net.kyori.text" to "com.sk89q.worldedit.util.formatting.text",
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori",
"net.kyori.adventure.nbt" to "com.sk89q.worldedit.util.nbt"
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori"
)
@ -53,9 +52,14 @@ fun Project.applyLibrariesConfiguration() {
exclude(dependency("com.google.guava:guava"))
exclude(dependency("com.google.code.gson:gson"))
exclude(dependency("com.google.errorprone:error_prone_annotations"))
exclude(dependency("com.google.guava:failureaccess"))
exclude(dependency("org.checkerframework:checker-qual"))
exclude(dependency("org.jetbrains:annotations"))
exclude(dependency("org.apache.logging.log4j:log4j-api"))
exclude(dependency("com.google.code.findbugs:jsr305"))
exclude {
it.moduleGroup == "org.jetbrains.kotlin"
}
}
relocations.forEach { (from, to) ->
@ -67,12 +71,20 @@ fun Project.applyLibrariesConfiguration() {
.filterIsInstance<ModuleDependency>()
.map { it.copy() }
.map { dependency ->
val category = dependency.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)?.name
if (category == Category.REGULAR_PLATFORM || category == Category.ENFORCED_PLATFORM) {
return@map dependency
}
try {
dependency.artifact {
name = dependency.name
type = artifactType
extension = "jar"
classifier = artifactType
}
} catch (e: Exception) {
throw RuntimeException("Failed to add artifact to dependency: $dependency", e)
}
dependency
}
@ -85,6 +97,10 @@ fun Project.applyLibrariesConfiguration() {
from({
altConfigFiles("sources")
})
// Yeet module-info's
exclude("module-info.java")
relocations.forEach { (from, to) ->
val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)")
val textPattern = Regex.fromLiteral(from)

View File

@ -40,6 +40,7 @@ paperlib = "1.0.8"
paster = "1.1.6"
vault = "1.7.1"
serverlib = "2.3.6"
linbus = "0.1.0"
## Internal
text-adapter = "3.0.6"
text = "3.0.4"
@ -78,7 +79,6 @@ bstatsBase = { group = "org.bstats", name = "bstats-base", version.ref = "bstats
bstatsBukkit = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
sparsebitset = { group = "com.zaxxer", name = "SparseBitSet", version.ref = "sparsebitset" }
parallelgzip = { group = "org.anarres", name = "parallelgzip", version.ref = "parallelgzip" }
adventureNbt = { group = "net.kyori", name = "adventure-nbt", version.ref = "adventure" }
truezip = { group = "de.schlichtherle", name = "truezip", version.ref = "truezip" }
autoValueAnnotations = { group = "com.google.auto.value", name = "auto-value-annotations", version.ref = "auto-value" }
autoValue = { group = "com.google.auto.value", name = "auto-value", version.ref = "auto-value" }
@ -101,6 +101,11 @@ paster = { group = "com.intellectualsites.paster", name = "Paster", version.ref
vault = { group = "com.github.MilkBowl", name = "VaultAPI", version.ref = "vault" }
serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib", version.ref = "serverlib" }
checkerqual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerqual" }
linBus-bom = { group = "org.enginehub.lin-bus", name = "lin-bus-bom", version.ref = "linbus" }
linBus-common = { group = "org.enginehub.lin-bus", name = "lin-bus-common" }
linBus-stream = { group = "org.enginehub.lin-bus", name = "lin-bus-stream" }
linBus-tree = { group = "org.enginehub.lin-bus", name = "lin-bus-tree" }
linBus-format-snbt = { group = "org.enginehub.lin-bus.format", name = "lin-bus-format-snbt" }
# Internal
## Text

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,9 +104,16 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
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
public void notifyBlockUpdate(LevelChunk chunk, BlockPos position, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) {

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,9 +104,16 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
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
public void notifyBlockUpdate(LevelChunk chunk, BlockPos position, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) {

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,9 +104,16 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
}
@Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
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
public void notifyBlockUpdate(LevelChunk chunk, BlockPos position, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) {

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());
}
/**
@ -949,14 +949,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();
}
/**
@ -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();

View File

@ -178,9 +178,6 @@ tasks.named<ShadowJar>("shadowJar") {
relocate("org.lz4", "com.fastasyncworldedit.core.lz4") {
include(dependency("org.lz4:lz4-java:1.8.0"))
}
relocate("net.kyori", "com.fastasyncworldedit.core.adventure") {
include(dependency("net.kyori:adventure-nbt:4.17.0"))
}
relocate("com.zaxxer", "com.fastasyncworldedit.core.math") {
include(dependency("com.zaxxer:SparseBitSet:1.3"))
}

View File

@ -12,11 +12,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
@ -33,6 +30,8 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.util.Map;
@ -81,7 +80,7 @@ public interface IDelegateBukkitImplAdapter<T> extends BukkitImplAdapter<T> {
}
@Override
default void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
default void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData) {
getParent().sendFakeNBT(player, pos, nbtData);
}
@ -131,8 +130,8 @@ public interface IDelegateBukkitImplAdapter<T> extends BukkitImplAdapter<T> {
}
@Override
default BinaryTag toNativeBinary(T foreign) {
return getParent().toNativeBinary(foreign);
default LinTag<?> toNativeLin(T foreign) {
return getParent().toNativeLin(foreign);
}
@Override
@ -141,8 +140,8 @@ public interface IDelegateBukkitImplAdapter<T> extends BukkitImplAdapter<T> {
}
@Override
default T fromNativeBinary(BinaryTag foreign) {
return getParent().fromNativeBinary(foreign);
default T fromNativeLin(LinTag foreign) {
return getParent().fromNativeLin(foreign);
}
@Override

View File

@ -194,7 +194,7 @@ public class FaweDelegateSchematicHandler {
} else {
try (OutputStream stream = new FileOutputStream(tmp);
NBTOutputStream output = new NBTOutputStream(new ParallelGZIPOutputStream(stream))) {
Map<String, Tag> map = tag.getValue();
Map<String, Tag<?, ?>> map = tag.getValue();
output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
}
}
@ -226,7 +226,7 @@ public class FaweDelegateSchematicHandler {
try {
try (ParallelGZIPOutputStream gzip = new ParallelGZIPOutputStream(output)) {
try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
Map<String, Tag> map = weTag.getValue();
Map<String, Tag<?, ?>> map = weTag.getValue();
nos.writeNamedTag("Schematic", map.getOrDefault("Schematic", weTag));
}
}

View File

@ -45,7 +45,6 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -61,6 +60,7 @@ import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachment;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -430,7 +430,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK && block instanceof BaseBlock) {
CompoundBinaryTag nbt = ((BaseBlock) block).getNbt();
LinCompoundTag nbt = ((BaseBlock) block).getNbt();
if (nbt != null) {
adapter.sendFakeNBT(player, pos, nbt);
adapter.sendFakeOP(player);

View File

@ -27,7 +27,7 @@ import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.LinBusConverter;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
@ -41,8 +41,6 @@ import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
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.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -61,6 +59,8 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinTag;
import javax.annotation.Nullable;
import java.util.Arrays;
@ -183,7 +183,7 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData);
void sendFakeNBT(Player player, BlockVector3 pos, LinCompoundTag nbtData);
/**
* Make the client think it has operator status.
@ -291,11 +291,11 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
@Deprecated
default Tag toNative(T foreign) {
return AdventureNBTConverter.fromAdventure(toNativeBinary(foreign));
return LinBusConverter.toJnbtTag(toNativeLin(foreign));
}
default BinaryTag toNativeBinary(T foreign) {
return toNative(foreign).asBinaryTag();
default LinTag<?> toNativeLin(T foreign) {
return toNative(foreign).toLinTag();
}
@Deprecated
@ -303,14 +303,14 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
if (foreign == null) {
return null;
}
return fromNativeBinary(foreign.asBinaryTag());
return fromNativeLin(foreign.toLinTag());
}
default T fromNativeBinary(BinaryTag foreign) {
default T fromNativeLin(LinTag<?> foreign) {
if (foreign == null) {
return null;
}
return fromNative(AdventureNBTConverter.fromAdventure(foreign));
return fromNative(LinBusConverter.toJnbtTag(foreign));
}
@Nullable

View File

@ -46,7 +46,6 @@ dependencies {
implementation(libs.findbugs)
implementation(libs.rhino)
compileOnly(libs.adventureApi)
compileOnlyApi(libs.adventureNbt)
compileOnlyApi(libs.adventureMiniMessage)
implementation(libs.zstd) { isTransitive = false }
compileOnly(libs.paster)
@ -56,10 +55,10 @@ dependencies {
antlr(libs.antlr4)
implementation(libs.antlr4Runtime)
implementation(libs.jsonSimple) { isTransitive = false }
implementation(platform(libs.linBus.bom))
// Tests
testRuntimeOnly(libs.log4jCore)
testImplementation(libs.adventureNbt)
testImplementation(libs.parallelgzip)
}

View File

@ -125,7 +125,7 @@ public class MobSpawnerBlock extends BaseBlock {
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
values.put("Delay", new ShortTag(delay));
values.put("SpawnCount", new ShortTag(spawnCount));
values.put("SpawnRange", new ShortTag(spawnRange));
@ -170,7 +170,7 @@ public class MobSpawnerBlock extends BaseBlock {
return;
}
Map<String, Tag> values = rootTag.getValue();
Map<String, Tag<?, ?>> values = rootTag.getValue();
Tag t = values.get("id");
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) {

View File

@ -104,7 +104,7 @@ public class SignBlock extends BaseBlock {
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
if (isLegacy()) {
values.put("Text1", new StringTag(text[0]));
values.put("Text2", new StringTag(text[1]));
@ -112,7 +112,7 @@ public class SignBlock extends BaseBlock {
values.put("Text4", new StringTag(text[3]));
} else {
ListTag messages = new ListTag(StringTag.class, Arrays.stream(text).map(StringTag::new).collect(Collectors.toList()));
Map<String, Tag> frontTextTag = new HashMap<>();
Map<String, Tag<?, ?>> frontTextTag = new HashMap<>();
frontTextTag.put("messages", messages);
values.put("front_text", new CompoundTag(frontTextTag));
}
@ -125,9 +125,9 @@ public class SignBlock extends BaseBlock {
return;
}
Map<String, Tag> values = rootTag.getValue();
Map<String, Tag<?, ?>> values = rootTag.getValue();
Tag t;
Tag<?, ?> t;
text = new String[]{EMPTY, EMPTY, EMPTY, EMPTY};

View File

@ -100,8 +100,8 @@ public class SkullBlock extends BaseBlock {
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag> inner = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
Map<String, Tag<?, ?>> inner = new HashMap<>();
inner.put("Name", new StringTag(owner));
values.put(DeprecationUtil.getHeadOwnerKey(), new CompoundTag(inner));
return new CompoundTag(values);
@ -113,7 +113,7 @@ public class SkullBlock extends BaseBlock {
return;
}
Map<String, Tag> values = rootTag.getValue();
Map<String, Tag<?, ?>> values = rootTag.getValue();
Tag t;

View File

@ -532,7 +532,7 @@ public enum FaweCache implements Trimable {
}
public CompoundTag asTag(Map<String, Object> value) {
HashMap<String, Tag> map = new HashMap<>();
HashMap<String, Tag<?, ?>> map = new HashMap<>();
for (Map.Entry<String, Object> entry : value.entrySet()) {
Object child = entry.getValue();
Tag tag = asTag(child);

View File

@ -3,25 +3,25 @@ package com.fastasyncworldedit.core.entity;
import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.util.TaskManager;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.entity.EntityType;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.util.function.Supplier;
public class LazyBaseEntity extends BaseEntity {
private Supplier<CompoundBinaryTag> saveTag;
private Supplier<LinCompoundTag> saveTag;
public LazyBaseEntity(EntityType type, Supplier<CompoundBinaryTag> saveTag) {
public LazyBaseEntity(EntityType type, Supplier<LinCompoundTag> saveTag) {
super(type);
this.saveTag = saveTag;
}
@Nullable
@Override
public CompoundBinaryTag getNbt() {
Supplier<CompoundBinaryTag> tmp = saveTag;
public LinCompoundTag getNbt() {
Supplier<LinCompoundTag> tmp = saveTag;
if (tmp != null) {
saveTag = null;
if (Fawe.isMainThread()) {

View File

@ -29,8 +29,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@ -81,7 +79,7 @@ public class StripNBTExtent extends AbstractDelegateExtent implements IBatchProc
return block;
}
CompoundTag nbt = localBlock.getNbtData();
Map<String, Tag> value = new HashMap<>(nbt.getValue());
Map<String, Tag<?, ?>> value = new HashMap<>(nbt.getValue());
for (String key : strip) {
value.remove(key);
}
@ -93,7 +91,7 @@ public class StripNBTExtent extends AbstractDelegateExtent implements IBatchProc
return entity;
}
CompoundTag nbt = entity.getNbtData();
Map<String, Tag> value = new HashMap<>(nbt.getValue());
Map<String, Tag<?, ?>> value = new HashMap<>(nbt.getValue());
for (String key : strip) {
value.remove(key);
}
@ -110,7 +108,7 @@ public class StripNBTExtent extends AbstractDelegateExtent implements IBatchProc
}
boolean isBv3ChunkMap = tiles instanceof BlockVector3ChunkMap;
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) {
ImmutableMap.Builder<String, Tag> map = ImmutableMap.builder();
ImmutableMap.Builder<String, Tag<?, ?>> map = ImmutableMap.builder();
final AtomicBoolean isStripped = new AtomicBoolean(false);
entry.getValue().getValue().forEach((k, v) -> {
if (strip.contains(k.toLowerCase())) {
@ -132,7 +130,7 @@ public class StripNBTExtent extends AbstractDelegateExtent implements IBatchProc
Iterator<CompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) {
CompoundTag entity = iterator.next();
ImmutableMap.Builder<String, Tag> map = ImmutableMap.builder();
ImmutableMap.Builder<String, Tag<?, ?>> map = ImmutableMap.builder();
final AtomicBoolean isStripped = new AtomicBoolean(false);
entity.getValue().forEach((k, v) -> {
if (strip.contains(k.toUpperCase(Locale.ROOT))) {

View File

@ -152,7 +152,7 @@ public class CPUOptimizedClipboard extends LinearClipboard {
public Collection<CompoundTag> getTileEntities() {
convertTilesToIndex();
nbtMapIndex.replaceAll((index, tag) -> {
Map<String, Tag> values = new HashMap<>(tag.getValue());
Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue());
if (!values.containsKey("x")) {
int y = index / getArea();
index -= y * getArea();
@ -176,7 +176,7 @@ public class CPUOptimizedClipboard extends LinearClipboard {
}
private boolean setTile(int index, CompoundTag tag) {
final Map<String, Tag> values = new HashMap<>(tag.getValue());
final Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue());
values.remove("x");
values.remove("y");
values.remove("z");

View File

@ -586,7 +586,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
for (BlockArrayClipboard.ClipboardEntity entity : entities) {
if (entity.getState() != null && entity.getState().getNbtData() != null) {
CompoundTag data = entity.getState().getNbtData();
HashMap<String, Tag> value = new HashMap<>(data.getValue());
HashMap<String, Tag<?, ?>> value = new HashMap<>(data.getValue());
List<DoubleTag> pos = new ArrayList<>(3);
pos.add(new DoubleTag(entity.getLocation().x()));
pos.add(new DoubleTag(entity.getLocation().x()));
@ -710,7 +710,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
@Override
public boolean setTile(int x, int y, int z, CompoundTag tag) {
final Map<String, Tag> values = new HashMap<>(tag.getValue());
final Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue());
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));

View File

@ -106,7 +106,7 @@ public abstract class LinearClipboard extends SimpleClipboard {
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
Map<String, Tag> map = new HashMap<>(entity.getNbtData().getValue());
Map<String, Tag<?, ?>> map = new HashMap<>(entity.getNbtData().getValue());
NBTUtils.addUUIDToMap(map, uuid);
entity.setNbtData(new CompoundTag(map));
BlockArrayClipboard.ClipboardEntity ret = new BlockArrayClipboard.ClipboardEntity(location, entity);

View File

@ -254,7 +254,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
@Override
public boolean setTile(int x, int y, int z, CompoundTag tag) {
final Map<String, Tag> values = new HashMap<>(tag.getValue());
final Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue());
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));

View File

@ -9,7 +9,7 @@ import com.fastasyncworldedit.core.internal.io.FaweInputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
import com.fastasyncworldedit.core.jnbt.streamer.StreamDelegate;
import com.fastasyncworldedit.core.jnbt.streamer.ValueReader;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.LinBusConverter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.NBTInputStream;
@ -109,10 +109,10 @@ public class FastSchematicReader extends NBTSchematicReader {
if (fixer == null || dataVersion == -1) {
return tag;
}
//FAWE start - BinaryTag
return (CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
//FAWE start - LinTag
return (CompoundTag) LinBusConverter.fromLinBus(fixer.fixUp(
DataFixer.FixTypes.BLOCK_ENTITY,
tag.asBinaryTag(),
tag.toLinTag(),
dataVersion
));
//FAWE end
@ -122,10 +122,10 @@ public class FastSchematicReader extends NBTSchematicReader {
if (fixer == null || dataVersion == -1) {
return tag;
}
//FAWE start - BinaryTag
return (CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
//FAWE start - LinTag
return (CompoundTag) LinBusConverter.fromLinBus(fixer.fixUp(
DataFixer.FixTypes.ENTITY,
tag.asBinaryTag(),
tag.toLinTag(),
dataVersion
));
//FAWE end
@ -344,7 +344,7 @@ public class FastSchematicReader extends NBTSchematicReader {
y = pos[1];
z = pos[2];
}
Map<String, Tag> values = new HashMap<>(tile.getValue());
Map<String, Tag<?, ?>> values = new HashMap<>(tile.getValue());
Tag id = values.get("Id");
if (id != null) {
values.put("x", new IntTag(x));
@ -371,7 +371,7 @@ public class FastSchematicReader extends NBTSchematicReader {
// entities
if (entities != null && !entities.isEmpty()) {
for (Map<String, Object> entRaw : entities) {
Map<String, Tag> value = new HashMap<>(FaweCache.INSTANCE.asTag(entRaw).getValue());
Map<String, Tag<?, ?>> value = new HashMap<>(FaweCache.INSTANCE.asTag(entRaw).getValue());
StringTag id = (StringTag) value.get("Id");
if (id == null) {
id = (StringTag) value.get("id");

View File

@ -149,7 +149,7 @@ public class FastSchematicWriter implements ClipboardWriter {
BaseBlock block = pos.getFullBlock(finalClipboard);
CompoundTag nbt = block.getNbtData();
if (nbt != null) {
Map<String, Tag> values = new HashMap<>(nbt.getValue());
Map<String, Tag<?, ?>> values = new HashMap<>(nbt.getValue());
// Positions are kept in NBT, we don't want that.
values.remove("x");
@ -223,7 +223,7 @@ public class FastSchematicWriter implements ClipboardWriter {
BaseEntity state = entity.getState();
if (state != null) {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag<?, ?>> values = new HashMap<>();
// Put NBT provided data
CompoundTag rawTag = state.getNbtData();

View File

@ -70,7 +70,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
throw new IOException("Root tag has name - are you sure this is a structure?");
}
Map<String, Tag> tags = ((CompoundTag) rootTag.getTag()).getValue();
Map<String, Tag<?, ?>> tags = ((CompoundTag) rootTag.getTag()).getValue();
ListTag size = (ListTag) tags.get("size");
int width = size.getInt(0);
@ -89,13 +89,13 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
BlockState[] combinedArray = new BlockState[palette.size()];
for (int i = 0; i < palette.size(); i++) {
CompoundTag compound = palette.get(i);
Map<String, Tag> map = compound.getValue();
Map<String, Tag<?, ?>> map = compound.getValue();
String name = ((StringTag) map.get("Name")).getValue();
BlockType type = BlockTypes.get(name);
BlockState state = type.getDefaultState();
CompoundTag properties = (CompoundTag) map.get("Properties");
if (properties != null) {
for (Map.Entry<String, Tag> entry : properties.getValue().entrySet()) {
for (Map.Entry<String, Tag<?, ?>> entry : properties.getValue().entrySet()) {
String key = entry.getKey();
String value = ((StringTag) entry.getValue()).getValue();
Property<Object> property = type.getProperty(key);
@ -108,7 +108,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
List<CompoundTag> blocksList = (List<CompoundTag>) tags.get("blocks").getValue();
try {
for (CompoundTag compound : blocksList) {
Map<String, Tag> blockMap = compound.getValue();
Map<String, Tag<?, ?>> blockMap = compound.getValue();
IntTag stateTag = (IntTag) blockMap.get("state");
ListTag posTag = (ListTag) blockMap.get("pos");
BlockState state = combinedArray[stateTag.getValue()];
@ -136,7 +136,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
if (entities != null) {
List<CompoundTag> entityList = (List<CompoundTag>) (List<?>) entities.getValue();
for (CompoundTag entityEntry : entityList) {
Map<String, Tag> entityEntryMap = entityEntry.getValue();
Map<String, Tag<?, ?>> entityEntryMap = entityEntry.getValue();
ListTag posTag = (ListTag) entityEntryMap.get("pos");
CompoundTag nbtTag = (CompoundTag) entityEntryMap.get("nbt");
String id = nbtTag.getString("Id");
@ -216,7 +216,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
if (!block.hasNbtData()) {
blocks.add(FaweCache.INSTANCE.asMap("state", index, "pos", pos));
} else {
Map<String, Tag> tag = new HashMap<>(block.getNbtData().getValue());
Map<String, Tag<?, ?>> tag = new HashMap<>(block.getNbtData().getValue());
tag.remove("x");
tag.remove("y");
tag.remove("z");
@ -246,7 +246,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
BaseEntity state = entity.getState();
if (state != null) {
CompoundTag nbt = state.getNbtData();
Map<String, Tag> nbtMap = new HashMap<>(nbt.getValue());
Map<String, Tag<?, ?>> nbtMap = new HashMap<>(nbt.getValue());
// Replace rotation data
nbtMap.put("Rotation", writeRotation(entity.getLocation()));
nbtMap.put("id", new StringTag(state.getType().id()));

View File

@ -3,7 +3,6 @@ package com.fastasyncworldedit.core.history.change;
import com.fastasyncworldedit.core.util.MathMan;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
@ -52,7 +51,7 @@ public class MutableEntityChange implements Change {
@SuppressWarnings({"unchecked"})
public void delete(UndoContext context) {
Map<String, Tag> map = tag.getValue();
Map<String, Tag<?, ?>> map = tag.getValue();
UUID uuid = tag.getUUID();
if (uuid == null) {
LOGGER.info("Skipping entity without uuid.");
@ -66,7 +65,7 @@ public class MutableEntityChange implements Change {
}
public void create(UndoContext context) {
Map<String, Tag> map = tag.getValue();
Map<String, Tag<?, ?>> map = tag.getValue();
Tag posTag = map.get("Pos");
if (posTag == null) {
LOGGER.warn("Missing pos tag: {}", tag);

View File

@ -112,7 +112,7 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet {
@Override
public void addTileCreate(CompoundTag nbt) {
if (nbt.containsKey("items")) {
Map<String, Tag> map = new HashMap<>(nbt.getValue());
Map<String, Tag<?, ?>> map = new HashMap<>(nbt.getValue());
map.remove("items");
}
super.addTileCreate(nbt);

View File

@ -19,7 +19,7 @@ public abstract class CompressedCompoundTag<T> extends CompoundTag {
}
@Override
public Map<String, Tag> getValue() {
public Map<String, Tag<?, ?>> getValue() {
if (in != null) {
decompress();
}
@ -36,8 +36,8 @@ public abstract class CompressedCompoundTag<T> extends CompoundTag {
try (NBTInputStream nbtIn = new NBTInputStream(adapt(in))) {
in = null;
CompoundTag tag = (CompoundTag) nbtIn.readTag();
Map<String, Tag> value = tag.getValue();
Map<String, Tag> raw = super.getValue();
Map<String, Tag<?, ?>> value = tag.getValue();
Map<String, Tag<?, ?>> raw = super.getValue();
raw.putAll(value);
} catch (IOException e) {
throw new RuntimeException(e);

View File

@ -17,7 +17,6 @@ import com.sk89q.jnbt.Tag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Stack;
import java.util.regex.Pattern;
@ -409,7 +408,7 @@ public class JSON2NBT {
}
public Tag parse() throws NBTException {
HashMap<String, Tag> map = new HashMap<>();
HashMap<String, Tag<?, ?>> map = new HashMap<>();
for (Any JSON2NBT$any : this.tagList) {
map.put(JSON2NBT$any.json, JSON2NBT$any.parse());

View File

@ -1,11 +1,16 @@
package com.fastasyncworldedit.core.jnbt;
import com.sk89q.jnbt.Tag;
import org.enginehub.linbus.tree.LinTag;
/**
* A numerical {@link Tag}
*/
public abstract class NumberTag extends Tag {
public abstract class NumberTag<LT extends LinTag<? extends Number>> extends Tag<Number, LT> {
protected NumberTag(LT linTag) {
super(linTag);
}
@Override
public abstract Number getValue();

View File

@ -124,7 +124,7 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
@Override
default Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4);
Map<String, Tag> map = new HashMap<>(entity.getNbtData().getValue()); //do not modify original entity data
Map<String, Tag<?, ?>> map = new HashMap<>(entity.getNbtData().getValue()); //do not modify original entity data
map.put("Id", new StringTag(entity.getType().getName()));
//Set pos

View File

@ -82,7 +82,7 @@ public final class BrushCache {
}
CompoundTag nbt = item.getNbtData();
Map<String, Tag> map;
Map<String, Tag<?, ?>> map;
if (nbt == null) {
if (tool == null) {
item.setNbtData(null);
@ -92,9 +92,10 @@ public final class BrushCache {
} else {
map = nbt.getValue();
}
item.setNbtData(nbt);
brushCache.remove(getKey(item));
CompoundTag display = (CompoundTag) map.get("display");
Map<String, Tag> displayMap;
Map<String, Tag<?, ?>> displayMap;
return tool;
}

View File

@ -427,7 +427,7 @@ public class MainUtil {
*/
@Nonnull
public static CompoundTag setPosition(@Nonnull CompoundTag tag, int x, int y, int z) {
Map<String, Tag> value = new HashMap<>(tag.getValue());
Map<String, Tag<?, ?>> value = new HashMap<>(tag.getValue());
value.put("x", new IntTag(x));
value.put("y", new IntTag(y));
value.put("z", new IntTag(z));
@ -443,7 +443,7 @@ public class MainUtil {
*/
@Nonnull
public static CompoundTag setEntityInfo(@Nonnull CompoundTag tag, @Nonnull Entity entity) {
Map<String, Tag> map = new HashMap<>(tag.getValue());
Map<String, Tag<?, ?>> map = new HashMap<>(tag.getValue());
map.put("Id", new StringTag(entity.getState().getType().id()));
ListTag pos = (ListTag) map.get("Pos");
if (pos != null) {

View File

@ -1,13 +1,12 @@
package com.fastasyncworldedit.core.util;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTagType;
import com.sk89q.worldedit.util.nbt.BinaryTagTypes;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import java.util.HashMap;
import java.util.Map;
@ -23,9 +22,9 @@ public class NbtUtils {
* @return child tag
* @throws InvalidFormatException if the format of the items is invalid
*/
public static <T extends BinaryTag> T getChildTag(CompoundBinaryTag tag, String key, BinaryTagType<T> expected) throws
public static <T extends LinTag> T getChildTag(LinCompoundTag tag, String key, LinTagType expected) throws
InvalidFormatException {
BinaryTag childTag = tag.get(key);
LinTag childTag = tag.value().get(key);
if (childTag == null) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
}
@ -48,35 +47,35 @@ public class NbtUtils {
* @throws InvalidFormatException if the format of the items is invalid
* @since 2.1.0
*/
public static int getInt(CompoundBinaryTag tag, String key) throws InvalidFormatException {
BinaryTag childTag = tag.get(key);
public static int getInt(LinCompoundTag tag, String key) throws InvalidFormatException {
LinTag childTag = tag.value().get(key);
if (childTag == null) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
}
BinaryTagType<?> type = childTag.type();
if (type == BinaryTagTypes.INT) {
return ((IntBinaryTag) childTag).intValue();
LinTagType<?> type = childTag.type();
if (type == LinTagType.intTag()) {
return ((LinIntTag) childTag).value();
}
if (type == BinaryTagTypes.BYTE) {
return ((ByteBinaryTag) childTag).intValue();
if (type == LinTagType.byteTag()) {
return ((LinByteTag) childTag).value();
}
if (type == BinaryTagTypes.SHORT) {
return ((ShortBinaryTag) childTag).intValue();
if (type == LinTagType.shortTag()) {
return ((LinShortTag) childTag).value();
}
throw new InvalidFormatException(key + " tag is not of int, short or byte tag type.");
}
/**
* Get a mutable map of the values stored inside a {@link CompoundBinaryTag}
* Get a mutable map of the values stored inside a {@link LinCompoundTag}
*
* @param tag {@link CompoundBinaryTag} to get values for
* @param tag {@link LinCompoundTag} to get values for
* @return Mutable map of values
* @since 2.1.0
*/
public static Map<String, BinaryTag> getCompoundBinaryTagValues(CompoundBinaryTag tag) {
Map<String, BinaryTag> value = new HashMap<>();
tag.forEach((e) -> value.put(e.getKey(), e.getValue()));
public static Map<String, LinTag<?>> getLinCompoundTagValues(LinCompoundTag tag) {
Map<String, LinTag<?>> value = new HashMap<>();
value.putAll(tag.value());
return value;
}

View File

@ -10,9 +10,10 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.nbt.TagStringIO;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.enginehub.linbus.format.snbt.LinStringIO;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.io.IOException;
import java.lang.reflect.Type;
@ -36,7 +37,10 @@ public final class BaseItemAdapter implements JsonDeserializer<BaseItem>, JsonSe
return new BaseItem(itemType);
}
try {
return new BaseItem(itemType, LazyReference.computed(TagStringIO.get().asCompound(nbt.getAsString())));
return new BaseItem(
itemType,
LazyReference.computed(LinCompoundTag.readFrom(LinStringIO.readFromString(nbt.getAsString())))
);
} catch (IOException e) {
throw new JsonParseException("Could not deserialize BaseItem", e);
}
@ -50,12 +54,8 @@ public final class BaseItemAdapter implements JsonDeserializer<BaseItem>, JsonSe
) {
JsonObject obj = new JsonObject();
obj.add("itemType", jsonSerializationContext.serialize(baseItem.getType()));
try {
obj.add("nbt", baseItem.getNbt() == null ? null : new JsonPrimitive(TagStringIO.get().asString(baseItem.getNbt())));
obj.add("nbt", baseItem.getNbt() == null ? null : new JsonPrimitive(LinStringIO.writeToString(baseItem.getNbt())));
return obj;
} catch (IOException e) {
throw new JsonParseException("Could not deserialize BaseItem", e);
}
}
}

View File

@ -1,110 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.jnbt;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTagType;
import com.sk89q.worldedit.util.nbt.BinaryTagTypes;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
/**
* Converts between JNBT and Adventure-NBT classes.
*
* @deprecated JNBT is being removed in WE8.
*/
@Deprecated(forRemoval = true)
public class AdventureNBTConverter {
private static final BiMap<Class<? extends Tag>, BinaryTagType<?>> TAG_TYPES =
new ImmutableBiMap.Builder<Class<? extends Tag>, BinaryTagType<?>>()
.put(ByteArrayTag.class, BinaryTagTypes.BYTE_ARRAY)
.put(ByteTag.class, BinaryTagTypes.BYTE)
.put(CompoundTag.class, BinaryTagTypes.COMPOUND)
.put(DoubleTag.class, BinaryTagTypes.DOUBLE)
.put(EndTag.class, BinaryTagTypes.END)
.put(FloatTag.class, BinaryTagTypes.FLOAT)
.put(IntArrayTag.class, BinaryTagTypes.INT_ARRAY)
.put(IntTag.class, BinaryTagTypes.INT)
.put(ListTag.class, BinaryTagTypes.LIST)
.put(LongArrayTag.class, BinaryTagTypes.LONG_ARRAY)
.put(LongTag.class, BinaryTagTypes.LONG)
.put(ShortTag.class, BinaryTagTypes.SHORT)
.put(StringTag.class, BinaryTagTypes.STRING)
.build();
private static final Map<BinaryTagType<?>, Function<BinaryTag, Tag>> CONVERSION;
static {
ImmutableMap.Builder<BinaryTagType<?>, Function<BinaryTag, Tag>> conversion =
ImmutableMap.builder();
for (Map.Entry<Class<? extends Tag>, BinaryTagType<?>> tag : TAG_TYPES.entrySet()) {
Constructor<?>[] constructors = tag.getKey().getConstructors();
for (Constructor<?> c : constructors) {
if (c.getParameterCount() == 1 && BinaryTag.class.isAssignableFrom(c.getParameterTypes()[0])) {
conversion.put(tag.getValue(), binaryTag -> {
try {
return (Tag) c.newInstance(binaryTag);
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
// I assume this is always a RuntimeException since we control the ctor
throw (RuntimeException) e.getCause();
}
});
break;
}
}
}
CONVERSION = conversion.build();
}
public static BinaryTagType<?> getAdventureType(Class<? extends Tag> type) {
return Objects.requireNonNull(TAG_TYPES.get(type), () -> "Missing entry for " + type);
}
public static Class<? extends Tag> getJNBTType(BinaryTagType<?> type) {
return Objects.requireNonNull(TAG_TYPES.inverse().get(type), () -> "Missing entry for " + type);
}
private AdventureNBTConverter() {
}
public static Tag fromAdventure(BinaryTag other) {
if (other == null) {
return null;
}
Function<BinaryTag, Tag> conversion = CONVERSION.get(other.type());
if (conversion == null) {
throw new IllegalArgumentException("Can't convert other of type " + other.getClass().getCanonicalName());
}
return conversion.apply(other);
}
}

View File

@ -19,41 +19,26 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import org.enginehub.linbus.tree.LinByteArrayTag;
/**
* The {@code TAG_Byte_Array} tag.
*
* @deprecated Use {@link ByteArrayBinaryTag}.
* @deprecated Use {@link LinByteArrayTag}.
*/
@Deprecated
public final class ByteArrayTag extends Tag {
private final ByteArrayBinaryTag innerTag;
public final class ByteArrayTag extends Tag<byte[], LinByteArrayTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public ByteArrayTag(byte[] value) {
super();
this.innerTag = ByteArrayBinaryTag.of(value);
this(LinByteArrayTag.of(value));
}
public ByteArrayTag(ByteArrayBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public byte[] getValue() {
return innerTag.value();
}
@Override
public ByteArrayBinaryTag asBinaryTag() {
return innerTag;
public ByteArrayTag(LinByteArrayTag tag) {
super(tag);
}
//FAWE start

View File

@ -19,41 +19,32 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.fastasyncworldedit.core.jnbt.NumberTag;
import org.enginehub.linbus.tree.LinByteTag;
/**
* The {@code TAG_Byte} tag.
*
* @deprecated Use {@link ByteBinaryTag}.
* @deprecated Use {@link LinByteTag}.
*/
@Deprecated
public final class ByteTag extends Tag {
private final ByteBinaryTag innerTag;
public final class ByteTag extends NumberTag<LinByteTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public ByteTag(byte value) {
super();
this.innerTag = ByteBinaryTag.of(value);
this(LinByteTag.of(value));
}
public ByteTag(ByteBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
public ByteTag(LinByteTag tag) {
super(tag);
}
@Override
public Byte getValue() {
return innerTag.value();
}
@Override
public ByteBinaryTag asBinaryTag() {
return innerTag;
return linTag.value();
}
//FAWE start

View File

@ -25,10 +25,11 @@ import com.google.common.collect.Maps;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTagLike;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.NumberBinaryTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinNumberTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import java.util.Collections;
import java.util.HashMap;
@ -39,26 +40,24 @@ import java.util.UUID;
/**
* The {@code TAG_Compound} tag.
*
* @deprecated Use {@link com.sk89q.worldedit.util.nbt.CompoundBinaryTag}.
* @deprecated Use {@link LinCompoundTag}.
*/
@Deprecated
public class CompoundTag extends Tag {
private final CompoundBinaryTag innerTag;
//FAWE start - nonfinal
public class CompoundTag extends Tag<Object, LinCompoundTag> {
//FAWE end
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public CompoundTag(Map<String, Tag> value) {
this(CompoundBinaryTag.builder()
.put(Maps.transformValues(value, BinaryTagLike::asBinaryTag))
.build());
public CompoundTag(Map<String, Tag<?, ?>> value) {
this(LinCompoundTag.of(Maps.transformValues(value, Tag::toLinTag)));
}
public CompoundTag(CompoundBinaryTag adventureTag) {
this.innerTag = adventureTag;
public CompoundTag(LinCompoundTag tag) {
super(tag);
}
/**
@ -68,16 +67,16 @@ public class CompoundTag extends Tag {
* @return true if the tag contains the given key
*/
public boolean containsKey(String key) {
return innerTag.keySet().contains(key);
return linTag.value().containsKey(key);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, Tag> getValue() {
ImmutableMap.Builder<String, Tag> map = ImmutableMap.builder();
for (String key : innerTag.keySet()) {
map.put(key, AdventureNBTConverter.fromAdventure(innerTag.get(key)));
}
return map.build();
public Map<String, Tag<?, ?>> getValue() {
return ImmutableMap.copyOf(Maps.transformValues(
linTag.value(),
tag -> (Tag<?, ?>) LinBusConverter.toJnbtTag((LinTag) tag)
));
}
/**
@ -86,7 +85,7 @@ public class CompoundTag extends Tag {
* @param value the value
* @return the new compound tag
*/
public CompoundTag setValue(Map<String, Tag> value) {
public CompoundTag setValue(Map<String, Tag<?, ?>> value) {
return new CompoundTag(value);
}
@ -96,7 +95,7 @@ public class CompoundTag extends Tag {
* @return the builder
*/
public CompoundTagBuilder createBuilder() {
return new CompoundTagBuilder(innerTag);
return new CompoundTagBuilder(linTag);
}
/**
@ -109,7 +108,8 @@ public class CompoundTag extends Tag {
* @return a byte array
*/
public byte[] getByteArray(String key) {
return this.innerTag.getByteArray(key);
var tag = linTag.findTag(key, LinTagType.byteArrayTag());
return tag == null ? new byte[0] : tag.value();
}
/**
@ -122,7 +122,8 @@ public class CompoundTag extends Tag {
* @return a byte
*/
public byte getByte(String key) {
return this.innerTag.getByte(key);
var tag = linTag.findTag(key, LinTagType.byteTag());
return tag == null ? 0 : tag.value();
}
/**
@ -135,7 +136,8 @@ public class CompoundTag extends Tag {
* @return a double
*/
public double getDouble(String key) {
return this.innerTag.getDouble(key);
var tag = linTag.findTag(key, LinTagType.doubleTag());
return tag == null ? 0 : tag.value();
}
/**
@ -149,9 +151,10 @@ public class CompoundTag extends Tag {
* @return a double
*/
public double asDouble(String key) {
BinaryTag tag = this.innerTag.get(key);
if (tag instanceof NumberBinaryTag) {
return ((NumberBinaryTag) tag).doubleValue();
var tag = linTag.value().get(key);
if (tag instanceof LinNumberTag<?> numberTag) {
Number value = numberTag.value();
return value.doubleValue();
}
return 0;
}
@ -166,7 +169,8 @@ public class CompoundTag extends Tag {
* @return a float
*/
public float getFloat(String key) {
return this.innerTag.getFloat(key);
var tag = linTag.findTag(key, LinTagType.floatTag());
return tag == null ? 0 : tag.value();
}
/**
@ -179,7 +183,8 @@ public class CompoundTag extends Tag {
* @return an int array
*/
public int[] getIntArray(String key) {
return this.innerTag.getIntArray(key);
var tag = linTag.findTag(key, LinTagType.intArrayTag());
return tag == null ? new int[0] : tag.value();
}
/**
@ -192,7 +197,8 @@ public class CompoundTag extends Tag {
* @return an int
*/
public int getInt(String key) {
return this.innerTag.getInt(key);
var tag = linTag.findTag(key, LinTagType.intTag());
return tag == null ? 0 : tag.value();
}
/**
@ -206,9 +212,10 @@ public class CompoundTag extends Tag {
* @return an int
*/
public int asInt(String key) {
BinaryTag tag = this.innerTag.get(key);
if (tag instanceof NumberBinaryTag) {
return ((NumberBinaryTag) tag).intValue();
var tag = linTag.value().get(key);
if (tag instanceof LinNumberTag<?> numberTag) {
Number value = numberTag.value();
return value.intValue();
}
return 0;
}
@ -222,7 +229,7 @@ public class CompoundTag extends Tag {
* @param key the key
* @return a list of tags
*/
public List<Tag> getList(String key) {
public List<? extends Tag<?, ?>> getList(String key) {
return getListTag(key).getValue();
}
@ -235,8 +242,15 @@ public class CompoundTag extends Tag {
* @param key the key
* @return a tag list instance
*/
public ListTag getListTag(String key) {
return new ListTag(this.innerTag.getList(key));
public <EV, E extends LinTag<EV>> ListTag<EV, E> getListTag(String key) {
LinListTag<E> tag = linTag.findTag(key, LinTagType.listTag());
if (tag == null) {
// This is actually hella unsafe. But eh.
@SuppressWarnings("unchecked")
LinTagType<E> endGenerically = (LinTagType<E>) LinTagType.endTag();
return new ListTag<>(LinListTag.empty(endGenerically));
}
return new ListTag<>(tag);
}
/**
@ -253,8 +267,8 @@ public class CompoundTag extends Tag {
* @return a list of tags
*/
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
ListTag listTag = getListTag(key);
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();
} else {
@ -272,7 +286,8 @@ public class CompoundTag extends Tag {
* @return an int array
*/
public long[] getLongArray(String key) {
return this.innerTag.getLongArray(key);
var tag = linTag.findTag(key, LinTagType.longArrayTag());
return tag == null ? new long[0] : tag.value();
}
/**
@ -285,7 +300,8 @@ public class CompoundTag extends Tag {
* @return a long
*/
public long getLong(String key) {
return this.innerTag.getLong(key);
var tag = linTag.findTag(key, LinTagType.longTag());
return tag == null ? 0 : tag.value();
}
/**
@ -299,9 +315,10 @@ public class CompoundTag extends Tag {
* @return a long
*/
public long asLong(String key) {
BinaryTag tag = this.innerTag.get(key);
if (tag instanceof NumberBinaryTag) {
return ((NumberBinaryTag) tag).longValue();
var tag = linTag.value().get(key);
if (tag instanceof LinNumberTag<?> numberTag) {
Number value = numberTag.value();
return value.longValue();
}
return 0;
}
@ -316,7 +333,8 @@ public class CompoundTag extends Tag {
* @return a short
*/
public short getShort(String key) {
return this.innerTag.getShort(key);
var tag = linTag.findTag(key, LinTagType.shortTag());
return tag == null ? 0 : tag.value();
}
/**
@ -329,12 +347,8 @@ public class CompoundTag extends Tag {
* @return a string
*/
public String getString(String key) {
return this.innerTag.getString(key);
}
@Override
public CompoundBinaryTag asBinaryTag() {
return this.innerTag;
var tag = linTag.findTag(key, LinTagType.stringTag());
return tag == null ? "" : tag.value();
}
@ -357,7 +371,7 @@ public class CompoundTag extends Tag {
}
public Vector3 getEntityPosition() {
List<Tag> posTags = getList("Pos");
List<? extends Tag<?, ?>> posTags = getList("Pos");
double x = ((NumberTag) posTags.get(0)).getValue().doubleValue();
double y = ((NumberTag) posTags.get(1)).getValue().doubleValue();
double z = ((NumberTag) posTags.get(2)).getValue().doubleValue();
@ -365,7 +379,7 @@ public class CompoundTag extends Tag {
}
public Location getEntityLocation(Extent extent) {
List<Tag> rotTag = getList("Rotation");
List<? extends Tag<?, ?>> rotTag = getList("Rotation");
float yaw = ((NumberTag) rotTag.get(0)).getValue().floatValue();
float pitch = ((NumberTag) rotTag.get(1)).getValue().floatValue();
return new Location(extent, getEntityPosition(), yaw, pitch);
@ -382,7 +396,7 @@ public class CompoundTag extends Tag {
if (this.getValue().isEmpty()) {
return raw;
}
for (Map.Entry<String, Tag> entry : getValue().entrySet()) {
for (Map.Entry<String, Tag<?, ?>> entry : getValue().entrySet()) {
raw.put(entry.getKey(), entry.getValue().toRaw());
}
return raw;

View File

@ -19,27 +19,27 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.Map;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helps create compound tags.
*
* @deprecated Use {@link com.sk89q.worldedit.util.nbt.CompoundBinaryTag.Builder}.
* @deprecated Use {@link LinCompoundTag.Builder}.
*/
@Deprecated
public class CompoundTagBuilder {
private final CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder();
private final LinCompoundTag.Builder builder;
/**
* Create a new instance.
*/
CompoundTagBuilder() {
this.builder = LinCompoundTag.builder();
}
/**
@ -47,11 +47,9 @@ public class CompoundTagBuilder {
*
* @param source the value
*/
CompoundTagBuilder(CompoundBinaryTag source) {
CompoundTagBuilder(LinCompoundTag source) {
checkNotNull(source);
for (String key : source.keySet()) {
this.builder.put(key, Objects.requireNonNull(source.get(key)));
}
this.builder = source.toBuilder();
}
/**
@ -61,10 +59,10 @@ public class CompoundTagBuilder {
* @param value the value
* @return this object
*/
public CompoundTagBuilder put(String key, Tag value) {
public CompoundTagBuilder put(String key, Tag<?, ?> value) {
checkNotNull(key);
checkNotNull(value);
this.builder.put(key, value.asBinaryTag());
this.builder.put(key, value.toLinTag());
return this;
}
@ -215,9 +213,9 @@ public class CompoundTagBuilder {
* @param value the map of tags
* @return this object
*/
public CompoundTagBuilder putAll(Map<String, ? extends Tag> value) {
public CompoundTagBuilder putAll(Map<String, ? extends Tag<?, ?>> value) {
checkNotNull(value);
for (Map.Entry<String, ? extends Tag> entry : value.entrySet()) {
for (Map.Entry<String, ? extends Tag<?, ?>> entry : value.entrySet()) {
put(entry.getKey(), entry.getValue());
}
return this;

View File

@ -20,17 +20,15 @@
package com.sk89q.jnbt;
import com.fastasyncworldedit.core.jnbt.NumberTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import org.enginehub.linbus.tree.LinDoubleTag;
/**
* The {@code TAG_Double} tag.
*
* @deprecated Use {@link DoubleBinaryTag}.
* @deprecated Use {@link LinDoubleTag}.
*/
@Deprecated
public final class DoubleTag extends NumberTag {
private final DoubleBinaryTag innerTag;
public final class DoubleTag extends NumberTag<LinDoubleTag> {
/**
* Creates the tag with an empty name.
@ -38,23 +36,16 @@ public final class DoubleTag extends NumberTag {
* @param value the value of the tag
*/
public DoubleTag(double value) {
super();
this.innerTag = DoubleBinaryTag.of(value);
this(LinDoubleTag.of(value));
}
public DoubleTag(DoubleBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public DoubleBinaryTag asBinaryTag() {
return this.innerTag;
public DoubleTag(LinDoubleTag tag) {
super(tag);
}
@Override
public Double getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -19,24 +19,17 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import org.enginehub.linbus.tree.LinEndTag;
/**
* The {@code TAG_End} tag.
*
* @deprecated Use {@link com.sk89q.worldedit.util.nbt.EndBinaryTag}.
* @deprecated Use {@link LinEndTag}.
*/
@Deprecated
public final class EndTag extends Tag {
@Override
public Object getValue() {
return null;
}
@Override
public EndBinaryTag asBinaryTag() {
return EndBinaryTag.get();
public final class EndTag extends Tag<Object, LinEndTag> {
public EndTag() {
super(LinEndTag.instance());
}
//FAWE start

View File

@ -20,17 +20,14 @@
package com.sk89q.jnbt;
import com.fastasyncworldedit.core.jnbt.NumberTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import org.enginehub.linbus.tree.LinFloatTag;
/**
* The {@code TAG_Float} tag.
*
* @deprecated Use {@link FloatBinaryTag}.
* @deprecated Use {@link LinFloatTag}.
*/
@Deprecated
public final class FloatTag extends NumberTag {
private final FloatBinaryTag innerTag;
public final class FloatTag extends NumberTag<LinFloatTag> {
/**
* Creates the tag with an empty name.
@ -38,23 +35,16 @@ public final class FloatTag extends NumberTag {
* @param value the value of the tag
*/
public FloatTag(float value) {
super();
this.innerTag = FloatBinaryTag.of(value);
this(LinFloatTag.of(value));
}
public FloatTag(FloatBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public FloatBinaryTag asBinaryTag() {
return this.innerTag;
public FloatTag(LinFloatTag tag) {
super(tag);
}
@Override
public Float getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -19,44 +19,33 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The {@code TAG_Int_Array} tag.
*
* @deprecated Use {@link IntArrayBinaryTag}.
* @deprecated Use {@link LinIntArrayTag}.
*/
@Deprecated
public final class IntArrayTag extends Tag {
private final IntArrayBinaryTag innerTag;
public final class IntArrayTag extends Tag<int[], LinIntArrayTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public IntArrayTag(int[] value) {
super();
checkNotNull(value);
this.innerTag = IntArrayBinaryTag.of(value);
this(LinIntArrayTag.of(checkNotNull(value)));
}
public IntArrayTag(IntArrayBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public IntArrayBinaryTag asBinaryTag() {
return this.innerTag;
public IntArrayTag(LinIntArrayTag tag) {
super(tag);
}
@Override
public int[] getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -19,17 +19,16 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.fastasyncworldedit.core.jnbt.NumberTag;
import org.enginehub.linbus.tree.LinIntTag;
/**
* The {@code TAG_Int} tag.
*
* @deprecated Use {@link IntBinaryTag}.
* @deprecated Use {@link LinIntTag}.
*/
@Deprecated
public final class IntTag extends Tag {
private final IntBinaryTag innerTag;
public final class IntTag extends NumberTag<LinIntTag> {
/**
* Creates the tag with an empty name.
@ -37,23 +36,16 @@ public final class IntTag extends Tag {
* @param value the value of the tag
*/
public IntTag(int value) {
super();
this.innerTag = IntBinaryTag.of(value);
this(LinIntTag.of(value));
}
public IntTag(IntBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public IntBinaryTag asBinaryTag() {
return this.innerTag;
public IntTag(LinIntTag tag) {
super(tag);
}
@Override
public Integer getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -20,27 +20,27 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.Map;
/**
* Allows detection of the version-specific LazyCompoundTag classes.
*
* @deprecated Use {@link CompoundBinaryTag}.
* @deprecated Use {@link LinCompoundTag}.
*/
@Deprecated
public abstract class LazyCompoundTag extends CompoundTag {
public LazyCompoundTag(Map<String, Tag> value) {
public LazyCompoundTag(Map<String, Tag<?, ?>> value) {
super(value);
}
public LazyCompoundTag(CompoundBinaryTag adventureTag) {
public LazyCompoundTag(LinCompoundTag adventureTag) {
super(adventureTag);
}
@Override
public abstract CompoundBinaryTag asBinaryTag();
public abstract LinCompoundTag toLinTag();
}

View File

@ -0,0 +1,140 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.jnbt;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
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.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 java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
/**
* Converts between JNBT and Adventure-NBT classes.
*
* @deprecated JNBT is being removed in WE8.
*/
@Deprecated(forRemoval = true)
public class LinBusConverter {
private static final BiMap<Class<? extends Tag>, LinTagType<?>> TAG_TYPES =
new ImmutableBiMap.Builder<Class<? extends Tag>, LinTagType<?>>()
.put(ByteArrayTag.class, LinTagType.byteArrayTag())
.put(ByteTag.class, LinTagType.byteTag())
.put(CompoundTag.class, LinTagType.compoundTag())
.put(DoubleTag.class, LinTagType.doubleTag())
.put(EndTag.class, LinTagType.endTag())
.put(FloatTag.class, LinTagType.floatTag())
.put(IntArrayTag.class, LinTagType.intArrayTag())
.put(IntTag.class, LinTagType.intTag())
.put(ListTag.class, LinTagType.listTag())
.put(LongArrayTag.class, LinTagType.longArrayTag())
.put(LongTag.class, LinTagType.longTag())
.put(ShortTag.class, LinTagType.shortTag())
.put(StringTag.class, LinTagType.stringTag())
.build();
private static final Map<LinTagType<?>, Function<LinTag, Tag>> CONVERSION;
static {
ImmutableMap.Builder<LinTagType<?>, Function<LinTag, Tag>> conversion =
ImmutableMap.builder();
for (Map.Entry<Class<? extends Tag>, LinTagType<?>> tag : TAG_TYPES.entrySet()) {
Constructor<?>[] constructors = tag.getKey().getConstructors();
for (Constructor<?> c : constructors) {
if (c.getParameterCount() == 1 && LinTag.class.isAssignableFrom(c.getParameterTypes()[0])) {
conversion.put(tag.getValue(), linTag -> {
try {
return (Tag) c.newInstance(linTag);
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
// I assume this is always a RuntimeException since we control the ctor
throw (RuntimeException) e.getCause();
}
});
break;
}
}
}
CONVERSION = conversion.build();
}
public static LinTagType<?> getAdventureType(Class<? extends Tag> type) {
return Objects.requireNonNull(TAG_TYPES.get(type), () -> "Missing entry for " + type);
}
public static Class<? extends Tag> getJNBTType(LinTagType<?> type) {
return Objects.requireNonNull(TAG_TYPES.inverse().get(type), () -> "Missing entry for " + type);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <V, LT extends LinTag<? extends V>> Tag<V, LT> toJnbtTag(LT tag) {
return (Tag<V, LT>) switch (tag.type().id()) {
case BYTE_ARRAY -> new ByteArrayTag((LinByteArrayTag) tag);
case BYTE -> new ByteTag((LinByteTag) tag);
case COMPOUND -> new CompoundTag((LinCompoundTag) tag);
case DOUBLE -> new DoubleTag((LinDoubleTag) tag);
case END -> new EndTag();
case FLOAT -> new FloatTag((LinFloatTag) tag);
case INT_ARRAY -> new IntArrayTag((LinIntArrayTag) tag);
case INT -> new IntTag((LinIntTag) tag);
case LIST -> new ListTag((LinListTag<?>) tag);
case LONG_ARRAY -> new LongArrayTag((LinLongArrayTag) tag);
case LONG -> new LongTag((LinLongTag) tag);
case SHORT -> new ShortTag((LinShortTag) tag);
case STRING -> new StringTag((LinStringTag) tag);
};
}
private LinBusConverter() {
}
public static Tag fromLinBus(LinTag other) {
if (other == null) {
return null;
}
Function<LinTag, Tag> conversion = CONVERSION.get(other.type());
if (conversion == null) {
throw new IllegalArgumentException("Can't convert other of type " + other.getClass().getCanonicalName());
}
return conversion.apply(other);
}
}

View File

@ -19,10 +19,20 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTagLike;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.NumberBinaryTag;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinDoubleTag;
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.LinLongTag;
import org.enginehub.linbus.tree.LinNumberTag;
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 javax.annotation.Nullable;
import java.util.Collections;
@ -34,12 +44,10 @@ import java.util.stream.Collectors;
/**
* The {@code TAG_List} tag.
*
* @deprecated Use {@link com.sk89q.worldedit.util.nbt.ListBinaryTag}.
* @deprecated Use {@link LinListTag}.
*/
@Deprecated
public final class ListTag extends Tag {
private final ListBinaryTag innerTag;
public final class ListTag<EV, E extends LinTag<EV>> extends Tag<Object, LinListTag<E>> {
/**
* Creates the tag with an empty name.
@ -47,20 +55,15 @@ public final class ListTag extends Tag {
* @param type the type of tag
* @param value the value of the tag
*/
public ListTag(Class<? extends Tag> type, List<? extends Tag> value) {
this(ListBinaryTag.of(
AdventureNBTConverter.getAdventureType(type),
value.stream().map(BinaryTagLike::asBinaryTag).collect(Collectors.toList())
public ListTag(Class<? extends Tag<EV, E>> type, List<? extends Tag<EV, E>> value) {
this(LinListTag.of(
LinTagType.fromId(LinTagId.fromId(NBTUtils.getTypeCode(type))),
value.stream().map(Tag::toLinTag).collect(Collectors.toList())
));
}
public ListTag(ListBinaryTag adventureTag) {
this.innerTag = adventureTag;
}
@Override
public ListBinaryTag asBinaryTag() {
return this.innerTag;
public ListTag(LinListTag<E> tag) {
super(tag);
}
/**
@ -68,15 +71,14 @@ public final class ListTag extends Tag {
*
* @return The type of item in this list.
*/
public Class<? extends Tag> getType() {
return AdventureNBTConverter.getJNBTType(this.innerTag.elementType());
@SuppressWarnings("unchecked")
public Class<? extends Tag<EV, E>> getType() {
return (Class<? extends Tag<EV, E>>) NBTUtils.getTypeClass(linTag.elementType().id().id());
}
@Override
public List<Tag> getValue() {
return this.innerTag.stream()
.map(AdventureNBTConverter::fromAdventure)
.collect(Collectors.toList());
public List<? extends Tag<EV, E>> getValue() {
return linTag.value().stream().map(LinBusConverter::toJnbtTag).toList();
}
/**
@ -85,17 +87,31 @@ public final class ListTag extends Tag {
* @param list the new list
* @return a new list tag
*/
public ListTag setValue(List<Tag> list) {
return new ListTag(getType(), list);
public ListTag<EV, E> setValue(List<? extends Tag<EV, E>> list) {
return new ListTag<>(getType(), list);
}
private <T> T accessIfExists(int index, Supplier<T> defaultValue, IntFunction<T> accessor) {
if (index >= this.innerTag.size()) {
if (index >= this.linTag.value().size()) {
return defaultValue.get();
}
return accessor.apply(index);
}
@SuppressWarnings("unchecked")
private <T, LT extends LinTag<T>> T extractViaValue(
int index, Class<LT> requiredType, Supplier<T> defaultValue
) {
if (index >= this.linTag.value().size()) {
return defaultValue.get();
}
E value = this.linTag.get(index);
if (!requiredType.isInstance(value)) {
return defaultValue.get();
}
return (T) value.value();
}
/**
* Get the tag if it exists at the given index.
*
@ -103,11 +119,11 @@ public final class ListTag extends Tag {
* @return the tag or null
*/
@Nullable
public Tag getIfExists(int index) {
public Tag<EV, E> getIfExists(int index) {
return accessIfExists(
index,
() -> null,
i -> AdventureNBTConverter.fromAdventure(this.innerTag.get(i))
i -> LinBusConverter.toJnbtTag(this.linTag.get(i))
);
}
@ -121,11 +137,7 @@ public final class ListTag extends Tag {
* @return a byte array
*/
public byte[] getByteArray(int index) {
return accessIfExists(
index,
() -> new byte[0],
this.innerTag::getByteArray
);
return extractViaValue(index, LinByteArrayTag.class, () -> new byte[0]);
}
/**
@ -138,11 +150,7 @@ public final class ListTag extends Tag {
* @return a byte
*/
public byte getByte(int index) {
return accessIfExists(
index,
() -> (byte) 0,
this.innerTag::getByte
);
return extractViaValue(index, LinByteTag.class, () -> (byte) 0);
}
/**
@ -155,11 +163,7 @@ public final class ListTag extends Tag {
* @return a double
*/
public double getDouble(int index) {
return accessIfExists(
index,
() -> 0.0,
this.innerTag::getDouble
);
return extractViaValue(index, LinDoubleTag.class, () -> 0.0);
}
/**
@ -176,13 +180,9 @@ public final class ListTag extends Tag {
return accessIfExists(
index,
() -> 0.0,
i -> {
BinaryTag tag = this.innerTag.get(i);
if (tag instanceof NumberBinaryTag) {
return ((NumberBinaryTag) tag).doubleValue();
}
return 0.0;
}
i -> this.linTag.get(i) instanceof LinNumberTag<?> tag
? tag.value().doubleValue()
: 0.0
);
}
@ -196,11 +196,7 @@ public final class ListTag extends Tag {
* @return a float
*/
public float getFloat(int index) {
return accessIfExists(
index,
() -> 0.0f,
this.innerTag::getFloat
);
return extractViaValue(index, LinFloatTag.class, () -> 0f);
}
/**
@ -213,11 +209,7 @@ public final class ListTag extends Tag {
* @return an int array
*/
public int[] getIntArray(int index) {
return accessIfExists(
index,
() -> new int[0],
this.innerTag::getIntArray
);
return extractViaValue(index, LinIntArrayTag.class, () -> new int[0]);
}
/**
@ -230,11 +222,7 @@ public final class ListTag extends Tag {
* @return an int
*/
public int getInt(int index) {
return accessIfExists(
index,
() -> 0,
this.innerTag::getInt
);
return extractViaValue(index, LinIntTag.class, () -> 0);
}
/**
@ -251,13 +239,9 @@ public final class ListTag extends Tag {
return accessIfExists(
index,
() -> 0,
i -> {
BinaryTag tag = this.innerTag.get(i);
if (tag instanceof NumberBinaryTag) {
return ((NumberBinaryTag) tag).intValue();
}
return 0;
}
i -> this.linTag.get(i) instanceof LinNumberTag<?> tag
? tag.value().intValue()
: 0
);
}
@ -270,7 +254,7 @@ public final class ListTag extends Tag {
* @param index the index
* @return a list of tags
*/
public List<Tag> getList(int index) {
public List<? extends Tag<?, ?>> getList(int index) {
return getListTag(index).getValue();
}
@ -283,11 +267,12 @@ public final class ListTag extends Tag {
* @param index the index
* @return a tag list instance
*/
public ListTag getListTag(int index) {
return new ListTag(accessIfExists(
@SuppressWarnings("unchecked")
public ListTag<?, ?> getListTag(int index) {
return new ListTag<>(extractViaValue(
index,
ListBinaryTag::empty,
this.innerTag::getList
LinListTag.class,
() -> LinListTag.empty(LinTagType.endTag())
));
}
@ -305,8 +290,8 @@ public final class ListTag extends Tag {
* @return a list of tags
*/
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(int index, Class<T> listType) {
ListTag listTag = getListTag(index);
public <T extends Tag<?, ?>> List<T> getList(int index, Class<T> listType) {
ListTag<?, ?> listTag = getListTag(index);
if (listTag.getType().equals(listType)) {
return (List<T>) listTag.getValue();
} else {
@ -324,11 +309,7 @@ public final class ListTag extends Tag {
* @return a long
*/
public long getLong(int index) {
return accessIfExists(
index,
() -> 0L,
this.innerTag::getLong
);
return extractViaValue(index, LinLongTag.class, () -> 0L);
}
/**
@ -345,13 +326,9 @@ public final class ListTag extends Tag {
return accessIfExists(
index,
() -> 0L,
i -> {
BinaryTag tag = this.innerTag.get(i);
if (tag instanceof NumberBinaryTag) {
return ((NumberBinaryTag) tag).longValue();
}
return 0L;
}
i -> this.linTag.get(i) instanceof LinNumberTag<?> tag
? tag.value().longValue()
: 0L
);
}
@ -365,11 +342,7 @@ public final class ListTag extends Tag {
* @return a short
*/
public short getShort(int index) {
return accessIfExists(
index,
() -> (short) 0,
this.innerTag::getShort
);
return extractViaValue(index, LinShortTag.class, () -> (short) 0);
}
/**
@ -382,11 +355,7 @@ public final class ListTag extends Tag {
* @return a string
*/
public String getString(int index) {
return accessIfExists(
index,
() -> "",
this.innerTag::getString
);
return extractViaValue(index, LinStringTag.class, () -> "");
}
//FAWE start

View File

@ -19,11 +19,11 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTagType;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import org.enginehub.linbus.common.LinTagId;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import java.util.Arrays;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;
@ -31,12 +31,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helps create list tags.
*
* @deprecated Use {@link com.sk89q.worldedit.util.nbt.ListBinaryTag.Builder}.
* @deprecated Use {@link LinListTag.Builder}.
*/
@Deprecated
public class ListTagBuilder {
public class ListTagBuilder<V, LT extends LinTag<V>> {
private final ListBinaryTag.Builder<BinaryTag> builder;
private final LinListTag.Builder<LT> builder;
/**
* Create a new instance.
@ -44,11 +44,11 @@ public class ListTagBuilder {
* @param type of tag contained in this list
*/
@SuppressWarnings("unchecked")
ListTagBuilder(Class<? extends Tag> type) {
ListTagBuilder(Class<? extends Tag<V, LT>> type) {
checkNotNull(type);
this.builder = type != EndTag.class
? ListBinaryTag.builder((BinaryTagType<BinaryTag>) AdventureNBTConverter.getAdventureType(type))
: ListBinaryTag.builder();
this.builder = (LinListTag.Builder<LT>) LinListTag.builder(LinTagType.fromId(LinTagId.fromId(
NBTUtils.getTypeCode(type)
)));
}
/**
@ -57,9 +57,9 @@ public class ListTagBuilder {
* @param value the tag
* @return this object
*/
public ListTagBuilder add(Tag value) {
public ListTagBuilder<V, LT> add(Tag<V, LT> value) {
checkNotNull(value);
builder.add(value.asBinaryTag());
builder.add(value.toLinTag());
return this;
}
@ -69,9 +69,9 @@ public class ListTagBuilder {
* @param value a list of tags
* @return this object
*/
public ListTagBuilder addAll(Collection<? extends Tag> value) {
public ListTagBuilder<V, LT> addAll(Collection<? extends Tag<V, LT>> value) {
checkNotNull(value);
for (Tag v : value) {
for (Tag<V, LT> v : value) {
add(v);
}
return this;
@ -82,8 +82,8 @@ public class ListTagBuilder {
*
* @return the new list tag
*/
public ListTag build() {
return new ListTag(this.builder.build());
public ListTag<V, LT> build() {
return new ListTag<>(this.builder.build());
}
/**
@ -91,8 +91,8 @@ public class ListTagBuilder {
*
* @return a new builder
*/
public static ListTagBuilder create(Class<? extends Tag> type) {
return new ListTagBuilder(type);
public static <V, LT extends LinTag<V>> ListTagBuilder<V, LT> create(Class<? extends Tag<V, LT>> type) {
return new ListTagBuilder<>(type);
}
/**
@ -100,22 +100,24 @@ public class ListTagBuilder {
*
* @return a new builder
*/
public static ListTagBuilder createWith(Tag... entries) {
@SafeVarargs
public static <V, LT extends LinTag<V>> ListTagBuilder<V, LT> createWith(Tag<V, LT>... entries) {
checkNotNull(entries);
if (entries.length == 0) {
throw new IllegalArgumentException("This method needs an array of at least one entry");
}
Class<? extends Tag> type = entries[0].getClass();
for (int i = 1; i < entries.length; i++) {
if (!type.isInstance(entries[i])) {
@SuppressWarnings("unchecked")
Class<? extends Tag<V, LT>> type = (Class<? extends Tag<V, LT>>) entries[0].getClass();
ListTagBuilder<V, LT> builder = new ListTagBuilder<>(type);
for (Tag<V, LT> entry : entries) {
if (!type.isInstance(entry)) {
throw new IllegalArgumentException("An array of different tag types was provided");
}
builder.add(entry);
}
ListTagBuilder builder = new ListTagBuilder(type);
builder.addAll(Arrays.asList(entries));
return builder;
}

View File

@ -19,44 +19,33 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import org.enginehub.linbus.tree.LinLongArrayTag;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The {@code TAG_Long_Array} tag.
*
* @deprecated Use {@link LongArrayBinaryTag}.
* @deprecated Use {@link LinLongArrayTag}.
*/
@Deprecated
public class LongArrayTag extends Tag {
private final LongArrayBinaryTag innerTag;
public class LongArrayTag extends Tag<long[], LinLongArrayTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public LongArrayTag(long[] value) {
super();
checkNotNull(value);
this.innerTag = LongArrayBinaryTag.of(value);
this(LinLongArrayTag.of(checkNotNull(value)));
}
public LongArrayTag(LongArrayBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public LongArrayBinaryTag asBinaryTag() {
return this.innerTag;
public LongArrayTag(LinLongArrayTag tag) {
super(tag);
}
@Override
public long[] getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -19,41 +19,32 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.fastasyncworldedit.core.jnbt.NumberTag;
import org.enginehub.linbus.tree.LinLongTag;
/**
* The {@code TAG_Long} tag.
*
* @deprecated Use {@link LongBinaryTag}.
* @deprecated Use {@link LinLongTag}.
*/
@Deprecated
public final class LongTag extends Tag {
private final LongBinaryTag innerTag;
public final class LongTag extends NumberTag<LinLongTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public LongTag(long value) {
super();
this.innerTag = LongBinaryTag.of(value);
this(LinLongTag.of(value));
}
public LongTag(LongBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public LongBinaryTag asBinaryTag() {
return this.innerTag;
public LongTag(LinLongTag tag) {
super(tag);
}
@Override
public Long getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -50,7 +50,6 @@ public final class NBTConstants {
* Default private constructor.
*/
private NBTConstants() {
}
/**
@ -60,37 +59,27 @@ public final class NBTConstants {
* @return tag class
* @throws IllegalArgumentException thrown if the tag ID is not valid
*/
public static Class<? extends Tag> getClassFromType(int id) {
switch (id) {
case TYPE_END:
return EndTag.class;
case TYPE_BYTE:
return ByteTag.class;
case TYPE_SHORT:
return ShortTag.class;
case TYPE_INT:
return IntTag.class;
case TYPE_LONG:
return LongTag.class;
case TYPE_FLOAT:
return FloatTag.class;
case TYPE_DOUBLE:
return DoubleTag.class;
case TYPE_BYTE_ARRAY:
return ByteArrayTag.class;
case TYPE_STRING:
return StringTag.class;
case TYPE_LIST:
return ListTag.class;
case TYPE_COMPOUND:
return CompoundTag.class;
case TYPE_INT_ARRAY:
return IntArrayTag.class;
case TYPE_LONG_ARRAY:
return LongArrayTag.class;
default:
throw new IllegalArgumentException("Unknown tag type ID of " + id);
public static Class<? extends Tag<?, ?>> getClassFromType(int id) {
return switch (id) {
case TYPE_END -> EndTag.class;
case TYPE_BYTE -> ByteTag.class;
case TYPE_SHORT -> ShortTag.class;
case TYPE_INT -> IntTag.class;
case TYPE_LONG -> LongTag.class;
case TYPE_FLOAT -> FloatTag.class;
case TYPE_DOUBLE -> DoubleTag.class;
case TYPE_BYTE_ARRAY -> ByteArrayTag.class;
case TYPE_STRING -> StringTag.class;
case TYPE_LIST -> {
@SuppressWarnings("unchecked")
var aClass = (Class<? extends Tag<?, ?>>) (Class<?>) ListTag.class;
yield aClass;
}
case TYPE_COMPOUND -> CompoundTag.class;
case TYPE_INT_ARRAY -> IntArrayTag.class;
case TYPE_LONG_ARRAY -> LongArrayTag.class;
default -> throw new IllegalArgumentException("Unknown tag type ID of " + id);
};
}
}

View File

@ -21,6 +21,7 @@ package com.sk89q.jnbt;
import com.fastasyncworldedit.core.jnbt.streamer.StreamDelegate;
import com.fastasyncworldedit.core.jnbt.streamer.ValueReader;
import org.enginehub.linbus.stream.LinBinaryIO;
import java.io.Closeable;
import java.io.DataInputStream;
@ -44,8 +45,9 @@ import java.util.Map;
* https://minecraft.gamepedia.com/NBT_format</a>.
* </p>
*
* @deprecated JNBT is being removed for adventure-nbt in WorldEdit 8.
* @deprecated JNBT is being removed for lin-bus in WorldEdit 8, use {@link LinBinaryIO} instead
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public final class NBTInputStream implements Closeable {
@ -77,7 +79,6 @@ public final class NBTInputStream implements Closeable {
* Reads an NBT tag from the stream.
*
* @return The tag that was read.
* @throws IOException if an I/O error occurs.
*/
public NamedTag readNamedTag() throws IOException {
return readNamedTag(0);
@ -617,7 +618,7 @@ public final class NBTInputStream implements Closeable {
return new ListTag(NBTUtils.getTypeClass(childType), tagList);
case NBTConstants.TYPE_COMPOUND:
Map<String, Tag> tagMap = new HashMap<>();
Map<String, Tag<?, ?>> tagMap = new HashMap<>();
while (true) {
NamedTag namedTag = readNamedTag(depth + 1);
Tag tag = namedTag.getTag();

View File

@ -20,6 +20,7 @@
package com.sk89q.jnbt;
import com.fastasyncworldedit.core.internal.io.LittleEndianOutputStream;
import org.enginehub.linbus.stream.LinBinaryIO;
import java.io.Closeable;
import java.io.DataOutput;
@ -44,8 +45,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
* https://minecraft.gamepedia.com/NBT_format</a>.
* </p>
*
* @deprecated JNBT is being removed for adventure-nbt in WorldEdit 8.
* @deprecated JNBT is being removed for lin-bus in WorldEdit 8, use {@link LinBinaryIO} instead
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public final class NBTOutputStream extends OutputStream implements Closeable, DataOutput {
@ -61,7 +63,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @param os The output stream.
* @throws IOException if an I/O error occurs.
*/
public NBTOutputStream(OutputStream os) throws IOException {
public NBTOutputStream(OutputStream os) {
this(os instanceof DataOutput ? (DataOutput) os : new DataOutputStream(os));
}
@ -91,11 +93,11 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @param tag The tag to write.
* @throws IOException if an I/O error occurs.
*/
public void writeNamedTag(String name, Tag tag) throws IOException {
public void writeNamedTag(String name, Tag<?, ?> tag) throws IOException {
checkNotNull(name);
checkNotNull(tag);
int type = NBTUtils.getTypeCode(tag.getClass());
int type = tag.getTypeCode();
writeNamedTagName(name, type);
if (type == NBTConstants.TYPE_END) {
@ -196,7 +198,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
}
public void writeTag(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass());
int type = tag.getTypeCode();
os.writeByte(type);
writeTagPayload(tag);
}
@ -212,7 +214,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @throws IOException if an I/O error occurs.
*/
public void writeTagPayload(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass());
int type = tag.getTypeCode();
switch (type) {
case NBTConstants.TYPE_END:
writeEndTagPayload((EndTag) tag);
@ -287,7 +289,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @throws IOException if an I/O error occurs.
*/
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
for (Map.Entry<String, Tag> entry : tag.getValue().entrySet()) {
for (Map.Entry<String, Tag<?, ?>> entry : tag.getValue().entrySet()) {
writeNamedTag(entry.getKey(), entry.getValue());
}
os.writeByte((byte) 0); // end tag - better way?
@ -300,7 +302,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @throws IOException if an I/O error occurs.
*/
private void writeListTagPayload(ListTag tag) throws IOException {
Class<? extends Tag> clazz = tag.getType();
Class<? extends Tag<?, ?>> clazz = tag.getType();
if (clazz == null) {
clazz = CompoundTag.class;
}

View File

@ -20,7 +20,6 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.nbt.BinaryTagTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.Map;
@ -33,6 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
*
* @deprecated JNBT is being removed for adventure-nbt in WorldEdit 8.
*/
@SuppressWarnings("ALL")
@Deprecated
public final class NBTUtils {
@ -48,7 +48,7 @@ public final class NBTUtils {
* @param clazz the tag class
* @return The type name.
*/
public static String getTypeName(Class<? extends Tag> clazz) {
public static String getTypeName(Class<? extends Tag<?, ?>> clazz) {
if (clazz.equals(ByteArrayTag.class)) {
return "TAG_Byte_Array";
} else if (clazz.equals(ByteTag.class)) {
@ -88,11 +88,35 @@ public final class NBTUtils {
* @return The type code.
* @throws IllegalArgumentException if the tag class is invalid.
*/
public static int getTypeCode(Class<? extends Tag> clazz) {
if (LazyCompoundTag.class.isAssignableFrom(clazz)) {
return BinaryTagTypes.COMPOUND.id();
public static int getTypeCode(Class<? extends Tag<?, ?>> clazz) {
if (clazz == ByteArrayTag.class) {
return NBTConstants.TYPE_BYTE_ARRAY;
} else if (clazz == ByteTag.class) {
return NBTConstants.TYPE_BYTE;
} else if (clazz == CompoundTag.class) {
return NBTConstants.TYPE_COMPOUND;
} else if (clazz == DoubleTag.class) {
return NBTConstants.TYPE_DOUBLE;
} else if (clazz == EndTag.class) {
return NBTConstants.TYPE_END;
} else if (clazz == FloatTag.class) {
return NBTConstants.TYPE_FLOAT;
} else if (clazz == IntArrayTag.class) {
return NBTConstants.TYPE_INT_ARRAY;
} else if (clazz == IntTag.class) {
return NBTConstants.TYPE_INT;
} else if (clazz.equals(ListTag.class) /* I hate this, it wouldn't do == b/c generics */) {
return NBTConstants.TYPE_LIST;
} else if (clazz == LongArrayTag.class) {
return NBTConstants.TYPE_LONG_ARRAY;
} else if (clazz == LongTag.class) {
return NBTConstants.TYPE_LONG;
} else if (clazz == ShortTag.class) {
return NBTConstants.TYPE_SHORT;
} else if (clazz == StringTag.class) {
return NBTConstants.TYPE_STRING;
}
return AdventureNBTConverter.getAdventureType(clazz).id();
throw new IllegalArgumentException("Invalid tag class (" + clazz.getName() + ")");
}
/**
@ -102,38 +126,8 @@ public final class NBTUtils {
* @return The class.
* @throws IllegalArgumentException if the tag type is invalid.
*/
public static Class<? extends Tag> getTypeClass(int type) {
switch (type) {
case NBTConstants.TYPE_END:
return EndTag.class;
case NBTConstants.TYPE_BYTE:
return ByteTag.class;
case NBTConstants.TYPE_SHORT:
return ShortTag.class;
case NBTConstants.TYPE_INT:
return IntTag.class;
case NBTConstants.TYPE_LONG:
return LongTag.class;
case NBTConstants.TYPE_FLOAT:
return FloatTag.class;
case NBTConstants.TYPE_DOUBLE:
return DoubleTag.class;
case NBTConstants.TYPE_BYTE_ARRAY:
return ByteArrayTag.class;
case NBTConstants.TYPE_STRING:
return StringTag.class;
case NBTConstants.TYPE_LIST:
return ListTag.class;
case NBTConstants.TYPE_COMPOUND:
return CompoundTag.class;
case NBTConstants.TYPE_INT_ARRAY:
return IntArrayTag.class;
case NBTConstants.TYPE_LONG_ARRAY:
return LongArrayTag.class;
default:
throw new IllegalArgumentException("Invalid tag type : " + type
+ ".");
}
public static Class<? extends Tag<?, ?>> getTypeClass(int type) {
return NBTConstants.getClassFromType(type);
}
/**
@ -145,7 +139,7 @@ public final class NBTUtils {
* @param listTag the list tag
* @return a vector
*/
public static Vector3 toVector(ListTag listTag) {
public static Vector3 toVector(ListTag<?, ?> listTag) {
checkNotNull(listTag);
return Vector3.at(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2));
}
@ -159,12 +153,12 @@ public final class NBTUtils {
* @return child tag
* @throws InvalidFormatException if the format of the items is invalid
*/
public static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws
public static <T extends Tag<?, ?>> T getChildTag(Map<String, Tag<?, ?>> items, String key, Class<T> expected) throws
InvalidFormatException {
if (!items.containsKey(key)) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
}
Tag tag = items.get(key);
Tag<?, ?> tag = items.get(key);
if (!expected.isInstance(tag)) {
throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName());
}
@ -179,7 +173,7 @@ public final class NBTUtils {
* @param uuid {@link UUID} to add
* @since 2.4.0
*/
public static void addUUIDToMap(Map<String, Tag> map, UUID uuid) {
public static void addUUIDToMap(Map<String, Tag<?, ?>> map, UUID uuid) {
int[] uuidArray = new int[4];
uuidArray[0] = (int) (uuid.getMostSignificantBits() >> 32);
uuidArray[1] = (int) uuid.getMostSignificantBits();

View File

@ -30,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class NamedTag {
private final String name;
private final Tag tag;
private final Tag<?, ?> tag;
/**
* Create a new named tag.
@ -38,7 +38,7 @@ public class NamedTag {
* @param name the name
* @param tag the tag
*/
public NamedTag(String name, Tag tag) {
public NamedTag(String name, Tag<?, ?> tag) {
checkNotNull(name);
checkNotNull(tag);
this.name = name;
@ -59,7 +59,7 @@ public class NamedTag {
*
* @return the tag
*/
public Tag getTag() {
public Tag<?, ?> getTag() {
return tag;
}

View File

@ -19,41 +19,32 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.fastasyncworldedit.core.jnbt.NumberTag;
import org.enginehub.linbus.tree.LinShortTag;
/**
* The {@code TAG_Short} tag.
*
* @deprecated Use {@link ShortBinaryTag}.
* @deprecated Use {@link LinShortTag}.
*/
@Deprecated
public final class ShortTag extends Tag {
private final ShortBinaryTag innerTag;
public final class ShortTag extends NumberTag<LinShortTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public ShortTag(short value) {
super();
this.innerTag = ShortBinaryTag.of(value);
super(LinShortTag.of(value));
}
public ShortTag(ShortBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public ShortBinaryTag asBinaryTag() {
return this.innerTag;
public ShortTag(LinShortTag tag) {
super(tag);
}
@Override
public Short getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -19,44 +19,33 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import org.enginehub.linbus.tree.LinStringTag;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The {@code TAG_String} tag.
*
* @deprecated Use {@link StringBinaryTag}.
* @deprecated Use {@link LinStringTag}.
*/
@Deprecated
public final class StringTag extends Tag {
private final StringBinaryTag innerTag;
public final class StringTag extends Tag<String, LinStringTag> {
/**
* Creates the tag with an empty name.
*
* @param value the value of the tag
*/
public StringTag(String value) {
super();
checkNotNull(value);
this.innerTag = StringBinaryTag.of(value);
super(LinStringTag.of(checkNotNull(value)));
}
public StringTag(StringBinaryTag adventureTag) {
super();
this.innerTag = adventureTag;
}
@Override
public StringBinaryTag asBinaryTag() {
return this.innerTag;
public StringTag(LinStringTag tag) {
super(tag);
}
@Override
public String getValue() {
return innerTag.value();
return linTag.value();
}
//FAWE start

View File

@ -19,26 +19,43 @@
package com.sk89q.jnbt;
import com.sk89q.worldedit.util.nbt.BinaryTagLike;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.ToLinTag;
import javax.annotation.Nonnull;
/**
* Represents a NBT tag.
*
* @deprecated JNBT is being removed for adventure-nbt in WorldEdit 8.
* @deprecated JNBT is being removed for lin-bus in WorldEdit 8, use {@link LinTag} instead
*/
@Deprecated(forRemoval = true)
public abstract class Tag implements BinaryTagLike {
@Deprecated
public abstract class Tag<V, LT extends LinTag<? extends V>> implements ToLinTag<LT> {
protected final LT linTag;
protected Tag(LT linTag) {
this.linTag = linTag;
}
/**
* Gets the value of this tag.
*
* @return the value
*/
public abstract Object getValue();
public V getValue() {
return linTag.value();
}
@Override
public String toString() {
return asBinaryTag().toString();
return toLinTag().toString();
}
@Override
@Nonnull
public LT toLinTag() {
return linTag;
}
//FAWE start

View File

@ -76,7 +76,6 @@ import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Identifiable;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -84,6 +83,8 @@ import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
import com.zaxxer.sparsebits.SparseBitSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinTagType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -1513,13 +1514,13 @@ public class LocalSession implements TextureHolder {
BaseBlock block = ServerCUIHandler.createStructureBlock(player);
if (block != null) {
CompoundBinaryTag tags = Objects.requireNonNull(
LinCompoundTag tags = Objects.requireNonNull(
block.getNbt(), "createStructureBlock should return nbt"
);
BlockVector3 tempCuiTemporaryBlock = BlockVector3.at(
tags.getInt("x"),
tags.getInt("y"),
tags.getInt("z")
tags.getTag("x", LinTagType.intTag()).valueAsInt(),
tags.getTag("y", LinTagType.intTag()).valueAsInt(),
tags.getTag("z", LinTagType.intTag()).valueAsInt()
);
// If it's null, we don't need to do anything. The old was already removed.
if (cuiTemporaryBlock != null && !tempCuiTemporaryBlock.equals(cuiTemporaryBlock)) {

View File

@ -20,15 +20,13 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.TagStringIO;
import com.sk89q.worldedit.world.NbtValued;
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.linbus.format.snbt.LinStringIO;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.io.IOException;
import static com.google.common.base.Preconditions.checkNotNull;
@ -42,9 +40,7 @@ public class BaseItem implements NbtValued {
private ItemType itemType;
@Nullable
//FAWE start - Use LR & CBT over CompoundTag
private LazyReference<CompoundBinaryTag> nbtData;
//FAWE end
private LazyReference<LinCompoundTag> nbtData;
/**
* Construct the object.
@ -56,6 +52,29 @@ public class BaseItem implements NbtValued {
this.itemType = itemType;
}
/**
* Construct the object.
*
* @param itemType Type of the item
* @param nbtData NBT Compound tag
*/
@Deprecated
public BaseItem(ItemType itemType, @Nullable CompoundTag nbtData) {
this(itemType, nbtData == null ? null : LazyReference.from(nbtData::toLinTag));
}
/**
* Construct the object.
*
* @param itemType Type of the item
* @param tag NBT Compound tag
*/
public BaseItem(ItemType itemType, @Nullable LazyReference<LinCompoundTag> tag) {
checkNotNull(itemType);
this.itemType = itemType;
this.nbtData = tag;
}
/**
* Get the type of item.
*
@ -77,29 +96,6 @@ public class BaseItem implements NbtValued {
//FAWE start
/**
* Construct the object.
*
* @param itemType Type of the item
* @param nbtData NBT Compound tag
*/
@Deprecated
public BaseItem(ItemType itemType, @Nullable CompoundTag nbtData) {
this(itemType, nbtData == null ? null : LazyReference.from(nbtData::asBinaryTag));
}
/**
* Construct the object.
*
* @param itemType Type of the item
* @param tag NBT Compound tag
*/
public BaseItem(ItemType itemType, @Nullable LazyReference<CompoundBinaryTag> tag) {
checkNotNull(itemType);
this.itemType = itemType;
this.nbtData = tag;
}
@Deprecated
@Nullable
public Object getNativeItem() {
@ -108,25 +104,20 @@ public class BaseItem implements NbtValued {
@Nullable
@Override
public LazyReference<CompoundBinaryTag> getNbtReference() {
public LazyReference<LinCompoundTag> getNbtReference() {
return this.nbtData;
}
@Override
public void setNbtReference(@Nullable LazyReference<CompoundBinaryTag> nbtData) {
public void setNbtReference(@Nullable LazyReference<LinCompoundTag> nbtData) {
this.nbtData = nbtData;
}
@Override
public String toString() {
String nbtString = "";
LazyReference<CompoundBinaryTag> nbtData = this.nbtData;
if (nbtData != null) {
try {
nbtString = TagStringIO.get().asString(nbtData.getValue());
} catch (IOException e) {
WorldEdit.logger.error("Failed to serialize NBT of Item", e);
}
nbtString = LinStringIO.writeToString(nbtData.getValue());
}
return getType().id() + nbtString;

View File

@ -24,8 +24,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.linbus.tree.LinCompoundTag;
/**
* Represents a stack of BaseItems.
@ -70,6 +70,18 @@ public class BaseItemStack extends BaseItem {
this.amount = amount;
}
/**
* Construct the object.
*
* @param id The item type
* @param tag Tag value
* @param amount amount in the stack
*/
public BaseItemStack(ItemType id, LazyReference<LinCompoundTag> tag, int amount) {
super(id, tag);
this.amount = amount;
}
/**
* Get the number of items in the stack.
*
@ -93,18 +105,4 @@ public class BaseItemStack extends BaseItem {
.getRegistries().getItemRegistry().getRichName(this);
}
//FAWE start
/**
* Construct the object.
*
* @param id The item type
* @param tag Tag value
* @param amount amount in the stack
*/
public BaseItemStack(ItemType id, LazyReference<CompoundBinaryTag> tag, int amount) {
super(id, tag);
this.amount = amount;
}
//FAWE end
}

View File

@ -21,10 +21,10 @@ package com.sk89q.worldedit.entity;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.NbtValued;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
@ -47,7 +47,7 @@ public class BaseEntity implements NbtValued {
private final EntityType type;
@Nullable
private LazyReference<CompoundBinaryTag> nbtData;
private LazyReference<LinCompoundTag> nbtData;
/**
* Create a new base entity.
@ -69,7 +69,7 @@ public class BaseEntity implements NbtValued {
* @param type the entity type
* @param nbtData NBT data
*/
public BaseEntity(EntityType type, LazyReference<CompoundBinaryTag> nbtData) {
public BaseEntity(EntityType type, LazyReference<LinCompoundTag> nbtData) {
this(type);
setNbtReference(nbtData);
}
@ -97,12 +97,12 @@ public class BaseEntity implements NbtValued {
@Nullable
@Override
public LazyReference<CompoundBinaryTag> getNbtReference() {
public LazyReference<LinCompoundTag> getNbtReference() {
return nbtData;
}
@Override
public void setNbtReference(@Nullable LazyReference<CompoundBinaryTag> nbtData) {
public void setNbtReference(@Nullable LazyReference<LinCompoundTag> nbtData) {
this.nbtData = nbtData;
}

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.extension.factory.parser;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
@ -35,13 +34,13 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.TagStringIO;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.enginehub.linbus.format.snbt.LinStringIO;
import org.enginehub.linbus.stream.exception.NbtParseException;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.io.IOException;
import java.util.Locale;
import java.util.stream.Stream;
@ -59,7 +58,7 @@ public class DefaultItemParser extends InputParser<BaseItem> {
@Override
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
ItemType itemType;
CompoundBinaryTag itemNbtData = null;
LinCompoundTag itemNbtData = null;
BaseItem item = null;
@ -128,20 +127,21 @@ public class DefaultItemParser extends InputParser<BaseItem> {
}
if (nbtString != null) {
LinCompoundTag otherTag;
try {
CompoundBinaryTag otherTag = TagStringIO.get().asCompound(nbtString);
if (itemNbtData == null) {
itemNbtData = otherTag;
} else {
itemNbtData.put(NbtUtils.getCompoundBinaryTagValues(otherTag));
}
} catch (IOException e) {
otherTag = LinStringIO.readFromStringUsing(nbtString, LinCompoundTag::readFrom);
} catch (NbtParseException e) {
throw new NoMatchException(TranslatableComponent.of(
"worldedit.error.invalid-nbt",
TextComponent.of(input),
TextComponent.of(e.getMessage())
));
}
if (itemNbtData == null) {
itemNbtData = otherTag;
} else {
itemNbtData = itemNbtData.toBuilder().putAll(otherTag.value()).build();
}
}
item = new BaseItem(itemType, itemNbtData == null ? null : LazyReference.computed(itemNbtData));

View File

@ -186,7 +186,7 @@ public class BlockArrayClipboard implements Clipboard {
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) {
if (region.contains(position)) {
//FAWE - get points
final int x = position.x();

View File

@ -153,7 +153,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag<?, ?>> schematic = schematicTag.getValue();
if (!schematic.containsKey("Version")) {
return false;
}

View File

@ -20,17 +20,7 @@
package com.sk89q.worldedit.extent.clipboard.io;
import com.google.common.collect.ImmutableList;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NamedTag;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -49,7 +39,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.collection.BlockMap;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.entity.EntityType;
@ -57,27 +47,25 @@ import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.storage.NBTConversions;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinByteArrayTag;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinRootEntry;
import org.enginehub.linbus.tree.LinTagType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.UncheckedIOException;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Reads schematic files that are compatible with MCEdit and other editors.
*/
public class MCEditSchematicReader extends NBTSchematicReader {
private static final Logger LOGGER = LogManagerCompat.getLogger();
private final NBTInputStream inputStream;
private final DataFixer fixer;
private final LinRootEntry root;
private static final ImmutableList<NBTCompatibilityHandler> COMPATIBILITY_HANDLERS
= ImmutableList.of(
new SignCompatibilityHandler(),
@ -98,30 +86,30 @@ public class MCEditSchematicReader extends NBTSchematicReader {
* @param inputStream the input stream to read from
*/
public MCEditSchematicReader(NBTInputStream inputStream) {
checkNotNull(inputStream);
this.inputStream = inputStream;
this.fixer = null;
//com.sk89q.worldedit.WorldEdit.getInstance().getPlatformManager().queryCapability(
//com.sk89q.worldedit.extension.platform.Capability.WORLD_EDITING).getDataFixer();
try {
var tag = inputStream.readNamedTag();
this.root = new LinRootEntry(tag.getName(), (LinCompoundTag) tag.getTag().toLinTag());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
MCEditSchematicReader(LinRootEntry root) {
this.root = root;
}
@Override
public Clipboard read() throws IOException {
// Schematic tag
NamedTag rootTag = inputStream.readNamedTag();
if (!rootTag.getName().equals("Schematic")) {
if (!root.name().equals("Schematic")) {
throw new IOException("Tag 'Schematic' does not exist or is not first");
}
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
var schematicTag = root.value();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) {
if (!schematicTag.value().containsKey("Blocks")) {
throw new IOException("Schematic file is missing a 'Blocks' tag");
}
// Check type of Schematic
String materials = requireTag(schematic, "Materials", StringTag.class).getValue();
String materials = schematicTag.getTag("Materials", LinTagType.stringTag()).value();
if (!materials.equals("Alpha")) {
throw new IOException("Schematic file is not an Alpha schematic");
}
@ -134,42 +122,38 @@ public class MCEditSchematicReader extends NBTSchematicReader {
Region region;
// Get information
short width = requireTag(schematic, "Width", ShortTag.class).getValue();
short height = requireTag(schematic, "Height", ShortTag.class).getValue();
short length = requireTag(schematic, "Length", ShortTag.class).getValue();
short width = schematicTag.getTag("Width", LinTagType.shortTag()).valueAsShort();
short height = schematicTag.getTag("Height", LinTagType.shortTag()).valueAsShort();
short length = schematicTag.getTag("Length", LinTagType.shortTag()).valueAsShort();
try {
int originX = requireTag(schematic, "WEOriginX", IntTag.class).getValue();
int originY = requireTag(schematic, "WEOriginY", IntTag.class).getValue();
int originZ = requireTag(schematic, "WEOriginZ", IntTag.class).getValue();
int originX = schematicTag.getTag("WEOriginX", LinTagType.intTag()).valueAsInt();
int originY = schematicTag.getTag("WEOriginY", LinTagType.intTag()).valueAsInt();
int originZ = schematicTag.getTag("WEOriginZ", LinTagType.intTag()).valueAsInt();
BlockVector3 min = BlockVector3.at(originX, originY, originZ);
int offsetX = requireTag(schematic, "WEOffsetX", IntTag.class).getValue();
int offsetY = requireTag(schematic, "WEOffsetY", IntTag.class).getValue();
int offsetZ = requireTag(schematic, "WEOffsetZ", IntTag.class).getValue();
int offsetX = schematicTag.getTag("WEOffsetX", LinTagType.intTag()).valueAsInt();
int offsetY = schematicTag.getTag("WEOffsetY", LinTagType.intTag()).valueAsInt();
int offsetZ = schematicTag.getTag("WEOffsetZ", LinTagType.intTag()).valueAsInt();
BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ);
origin = min.subtract(offset);
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
} catch (IOException ignored) {
origin = BlockVector3.ZERO;
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
}
// ====================================================================
// Blocks
// ====================================================================
// Get blocks
byte[] blockId = requireTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = requireTag(schematic, "Data", ByteArrayTag.class).getValue();
byte[] blockId = schematicTag.getTag("Blocks", LinTagType.byteArrayTag()).value();
byte[] blockData = schematicTag.getTag("Data", LinTagType.byteArrayTag()).value();
byte[] addId = new byte[0];
short[] blocks = new short[blockId.length]; // Have to later combine IDs
// We support 4096 block IDs using the same method as vanilla Minecraft, where
// the highest 4 bits are stored in a separate byte array.
if (schematic.containsKey("AddBlocks")) {
addId = requireTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
LinByteArrayTag addBlocks = schematicTag.findTag("AddBlocks", LinTagType.byteArrayTag());
if (addBlocks != null) {
addId = addBlocks.value();
}
// Combine the AddBlocks data with the first 8-bit block ID
@ -186,21 +170,17 @@ public class MCEditSchematicReader extends NBTSchematicReader {
}
// Need to pull out tile entities
final ListTag tileEntityTag = getTag(schematic, "TileEntities", ListTag.class);
List<Tag> tileEntities = tileEntityTag == null ? new ArrayList<>() : tileEntityTag.getValue();
var tileEntityTag = schematicTag.findListTag("TileEntities", LinTagType.compoundTag());
List<LinCompoundTag> tileEntities = tileEntityTag == null ? List.of() : tileEntityTag.value();
BlockMap<BaseBlock> tileEntityBlocks = BlockMap.createForBaseBlock();
for (Tag tag : tileEntities) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag t = (CompoundTag) tag;
Map<String, Tag> values = new HashMap<>(t.getValue());
String id = t.getString("id");
values.put("id", new StringTag(convertBlockEntityId(id)));
int x = t.getInt("x");
int y = t.getInt("y");
int z = t.getInt("z");
for (LinCompoundTag tag : tileEntities) {
var newTag = tag.toBuilder();
String id = tag.getTag("id", LinTagType.stringTag()).value();
newTag.putString("id", convertBlockEntityId(id));
int x = tag.getTag("x", LinTagType.intTag()).valueAsInt();
int y = tag.getTag("y", LinTagType.intTag()).valueAsInt();
int z = tag.getTag("z", LinTagType.intTag()).valueAsInt();
int index = y * width * length + z * width + x;
//FAWE start - tile entity safety - perhaps caused by the old issue with tile entities created in the wrong
@ -211,44 +191,17 @@ public class MCEditSchematicReader extends NBTSchematicReader {
}
BlockState block = getBlockState(blocks[index], blockData[index]);
BlockState newBlock = block;
if (newBlock != null) {
if (block == null) {
continue;
}
var updatedBlock = block.toBaseBlock(LazyReference.from(newTag::build));
for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) {
if (handler.isAffectedBlock(newBlock)) {
newBlock = handler.updateNBT(block, values).toImmutableState();
if (newBlock == null || values.isEmpty()) {
updatedBlock = handler.updateNbt(updatedBlock);
if (updatedBlock.getNbtReference() == null) {
break;
}
}
}
}
if (values.isEmpty()) {
t = null;
} else {
t = new CompoundTag(values);
}
if (fixer != null && t != null) {
//FAWE start - BinaryTag
t = (CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
DataFixer.FixTypes.BLOCK_ENTITY,
t.asBinaryTag(),
-1
));
//FAWE end
}
BlockVector3 vec = BlockVector3.at(x, y, z);
// Insert into the map if we have changed the block or have a tag
BlockState blockToInsert = newBlock != null
? newBlock
: (t != null ? block : null);
if (blockToInsert != null) {
BaseBlock baseBlock = t != null
? blockToInsert.toBaseBlock(new CompoundTag(t.getValue()))
: blockToInsert.toBaseBlock();
tileEntityBlocks.put(vec, baseBlock);
}
tileEntityBlocks.put(BlockVector3.at(x, y, z), updatedBlock);
}
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
@ -261,16 +214,10 @@ public class MCEditSchematicReader extends NBTSchematicReader {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
BlockVector3 pt = BlockVector3.at(x, y, z);
BaseBlock state = Optional.ofNullable(tileEntityBlocks.get(pt))
.orElseGet(() -> {
BaseBlock state = tileEntityBlocks.get(pt);
if (state == null) {
BlockState blockState = getBlockState(blocks[index], blockData[index]);
return blockState == null ? null : blockState.toBaseBlock();
});
try {
if (state != null) {
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
} else {
if (blockState == null) {
short block = blocks[index];
byte data = blockData[index];
int combined = block << 8 | data;
@ -278,9 +225,12 @@ public class MCEditSchematicReader extends NBTSchematicReader {
LOGGER.warn("Unknown block when loading schematic: {} {}. This is most likely a" +
"bad schematic.", block, data);
}
continue;
}
} catch (WorldEditException ignored) { // BlockArrayClipboard won't throw this
state = blockState.toBaseBlock();
}
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
}
}
}
@ -289,36 +239,22 @@ public class MCEditSchematicReader extends NBTSchematicReader {
// Entities
// ====================================================================
ListTag entityList = getTag(schematic, "Entities", ListTag.class);
var entityList = schematicTag.findListTag("Entities", LinTagType.compoundTag());
if (entityList != null) {
List<Tag> entityTags = entityList.getValue();
for (Tag tag : entityTags) {
if (tag instanceof CompoundTag) {
CompoundTag compound = (CompoundTag) tag;
if (fixer != null) {
//FAWE start - BinaryTag
compound = (CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
DataFixer.FixTypes.ENTITY,
compound.asBinaryTag(),
-1
));
//FAWE end
}
String id = convertEntityId(compound.getString("id"));
for (LinCompoundTag tag : entityList.value()) {
String id = convertEntityId(tag.getTag("id", LinTagType.stringTag()).value());
Location location = NBTConversions.toLocation(
clipboard,
compound.getListTag("Pos"),
compound.getListTag("Rotation")
tag.getListTag("Pos", LinTagType.doubleTag()),
tag.getListTag("Rotation", LinTagType.floatTag())
);
if (!id.isEmpty()) {
EntityType entityType = EntityTypes.get(id.toLowerCase(Locale.ROOT));
if (entityType != null) {
for (EntityNBTCompatibilityHandler compatibilityHandler : ENTITY_COMPATIBILITY_HANDLERS) {
if (compatibilityHandler.isAffectedEntity(entityType, compound)) {
compound = compatibilityHandler.updateNBT(entityType, compound);
tag = compatibilityHandler.updateNbt(entityType, tag);
}
}
BaseEntity state = new BaseEntity(entityType, compound);
BaseEntity state = new BaseEntity(entityType, LazyReference.computed(tag));
clipboard.createEntity(location, state);
} else {
LOGGER.warn("Unknown entity when pasting schematic: " + id.toLowerCase(Locale.ROOT));
@ -326,7 +262,6 @@ public class MCEditSchematicReader extends NBTSchematicReader {
}
}
}
}
return clipboard;
}
@ -494,7 +429,6 @@ public class MCEditSchematicReader extends NBTSchematicReader {
@Override
public void close() throws IOException {
inputStream.close();
}
}

View File

@ -30,13 +30,13 @@ import java.util.Map;
*/
public abstract class NBTSchematicReader implements ClipboardReader {
protected static <T extends Tag> T requireTag(Map<String, Tag> items, String key, Class<T> expected) throws IOException {
protected static <T extends Tag<?, ?>> T requireTag(Map<String, Tag<?, ?>> items, String key, Class<T> expected) throws IOException {
if (!items.containsKey(key)) {
throw new IOException("Schematic file is missing a \"" + key + "\" tag of type "
+ expected.getName());
}
Tag tag = items.get(key);
Tag<?, ?> tag = items.get(key);
if (!expected.isInstance(tag)) {
throw new IOException(key + " tag is not of tag type " + expected.getName() + ", got "
+ tag.getClass().getName() + " instead");
@ -46,12 +46,12 @@ public abstract class NBTSchematicReader implements ClipboardReader {
}
@Nullable
protected static <T extends Tag> T getTag(Map<String, Tag> items, String key, Class<T> expected) {
protected static <T extends Tag<?, ?>> T getTag(Map<String, Tag<?, ?>> items, String key, Class<T> expected) {
if (!items.containsKey(key)) {
return null;
}
Tag test = items.get(key);
Tag<?, ?> test = items.get(key);
if (!expected.isInstance(test)) {
return null;
}

View File

@ -21,7 +21,7 @@ package com.sk89q.worldedit.extent.clipboard.io;
import com.fastasyncworldedit.core.configuration.Caption;
import com.google.common.collect.Maps;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.LinBusConverter;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntArrayTag;
@ -64,7 +64,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.OptionalInt;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -97,7 +96,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
@Override
public Clipboard read() throws IOException {
CompoundTag schematicTag = getBaseTag();
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag<?, ?>> schematic = schematicTag.getValue();
final Platform platform = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.WORLD_EDITING);
@ -147,7 +146,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
public OptionalInt getDataVersion() {
try {
CompoundTag schematicTag = getBaseTag();
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag<?, ?>> schematic = schematicTag.getValue();
if (schematicVersion == 1) {
return OptionalInt.of(Constants.DATA_VERSION_MC_1_13_2);
} else if (schematicVersion == 2) {
@ -168,7 +167,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag<?, ?>> schematic = schematicTag.getValue();
// Be lenient about the specific nesting level of the Schematic tag
// Also allows checking the version from newer versions of the specification
@ -184,7 +183,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
private BlockArrayClipboard readVersion1(CompoundTag schematicTag) throws IOException {
BlockVector3 origin;
Region region;
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag<?, ?>> schematic = schematicTag.getValue();
int width = requireTag(schematic, "Width", ShortTag.class).getValue();
int height = requireTag(schematic, "Height", ShortTag.class).getValue();
@ -206,7 +205,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
CompoundTag metadataTag = getTag(schematic, "Metadata", CompoundTag.class);
if (metadataTag != null && metadataTag.containsKey("WEOffsetX")) {
// We appear to have WorldEdit Metadata
Map<String, Tag> metadata = metadataTag.getValue();
Map<String, Tag<?, ?>> metadata = metadataTag.getValue();
int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue();
int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue();
int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue();
@ -219,7 +218,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
}
IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class);
Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
Map<String, Tag<?, ?>> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue()) {
throw new IOException("Block palette size does not match expected size.");
}
@ -248,21 +247,17 @@ public class SpongeSchematicReader extends NBTSchematicReader {
byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
Map<BlockVector3, Map<String, Tag<?, ?>>> tileEntitiesMap = new HashMap<>();
ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class);
if (tileEntities == null) {
tileEntities = getTag(schematic, "TileEntities", ListTag.class);
}
if (tileEntities != null) {
List<Map<String, Tag>> tileEntityTags = tileEntities.getValue().stream()
.map(tag -> (CompoundTag) tag)
.map(CompoundTag::getValue)
.collect(Collectors.toList());
for (Map<String, Tag> tileEntity : tileEntityTags) {
for (Object tileTag : tileEntities.getValue()) {
Map<String, Tag<?, ?>> tileEntity = ((CompoundTag) tileTag).getValue();
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
final BlockVector3 pt = BlockVector3.at(pos[0], pos[1], pos[2]);
Map<String, Tag> values = Maps.newHashMap(tileEntity);
Map<String, Tag<?, ?>> values = Maps.newHashMap(tileEntity);
values.put("x", new IntTag(pt.x()));
values.put("y", new IntTag(pt.y()));
values.put("z", new IntTag(pt.z()));
@ -279,10 +274,10 @@ public class SpongeSchematicReader extends NBTSchematicReader {
values.remove("Id");
values.remove("Pos");
if (fixer != null) {
//FAWE start - BinaryTag
tileEntity = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
//FAWE start - LinTag
tileEntity = ((CompoundTag) LinBusConverter.fromLinBus(fixer.fixUp(
DataFixer.FixTypes.BLOCK_ENTITY,
new CompoundTag(values).asBinaryTag(),
new CompoundTag(values).toLinTag(),
dataVersion
))).getValue();
//FAWE end
@ -341,7 +336,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
}
private Clipboard readVersion2(BlockArrayClipboard version1, CompoundTag schematicTag) throws IOException {
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag<?, ?>> schematic = schematicTag.getValue();
if (schematic.containsKey("BiomeData")) {
readBiomes(version1, schematic);
}
@ -351,7 +346,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
return version1;
}
private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag<?, ?>> schematic) throws IOException {
ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class);
IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class);
CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class);
@ -361,7 +356,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
throw new IOException("Biome palette size does not match expected size.");
}
for (Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
for (Entry<String, Tag<?, ?>> palettePart : paletteTag.getValue().entrySet()) {
String key = palettePart.getKey();
if (fixer != null) {
key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
@ -411,7 +406,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
}
}
private void readEntities(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
private void readEntities(BlockArrayClipboard clipboard, Map<String, Tag<?, ?>> schematic) throws IOException {
List<Tag> entList = requireTag(schematic, "Entities", ListTag.class).getValue();
if (entList.isEmpty()) {
return;
@ -421,15 +416,15 @@ public class SpongeSchematicReader extends NBTSchematicReader {
continue;
}
CompoundTag entityTag = (CompoundTag) et;
Map<String, Tag> tags = entityTag.getValue();
Map<String, Tag<?, ?>> tags = entityTag.getValue();
String id = requireTag(tags, "Id", StringTag.class).getValue();
entityTag = entityTag.createBuilder().putString("id", id).remove("Id").build();
if (fixer != null) {
//FAWE start - BinaryTag
entityTag = (CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
//FAWE start - LinTag
entityTag = (CompoundTag) LinBusConverter.fromLinBus(fixer.fixUp(
DataFixer.FixTypes.ENTITY,
entityTag.asBinaryTag(),
entityTag.toLinTag(),
dataVersion
));
//FAWE end

Some files were not shown because too many files have changed in this diff Show More