From fe92fae94f8db7a4612637833a55261261b53552 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:04:35 +0700 Subject: [PATCH] 1.20.2 --- gradle.properties | 8 ++-- .../songplayer/FakePlayerEntity.java | 2 +- .../item/SongItemConfirmationScreen.java | 2 +- .../mixin/ClientConnectionMixin.java | 47 +++++++++++++++++++ .../mixin/ClientPlayNetworkHandlerMixin.java | 36 +------------- src/main/resources/songplayer.mixins.json | 1 + 6 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientConnectionMixin.java diff --git a/gradle.properties b/gradle.properties index e74047f..884764f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.20.1 - yarn_mappings=1.20.1+build.2 - loader_version=0.14.21 + minecraft_version=1.20.2 + yarn_mappings=1.20.2+build.1 + loader_version=0.14.22 # Mod Properties mod_version = 3.1.1 @@ -15,4 +15,4 @@ org.gradle.parallel=true # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.83.1+1.20.1 + fabric_version=0.89.2+1.20.2 diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java b/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java index 9abaae5..b3259f3 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java @@ -41,7 +41,7 @@ public class FakePlayerEntity extends OtherClientPlayerEntity { capeY = getY(); capeZ = getZ(); - world.addEntity(getId(), this); + world.addEntity(this); } public void resetPlayerPosition() { diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java index 237ab90..12c273e 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java @@ -54,7 +54,7 @@ public class SongItemConfirmationScreen extends Screen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context); + this.renderBackground(context, mouseX, mouseY, delta); context.drawCenteredTextWithShadow(textRenderer, this.title, this.width / 2, 40, 0xFFFFFF); diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientConnectionMixin.java b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientConnectionMixin.java new file mode 100644 index 0000000..f7a969a --- /dev/null +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientConnectionMixin.java @@ -0,0 +1,47 @@ +package com.github.hhhzzzsss.songplayer.mixin; + +import com.github.hhhzzzsss.songplayer.Config; +import com.github.hhhzzzsss.songplayer.SongPlayer; +import com.github.hhhzzzsss.songplayer.playing.SongHandler; +import com.github.hhhzzzsss.songplayer.playing.Stage; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.EntityPose; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; +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(ClientConnection.class) +public class ClientConnectionMixin { + @Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;)V", cancellable = true) + private void sendPacket(Packet packet, CallbackInfo ci) { + Stage stage = SongHandler.getInstance().stage; + + if (stage != null && packet instanceof PlayerMoveC2SPacket) { + if (!Config.getConfig().rotate) { + MinecraftClient.getInstance().getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.Full(stage.position.getX() + 0.5, stage.position.getY(), stage.position.getZ() + 0.5, SongPlayer.MC.player.getYaw(), SongPlayer.MC.player.getPitch(), true)); + if (SongPlayer.fakePlayer != null) { + SongPlayer.fakePlayer.copyStagePosAndPlayerLook(); + } + } + ci.cancel(); + } + else if (packet instanceof ClientCommandC2SPacket) { + ClientCommandC2SPacket.Mode mode = ((ClientCommandC2SPacket) packet).getMode(); + if (SongPlayer.fakePlayer != null) { + if (mode == ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY) { + SongPlayer.fakePlayer.setSneaking(true); + SongPlayer.fakePlayer.setPose(EntityPose.CROUCHING); + } + else if (mode == ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY) { + SongPlayer.fakePlayer.setSneaking(false); + SongPlayer.fakePlayer.setPose(EntityPose.STANDING); + } + } + } + } +} diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java index f3b9df2..111e956 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java @@ -5,6 +5,7 @@ import com.github.hhhzzzsss.songplayer.Config; import com.github.hhhzzzsss.songplayer.SongPlayer; import com.github.hhhzzzsss.songplayer.playing.SongHandler; import com.github.hhhzzzsss.songplayer.playing.Stage; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.entity.EntityPose; import net.minecraft.network.ClientConnection; @@ -23,41 +24,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPlayNetworkHandler.class) public class ClientPlayNetworkHandlerMixin { - @Shadow - private final ClientConnection connection; - - public ClientPlayNetworkHandlerMixin() { - connection = null; - } - - @Inject(at = @At("HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;)V", cancellable = true) - private void onSendPacket(Packet packet, CallbackInfo ci) { - Stage stage = SongHandler.getInstance().stage; - - if (stage != null && packet instanceof PlayerMoveC2SPacket) { - if (!Config.getConfig().rotate) { - connection.send(new PlayerMoveC2SPacket.Full(stage.position.getX() + 0.5, stage.position.getY(), stage.position.getZ() + 0.5, SongPlayer.MC.player.getYaw(), SongPlayer.MC.player.getPitch(), true)); - if (SongPlayer.fakePlayer != null) { - SongPlayer.fakePlayer.copyStagePosAndPlayerLook(); - } - } - ci.cancel(); - } - else if (packet instanceof ClientCommandC2SPacket) { - ClientCommandC2SPacket.Mode mode = ((ClientCommandC2SPacket) packet).getMode(); - if (SongPlayer.fakePlayer != null) { - if (mode == ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY) { - SongPlayer.fakePlayer.setSneaking(true); - SongPlayer.fakePlayer.setPose(EntityPose.CROUCHING); - } - else if (mode == ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY) { - SongPlayer.fakePlayer.setSneaking(false); - SongPlayer.fakePlayer.setPose(EntityPose.STANDING); - } - } - } - } - @Inject(at = @At("HEAD"), method = "sendChatMessage(Ljava/lang/String;)V", cancellable=true) private void onSendChatMessage(String content, CallbackInfo ci) { boolean isCommand = CommandProcessor.processChatMessage(content); diff --git a/src/main/resources/songplayer.mixins.json b/src/main/resources/songplayer.mixins.json index ccce863..d1272b5 100644 --- a/src/main/resources/songplayer.mixins.json +++ b/src/main/resources/songplayer.mixins.json @@ -10,6 +10,7 @@ "ClientPlayerInteractionManagerAccessor", "ClientPlayNetworkHandlerAccessor", "ClientPlayNetworkHandlerMixin", + "ClientConnectionMixin", "InGameHudMixin", "MinecraftClientMixin" ],