Less unnecessary teleportation and restore gamemode after playing
This commit is contained in:
parent
d845c6259e
commit
96a3dd8464
5 changed files with 50 additions and 15 deletions
|
@ -241,7 +241,7 @@ public class CommandProcessor {
|
|||
if (SongHandler.getInstance().stage != null) {
|
||||
SongHandler.getInstance().stage.movePlayerToStagePosition();
|
||||
}
|
||||
SongHandler.getInstance().cleanup();
|
||||
SongHandler.getInstance().restoreStateAndCleanUp();
|
||||
SongPlayer.addChatMessage("§6Stopped playing");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,6 @@ public class SPConverter {
|
|||
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
|
||||
writeInt(os, bytes.length);
|
||||
os.write(bytes);
|
||||
System.out.println(string);
|
||||
}
|
||||
|
||||
private static long getVarLong(ByteBuffer buffer) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
|
|||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||
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.PlayerRespawnS2CPacket;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@ -34,9 +35,7 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
Stage stage = SongHandler.getInstance().stage;
|
||||
|
||||
if (stage != null && packet instanceof PlayerMoveC2SPacket) {
|
||||
if (Config.getConfig().rotate) {
|
||||
connection.send(new PlayerMoveC2SPacket.PositionAndOnGround(stage.position.getX()+0.5, stage.position.getY(), stage.position.getZ()+0.5, true));
|
||||
} else {
|
||||
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();
|
||||
|
@ -76,4 +75,12 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
public void onOnPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo ci) {
|
||||
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();
|
||||
if (handler.currentSong != null || handler.currentPlaylist != null || handler.songQueue.size() > 0) {
|
||||
SongPlayer.MC.player.getAbilities().flying = handler.wasFlying;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.github.hhhzzzsss.songplayer.Util;
|
|||
import com.github.hhhzzzsss.songplayer.mixin.ClientPlayerInteractionManagerAccessor;
|
||||
import com.github.hhhzzzsss.songplayer.song.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.RunArgs;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -44,6 +45,9 @@ public class SongHandler {
|
|||
public Stage stage = null;
|
||||
public boolean building = false;
|
||||
|
||||
public boolean wasFlying = false;
|
||||
public GameMode originalGamemode = GameMode.CREATIVE;
|
||||
|
||||
boolean playlistChecked = false;
|
||||
|
||||
public void onUpdate(boolean tick) {
|
||||
|
@ -89,13 +93,15 @@ public class SongHandler {
|
|||
loaderThread = null;
|
||||
}
|
||||
|
||||
checkCommandCache();
|
||||
|
||||
// Check if no song is playing and, if necessary, handle cleanup
|
||||
if (currentSong == null) {
|
||||
if (stage != null || SongPlayer.fakePlayer != null) {
|
||||
if (stage != null) {
|
||||
stage.movePlayerToStagePosition();
|
||||
}
|
||||
cleanup();
|
||||
restoreStateAndCleanUp();
|
||||
}
|
||||
else {
|
||||
originalGamemode = SongPlayer.MC.interactionManager.getCurrentGameMode();
|
||||
}
|
||||
}
|
||||
// Otherwise, handle song playing
|
||||
|
@ -112,9 +118,9 @@ public class SongHandler {
|
|||
SongPlayer.removeFakePlayer();
|
||||
}
|
||||
|
||||
checkCommandCache();
|
||||
|
||||
SongPlayer.MC.player.getAbilities().allowFlying = true;
|
||||
wasFlying = SongPlayer.MC.player.getAbilities().flying;
|
||||
|
||||
if (building) {
|
||||
if (tick) {
|
||||
handleBuilding();
|
||||
|
@ -159,9 +165,13 @@ public class SongHandler {
|
|||
currentSong = song;
|
||||
building = true;
|
||||
setCreativeIfNeeded();
|
||||
if (stage != null) {
|
||||
if (stage == null) {
|
||||
stage = new Stage();
|
||||
stage.movePlayerToStagePosition();
|
||||
}
|
||||
else {
|
||||
stage.sendMovementPacketToStagePosition();
|
||||
}
|
||||
getAndSaveBuildSlot();
|
||||
SongPlayer.addChatMessage("§6Building noteblocks");
|
||||
}
|
||||
|
@ -251,7 +261,7 @@ public class SongHandler {
|
|||
restoreBuildSlot();
|
||||
building = false;
|
||||
setSurvivalIfNeeded();
|
||||
stage.movePlayerToStagePosition();
|
||||
stage.sendMovementPacketToStagePosition();
|
||||
SongPlayer.addChatMessage("§6Now playing §3" + currentSong.name);
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +303,7 @@ public class SongHandler {
|
|||
if (!stage.nothingToBuild()) { // Switch to building
|
||||
building = true;
|
||||
setCreativeIfNeeded();
|
||||
stage.movePlayerToStagePosition();
|
||||
stage.sendMovementPacketToStagePosition();
|
||||
currentSong.pause();
|
||||
buildStartDelay = 20;
|
||||
System.out.println("Total missing notes: " + stage.missingNotes.size());
|
||||
|
@ -369,6 +379,21 @@ public class SongHandler {
|
|||
SongPlayer.removeFakePlayer();
|
||||
}
|
||||
|
||||
public void restoreStateAndCleanUp() {
|
||||
if (stage != null) {
|
||||
stage.movePlayerToStagePosition();
|
||||
}
|
||||
if (originalGamemode != SongPlayer.MC.interactionManager.getCurrentGameMode()) {
|
||||
if (originalGamemode == GameMode.CREATIVE) {
|
||||
sendGamemodeCommand(Config.getConfig().creativeCommand);
|
||||
}
|
||||
else if (originalGamemode == GameMode.SURVIVAL) {
|
||||
sendGamemodeCommand(Config.getConfig().survivalCommand);
|
||||
}
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public void onNotIngame() {
|
||||
currentSong = null;
|
||||
currentPlaylist = null;
|
||||
|
|
|
@ -38,7 +38,11 @@ public class Stage {
|
|||
player.getAbilities().flying = true;
|
||||
player.refreshPositionAndAngles(position.getX() + 0.5, position.getY() + 0.0, position.getZ() + 0.5, player.getYaw(), player.getPitch());
|
||||
player.setVelocity(Vec3d.ZERO);
|
||||
SongPlayer.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.Full(position.getX()+0.5, position.getY(), position.getZ()+0.5, SongPlayer.MC.player.getYaw(), SongPlayer.MC.player.getPitch(), true));
|
||||
sendMovementPacketToStagePosition();
|
||||
}
|
||||
|
||||
public void sendMovementPacketToStagePosition() {
|
||||
SongPlayer.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(position.getX()+0.5, position.getY(), position.getZ()+0.5, true));
|
||||
}
|
||||
|
||||
public void checkBuildStatus(Song song) {
|
||||
|
|
Loading…
Reference in a new issue