From edd4e89a6eeaeb2a06c901c9f0e4a72ca33cd98c Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 9 May 2023 12:30:50 +0200 Subject: [PATCH] Update WorldVersion/DataVersion reflect wrappers for new paper version --- .../paper/reflect/PandalibPaperReflect.java | 4 +-- .../wrapper/minecraft/GameVersion.java | 28 ----------------- .../wrapper/minecraft/SharedConstants.java | 2 +- .../wrapper/minecraft/WorldVersion.java | 11 ++++++- .../wrapper/minecraft/world/DataVersion.java | 31 +++++++++++++++++++ 5 files changed, 44 insertions(+), 32 deletions(-) delete mode 100644 pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/GameVersion.java create mode 100644 pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/DataVersion.java diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java index 7cd09db..7991317 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java @@ -14,7 +14,6 @@ import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCDataConverter; import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCDataType; import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCTypeRegistry; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.DetectedVersion; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.GameVersion; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.SharedConstants; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.WorldVersion; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.BlockPosArgument; @@ -58,6 +57,7 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkPos; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkStorage; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSources; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DataVersion; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level; @@ -176,6 +176,7 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(ChunkStorage.class, ChunkStorage.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(DamageSource.class, DamageSource.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(DamageSources.class, DamageSources.MAPPING.runtimeClass())); + thAcc.catchThrowable(() -> initWrapper(DataVersion.class, DataVersion.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(Entity.class, Entity.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(ItemStack.class, ItemStack.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(Level.class, Level.MAPPING.runtimeClass())); @@ -186,7 +187,6 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(VoxelShape.class, VoxelShape.MAPPING.runtimeClass())); // minecraft thAcc.catchThrowable(() -> initWrapper(DetectedVersion.class, DetectedVersion.MAPPING.runtimeClass())); - thAcc.catchThrowable(() -> initWrapper(GameVersion.class, GameVersion.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(SharedConstants.class, SharedConstants.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(WorldVersion.class, WorldVersion.MAPPING.runtimeClass())); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/GameVersion.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/GameVersion.java deleted file mode 100644 index 06a6102..0000000 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/GameVersion.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.pandacube.lib.paper.reflect.wrapper.minecraft; - -import fr.pandacube.lib.reflect.Reflect; -import fr.pandacube.lib.reflect.ReflectClass; -import fr.pandacube.lib.reflect.ReflectMethod; -import fr.pandacube.lib.reflect.wrapper.ConcreteWrapper; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapperI; - -import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; -import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; - -@ConcreteWrapper(GameVersion.__concrete.class) -public interface GameVersion extends ReflectWrapperI { - ReflectClass REFLECT = wrapEx(() -> Reflect.ofClass("com.mojang.bridge.game.GameVersion")); - ReflectMethod getWorldVersion = wrapEx(() -> REFLECT.method("getWorldVersion")); - - default int getWorldVersion() { - return (int) wrapReflectEx(() -> getWorldVersion.invoke(__getRuntimeInstance())); - } - - - class __concrete extends ReflectWrapper implements GameVersion { - private __concrete(Object obj) { - super(obj); - } - } -} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/SharedConstants.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/SharedConstants.java index 262eab8..7b68f47 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/SharedConstants.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/SharedConstants.java @@ -1,8 +1,8 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft; import fr.pandacube.lib.paper.reflect.NMSReflect; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; import fr.pandacube.lib.reflect.ReflectMethod; +import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/WorldVersion.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/WorldVersion.java index 6f58c43..c389cd4 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/WorldVersion.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/WorldVersion.java @@ -2,15 +2,24 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft; import fr.pandacube.lib.paper.reflect.NMSReflect; import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DataVersion; +import fr.pandacube.lib.reflect.ReflectMethod; import fr.pandacube.lib.reflect.wrapper.ConcreteWrapper; import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; import fr.pandacube.lib.reflect.wrapper.ReflectWrapperI; +import static fr.pandacube.lib.reflect.wrapper.ReflectWrapper.wrap; import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; +import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; @ConcreteWrapper(WorldVersion.__concrete.class) -public interface WorldVersion extends GameVersion { +public interface WorldVersion extends ReflectWrapperI { ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion")); + ReflectMethod getDataVersion = wrapEx(() -> MAPPING.mojMethod("getDataVersion")); + + default DataVersion getDataVersion() { + return wrap(wrapReflectEx(() -> getDataVersion.invoke(__getRuntimeInstance())), DataVersion.class); + } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/DataVersion.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/DataVersion.java new file mode 100644 index 0000000..ce70ea9 --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/DataVersion.java @@ -0,0 +1,31 @@ +package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world; + +import fr.pandacube.lib.paper.reflect.NMSReflect; +import fr.pandacube.lib.reflect.ReflectMethod; +import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; + +import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; +import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; + +public class DataVersion extends ReflectWrapper { + public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.storage.DataVersion")); + private static final ReflectMethod getVersion = wrapEx(() -> MAPPING.mojMethod("getVersion")); + private static final ReflectMethod getSeries = wrapEx(() -> MAPPING.mojMethod("getSeries")); + + + + public int getVersion() { + return (int) wrapReflectEx(() -> getVersion.invoke(__getRuntimeInstance())); + } + + public String getSeries() { + return (String) wrapReflectEx(() -> getSeries.invoke(__getRuntimeInstance())); + } + + + + + protected DataVersion(Object obj) { + super(obj); + } +}