Skip to content

Commit ad5739e

Browse files
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>
1 parent 6dd779f commit ad5739e

File tree

134 files changed

+2252
-2536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2252
-2536
lines changed

buildSrc/src/main/kotlin/LibsConfig.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ fun Project.applyLibrariesConfiguration() {
4040

4141
val relocations = mapOf(
4242
"net.kyori.text" to "com.sk89q.worldedit.util.formatting.text",
43-
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori",
44-
"net.kyori.adventure.nbt" to "com.sk89q.worldedit.util.nbt"
43+
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori"
4544

4645
)
4746

@@ -53,9 +52,14 @@ fun Project.applyLibrariesConfiguration() {
5352
exclude(dependency("com.google.guava:guava"))
5453
exclude(dependency("com.google.code.gson:gson"))
5554
exclude(dependency("com.google.errorprone:error_prone_annotations"))
55+
exclude(dependency("com.google.guava:failureaccess"))
5656
exclude(dependency("org.checkerframework:checker-qual"))
57+
exclude(dependency("org.jetbrains:annotations"))
5758
exclude(dependency("org.apache.logging.log4j:log4j-api"))
5859
exclude(dependency("com.google.code.findbugs:jsr305"))
60+
exclude {
61+
it.moduleGroup == "org.jetbrains.kotlin"
62+
}
5963
}
6064

6165
relocations.forEach { (from, to) ->
@@ -67,11 +71,19 @@ fun Project.applyLibrariesConfiguration() {
6771
.filterIsInstance<ModuleDependency>()
6872
.map { it.copy() }
6973
.map { dependency ->
70-
dependency.artifact {
71-
name = dependency.name
72-
type = artifactType
73-
extension = "jar"
74-
classifier = artifactType
74+
val category = dependency.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)?.name
75+
if (category == Category.REGULAR_PLATFORM || category == Category.ENFORCED_PLATFORM) {
76+
return@map dependency
77+
}
78+
try {
79+
dependency.artifact {
80+
name = dependency.name
81+
type = artifactType
82+
extension = "jar"
83+
classifier = artifactType
84+
}
85+
} catch (e: Exception) {
86+
throw RuntimeException("Failed to add artifact to dependency: $dependency", e)
7587
}
7688
dependency
7789
}
@@ -85,6 +97,10 @@ fun Project.applyLibrariesConfiguration() {
8597
from({
8698
altConfigFiles("sources")
8799
})
100+
101+
// Yeet module-info's
102+
exclude("module-info.java")
103+
88104
relocations.forEach { (from, to) ->
89105
val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)")
90106
val textPattern = Regex.fromLiteral(from)

gradle/libs.versions.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ paperlib = "1.0.8"
4040
paster = "1.1.6"
4141
vault = "1.7.1"
4242
serverlib = "2.3.6"
43+
linbus = "0.1.0"
4344
## Internal
4445
text-adapter = "3.0.6"
4546
text = "3.0.4"
@@ -78,7 +79,6 @@ bstatsBase = { group = "org.bstats", name = "bstats-base", version.ref = "bstats
7879
bstatsBukkit = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
7980
sparsebitset = { group = "com.zaxxer", name = "SparseBitSet", version.ref = "sparsebitset" }
8081
parallelgzip = { group = "org.anarres", name = "parallelgzip", version.ref = "parallelgzip" }
81-
adventureNbt = { group = "net.kyori", name = "adventure-nbt", version.ref = "adventure" }
8282
truezip = { group = "de.schlichtherle", name = "truezip", version.ref = "truezip" }
8383
autoValueAnnotations = { group = "com.google.auto.value", name = "auto-value-annotations", version.ref = "auto-value" }
8484
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
101101
vault = { group = "com.github.MilkBowl", name = "VaultAPI", version.ref = "vault" }
102102
serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib", version.ref = "serverlib" }
103103
checkerqual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerqual" }
104+
linBus-bom = { group = "org.enginehub.lin-bus", name = "lin-bus-bom", version.ref = "linbus" }
105+
linBus-common = { group = "org.enginehub.lin-bus", name = "lin-bus-common" }
106+
linBus-stream = { group = "org.enginehub.lin-bus", name = "lin-bus-stream" }
107+
linBus-tree = { group = "org.enginehub.lin-bus", name = "lin-bus-tree" }
108+
linBus-format-snbt = { group = "org.enginehub.lin-bus.format", name = "lin-bus-format-snbt" }
104109

105110
# Internal
106111
## Text

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_19_R3/PaperweightAdapter.java

Lines changed: 79 additions & 78 deletions
Large diffs are not rendered by default.

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_19_R3/PaperweightDataConverters.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.mojang.datafixers.DataFixerBuilder;
3636
import com.mojang.datafixers.schemas.Schema;
3737
import com.mojang.serialization.Dynamic;
38-
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
3938
import net.minecraft.core.Direction;
4039
import net.minecraft.nbt.NbtOps;
4140
import net.minecraft.network.chat.Component;
@@ -48,7 +47,9 @@
4847
import net.minecraft.world.item.DyeColor;
4948
import org.apache.logging.log4j.LogManager;
5049
import org.apache.logging.log4j.Logger;
50+
import org.enginehub.linbus.tree.LinCompoundTag;
5151

52+
import javax.annotation.Nullable;
5253
import java.lang.reflect.Type;
5354
import java.util.ArrayList;
5455
import java.util.EnumMap;
@@ -62,7 +63,6 @@
6263
import java.util.UUID;
6364
import java.util.concurrent.Executor;
6465
import java.util.stream.Collectors;
65-
import javax.annotation.Nullable;
6666

6767
/**
6868
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
@@ -78,16 +78,15 @@
7878
@SuppressWarnings({ "rawtypes", "unchecked" })
7979
class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
8080

81-
//FAWE start - BinaryTag
8281
@SuppressWarnings("unchecked")
8382
@Override
8483
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
8584
if (type == FixTypes.CHUNK) {
86-
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
85+
return (T) fixChunk((LinCompoundTag) original, srcVer);
8786
} else if (type == FixTypes.BLOCK_ENTITY) {
88-
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
87+
return (T) fixBlockEntity((LinCompoundTag) original, srcVer);
8988
} else if (type == FixTypes.ENTITY) {
90-
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
89+
return (T) fixEntity((LinCompoundTag) original, srcVer);
9190
} else if (type == FixTypes.BLOCK_STATE) {
9291
return (T) fixBlockState((String) original, srcVer);
9392
} else if (type == FixTypes.ITEM_TYPE) {
@@ -98,24 +97,23 @@ public <T> T fixUp(FixType<T> type, T original, int srcVer) {
9897
return original;
9998
}
10099

101-
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
102-
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
100+
private LinCompoundTag fixChunk(LinCompoundTag originalChunk, int srcVer) {
101+
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(originalChunk);
103102
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
104-
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
103+
return (LinCompoundTag) adapter.toNativeLin(fixed);
105104
}
106105

107-
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
108-
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
106+
private LinCompoundTag fixBlockEntity(LinCompoundTag origTileEnt, int srcVer) {
107+
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origTileEnt);
109108
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
110-
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
109+
return (LinCompoundTag) adapter.toNativeLin(fixed);
111110
}
112111

113-
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
114-
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
112+
private LinCompoundTag fixEntity(LinCompoundTag origEnt, int srcVer) {
113+
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(origEnt);
115114
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
116-
return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
115+
return (LinCompoundTag) adapter.toNativeLin(fixed);
117116
}
118-
//FAWE end
119117

120118
private String fixBlockState(String blockState, int srcVer) {
121119
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/ext/fawe/v1_19_R3/PaperweightWorldNativeAccess.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@
1919

2020
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_19_R3;
2121

22+
import com.sk89q.jnbt.CompoundTag;
2223
import com.sk89q.worldedit.bukkit.BukkitAdapter;
2324
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
2425
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
2526
import com.sk89q.worldedit.util.SideEffect;
2627
import com.sk89q.worldedit.util.SideEffectSet;
27-
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
2828
import com.sk89q.worldedit.world.block.BlockState;
2929
import net.minecraft.core.BlockPos;
30+
import net.minecraft.nbt.Tag;
3031
import net.minecraft.server.level.ChunkHolder;
3132
import net.minecraft.server.level.ServerLevel;
3233
import net.minecraft.world.level.block.Block;
34+
import net.minecraft.world.level.block.entity.BlockEntity;
3335
import net.minecraft.world.level.chunk.LevelChunk;
3436
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
3537
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
3638
import org.bukkit.event.block.BlockPhysicsEvent;
39+
import org.enginehub.linbus.tree.LinCompoundTag;
3740

41+
import javax.annotation.Nullable;
3842
import java.lang.ref.WeakReference;
3943
import java.util.Objects;
40-
import javax.annotation.Nullable;
4144

4245
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
4346
private static final int UPDATE = 1;
@@ -101,8 +104,15 @@ public void updateLightingForBlock(BlockPos position) {
101104
}
102105

103106
@Override
104-
public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
105-
return false;
107+
public boolean updateTileEntity(BlockPos position, LinCompoundTag tag) {
108+
// We will assume that the tile entity was created for us
109+
BlockEntity tileEntity = getWorld().getBlockEntity(position);
110+
if (tileEntity == null) {
111+
return false;
112+
}
113+
Tag nativeTag = adapter.fromNative(new CompoundTag(tag));
114+
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
115+
return true;
106116
}
107117

108118
@Override

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightFaweAdapter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
import com.sk89q.worldedit.util.SideEffect;
3636
import com.sk89q.worldedit.util.SideEffectSet;
3737
import com.sk89q.worldedit.util.formatting.text.Component;
38-
import com.sk89q.worldedit.util.nbt.BinaryTag;
39-
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
40-
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
4138
import com.sk89q.worldedit.world.RegenOptions;
4239
import com.sk89q.worldedit.world.biome.BiomeType;
4340
import com.sk89q.worldedit.world.block.BaseBlock;
@@ -83,6 +80,9 @@
8380
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
8481
import org.bukkit.craftbukkit.v1_19_R3.util.CraftNamespacedKey;
8582
import org.bukkit.entity.Player;
83+
import org.enginehub.linbus.tree.LinCompoundTag;
84+
import org.enginehub.linbus.tree.LinStringTag;
85+
import org.enginehub.linbus.tree.LinTag;
8686

8787
import javax.annotation.Nullable;
8888
import java.lang.ref.WeakReference;
@@ -274,7 +274,7 @@ public BaseBlock getFullBlock(final Location location) {
274274
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
275275
if (blockEntity != null) {
276276
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
277-
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
277+
return state.toBaseBlock((LinCompoundTag) toNativeLin(tag));
278278
}
279279
}
280280

@@ -302,14 +302,14 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
302302

303303
if (id != null) {
304304
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
305-
Supplier<CompoundBinaryTag> saveTag = () -> {
305+
Supplier<LinCompoundTag> saveTag = () -> {
306306
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
307307
PaperweightPlatformAdapter.readEntityIntoTag(mcEntity, minecraftTag);
308308
//add Id for AbstractChangeSet to work
309-
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
310-
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
311-
tags.put("Id", StringBinaryTag.of(id));
312-
return CompoundBinaryTag.from(tags);
309+
final LinCompoundTag tag = (LinCompoundTag) toNativeLin(minecraftTag);
310+
final Map<String, LinTag<?>> tags = NbtUtils.getLinCompoundTagValues(tag);
311+
tags.put("Id", LinStringTag.of(id));
312+
return LinCompoundTag.of(tags);
313313
};
314314
return new LazyBaseEntity(type, saveTag);
315315
} else {
@@ -514,7 +514,7 @@ protected ServerLevel getServerLevel(final World world) {
514514
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
515515
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
516516
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
517-
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
517+
weStack.setNbt((LinCompoundTag) toNativeLin(nmsStack.getTag()));
518518
return weStack;
519519
}
520520

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightFaweWorldNativeAccess.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
1010
import com.sk89q.worldedit.util.SideEffect;
1111
import com.sk89q.worldedit.util.SideEffectSet;
12-
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
1312
import com.sk89q.worldedit.world.block.BlockState;
1413
import net.minecraft.core.BlockPos;
1514
import net.minecraft.core.Direction;
@@ -24,6 +23,7 @@
2423
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
2524
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
2625
import org.bukkit.event.block.BlockPhysicsEvent;
26+
import org.enginehub.linbus.tree.LinCompoundTag;
2727

2828
import javax.annotation.Nullable;
2929
import java.lang.ref.WeakReference;
@@ -132,14 +132,14 @@ public void updateLightingForBlock(BlockPos blockPos) {
132132
}
133133

134134
@Override
135-
public boolean updateTileEntity(BlockPos blockPos, CompoundBinaryTag tag) {
135+
public boolean updateTileEntity(BlockPos blockPos, LinCompoundTag tag) {
136136
// We will assume that the tile entity was created for us,
137137
// though we do not do this on the other versions
138138
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
139139
if (blockEntity == null) {
140140
return false;
141141
}
142-
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeBinary(tag);
142+
net.minecraft.nbt.Tag nativeTag = paperweightFaweAdapter.fromNativeLin(tag);
143143
blockEntity.load((CompoundTag) nativeTag);
144144
return true;
145145
}

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/PaperweightGetBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
732732
Iterator<CompoundTag> iterator = entities.iterator();
733733
while (iterator.hasNext()) {
734734
final CompoundTag nativeTag = iterator.next();
735-
final Map<String, Tag> entityTagMap = nativeTag.getValue();
735+
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
736736
final StringTag idTag = (StringTag) entityTagMap.get("Id");
737737
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
738738
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");

worldedit-bukkit/adapters/adapter-1_19_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_19_R3/nbt/PaperweightLazyCompoundTag.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.sk89q.jnbt.StringTag;
77
import com.sk89q.jnbt.Tag;
88
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
9-
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
109
import net.minecraft.nbt.NumericTag;
10+
import org.enginehub.linbus.tree.LinCompoundTag;
1111

1212
import java.util.ArrayList;
1313
import java.util.Collections;
@@ -36,17 +36,17 @@ public net.minecraft.nbt.CompoundTag get() {
3636

3737
@Override
3838
@SuppressWarnings("unchecked")
39-
public Map<String, Tag> getValue() {
39+
public Map<String, Tag<?, ?>> getValue() {
4040
if (compoundTag == null) {
4141
compoundTag = (CompoundTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(compoundTagSupplier.get());
4242
}
4343
return compoundTag.getValue();
4444
}
4545

4646
@Override
47-
public CompoundBinaryTag asBinaryTag() {
47+
public LinCompoundTag toLinTag() {
4848
getValue();
49-
return compoundTag.asBinaryTag();
49+
return compoundTag.toLinTag();
5050
}
5151

5252
public boolean containsKey(String key) {
@@ -94,10 +94,10 @@ public int asInt(String key) {
9494
}
9595

9696
@SuppressWarnings("unchecked")
97-
public List<Tag> getList(String key) {
97+
public List<? extends Tag<?, ?>> getList(String key) {
9898
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
9999
if (tag instanceof net.minecraft.nbt.ListTag nbtList) {
100-
ArrayList<Tag> list = new ArrayList<>();
100+
ArrayList<Tag<?, ?>> list = new ArrayList<>();
101101
for (net.minecraft.nbt.Tag elem : nbtList) {
102102
if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) {
103103
list.add(new PaperweightLazyCompoundTag(compoundTag));
@@ -120,7 +120,7 @@ public ListTag getListTag(String key) {
120120
}
121121

122122
@SuppressWarnings("unchecked")
123-
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
123+
public <T extends Tag<?, ?>> List<T> getList(String key, Class<T> listType) {
124124
ListTag listTag = getListTag(key);
125125
if (listTag.getType().equals(listType)) {
126126
return (List<T>) listTag.getValue();

0 commit comments

Comments
 (0)