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>
Dieser Commit ist enthalten in:
Jordan 2024-06-26 21:55:47 +02:00 committet von GitHub
Ursprung 6dd779f90b
Commit ad5739e014
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
134 geänderte Dateien mit 2258 neuen und 2542 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -40,6 +40,7 @@ paperlib = "1.0.8"
paster = "1.1.6" paster = "1.1.6"
vault = "1.7.1" vault = "1.7.1"
serverlib = "2.3.6" serverlib = "2.3.6"
linbus = "0.1.0"
## Internal ## Internal
text-adapter = "3.0.6" text-adapter = "3.0.6"
text = "3.0.4" 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" } bstatsBukkit = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
sparsebitset = { group = "com.zaxxer", name = "SparseBitSet", version.ref = "sparsebitset" } sparsebitset = { group = "com.zaxxer", name = "SparseBitSet", version.ref = "sparsebitset" }
parallelgzip = { group = "org.anarres", name = "parallelgzip", version.ref = "parallelgzip" } 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" } truezip = { group = "de.schlichtherle", name = "truezip", version.ref = "truezip" }
autoValueAnnotations = { group = "com.google.auto.value", name = "auto-value-annotations", version.ref = "auto-value" } 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" } 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" } vault = { group = "com.github.MilkBowl", name = "VaultAPI", version.ref = "vault" }
serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib", version.ref = "serverlib" } serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib", version.ref = "serverlib" }
checkerqual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerqual" } 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 # Internal
## Text ## Text

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,25 +19,28 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_19_R3; 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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess; import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Objects; import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> { public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1; private static final int UPDATE = 1;
@ -101,8 +104,15 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) { public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
return false; // 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 @Override

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,7 +19,7 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R1; 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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess; 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.util.SideEffectSet;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Objects; import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> { public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1; private static final int UPDATE = 1;
@ -101,8 +104,15 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) { public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
return false; // 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 @Override

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,25 +19,28 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R3; 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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess; import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Objects; import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> { public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1; private static final int UPDATE = 1;
@ -101,8 +104,15 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) { public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
return false; // 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 @Override

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -178,9 +178,6 @@ tasks.named<ShadowJar>("shadowJar") {
relocate("org.lz4", "com.fastasyncworldedit.core.lz4") { relocate("org.lz4", "com.fastasyncworldedit.core.lz4") {
include(dependency("org.lz4:lz4-java:1.8.0")) 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") { relocate("com.zaxxer", "com.fastasyncworldedit.core.math") {
include(dependency("com.zaxxer:SparseBitSet:1.3")) include(dependency("com.zaxxer:SparseBitSet:1.3"))
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -106,7 +106,7 @@ public abstract class LinearClipboard extends SimpleClipboard {
@Nullable @Nullable
@Override @Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) { 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); NBTUtils.addUUIDToMap(map, uuid);
entity.setNbtData(new CompoundTag(map)); entity.setNbtData(new CompoundTag(map));
BlockArrayClipboard.ClipboardEntity ret = new BlockArrayClipboard.ClipboardEntity(location, entity); BlockArrayClipboard.ClipboardEntity ret = new BlockArrayClipboard.ClipboardEntity(location, entity);

Datei anzeigen

@ -254,7 +254,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tag) { 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("x", new IntTag(x));
values.put("y", new IntTag(y)); values.put("y", new IntTag(y));
values.put("z", new IntTag(z)); values.put("z", new IntTag(z));

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,11 +1,16 @@
package com.fastasyncworldedit.core.jnbt; package com.fastasyncworldedit.core.jnbt;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import org.enginehub.linbus.tree.LinTag;
/** /**
* A numerical {@link Tag} * 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 @Override
public abstract Number getValue(); public abstract Number getValue();

Datei anzeigen

@ -124,7 +124,7 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
@Override @Override
default Entity createEntity(Location location, BaseEntity entity, UUID uuid) { default Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); 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())); map.put("Id", new StringTag(entity.getType().getName()));
//Set pos //Set pos

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,13 +1,12 @@
package com.fastasyncworldedit.core.util; 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 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.HashMap;
import java.util.Map; import java.util.Map;
@ -23,9 +22,9 @@ public class NbtUtils {
* @return child tag * @return child tag
* @throws InvalidFormatException if the format of the items is invalid * @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 { InvalidFormatException {
BinaryTag childTag = tag.get(key); LinTag childTag = tag.value().get(key);
if (childTag == null) { if (childTag == null) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag"); throw new InvalidFormatException("Missing a \"" + key + "\" tag");
} }
@ -48,35 +47,35 @@ public class NbtUtils {
* @throws InvalidFormatException if the format of the items is invalid * @throws InvalidFormatException if the format of the items is invalid
* @since 2.1.0 * @since 2.1.0
*/ */
public static int getInt(CompoundBinaryTag tag, String key) throws InvalidFormatException { public static int getInt(LinCompoundTag tag, String key) throws InvalidFormatException {
BinaryTag childTag = tag.get(key); LinTag childTag = tag.value().get(key);
if (childTag == null) { if (childTag == null) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag"); throw new InvalidFormatException("Missing a \"" + key + "\" tag");
} }
BinaryTagType<?> type = childTag.type(); LinTagType<?> type = childTag.type();
if (type == BinaryTagTypes.INT) { if (type == LinTagType.intTag()) {
return ((IntBinaryTag) childTag).intValue(); return ((LinIntTag) childTag).value();
} }
if (type == BinaryTagTypes.BYTE) { if (type == LinTagType.byteTag()) {
return ((ByteBinaryTag) childTag).intValue(); return ((LinByteTag) childTag).value();
} }
if (type == BinaryTagTypes.SHORT) { if (type == LinTagType.shortTag()) {
return ((ShortBinaryTag) childTag).intValue(); return ((LinShortTag) childTag).value();
} }
throw new InvalidFormatException(key + " tag is not of int, short or byte tag type."); 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 * @return Mutable map of values
* @since 2.1.0 * @since 2.1.0
*/ */
public static Map<String, BinaryTag> getCompoundBinaryTagValues(CompoundBinaryTag tag) { public static Map<String, LinTag<?>> getLinCompoundTagValues(LinCompoundTag tag) {
Map<String, BinaryTag> value = new HashMap<>(); Map<String, LinTag<?>> value = new HashMap<>();
tag.forEach((e) -> value.put(e.getKey(), e.getValue())); value.putAll(tag.value());
return value; return value;
} }

Datei anzeigen

@ -10,9 +10,10 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.util.concurrency.LazyReference; 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.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; 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.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -36,7 +37,10 @@ public final class BaseItemAdapter implements JsonDeserializer<BaseItem>, JsonSe
return new BaseItem(itemType); return new BaseItem(itemType);
} }
try { 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) { } catch (IOException e) {
throw new JsonParseException("Could not deserialize BaseItem", 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(); JsonObject obj = new JsonObject();
obj.add("itemType", jsonSerializationContext.serialize(baseItem.getType())); obj.add("itemType", jsonSerializationContext.serialize(baseItem.getType()));
try { obj.add("nbt", baseItem.getNbt() == null ? null : new JsonPrimitive(LinStringIO.writeToString(baseItem.getNbt())));
obj.add("nbt", baseItem.getNbt() == null ? null : new JsonPrimitive(TagStringIO.get().asString(baseItem.getNbt()))); return obj;
return obj;
} catch (IOException e) {
throw new JsonParseException("Could not deserialize BaseItem", e);
}
} }
} }

Datei anzeigen

@ -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);
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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);
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.jnbt; package com.sk89q.jnbt;
import com.fastasyncworldedit.core.internal.io.LittleEndianOutputStream; import com.fastasyncworldedit.core.internal.io.LittleEndianOutputStream;
import org.enginehub.linbus.stream.LinBinaryIO;
import java.io.Closeable; import java.io.Closeable;
import java.io.DataOutput; import java.io.DataOutput;
@ -44,8 +45,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
* https://minecraft.gamepedia.com/NBT_format</a>. * https://minecraft.gamepedia.com/NBT_format</a>.
* </p> * </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) @Deprecated(forRemoval = true)
public final class NBTOutputStream extends OutputStream implements Closeable, DataOutput { 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. * @param os The output stream.
* @throws IOException if an I/O error occurs. * @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)); 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. * @param tag The tag to write.
* @throws IOException if an I/O error occurs. * @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(name);
checkNotNull(tag); checkNotNull(tag);
int type = NBTUtils.getTypeCode(tag.getClass()); int type = tag.getTypeCode();
writeNamedTagName(name, type); writeNamedTagName(name, type);
if (type == NBTConstants.TYPE_END) { 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 { public void writeTag(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass()); int type = tag.getTypeCode();
os.writeByte(type); os.writeByte(type);
writeTagPayload(tag); writeTagPayload(tag);
} }
@ -212,7 +214,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @throws IOException if an I/O error occurs. * @throws IOException if an I/O error occurs.
*/ */
public void writeTagPayload(Tag tag) throws IOException { public void writeTagPayload(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass()); int type = tag.getTypeCode();
switch (type) { switch (type) {
case NBTConstants.TYPE_END: case NBTConstants.TYPE_END:
writeEndTagPayload((EndTag) tag); writeEndTagPayload((EndTag) tag);
@ -287,7 +289,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
* @throws IOException if an I/O error occurs. * @throws IOException if an I/O error occurs.
*/ */
private void writeCompoundTagPayload(CompoundTag tag) throws IOException { 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()); writeNamedTag(entry.getKey(), entry.getValue());
} }
os.writeByte((byte) 0); // end tag - better way? 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. * @throws IOException if an I/O error occurs.
*/ */
private void writeListTagPayload(ListTag tag) throws IOException { private void writeListTagPayload(ListTag tag) throws IOException {
Class<? extends Tag> clazz = tag.getType(); Class<? extends Tag<?, ?>> clazz = tag.getType();
if (clazz == null) { if (clazz == null) {
clazz = CompoundTag.class; clazz = CompoundTag.class;
} }

Datei anzeigen

@ -20,7 +20,6 @@
package com.sk89q.jnbt; package com.sk89q.jnbt;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.nbt.BinaryTagTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException; import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.Map; 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. * @deprecated JNBT is being removed for adventure-nbt in WorldEdit 8.
*/ */
@SuppressWarnings("ALL")
@Deprecated @Deprecated
public final class NBTUtils { public final class NBTUtils {
@ -48,7 +48,7 @@ public final class NBTUtils {
* @param clazz the tag class * @param clazz the tag class
* @return The type name. * @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)) { if (clazz.equals(ByteArrayTag.class)) {
return "TAG_Byte_Array"; return "TAG_Byte_Array";
} else if (clazz.equals(ByteTag.class)) { } else if (clazz.equals(ByteTag.class)) {
@ -77,7 +77,7 @@ public final class NBTUtils {
return "TAG_Long_Array"; return "TAG_Long_Array";
} else { } else {
throw new IllegalArgumentException("Invalid tag class (" throw new IllegalArgumentException("Invalid tag class ("
+ clazz.getName() + ")."); + clazz.getName() + ").");
} }
} }
@ -88,11 +88,35 @@ public final class NBTUtils {
* @return The type code. * @return The type code.
* @throws IllegalArgumentException if the tag class is invalid. * @throws IllegalArgumentException if the tag class is invalid.
*/ */
public static int getTypeCode(Class<? extends Tag> clazz) { public static int getTypeCode(Class<? extends Tag<?, ?>> clazz) {
if (LazyCompoundTag.class.isAssignableFrom(clazz)) { if (clazz == ByteArrayTag.class) {
return BinaryTagTypes.COMPOUND.id(); 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. * @return The class.
* @throws IllegalArgumentException if the tag type is invalid. * @throws IllegalArgumentException if the tag type is invalid.
*/ */
public static Class<? extends Tag> getTypeClass(int type) { public static Class<? extends Tag<?, ?>> getTypeClass(int type) {
switch (type) { return NBTConstants.getClassFromType(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
+ ".");
}
} }
/** /**
@ -145,7 +139,7 @@ public final class NBTUtils {
* @param listTag the list tag * @param listTag the list tag
* @return a vector * @return a vector
*/ */
public static Vector3 toVector(ListTag listTag) { public static Vector3 toVector(ListTag<?, ?> listTag) {
checkNotNull(listTag); checkNotNull(listTag);
return Vector3.at(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2)); return Vector3.at(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2));
} }
@ -159,12 +153,12 @@ public final class NBTUtils {
* @return child tag * @return child tag
* @throws InvalidFormatException if the format of the items is invalid * @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 { InvalidFormatException {
if (!items.containsKey(key)) { if (!items.containsKey(key)) {
throw new InvalidFormatException("Missing a \"" + key + "\" tag"); throw new InvalidFormatException("Missing a \"" + key + "\" tag");
} }
Tag tag = items.get(key); Tag<?, ?> tag = items.get(key);
if (!expected.isInstance(tag)) { if (!expected.isInstance(tag)) {
throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName()); 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 * @param uuid {@link UUID} to add
* @since 2.4.0 * @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]; int[] uuidArray = new int[4];
uuidArray[0] = (int) (uuid.getMostSignificantBits() >> 32); uuidArray[0] = (int) (uuid.getMostSignificantBits() >> 32);
uuidArray[1] = (int) uuid.getMostSignificantBits(); uuidArray[1] = (int) uuid.getMostSignificantBits();

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,26 +19,43 @@
package com.sk89q.jnbt; 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. * 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) @Deprecated
public abstract class Tag implements BinaryTagLike { 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. * Gets the value of this tag.
* *
* @return the value * @return the value
*/ */
public abstract Object getValue(); public V getValue() {
return linTag.value();
}
@Override @Override
public String toString() { public String toString() {
return asBinaryTag().toString(); return toLinTag().toString();
}
@Override
@Nonnull
public LT toLinTag() {
return linTag;
} }
//FAWE start //FAWE start

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -24,8 +24,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.concurrency.LazyReference; import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.linbus.tree.LinCompoundTag;
/** /**
* Represents a stack of BaseItems. * Represents a stack of BaseItems.
@ -70,6 +70,18 @@ public class BaseItemStack extends BaseItem {
this.amount = amount; 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. * Get the number of items in the stack.
* *
@ -93,18 +105,4 @@ public class BaseItemStack extends BaseItem {
.getRegistries().getItemRegistry().getRichName(this); .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
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -186,7 +186,7 @@ public class BlockArrayClipboard implements Clipboard {
} }
@Override @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)) { if (region.contains(position)) {
//FAWE - get points //FAWE - get points
final int x = position.x(); final int x = position.x();

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen