From 97f445004849863c621d2c4e470045ab1e9571d7 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 18 Dec 2023 01:06:52 +0000 Subject: [PATCH] Fix to support new ViaVersion --- gradle.properties | 6 +- .../carpet/Protocol1_20_2To1_20Mixin.java | 69 ++++++++++--------- src/main/resources/fabric.mod.json | 1 + 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/gradle.properties b/gradle.properties index f96e86d..028f401 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.parallel=true # check these on https://fabricmc.net/develop minecraft_version=1.20.2 yarn_mappings=1.20.2+build.4 -loader_version=0.14.24 +loader_version=0.15.2 # Mod Properties mod_version=1.1.0 @@ -16,5 +16,5 @@ archives_base_name=viavanillaplus # Dependencies carpet_version=1.4.121 fabric_version=0.90.4+1.20.2 -viafabricplus_version=2.9.7-SNAPSHOT -viaversion_version=4.9.0-23w42a-SNAPSHOT \ No newline at end of file +viafabricplus_version=2.10.1 +viaversion_version=4.9.3-SNAPSHOT \ No newline at end of file diff --git a/src/main/java/net/earthcomputer/viavanillaplus/mixin/carpet/Protocol1_20_2To1_20Mixin.java b/src/main/java/net/earthcomputer/viavanillaplus/mixin/carpet/Protocol1_20_2To1_20Mixin.java index 3d32084..b4f21ed 100644 --- a/src/main/java/net/earthcomputer/viavanillaplus/mixin/carpet/Protocol1_20_2To1_20Mixin.java +++ b/src/main/java/net/earthcomputer/viavanillaplus/mixin/carpet/Protocol1_20_2To1_20Mixin.java @@ -1,5 +1,6 @@ package net.earthcomputer.viavanillaplus.mixin.carpet; +import com.llamalad7.mixinextras.sugar.Local; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; @@ -15,7 +16,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(value = Protocol1_20_2To1_20.class, remap = false) public class Protocol1_20_2To1_20Mixin extends AbstractProtocol { @@ -23,40 +23,43 @@ public class Protocol1_20_2To1_20Mixin extends AbstractProtocol { + int command = wrapper.read(Type.VAR_INT); + if (command == 69) { // hi + String version = wrapper.read(Type.STRING); + CompoundTag dataTag = new CompoundTag(); + dataTag.put("69", new StringTag(version)); + wrapper.write(Type.COMPOUND_TAG, dataTag); + } else if (command == 1) { + wrapper.write(Type.COMPOUND_TAG, wrapper.read(Type.NAMED_COMPOUND_TAG)); + } else { + wrapper.cancel(); + } + } + case SERVERBOUND -> { + CompoundTag dataTag = wrapper.read(Type.COMPOUND_TAG); + Tag hello = dataTag.remove("420"); + if (hello instanceof StringTag versionTag) { + PacketWrapper newPacket = PacketWrapper.create(ServerboundPackets1_19_4.PLUGIN_MESSAGE, wrapper.user()); + newPacket.write(Type.STRING, "carpet:hello"); + newPacket.write(Type.VAR_INT, 420); // hello + newPacket.write(Type.STRING, versionTag.getValue()); + newPacket.sendToServer(Protocol1_20_2To1_20.class); + } + if (dataTag.isEmpty()) { + wrapper.cancel(); + } else { + wrapper.write(Type.VAR_INT, 1); // data + wrapper.write(Type.NAMED_COMPOUND_TAG, dataTag); + } + } } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 422fee0..4ffa066 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,6 +30,7 @@ } ], "depends": { + "fabricloader": ">=0.15.0", "minecraft": "~1.20.2", "java": ">=17" }