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 2255d67..95c592f 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java @@ -1,22 +1,16 @@ package com.github.hhhzzzsss.songplayer.mixin; import com.github.hhhzzzsss.songplayer.CommandProcessor; -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.network.ClientPlayNetworkHandler; -import net.minecraft.entity.EntityPose; -import net.minecraft.network.ClientConnection; -import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket; -import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket; -import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; +import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -41,6 +35,15 @@ public class ClientPlayNetworkHandlerMixin { SongHandler.getInstance().cleanup(); } + @Inject(at = @At("TAIL"), method = "onPlayerPositionLook(Lnet/minecraft/network/packet/s2c/play/PlayerPositionLookS2CPacket;)V") + public void onOnPlayerPositionLook(PlayerPositionLookS2CPacket packet, CallbackInfo ci) { + Stage stage = SongHandler.getInstance().stage; + if (!SongHandler.getInstance().isIdle() && stage != null && Vec3d.ofBottomCenter(stage.position).squaredDistanceTo(SongPlayer.MC.player.getPos()) > 3*3) { + SongPlayer.addChatMessage("ยง6Stopped playing because the server moved the player too far from the stage!"); + SongHandler.getInstance().cleanup(); + } + } + @Inject(at = @At("TAIL"), method = "onPlayerAbilities(Lnet/minecraft/network/packet/s2c/play/PlayerAbilitiesS2CPacket;)V") public void onOnPlayerAbilities(PlayerAbilitiesS2CPacket packet, CallbackInfo ci) { SongHandler handler = SongHandler.getInstance(); diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java index 0ffbbea..ead3ca6 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java @@ -13,7 +13,6 @@ import net.minecraft.component.type.BlockStateComponent; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.text.MutableText; import net.minecraft.text.Text; @@ -524,4 +523,8 @@ public class SongHandler { buildSlot = -1; } } + + public boolean isIdle() { + return currentSong == null && currentPlaylist == null && songQueue.isEmpty(); + } } \ No newline at end of file