From 8af7bccdfd1f027d8205635d8ac284aff0973e2e Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 23 Oct 2024 22:10:41 -0700 Subject: [PATCH] Adjust PlatformHooks#convertNBT to take TypeReference DataFixTypes has a limited number of types, which will limit its usage on Paper. --- .../ca/spottedleaf/moonrise/fabric/FabricHooks.java | 10 +++++++--- .../spottedleaf/moonrise/neoforge/NeoForgeHooks.java | 10 +++++++--- .../ca/spottedleaf/moonrise/common/PlatformHooks.java | 3 ++- .../patches/chunk_system/ChunkSystemConverters.java | 6 +++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java index 608bfcf9..e8cca6ce 100644 --- a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java +++ b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java @@ -2,16 +2,18 @@ import ca.spottedleaf.moonrise.common.PlatformHooks; import ca.spottedleaf.moonrise.common.util.ConfigHolder; +import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFixer; +import com.mojang.serialization.Dynamic; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.GenerationChunkHolder; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.datafix.DataFixTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ChunkPos; @@ -180,9 +182,11 @@ public boolean forceNoSave(final ChunkAccess chunk) { } @Override - public CompoundTag convertNBT(final DataFixTypes type, final DataFixer dataFixer, final CompoundTag nbt, + public CompoundTag convertNBT(final DSL.TypeReference type, final DataFixer dataFixer, final CompoundTag nbt, final int fromVersion, final int toVersion) { - return type.update(dataFixer, nbt, fromVersion, toVersion); + return (CompoundTag)dataFixer.update( + type, new Dynamic<>(NbtOps.INSTANCE, nbt), fromVersion, toVersion + ).getValue(); } @Override diff --git a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java index 63784c89..ab77acf1 100644 --- a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java +++ b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java @@ -3,14 +3,16 @@ import ca.spottedleaf.moonrise.common.PlatformHooks; import ca.spottedleaf.moonrise.common.util.ConfigHolder; import ca.spottedleaf.moonrise.common.util.CoordinateUtils; +import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFixer; +import com.mojang.serialization.Dynamic; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.GenerationChunkHolder; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.datafix.DataFixTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ChunkPos; @@ -207,9 +209,11 @@ public boolean forceNoSave(final ChunkAccess chunk) { } @Override - public CompoundTag convertNBT(final DataFixTypes type, final DataFixer dataFixer, final CompoundTag nbt, + public CompoundTag convertNBT(final DSL.TypeReference type, final DataFixer dataFixer, final CompoundTag nbt, final int fromVersion, final int toVersion) { - return type.update(dataFixer, nbt, fromVersion, toVersion); + return (CompoundTag)dataFixer.update( + type, new Dynamic<>(NbtOps.INSTANCE, nbt), fromVersion, toVersion + ).getValue(); } @Override diff --git a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java index 525cab23..27c5a749 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java @@ -1,5 +1,6 @@ package ca.spottedleaf.moonrise.common; +import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFixer; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -88,7 +89,7 @@ public void addToGetEntities(final Level world, final EntityT // support for CB chunk mustNotSave public boolean forceNoSave(final ChunkAccess chunk); - public CompoundTag convertNBT(final DataFixTypes type, final DataFixer dataFixer, final CompoundTag nbt, + public CompoundTag convertNBT(final DSL.TypeReference type, final DataFixer dataFixer, final CompoundTag nbt, final int fromVersion, final int toVersion); public boolean hasMainChunkLoadHook(); diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java index cee2c8ef..44bb2555 100644 --- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java @@ -5,7 +5,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.datafix.DataFixTypes; +import net.minecraft.util.datafix.fixes.References; public final class ChunkSystemConverters { @@ -26,13 +26,13 @@ private static int getDataVersion(final CompoundTag data, final int dfl) { public static CompoundTag convertPoiCompoundTag(final CompoundTag data, final ServerLevel world) { final int dataVersion = getDataVersion(data, DEFAULT_POI_DATA_VERSION); - return PlatformHooks.get().convertNBT(DataFixTypes.POI_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion()); + return PlatformHooks.get().convertNBT(References.POI_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion()); } public static CompoundTag convertEntityChunkCompoundTag(final CompoundTag data, final ServerLevel world) { final int dataVersion = getDataVersion(data, DEFAULT_ENTITY_CHUNK_DATA_VERSION); - return PlatformHooks.get().convertNBT(DataFixTypes.ENTITY_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion()); + return PlatformHooks.get().convertNBT(References.ENTITY_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion()); } private ChunkSystemConverters() {}