From 9d6f1072032a38481adf1db7effce2d2761df141 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 28 Oct 2023 23:10:15 +0100 Subject: [PATCH] Move syncmatica custom payloads out of configuration phase --- README.md | 1 + build.gradle | 1 + .../syncmatica/Protocol1_20_2To1_20Mixin.java | 34 +++++++++++++++++++ src/main/resources/viavanillaplus.mixins.json | 3 +- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/earthcomputer/viavanillaplus/mixin/syncmatica/Protocol1_20_2To1_20Mixin.java diff --git a/README.md b/README.md index ce44616..8bb34cf 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,6 @@ Handles protocol changes in Vanilla+ mods, intended as an addon to ViaFabricPlus Currently supported mods are: - [Carpet](https://modrinth.com/mod/carpet) +- [Syncmatica](https://modrinth.com/mod/syncmatica) Available on Modrinth at [https://modrinth.com/mod/viavanillaplus]. diff --git a/build.gradle b/build.gradle index 5963143..74b3c56 100644 --- a/build.gradle +++ b/build.gradle @@ -126,6 +126,7 @@ modrinth { optional.project 'viafabricplus' optional.project 'viafabric' optional.project 'carpet' + optional.project 'syncmatica' } } diff --git a/src/main/java/net/earthcomputer/viavanillaplus/mixin/syncmatica/Protocol1_20_2To1_20Mixin.java b/src/main/java/net/earthcomputer/viavanillaplus/mixin/syncmatica/Protocol1_20_2To1_20Mixin.java new file mode 100644 index 0000000..c73cdba --- /dev/null +++ b/src/main/java/net/earthcomputer/viavanillaplus/mixin/syncmatica/Protocol1_20_2To1_20Mixin.java @@ -0,0 +1,34 @@ +package net.earthcomputer.viavanillaplus.mixin.syncmatica; + +import com.viaversion.viaversion.api.protocol.AbstractProtocol; +import com.viaversion.viaversion.api.protocol.packet.Direction; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.exception.CancelException; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState; +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 = Protocol1_20_2To1_20.class, remap = false) +public class Protocol1_20_2To1_20Mixin extends AbstractProtocol { + @SuppressWarnings("deprecation") + public Protocol1_20_2To1_20Mixin() { + } + + @Inject(method = "transform", at = @At(value = "FIELD", target = "Lcom/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2;CUSTOM_PAYLOAD:Lcom/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2;")) + private void onClientboundPluginMessage(Direction direction, State state, PacketWrapper wrapper, CallbackInfo ci) throws Exception { + String channel = wrapper.passthrough(Type.STRING); + if (channel.startsWith("syncmatica:")) { + wrapper.user().get(ConfigurationState.class).addPacketToQueue(wrapper, true); + throw CancelException.generate(); + } + } +} diff --git a/src/main/resources/viavanillaplus.mixins.json b/src/main/resources/viavanillaplus.mixins.json index 0a04acb..33c4f9c 100644 --- a/src/main/resources/viavanillaplus.mixins.json +++ b/src/main/resources/viavanillaplus.mixins.json @@ -3,7 +3,8 @@ "package": "net.earthcomputer.viavanillaplus.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "carpet.Protocol1_20_2To1_20Mixin" + "carpet.Protocol1_20_2To1_20Mixin", + "syncmatica.Protocol1_20_2To1_20Mixin" ], "injectors": { "defaultRequire": 1