Added toggleFakePlayer command

This commit is contained in:
hhhzzzsss 2020-08-10 16:01:59 -05:00 committed by GitHub
parent fd72c990f8
commit a6d5a6c818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 72 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View file

@ -36,6 +36,7 @@ com/github/hhhzzzsss/songplayer/CommandProcessor.java
com.github.hhhzzzsss.songplayer.CommandProcessor$setSurvivalCommandCommand
com.github.hhhzzzsss.songplayer.CommandProcessor$songsCommand
com.github.hhhzzzsss.songplayer.CommandProcessor$stopCommand
com.github.hhhzzzsss.songplayer.CommandProcessor$toggleFakePlayerCommand
com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java
com.github.hhhzzzsss.songplayer.mixin.ClientPlayNetworkHandlerMixin
com/github/hhhzzzsss/songplayer/noteblocks/PlayingThread.java

View file

@ -26,6 +26,7 @@ public class CommandProcessor {
commands.add(new songsCommand());
commands.add(new setCreativeCommandCommand());
commands.add(new setSurvivalCommandCommand());
commands.add(new toggleFakePlayerCommand());
}
// returns true if it is a command and should be cancelled
@ -176,6 +177,10 @@ public class CommandProcessor {
return true;
}
if (args.length() == 0) {
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.remove();
SongPlayer.fakePlayer = null;
}
SongPlayer.stage.movePlayerToStagePosition();
SongPlayer.mode = Mode.IDLE;
SongPlayer.song.loop = false;
@ -330,7 +335,7 @@ public class CommandProcessor {
public boolean processCommand(String args) {
if (args.length() > 0) {
SongPlayer.creativeCommand = args;
SongPlayer.addChatMessage("Set creative command to " + SongPlayer.creativeCommand);
SongPlayer.addChatMessage("§6Set creative command to " + SongPlayer.creativeCommand);
return true;
}
else {
@ -352,7 +357,43 @@ public class CommandProcessor {
public boolean processCommand(String args) {
if (args.length() > 0) {
SongPlayer.survivalCommand = args;
SongPlayer.addChatMessage("Set survival command to " + SongPlayer.survivalCommand);
SongPlayer.addChatMessage("§6Set survival command to " + SongPlayer.survivalCommand);
return true;
}
else {
return false;
}
}
}
private static class toggleFakePlayerCommand extends Command {
public String getName() {
return "toggleFakePlayer";
}
public String getSyntax() {
return "$toggleFakePlayer";
}
public String getDescription() {
return "Shows a fake player representing your true position when playing songs";
}
public boolean processCommand(String args) {
if (args.length() == 0) {
SongPlayer.showFakePlayer = !SongPlayer.showFakePlayer;
if (SongPlayer.showFakePlayer) {
if (SongPlayer.mode == Mode.PLAYING || SongPlayer.mode == Mode.BUILDING) {
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.remove();
}
SongPlayer.fakePlayer = new FakePlayerEntity();
}
SongPlayer.addChatMessage("§6Enabled fake player");
}
else {
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.remove();
}
SongPlayer.addChatMessage("§6Disabled fake player");
}
return true;
}
else {

View file

@ -12,7 +12,7 @@ public class FakePlayerEntity extends OtherClientPlayerEntity {
public FakePlayerEntity() {
super(SongPlayer.MC.world, SongPlayer.MC.player.getGameProfile());
copyPositionAndRotation(player);
copyStagePosAndPlayerLook();
inventory.clone(player.inventory);
@ -32,4 +32,15 @@ public class FakePlayerEntity extends OtherClientPlayerEntity {
public void resetPlayerPosition() {
player.refreshPositionAndAngles(getX(), getY(), getZ(), yaw, pitch);
}
public void copyStagePosAndPlayerLook() {
if (SongPlayer.stage != null) {
refreshPositionAndAngles(SongPlayer.stage.position.getX()+0.5, SongPlayer.stage.position.getY(), SongPlayer.stage.position.getZ()+0.5, player.yaw, player.pitch);
headYaw = player.headYaw;
bodyYaw = player.bodyYaw;
}
else {
copyPositionAndRotation(player);
}
}
}

View file

@ -17,6 +17,8 @@ public class SongPlayer implements ModInitializer {
public static final File SONG_DIR = new File("songs");
public static Song song;
public static Stage stage;
public static boolean showFakePlayer = false;
public static FakePlayerEntity fakePlayer;
public static String creativeCommand = "/gmc";
public static String survivalCommand = "/gms";

View file

@ -31,6 +31,9 @@ public class ClientPlayNetworkHandlerMixin {
}*/
if (SongPlayer.mode != SongPlayer.Mode.IDLE && packet instanceof PlayerMoveC2SPacket) {
connection.send(new PlayerMoveC2SPacket.Both(SongPlayer.stage.position.getX()+0.5, SongPlayer.stage.position.getY(), SongPlayer.stage.position.getZ()+0.5, SongPlayer.MC.player.yaw, SongPlayer.MC.player.pitch, true));
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.copyStagePosAndPlayerLook();
}
ci.cancel();
}
}

View file

@ -2,6 +2,7 @@ package com.github.hhhzzzsss.songplayer.noteblocks;
import java.util.ArrayList;
import com.github.hhhzzzsss.songplayer.FakePlayerEntity;
import com.github.hhhzzzsss.songplayer.SongPlayer;
import com.github.hhhzzzsss.songplayer.song.Song;
@ -91,6 +92,12 @@ public class BuildingThread extends Thread {
player.abilities.allowFlying = true;
player.abilities.flying = true;
SongPlayer.stage.movePlayerToStagePosition();
if (SongPlayer.showFakePlayer) {
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.remove();
}
SongPlayer.fakePlayer = new FakePlayerEntity();
}
for (int dy : new int[] {0,1,3}) {
for (int dx = -4; dx <= 4; dx++) {

View file

@ -85,6 +85,10 @@ public class PlayingThread extends Thread{
player.abilities.allowFlying = true;
player.abilities.flying = true;
SongPlayer.stage.movePlayerToStagePosition();
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.remove();
SongPlayer.fakePlayer = null;
}
SongPlayer.addChatMessage("§6Finished playing.");
SongPlayer.mode = SongPlayer.Mode.IDLE;

View file

@ -46,7 +46,6 @@ public class Song {
}
if (!songPath.exists()) {
songPath = new File(SongPlayer.SONG_DIR, file + ".mid");
System.out.println(file + ".mid");
}
if (!songPath.exists()) {
songPath = new File(SongPlayer.SONG_DIR, file + ".midi");
@ -55,9 +54,6 @@ public class Song {
boolean isMidi = false;
String extension = getExtension(songPath);
if (extension.equalsIgnoreCase("mid") || extension.equalsIgnoreCase("midi")) isMidi = true;
System.out.println(songPath.getName());
System.out.println(extension);
System.out.println(isMidi);
if (isMidi) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(songPath));
song.notes.clear();