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 dd3600f..9f9bb50 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 @@ -39,6 +39,8 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.chat.Component; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.ClientboundCustomPayloadPacket; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.ClientboundGameEventPacket; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.Packet; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.custom.BrandPayload; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.custom.CustomPacketPayload; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources.ResourceLocation; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ChunkMap; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedPlayerList; @@ -47,6 +49,7 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedServerPr import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.MinecraftServer; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.PlayerList; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerChunkCache; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerCommonPacketListenerImpl; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerGamePacketListenerImpl; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerLevel; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerPlayer; @@ -67,9 +70,9 @@ 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; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.BambooStalkBlock; +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.AABBVoxelShape; 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.configuration.FallbackValue_Int; @@ -145,6 +148,9 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(Tag.class, Tag.MAPPING.runtimeClass())); // minecraft.network.chat thAcc.catchThrowable(() -> initWrapper(Component.class, Component.MAPPING.runtimeClass())); + // minecraft.network.protocol.custom + thAcc.catchThrowable(() -> initWrapper(BrandPayload.class, BrandPayload.MAPPING.runtimeClass())); + thAcc.catchThrowable(() -> initWrapper(CustomPacketPayload.class, CustomPacketPayload.MAPPING.runtimeClass())); // minecraft.network.protocol thAcc.catchThrowable(() -> initWrapper(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(ClientboundGameEventPacket.class, ClientboundGameEventPacket.MAPPING.runtimeClass())); @@ -162,6 +168,7 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(MinecraftServer.class, MinecraftServer.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(PlayerList.class, PlayerList.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(ServerChunkCache.class, ServerChunkCache.MAPPING.runtimeClass())); + thAcc.catchThrowable(() -> initWrapper(ServerCommonPacketListenerImpl.class, ServerCommonPacketListenerImpl.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(ServerGamePacketListenerImpl.class, ServerGamePacketListenerImpl.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(ServerLevel.class, ServerLevel.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(ServerPlayer.class, ServerPlayer.MAPPING.runtimeClass())); @@ -169,6 +176,7 @@ public class PandalibPaperReflect { // minecraft.util thAcc.catchThrowable(() -> initWrapper(ProgressListener.class, ProgressListener.MAPPING.runtimeClass())); // minecraft.world.block + thAcc.catchThrowable(() -> initWrapper(Block.class, Block.MAPPING.runtimeClass())); thAcc.catchThrowable(() -> initWrapper(BambooStalkBlock.class, BambooStalkBlock.MAPPING.runtimeClass())); // minecraft.world thAcc.catchThrowable(() -> initWrapper(AABB.class, AABB.MAPPING.runtimeClass())); @@ -199,7 +207,6 @@ public class PandalibPaperReflect { thAcc.catchThrowable(() -> initWrapper(WorldConfiguration.class, WorldConfiguration.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(WorldConfiguration.Chunks.class, WorldConfiguration.Chunks.REFLECT.get())); // paper - thAcc.catchThrowable(() -> initWrapper(AABBVoxelShape.class, AABBVoxelShape.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(PaperAdventure.class, PaperAdventure.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(QueuedChangesMapLong2Object.class, QueuedChangesMapLong2Object.REFLECT.get())); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java index ee084a5..1ee3e2b 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java @@ -1,9 +1,8 @@ package fr.pandacube.lib.paper.reflect.util; import fr.pandacube.lib.paper.PandaLibPaper; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.BambooStalkBlock; -import fr.pandacube.lib.paper.reflect.wrapper.paper.AABBVoxelShape; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.Block; import fr.pandacube.lib.util.log.Log; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -21,7 +20,7 @@ public final class BedrockBambooCollisionFixer implements Listener { public BedrockBambooCollisionFixer() { // Make the bamboo block have zero collision. try { - BambooStalkBlock.COLLISION_SHAPE(new AABBVoxelShape(new AABB(0.5, 0, 0.5, 0.5, 0, 0.5))); + BambooStalkBlock.COLLISION_SHAPE(Block.box(8, 0, 8, 8, 0, 8)); Log.info("Bamboo block collision box removed successfully."); } catch (Exception e) { Log.severe("Unable to remove the collision box of the Bamboo block.", e); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/ClientboundCustomPayloadPacket.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/ClientboundCustomPayloadPacket.java index 79ae083..8a7a457 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/ClientboundCustomPayloadPacket.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/ClientboundCustomPayloadPacket.java @@ -1,29 +1,22 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol; import fr.pandacube.lib.paper.reflect.NMSReflect; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.FriendlyByteBuf; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources.ResourceLocation; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.custom.CustomPacketPayload; import fr.pandacube.lib.reflect.ReflectConstructor; -import fr.pandacube.lib.reflect.ReflectField; +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 ClientboundCustomPayloadPacket extends ReflectWrapper implements Packet { - public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket")); - private static final ReflectConstructor CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(ResourceLocation.MAPPING.runtimeClass(), FriendlyByteBuf.MAPPING.runtimeClass())); - private static final ReflectField FIELD_BRAND = wrapEx(() -> MAPPING.mojField("BRAND")); - - public static ResourceLocation BRAND() { - return wrap(wrapReflectEx(FIELD_BRAND::getStaticValue), ResourceLocation.class); - } + public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket")); + private static final ReflectConstructor CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(CustomPacketPayload.MAPPING.runtimeClass())); protected ClientboundCustomPayloadPacket(Object obj) { super(obj); } - public ClientboundCustomPayloadPacket(ResourceLocation res, FriendlyByteBuf buff) { - this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(res), unwrap(buff)))); + public ClientboundCustomPayloadPacket(CustomPacketPayload payload) { + this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(payload)))); } } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/custom/BrandPayload.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/custom/BrandPayload.java new file mode 100644 index 0000000..8085013 --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/custom/BrandPayload.java @@ -0,0 +1,21 @@ +package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.custom; + +import fr.pandacube.lib.paper.reflect.NMSReflect; +import fr.pandacube.lib.reflect.ReflectConstructor; +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 BrandPayload extends ReflectWrapper implements CustomPacketPayload { + public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.common.custom.BrandPayload")); + private static final ReflectConstructor CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(String.class)); + + public BrandPayload(String brand) { + this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(brand))); + } + + protected BrandPayload(Object obj) { + super(obj); + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/custom/CustomPacketPayload.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/custom/CustomPacketPayload.java new file mode 100644 index 0000000..217703c --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/network/protocol/custom/CustomPacketPayload.java @@ -0,0 +1,19 @@ +package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.custom; + +import fr.pandacube.lib.paper.reflect.NMSReflect; +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; + +@ConcreteWrapper(CustomPacketPayload.__concrete.class) +public interface CustomPacketPayload extends ReflectWrapperI { + NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.common.custom.CustomPacketPayload")); + + class __concrete extends ReflectWrapper implements CustomPacketPayload { + protected __concrete(Object obj) { + super(obj); + } + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerCommonPacketListenerImpl.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerCommonPacketListenerImpl.java new file mode 100644 index 0000000..44d1bbd --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerCommonPacketListenerImpl.java @@ -0,0 +1,22 @@ +package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server; + +import fr.pandacube.lib.paper.reflect.NMSReflect; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.Packet; +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 ServerCommonPacketListenerImpl extends ReflectWrapper { + public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.network.ServerCommonPacketListenerImpl")); + public static final ReflectMethod send = wrapEx(() -> MAPPING.mojMethod("send", Packet.MAPPING)); + + public void send(Packet packet) { + wrapReflectEx(() -> send.invoke(__getRuntimeInstance(), unwrap(packet))); + } + + protected ServerCommonPacketListenerImpl(Object obj) { + super(obj); + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerGamePacketListenerImpl.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerGamePacketListenerImpl.java index b0cebaf..17ac09b 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerGamePacketListenerImpl.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/server/ServerGamePacketListenerImpl.java @@ -1,20 +1,11 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server; import fr.pandacube.lib.paper.reflect.NMSReflect; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.Packet; -import fr.pandacube.lib.reflect.ReflectMethod; import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; -import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; -public class ServerGamePacketListenerImpl extends ReflectWrapper { +public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl { public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.network.ServerGamePacketListenerImpl")); - public static final ReflectMethod send = wrapEx(() -> MAPPING.mojMethod("send", Packet.MAPPING)); - - public void send(Packet packet) { - wrapReflectEx(() -> send.invoke(__getRuntimeInstance(), unwrap(packet))); - } protected ServerGamePacketListenerImpl(Object obj) { super(obj); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/BambooStalkBlock.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/BambooStalkBlock.java index e94c80c..ec5fbfc 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/BambooStalkBlock.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/BambooStalkBlock.java @@ -1,14 +1,13 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block; import fr.pandacube.lib.paper.reflect.NMSReflect; -import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape; import fr.pandacube.lib.reflect.ReflectField; import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; -public class BambooStalkBlock extends ReflectWrapper { +public class BambooStalkBlock extends Block { public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.block.BambooStalkBlock")); public static final ReflectField COLLISION_SHAPE = wrapEx(() -> MAPPING.mojField("COLLISION_SHAPE")); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/Block.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/Block.java new file mode 100644 index 0000000..eeb04a7 --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/world/block/Block.java @@ -0,0 +1,23 @@ +package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block; + +import fr.pandacube.lib.paper.reflect.NMSReflect; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape; +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 Block extends ReflectWrapper { + public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.block.Block")); + private static final ReflectMethod box = wrapEx(() -> MAPPING.mojMethod("box", double.class, double.class, double.class, double.class, double.class, double.class)); + + + public static VoxelShape box(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + return wrap(wrapReflectEx(() -> box.invokeStatic(minX, minY, minZ, maxX, maxY, maxZ)), VoxelShape.class); + } + + protected Block(Object obj) { + super(obj); + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/AABBVoxelShape.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/AABBVoxelShape.java deleted file mode 100644 index 5e65535..0000000 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/paper/AABBVoxelShape.java +++ /dev/null @@ -1,23 +0,0 @@ -package fr.pandacube.lib.paper.reflect.wrapper.paper; - -import fr.pandacube.lib.reflect.Reflect; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB; -import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape; -import fr.pandacube.lib.reflect.ReflectClass; -import fr.pandacube.lib.reflect.ReflectConstructor; - -import static fr.pandacube.lib.util.ThrowableUtil.wrapEx; -import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx; - -public class AABBVoxelShape extends VoxelShape { - public static final ReflectClass REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.voxel.AABBVoxelShape")); - private static final ReflectConstructor CONSTRUCTOR = wrapEx(() -> REFLECT.constructor(AABB.MAPPING.runtimeClass())); - - public AABBVoxelShape(AABB aabb) { - this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(aabb)))); - } - - protected AABBVoxelShape(Object obj) { - super(obj); - } -}