From 2b407d7f27f38f6a00f59447919c67729ddc366c Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 26 Dec 2024 00:23:53 +0100 Subject: [PATCH] Fix various reflection issues for Paper 1.21.1 --- .../paper/reflect/PandalibPaperReflect.java | 8 +++-- .../wrapper/minecraft/world/ChunkStorage.java | 11 +++---- .../minecraft/world/RegionFileStorage.java | 23 ++++++++++++++ .../paper/QueuedChangesMapLong2Object.java | 25 --------------- .../moonrise/ChunkSystemChunkStorage.java | 31 +++++++++++++++++++ 5 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/RegionFileStorage.java delete mode 100644 pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/QueuedChangesMapLong2Object.java create mode 100644 pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/spottedleaf/moonrise/ChunkSystemChunkStorage.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 df5fd0a..1c3a282 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 @@ -64,6 +64,7 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.PlayerDataStorage; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.RegionFileStorage; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.SavedData; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Vec3; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape; @@ -72,13 +73,13 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.Block; import fr.pandacube.lib.paper.reflect.wrapper.netty.ByteBuf; import fr.pandacube.lib.paper.reflect.wrapper.netty.Unpooled; import fr.pandacube.lib.paper.reflect.wrapper.paper.PaperAdventure; -import fr.pandacube.lib.paper.reflect.wrapper.paper.QueuedChangesMapLong2Object; import fr.pandacube.lib.paper.reflect.wrapper.paper.commands.BukkitCommandNode; import fr.pandacube.lib.paper.reflect.wrapper.paper.commands.PaperBrigadier; import fr.pandacube.lib.paper.reflect.wrapper.paper.commands.PluginCommandNode; import fr.pandacube.lib.paper.reflect.wrapper.paper.commands.ShadowBrigNode; import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.FallbackValue_Int; import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration; +import fr.pandacube.lib.paper.reflect.wrapper.spottedleaf.moonrise.ChunkSystemChunkStorage; import fr.pandacube.lib.reflect.ReflectionWrapperBypass; import fr.pandacube.lib.util.ThrowableAccumulator; @@ -193,6 +194,7 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(Level.class, Level.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(MapItemSavedData.class, MapItemSavedData.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(PlayerDataStorage.class, PlayerDataStorage.REFLECT.get())); + thAcc.catchThrowable(() -> initWrapper(RegionFileStorage.class, RegionFileStorage.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(SavedData.class, SavedData.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(Vec3.class, Vec3.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(VoxelShape.class, VoxelShape.REFLECT.get())); @@ -216,7 +218,9 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(WorldConfiguration.Chunks.class, WorldConfiguration.Chunks.REFLECT.get())); // paper thAcc.catchThrowable(() -> initWrapper(PaperAdventure.class, PaperAdventure.REFLECT.get())); - thAcc.catchThrowable(() -> initWrapper(QueuedChangesMapLong2Object.class, QueuedChangesMapLong2Object.REFLECT.get())); + + // spottedleaf + thAcc.catchThrowable(() -> initWrapper(ChunkSystemChunkStorage.class, ChunkSystemChunkStorage.REFLECT.get())); thAcc.throwCaught(); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/ChunkStorage.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/ChunkStorage.java index 8446d79..509b0bf 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/ChunkStorage.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/ChunkStorage.java @@ -1,6 +1,7 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag; +import fr.pandacube.lib.paper.reflect.wrapper.spottedleaf.moonrise.ChunkSystemChunkStorage; import fr.pandacube.lib.reflect.Reflect; import fr.pandacube.lib.reflect.ReflectClass; import fr.pandacube.lib.reflect.ReflectMethod; @@ -12,17 +13,13 @@ import java.util.concurrent.CompletableFuture; import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; -public class ChunkStorage extends ReflectWrapper { +public class ChunkStorage extends ReflectWrapper implements ChunkSystemChunkStorage { public static final ReflectClass REFLECT = wrapEx(() -> Reflect.ofClass("net.minecraft.world.level.chunk.storage.ChunkStorage")); - private static final ReflectMethod readSync = wrapEx(() -> REFLECT.method("readSync", ChunkPos.REFLECT.get())); // spigot/paper method - - public CompoundTag readSync(ChunkPos pos) { - return wrap(wrapReflectEx(() -> readSync.invoke(__getRuntimeInstance(), unwrap(pos))), CompoundTag.class); - } + private static final ReflectMethod read = wrapEx(() -> REFLECT.method("read", ChunkPos.REFLECT.get())); // spigot/paper method public CompletableFuture> read(ChunkPos pos) { @SuppressWarnings("unchecked") - CompletableFuture> nmsFuture = (CompletableFuture>) wrapReflectEx(() -> readSync.invoke(__getRuntimeInstance(), unwrap(pos))); + CompletableFuture> nmsFuture = ((CompletableFuture>) wrapReflectEx(() -> read.invoke(__getRuntimeInstance(), unwrap(pos)))); return nmsFuture.thenApply(o -> o.map(c -> wrap(c, CompoundTag.class))); } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/RegionFileStorage.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/RegionFileStorage.java new file mode 100644 index 0000000..c73fbd0 --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/RegionFileStorage.java @@ -0,0 +1,23 @@ +package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world; + +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag; +import fr.pandacube.lib.reflect.Reflect; +import fr.pandacube.lib.reflect.ReflectClass; +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 RegionFileStorage extends ReflectWrapper { + public static final ReflectClass REFLECT = wrapEx(() -> Reflect.ofClass("net.minecraft.world.level.chunk.storage.RegionFileStorage")); + private static final ReflectMethod read = wrapEx(() -> REFLECT.method("read", ChunkPos.REFLECT.get())); // spigot/paper method + + public CompoundTag read(ChunkPos pos) { + return wrap(wrapReflectEx(() -> read.invoke(__getRuntimeInstance(), unwrap(pos))), CompoundTag.class); + } + + protected RegionFileStorage(Object obj) { + super(obj); + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/QueuedChangesMapLong2Object.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/QueuedChangesMapLong2Object.java deleted file mode 100644 index a5e7f9b..0000000 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/QueuedChangesMapLong2Object.java +++ /dev/null @@ -1,25 +0,0 @@ -package fr.pandacube.lib.paper.reflect.wrapper.paper; - -import fr.pandacube.lib.reflect.Reflect; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; -import fr.pandacube.lib.reflect.ReflectClass; -import fr.pandacube.lib.reflect.ReflectMethod; - -import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; - -import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; -import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; - -public class QueuedChangesMapLong2Object extends ReflectWrapper { - public static final ReflectClass REFLECT = wrapEx(() -> Reflect.ofClass("com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object")); - public static final ReflectMethod getVisibleMap = wrapEx(() -> REFLECT.method("getVisibleMap")); - - /** The entries in the returned value are not mapped */ - public Long2ObjectLinkedOpenHashMap getVisibleMap() { - return (Long2ObjectLinkedOpenHashMap) wrapReflectEx(() -> getVisibleMap.invoke(__getRuntimeInstance())); - } - - protected QueuedChangesMapLong2Object(Object obj) { - super(obj); - } -} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/spottedleaf/moonrise/ChunkSystemChunkStorage.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/spottedleaf/moonrise/ChunkSystemChunkStorage.java new file mode 100644 index 0000000..7e5d64b --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/spottedleaf/moonrise/ChunkSystemChunkStorage.java @@ -0,0 +1,31 @@ +package fr.pandacube.lib.paper.reflect.wrapper.spottedleaf.moonrise; + +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DataVersion; +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.reflect.wrapper.ReflectWrapper.wrap; +import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; +import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; + +@ConcreteWrapper(ChunkSystemChunkStorage.__concrete.class) +public interface ChunkSystemChunkStorage extends ReflectWrapperI { + ReflectClass REFLECT = wrapEx(() -> Reflect.ofClass("ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemChunkStorage")); + ReflectMethod moonrise$getRegionStorage = wrapEx(() -> REFLECT.method("moonrise$getRegionStorage")); + + default DataVersion moonrise$getRegionStorage() { + return wrap(wrapReflectEx(() -> moonrise$getRegionStorage.invoke(__getRuntimeInstance())), DataVersion.class); + } + + + + class __concrete extends ReflectWrapper implements ChunkSystemChunkStorage { + private __concrete(Object obj) { + super(obj); + } + } +}