-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hendrix-Shen <[email protected]>
- Loading branch information
1 parent
8c5adab
commit d193e20
Showing
15 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...endrixshen/tweakmyclient/mixin/patch/legacyCarpetHandshake/MixinClientPacketListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package top.hendrixshen.tweakmyclient.mixin.patch.legacyCarpetHandshake; | ||
|
||
import net.minecraft.client.multiplayer.ClientPacketListener; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
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; | ||
import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; | ||
import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; | ||
import top.hendrixshen.tweakmyclient.config.Configs; | ||
import top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake.LegacyCarpetVersionPayload; | ||
import top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake.LegacyClientNetworkHandler; | ||
|
||
@Dependencies(and = { | ||
@Dependency(value = "carpet", versionPredicate = ">1.4.113"), | ||
@Dependency(value = "minecraft", versionPredicate = ">1.20.1") | ||
}) | ||
@Mixin(ClientPacketListener.class) | ||
public class MixinClientPacketListener { | ||
@Inject( | ||
method = "handleUnknownCustomPayload", | ||
at = @At( | ||
value = "HEAD" | ||
), | ||
cancellable = true | ||
) | ||
private void onHandleUnknownCustomPayload(CustomPacketPayload packet, CallbackInfo ci) { | ||
if (Configs.legacyCarpetHandshake && packet instanceof LegacyCarpetVersionPayload cpp) { | ||
LegacyClientNetworkHandler.handleData(cpp); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../tweakmyclient/mixin/patch/legacyCarpetHandshake/MixinClientboundCustomPayloadPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package top.hendrixshen.tweakmyclient.mixin.patch.legacyCarpetHandshake; | ||
|
||
import carpet.network.CarpetClient; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
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.CallbackInfoReturnable; | ||
import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; | ||
import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; | ||
import top.hendrixshen.tweakmyclient.TweakMyClientReference; | ||
import top.hendrixshen.tweakmyclient.config.Configs; | ||
import top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake.LegacyCarpetVersionPayload; | ||
|
||
@Dependencies(and = { | ||
@Dependency(value = "carpet", versionPredicate = ">1.4.113"), | ||
@Dependency(value = "minecraft", versionPredicate = ">1.20.1") | ||
}) | ||
@Mixin(value = ClientboundCustomPayloadPacket.class, priority = 990) | ||
public class MixinClientboundCustomPayloadPacket { | ||
@Inject( | ||
method = "readPayload", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;readUnknownPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/DiscardedPayload;" | ||
), | ||
cancellable = true | ||
) | ||
private static void onReadPayload(@NotNull ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, | ||
@NotNull CallbackInfoReturnable<CustomPacketPayload> cir) { | ||
if (Configs.legacyCarpetHandshake && resourceLocation.equals(CarpetClient.CARPET_CHANNEL)) { | ||
try { | ||
cir.setReturnValue(new LegacyCarpetVersionPayload(new FriendlyByteBuf(friendlyByteBuf.copy()))); | ||
} catch (Exception ignore) { | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...p/hendrixshen/tweakmyclient/network/legacyCarpetHandshake/LegacyCarpetVersionPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake; | ||
|
||
import carpet.network.CarpetClient; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record LegacyCarpetVersionPayload(int command, String data) implements CustomPacketPayload { | ||
public LegacyCarpetVersionPayload(@NotNull FriendlyByteBuf input) throws RuntimeException { | ||
this(input.readVarInt(), input.readUtf()); | ||
|
||
if (this.command != LegacyClientNetworkHandler.HI && this.command != LegacyClientNetworkHandler.DATA) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
@Override | ||
public void write(@NotNull FriendlyByteBuf output) { | ||
output.writeVarInt(command); | ||
output.writeUtf(data); | ||
} | ||
|
||
@Override | ||
public @NotNull ResourceLocation id() { | ||
return CarpetClient.CARPET_CHANNEL; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...p/hendrixshen/tweakmyclient/network/legacyCarpetHandshake/LegacyClientNetworkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake; | ||
|
||
import carpet.CarpetSettings; | ||
import carpet.network.CarpetClient; | ||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class LegacyClientNetworkHandler { | ||
public static final int HI = 69; | ||
public static final int HELLO = 420; | ||
public static final int DATA = 1; | ||
|
||
public static void handleData(@NotNull LegacyCarpetVersionPayload data) { | ||
if (data.command() == LegacyClientNetworkHandler.HI) { | ||
LegacyClientNetworkHandler.onHi(data.data()); | ||
} | ||
} | ||
|
||
public static void onHi(@NotNull String version) { | ||
CarpetClient.setCarpet(); | ||
CarpetClient.serverCarpetVersion = version; | ||
|
||
if (CarpetSettings.carpetVersion.equals(CarpetClient.serverCarpetVersion)) { | ||
CarpetSettings.LOG.info("Joined carpet server with matching carpet version"); | ||
} else { | ||
CarpetSettings.LOG.warn("Joined carpet server with another carpet version: " + CarpetClient.serverCarpetVersion); | ||
} | ||
|
||
// We can ensure that this packet is | ||
// processed AFTER the player has joined | ||
LegacyClientNetworkHandler.respondHello(); | ||
} | ||
|
||
public static void respondHello() { | ||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket( | ||
new LegacyCarpetVersionPayload(LegacyClientNetworkHandler.HELLO, CarpetSettings.carpetVersion) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...endrixshen/tweakmyclient/mixin/patch/legacyCarpetHandshake/MixinClientPacketListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package top.hendrixshen.tweakmyclient.mixin.patch.legacyCarpetHandshake; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import top.hendrixshen.magiclib.compat.preprocess.api.DummyClass; | ||
|
||
@Mixin(DummyClass.class) | ||
public class MixinClientPacketListener { | ||
} |
8 changes: 8 additions & 0 deletions
8
.../tweakmyclient/mixin/patch/legacyCarpetHandshake/MixinClientboundCustomPayloadPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package top.hendrixshen.tweakmyclient.mixin.patch.legacyCarpetHandshake; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import top.hendrixshen.magiclib.compat.preprocess.api.DummyClass; | ||
|
||
@Mixin(DummyClass.class) | ||
public class MixinClientboundCustomPayloadPacket { | ||
} |
4 changes: 4 additions & 0 deletions
4
...p/hendrixshen/tweakmyclient/network/legacyCarpetHandshake/LegacyCarpetVersionPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake; | ||
|
||
public class LegacyCarpetVersionPayload { | ||
} |
4 changes: 4 additions & 0 deletions
4
...p/hendrixshen/tweakmyclient/network/legacyCarpetHandshake/LegacyClientNetworkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package top.hendrixshen.tweakmyclient.network.legacyCarpetHandshake; | ||
|
||
public class LegacyClientNetworkHandler { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters