Skip to content

Commit

Permalink
Move syncmatica custom payloads out of configuration phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Oct 28, 2023
1 parent 46ccc9b commit 9d6f107
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ modrinth {
optional.project 'viafabricplus'
optional.project 'viafabric'
optional.project 'carpet'
optional.project 'syncmatica'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ClientboundPackets1_19_4, ClientboundPackets1_20_2, ServerboundPackets1_19_4, ServerboundPackets1_20_2> {
@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();
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/viavanillaplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d6f107

Please sign in to comment.