diff options
Diffstat (limited to 'src/main/java/moe/nea/firmament')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/CustomPayloadEventDispatcher.java | 27 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/custompayload/CustomPayloadEventDispatcher.java | 27 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/custompayload/InjectCustomCodecIntoC2SCustomPayloadPacket.java (renamed from src/main/java/moe/nea/firmament/mixins/WrapCustomPayloadC2SPacketCodec.java) | 4 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/custompayload/InjectCustomCodecIntoS2CCustomPayloadPacket.java (renamed from src/main/java/moe/nea/firmament/mixins/WrapCustomPayloadS2CPacketCodec.java) | 25 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/custompayload/SplitJoinedCustomPayload.java | 33 |
5 files changed, 64 insertions, 52 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CustomPayloadEventDispatcher.java b/src/main/java/moe/nea/firmament/mixins/CustomPayloadEventDispatcher.java deleted file mode 100644 index 66710eb..0000000 --- a/src/main/java/moe/nea/firmament/mixins/CustomPayloadEventDispatcher.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -package moe.nea.firmament.mixins; - -import moe.nea.firmament.apis.ingame.FirmamentCustomPayload; -import moe.nea.firmament.events.FirmamentCustomPayloadEvent; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.packet.CustomPayload; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ClientPlayNetworkHandler.class) -public class CustomPayloadEventDispatcher { - @Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) - private void handleFirmamentParsedPayload(CustomPayload payload, CallbackInfo ci) { - if (payload instanceof FirmamentCustomPayload customPayload) { - FirmamentCustomPayloadEvent.Companion.publish(new FirmamentCustomPayloadEvent(customPayload)); - ci.cancel(); - } - } -} diff --git a/src/main/java/moe/nea/firmament/mixins/custompayload/CustomPayloadEventDispatcher.java b/src/main/java/moe/nea/firmament/mixins/custompayload/CustomPayloadEventDispatcher.java new file mode 100644 index 0000000..591d8c2 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custompayload/CustomPayloadEventDispatcher.java @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins.custompayload; + +import moe.nea.firmament.apis.ingame.FirmamentCustomPayload; +import moe.nea.firmament.events.FirmamentCustomPayloadEvent; +import net.minecraft.client.network.ClientCommonNetworkHandler; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ClientCommonNetworkHandler.class, priority = 500) +public class CustomPayloadEventDispatcher { + @Inject(method = "onCustomPayload(Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;)V", at = @At("HEAD"), cancellable = true) + private void handleFirmamentParsedPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) { + if (packet.payload() instanceof FirmamentCustomPayload customPayload) { + FirmamentCustomPayloadEvent.Companion.publishSync(new FirmamentCustomPayloadEvent(customPayload)); + ci.cancel(); + } + } +} diff --git a/src/main/java/moe/nea/firmament/mixins/WrapCustomPayloadC2SPacketCodec.java b/src/main/java/moe/nea/firmament/mixins/custompayload/InjectCustomCodecIntoC2SCustomPayloadPacket.java index 150611e..6586466 100644 --- a/src/main/java/moe/nea/firmament/mixins/WrapCustomPayloadC2SPacketCodec.java +++ b/src/main/java/moe/nea/firmament/mixins/custompayload/InjectCustomCodecIntoC2SCustomPayloadPacket.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -package moe.nea.firmament.mixins; +package moe.nea.firmament.mixins.custompayload; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.At; import java.util.List; @Mixin(priority = 1001, value = CustomPayloadC2SPacket.class) -public class WrapCustomPayloadC2SPacketCodec { +public class InjectCustomCodecIntoC2SCustomPayloadPacket { @WrapOperation(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/CustomPayload;createCodec(Lnet/minecraft/network/packet/CustomPayload$CodecFactory;Ljava/util/List;)Lnet/minecraft/network/codec/PacketCodec;")) private static PacketCodec<PacketByteBuf, CustomPayload> wrapFactory( diff --git a/src/main/java/moe/nea/firmament/mixins/WrapCustomPayloadS2CPacketCodec.java b/src/main/java/moe/nea/firmament/mixins/custompayload/InjectCustomCodecIntoS2CCustomPayloadPacket.java index 7cb8f47..1bdedad 100644 --- a/src/main/java/moe/nea/firmament/mixins/WrapCustomPayloadS2CPacketCodec.java +++ b/src/main/java/moe/nea/firmament/mixins/custompayload/InjectCustomCodecIntoS2CCustomPayloadPacket.java @@ -4,30 +4,22 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -package moe.nea.firmament.mixins; +package moe.nea.firmament.mixins.custompayload; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import moe.nea.firmament.apis.ingame.InGameCodecWrapper; -import moe.nea.firmament.apis.ingame.JoinedCustomPayload; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.listener.ClientCommonPacketListener; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.List; @Mixin(priority = 1001, value = CustomPayloadS2CPacket.class) -public abstract class WrapCustomPayloadS2CPacketCodec { - - @Shadow - public abstract CustomPayload payload(); +public abstract class InjectCustomCodecIntoS2CCustomPayloadPacket { @WrapOperation(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/CustomPayload;createCodec(Lnet/minecraft/network/packet/CustomPayload$CodecFactory;Ljava/util/List;)Lnet/minecraft/network/codec/PacketCodec;")) private static PacketCodec<PacketByteBuf, CustomPayload> wrapFactory( @@ -39,17 +31,4 @@ public abstract class WrapCustomPayloadS2CPacketCodec { return new InGameCodecWrapper(originalCodec, InGameCodecWrapper.Direction.S2C); } - - - // TODO: move to own class - @Inject(method = "apply(Lnet/minecraft/network/listener/ClientCommonPacketListener;)V", at = @At("HEAD"), cancellable = true) - private void onApply(ClientCommonPacketListener clientCommonPacketListener, CallbackInfo ci) { - if (payload() instanceof JoinedCustomPayload joinedCustomPayload) { - new CustomPayloadS2CPacket(joinedCustomPayload.getOriginal()).apply(clientCommonPacketListener); - new CustomPayloadS2CPacket(joinedCustomPayload.getSmuggled()).apply(clientCommonPacketListener); - ci.cancel(); - } - } - - } diff --git a/src/main/java/moe/nea/firmament/mixins/custompayload/SplitJoinedCustomPayload.java b/src/main/java/moe/nea/firmament/mixins/custompayload/SplitJoinedCustomPayload.java new file mode 100644 index 0000000..3ef4895 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custompayload/SplitJoinedCustomPayload.java @@ -0,0 +1,33 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins.custompayload; + +import moe.nea.firmament.apis.ingame.JoinedCustomPayload; +import net.minecraft.network.listener.ClientCommonPacketListener; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(CustomPayloadS2CPacket.class) +public abstract class SplitJoinedCustomPayload { + + @Shadow + public abstract CustomPayload payload(); + + @Inject(method = "apply(Lnet/minecraft/network/listener/ClientCommonPacketListener;)V", at = @At("HEAD"), cancellable = true) + private void onApply(ClientCommonPacketListener clientCommonPacketListener, CallbackInfo ci) { + if (payload() instanceof JoinedCustomPayload joinedCustomPayload) { + new CustomPayloadS2CPacket(joinedCustomPayload.getOriginal()).apply(clientCommonPacketListener); + new CustomPayloadS2CPacket(joinedCustomPayload.getSmuggled()).apply(clientCommonPacketListener); + ci.cancel(); + } + } +} |