Stop playing if player is moved too far from stage
This commit is contained in:
parent
ec56816612
commit
95df01fdc1
2 changed files with 15 additions and 9 deletions
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue