Skip to content

Commit

Permalink
chore(impl): Replace FlowNBT with AdventureNBT in all patches
Browse files Browse the repository at this point in the history
  • Loading branch information
ComputerNerd100 committed Dec 20, 2024
1 parent 07fe15a commit 7d00f4e
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 489 deletions.
361 changes: 175 additions & 186 deletions patches/server/0001-Build-Changes.patch

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Add support for serializing/deserializing PDC


diff --git a/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java b/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java
index d1ab18a2a2793807118ae1fc23d21248aa7e09a3..0c1e599aa7d148c40ece1957c89991e1d761162a 100644
index 98043b30614cc0ace252919367662a5e535fa1e1..68240b46ce911674ed288fe559737572fa44de6a 100644
--- a/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java
+++ b/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java
@@ -11,6 +11,7 @@ import com.mojang.serialization.Lifecycle;
Expand All @@ -29,18 +29,18 @@ index d1ab18a2a2793807118ae1fc23d21248aa7e09a3..0c1e599aa7d148c40ece1957c89991e1
}

diff --git a/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java b/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java
index ba337466525971885247c269c23aac7df96d2782..5d325e85a4634c21ab0bec12b493ea9b857d8ff3 100644
index 636c553f4407f19b3435d487250b041532b8f229..387954aae7ef1a39025a474ab1fe81b7216d8d6c 100644
--- a/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java
+++ b/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java
@@ -2,6 +2,7 @@ package com.infernalsuite.asp.level;
@@ -1,6 +1,7 @@
package com.infernalsuite.asp.level;

import com.flowpowered.nbt.CompoundTag;
import com.infernalsuite.asp.ChunkPos;
+import com.infernalsuite.asp.Converter;
import com.infernalsuite.asp.api.exceptions.WorldAlreadyExistsException;
import com.infernalsuite.asp.api.loaders.SlimeLoader;
import com.infernalsuite.asp.serialization.slime.SlimeSerializer;
@@ -235,6 +236,17 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
@@ -237,6 +238,17 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
cloned.put(entry.getKey(), clonedChunk);
}

Expand Down
36 changes: 17 additions & 19 deletions patches/server/0004-Fix-entity-loading.patch
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ index 7e7c560b89c45e8ff003813f3c7a141c2b0b7a1d..e2c67548ff6341c1c981af83f6df7711
throw death;
} catch (final Throwable thr2) {
diff --git a/src/main/java/com/infernalsuite/asp/level/SlimeChunkConverter.java b/src/main/java/com/infernalsuite/asp/level/SlimeChunkConverter.java
index ba0b401e0b39605303e90720f7c8dc48fcb0bc29..6b38f707b43e1e584c79a6c8d9ec1232ed2901b9 100644
index b0d45837e918ef720b49a3f4968d7781ecf6436d..b705b3133634c3696dee766cbfc95380293ccda3 100644
--- a/src/main/java/com/infernalsuite/asp/level/SlimeChunkConverter.java
+++ b/src/main/java/com/infernalsuite/asp/level/SlimeChunkConverter.java
@@ -15,6 +15,8 @@ import net.minecraft.core.Holder;
@@ -13,6 +13,8 @@ import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.NbtOps;
Expand All @@ -80,23 +80,22 @@ index ba0b401e0b39605303e90720f7c8dc48fcb0bc29..6b38f707b43e1e584c79a6c8d9ec1232
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
@@ -106,26 +108,11 @@ public class SlimeChunkConverter {
@@ -104,25 +106,11 @@ public class SlimeChunkConverter {


LevelChunk.PostLoadProcessor loadEntities = (nmsChunk) -> {
+ List<CompoundTag> entities = chunk.getEntities();
+ List<CompoundBinaryTag> entities = chunk.getEntities();

- // TODO
- // Load tile entities
- List<CompoundTag> tileEntities = chunk.getTileEntities();
- List<CompoundBinaryTag> tileEntities = chunk.getTileEntities();
-
- if (tileEntities != null) {
- for (CompoundTag tag : tileEntities) {
- Optional<String> type = tag.getStringValue("id");
- for (CompoundBinaryTag tag : tileEntities) {
- String type = tag.getString("id");
-
- // Sometimes null tile entities are saved
- if (type.isPresent()) {
- BlockPos blockPosition = new BlockPos(tag.getIntValue("x").get(), tag.getIntValue("y").get(), tag.getIntValue("z").get());
- if (!type.isEmpty()) {
- BlockPos blockPosition = new BlockPos(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
- BlockState blockData = nmsChunk.getBlockState(blockPosition);
- BlockEntity entity = BlockEntity.loadStatic(blockPosition, blockData, (net.minecraft.nbt.CompoundTag) Converter.convertTag(tag));
-
Expand All @@ -107,23 +106,22 @@ index ba0b401e0b39605303e90720f7c8dc48fcb0bc29..6b38f707b43e1e584c79a6c8d9ec1232
- }
+ if (entities != null) {
+ net.minecraft.server.level.ChunkMap.postLoadProtoChunk(instance, entities.stream()
+ .map(flowTag -> (net.minecraft.nbt.CompoundTag) Converter.convertTag(flowTag)).toList(), nmsChunk.getPos());
+ .map(tag -> (net.minecraft.nbt.CompoundTag) Converter.convertTag(tag)).toList(), nmsChunk.getPos());
}
};

@@ -133,6 +120,25 @@ public class SlimeChunkConverter {
@@ -130,6 +118,24 @@ public class SlimeChunkConverter {
LevelChunkTicks<Fluid> fluidLevelChunkTicks = new LevelChunkTicks<>();
SlimeChunkLevel nmsChunk = new SlimeChunkLevel(instance, pos, UpgradeData.EMPTY, blockLevelChunkTicks, fluidLevelChunkTicks, 0L, sections, loadEntities, null);

+ List<CompoundTag> tileEntities = chunk.getTileEntities();
+ List<CompoundBinaryTag> tileEntities = chunk.getTileEntities();
+
+ if (tileEntities != null) {
+ for (CompoundTag tag : tileEntities) {
+ Optional<String> type = tag.getStringValue("id");
+ for (CompoundBinaryTag tag : tileEntities) {
+ String type = tag.getString("id");
+
+ // Sometimes null tile entities are saved
+ if (type.isPresent()) {
+ BlockPos blockPosition = new BlockPos(tag.getIntValue("x").get(), tag.getIntValue("y").get(), tag.getIntValue("z").get());
+ if (!type.isEmpty()) {
+ BlockPos blockPosition = new BlockPos(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
+ BlockState blockData = nmsChunk.getBlockState(blockPosition);
+ BlockEntity entity = BlockEntity.loadStatic(blockPosition, blockData, (net.minecraft.nbt.CompoundTag) Converter.convertTag(tag));
+
Expand All @@ -136,4 +134,4 @@ index ba0b401e0b39605303e90720f7c8dc48fcb0bc29..6b38f707b43e1e584c79a6c8d9ec1232
+
// Height Maps
EnumSet<Heightmap.Types> heightMapTypes = nmsChunk.getStatus().heightmapsAfter();
CompoundMap heightMaps = chunk.getHeightMaps().getValue();
CompoundBinaryTag heightMaps = chunk.getHeightMaps();
8 changes: 4 additions & 4 deletions patches/server/0006-Handle-null-data-properly.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Handle null data properly


diff --git a/src/main/java/com/infernalsuite/asp/SimpleDataFixerConverter.java b/src/main/java/com/infernalsuite/asp/SimpleDataFixerConverter.java
index 2f5b79632226f5d0112a4c0ddfc903d6b2b93549..eb426271140d9e36b09ef96e4c59c21d265a5edc 100644
index 694bd135fd4398ecf02940e638fae1047e217a29..6856a7254685b2d005bcb2a91841f53d8743e38d 100644
--- a/src/main/java/com/infernalsuite/asp/SimpleDataFixerConverter.java
+++ b/src/main/java/com/infernalsuite/asp/SimpleDataFixerConverter.java
@@ -45,9 +45,12 @@ class SimpleDataFixerConverter implements SlimeWorldReader<SlimeWorld> {
@@ -44,9 +44,12 @@ class SimpleDataFixerConverter implements SlimeWorldReader<SlimeWorld> {
);
}

Expand All @@ -19,9 +19,9 @@ index 2f5b79632226f5d0112a4c0ddfc903d6b2b93549..eb426271140d9e36b09ef96e4c59c21d
SlimeChunkSection dataSection = chunk.getSections()[i];
+ if (dataSection == null) continue;

com.flowpowered.nbt.CompoundTag blockStateTag = blockStateTag = convertAndBack(dataSection.getBlockStatesTag(), (tag) -> {
CompoundBinaryTag blockStateTag = blockStateTag = convertAndBack(dataSection.getBlockStatesTag(), (tag) -> {
WalkerUtils.convertList(MCTypeRegistry.BLOCK_STATE, new NBTMapType(tag), "palette", currentVersion, newVersion);
@@ -63,17 +66,17 @@ class SimpleDataFixerConverter implements SlimeWorldReader<SlimeWorld> {
@@ -62,17 +65,17 @@ class SimpleDataFixerConverter implements SlimeWorldReader<SlimeWorld> {
dataSection.getBlockLight(),
dataSection.getSkyLight()
);
Expand Down
102 changes: 59 additions & 43 deletions patches/server/0007-Make-SlimeWorld-a-PersistentDataHolder.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ Subject: [PATCH] Make SlimeWorld a PersistentDataHolder


diff --git a/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java b/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java
index 0c1e599aa7d148c40ece1957c89991e1d761162a..4c503e5a31ba38c5a52e9b6738a6ade4fab94b49 100644
index 68240b46ce911674ed288fe559737572fa44de6a..7b702b41a1bc589bf405ea280b8fc1c744012081 100644
--- a/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java
+++ b/src/main/java/com/infernalsuite/asp/SlimeNMSBridgeImpl.java
@@ -1,5 +1,6 @@
package com.infernalsuite.asp;

+import com.flowpowered.nbt.CompoundMap;
import com.infernalsuite.asp.api.SlimeNMSBridge;
import com.infernalsuite.asp.api.world.SlimeWorld;
import com.infernalsuite.asp.api.world.SlimeWorldInstance;
@@ -12,6 +13,7 @@ import net.kyori.adventure.util.Services;
@@ -8,7 +8,7 @@ import com.infernalsuite.asp.level.SlimeBootstrap;
import com.infernalsuite.asp.level.SlimeInMemoryWorld;
import com.infernalsuite.asp.level.SlimeLevelInstance;
import com.mojang.serialization.Lifecycle;
-import net.kyori.adventure.util.Services;
+import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.minecraft.SharedConstants;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
@@ -30,13 +32,18 @@ import org.apache.logging.log4j.Logger;
@@ -30,6 +30,9 @@ import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld;
Expand All @@ -33,47 +27,51 @@ index 0c1e599aa7d148c40ece1957c89991e1d761162a..4c503e5a31ba38c5a52e9b6738a6ade4
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.Locale;
+import java.util.Map;
@@ -37,6 +40,7 @@ import java.util.Locale;

public class SlimeNMSBridgeImpl implements SlimeNMSBridge {

+ private static final CraftPersistentDataTypeRegistry REGISTRY = new CraftPersistentDataTypeRegistry();
private static final SimpleDataFixerConverter DATA_FIXER_CONVERTER = new SimpleDataFixerConverter();

private static final Logger LOGGER = LogManager.getLogger("SWM");
@@ -49,6 +56,26 @@ public class SlimeNMSBridgeImpl implements SlimeNMSBridge {
private static final Logger LOGGER = LogManager.getLogger("ASP");
@@ -49,6 +53,22 @@ public class SlimeNMSBridgeImpl implements SlimeNMSBridge {
return (SlimeNMSBridgeImpl) SlimeNMSBridge.instance();
}

+ @Override
+ public void extractCraftPDC(PersistentDataContainer source, CompoundMap target) {
+ public void extractCraftPDC(PersistentDataContainer source, CompoundBinaryTag.Builder builder) {
+ if (source instanceof CraftPersistentDataContainer craftPDC) {
+ for (Map.Entry<String, Tag> entry : craftPDC.getRaw().entrySet()) {
+ target.put(Converter.convertTag(entry.getKey(), entry.getValue()));
+ }
+ craftPDC.getRaw().forEach((key, nmsTag) -> builder.put(key, Converter.convertTag(nmsTag)));
+ } else {
+ throw new IllegalArgumentException("PersistentDataContainer is not a CraftPersistentDataContainer");
+ }
+ }
+
+ @Override
+ public PersistentDataContainer extractCompoundMapIntoCraftPDC(CompoundMap source) {
+ var container = new CraftPersistentDataContainer(REGISTRY);
+ for (Map.Entry<String, com.flowpowered.nbt.Tag<?>> entry : source.entrySet()) {
+ container.put(entry.getKey(), Converter.convertTag(entry.getValue()));
+ }
+ public PersistentDataContainer extractCompoundMapIntoCraftPDC(CompoundBinaryTag source) {
+ CraftPersistentDataContainer container = new CraftPersistentDataContainer(REGISTRY);
+ source.forEach(entry -> container.put(entry.getKey(), Converter.convertTag(entry.getValue())));
+ return container;
+ }
+
@Override
public boolean loadOverworldOverride() {
if (defaultWorld == null) {
@@ -179,7 +199,7 @@ public class SlimeNMSBridgeImpl implements SlimeNMSBridge {
// level.setReady(true);
level.setSpawnSettings(world.getPropertyMap().getValue(SlimeProperties.ALLOW_MONSTERS), world.getPropertyMap().getValue(SlimeProperties.ALLOW_ANIMALS));

- var nmsExtraData = (CompoundTag) Converter.convertTag(world.getExtraData());
+ CompoundTag nmsExtraData = (CompoundTag) Converter.convertTag(CompoundBinaryTag.from(world.getExtraData()));

//Attempt to read PDC
if (nmsExtraData.get("BukkitValues") != null) level.getWorld().readBukkitValues(nmsExtraData.get("BukkitValues"));
diff --git a/src/main/java/com/infernalsuite/asp/level/NMSSlimeWorld.java b/src/main/java/com/infernalsuite/asp/level/NMSSlimeWorld.java
index 3dc776b5387b4e2f1b669f754b5b064fc0142006..76ee216925d9ced3c9bf1e7e8e1d8b80ca9f8e50 100644
index 41119f2b0d208718c294076dc3c51f55680b0257..25249743caca6f354005d7f9e4498fdf413df629 100644
--- a/src/main/java/com/infernalsuite/asp/level/NMSSlimeWorld.java
+++ b/src/main/java/com/infernalsuite/asp/level/NMSSlimeWorld.java
@@ -9,6 +9,8 @@ import com.infernalsuite.asp.api.world.properties.SlimePropertyMap;
@@ -10,6 +10,8 @@ import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.minecraft.SharedConstants;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.world.level.chunk.LevelChunk;
Expand All @@ -82,30 +80,31 @@ index 3dc776b5387b4e2f1b669f754b5b064fc0142006..76ee216925d9ced3c9bf1e7e8e1d8b80

import java.io.IOException;
import java.util.Collection;
@@ -88,4 +90,9 @@ public class NMSSlimeWorld implements SlimeWorld {
@@ -90,4 +92,9 @@ public class NMSSlimeWorld implements SlimeWorld {
public int getDataVersion() {
return SharedConstants.getCurrentVersion().getDataVersion().getVersion();
}
-}
\ No newline at end of file
+
+ @Override
+ public @NotNull PersistentDataContainer getPersistentDataContainer() {
+ return memoryWorld.getPersistentDataContainer();
+ return this.memoryWorld.getPersistentDataContainer();
+ }
}
\ No newline at end of file
+}
diff --git a/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java b/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java
index 5d325e85a4634c21ab0bec12b493ea9b857d8ff3..35d0dd30b3c91b423c03a8f1682a422bf5eb8bc1 100644
index 387954aae7ef1a39025a474ab1fe81b7216d8d6c..70787a7b87a0ebb4d47de7d110fadc8952708c58 100644
--- a/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java
+++ b/src/main/java/com/infernalsuite/asp/level/SlimeInMemoryWorld.java
@@ -5,6 +5,7 @@ import com.infernalsuite.asp.ChunkPos;
@@ -4,6 +4,7 @@ import com.infernalsuite.asp.ChunkPos;
import com.infernalsuite.asp.Converter;
import com.infernalsuite.asp.api.exceptions.WorldAlreadyExistsException;
import com.infernalsuite.asp.api.loaders.SlimeLoader;
+import com.infernalsuite.asp.pdc.FlowPersistentDataContainer;
+import com.infernalsuite.asp.pdc.AdventurePersistentDataContainer;
import com.infernalsuite.asp.serialization.slime.SlimeSerializer;
import com.infernalsuite.asp.skeleton.SkeletonCloning;
import com.infernalsuite.asp.skeleton.SkeletonSlimeWorld;
@@ -19,6 +20,8 @@ import net.minecraft.world.level.chunk.UpgradeData;
@@ -20,6 +21,8 @@ import net.minecraft.world.level.chunk.UpgradeData;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.ticks.LevelChunkTicks;
import org.bukkit.World;
Expand All @@ -114,23 +113,40 @@ index 5d325e85a4634c21ab0bec12b493ea9b857d8ff3..35d0dd30b3c91b423c03a8f1682a422b

import java.io.IOException;
import java.util.ArrayList;
@@ -38,6 +41,7 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
@@ -40,6 +43,7 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
private final SlimeWorld liveWorld;

private final CompoundTag extra;
+ private final FlowPersistentDataContainer extraPDC;
private final ConcurrentMap<String, BinaryTag> extra;
+ private final AdventurePersistentDataContainer extraPDC;
private final SlimePropertyMap propertyMap;
private final SlimeLoader loader;

@@ -60,6 +64,7 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
@@ -62,6 +66,7 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
this.chunkStorage.put(pos, initial);
}

+ this.extraPDC = new FlowPersistentDataContainer(extra);
+ this.extraPDC = new AdventurePersistentDataContainer(this.extra);
this.liveWorld = new NMSSlimeWorld(this);
}

@@ -260,4 +265,9 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
@@ -241,13 +246,12 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
// Serialize Bukkit Values (PDC)

var nmsTag = new net.minecraft.nbt.CompoundTag();
-
- instance.getWorld().storeBukkitValues(nmsTag);
+ this.instance.getWorld().storeBukkitValues(nmsTag);

// Bukkit stores the relevant tag as a tag with the key "BukkitValues" in the tag we supply to it
- var flowTag = Converter.convertTag("BukkitValues", nmsTag.getCompound("BukkitValues"));
+ var adventureTag = Converter.convertTag(nmsTag.getCompound("BukkitValues"));

- world.getExtraData().getValue().put(flowTag);
+ world.getExtraData().put("BukkitValues", adventureTag);

return new SkeletonSlimeWorld(world.getName(),
world.getLoader(),
@@ -262,4 +266,9 @@ public class SlimeInMemoryWorld implements SlimeWorld, SlimeWorldInstance {
public SlimeLevelInstance getInstance() {
return instance;
}
Expand Down
Loading

0 comments on commit 7d00f4e

Please sign in to comment.