Added togglable movements

This commit is contained in:
hhhzzzsss 2023-06-18 15:11:03 -05:00
parent 681dfa752e
commit d845c6259e
4 changed files with 88 additions and 3 deletions

View file

@ -48,6 +48,7 @@ public class CommandProcessor {
commands.add(new useVanillaCommandsCommand());
commands.add(new toggleFakePlayerCommand());
commands.add(new setStageTypeCommand());
commands.add(new toggleMovementCommand());
commands.add(new songItemCommand());
commands.add(new testSongCommand());
@ -841,6 +842,55 @@ public class CommandProcessor {
}
}
private static class toggleMovementCommand extends Command {
public String getName() {
return "toggleMovement";
}
public String[] getAliases() {
return new String[]{"movement"};
}
public String[] getSyntax() {
return new String[] {"<swing | rotate>"};
}
public String getDescription() {
return "Toggles different types of movements";
}
public boolean processCommand(String args) {
switch (args.toLowerCase(Locale.ROOT)) {
case "swing":
Config.getConfig().swing = !Config.getConfig().swing;
if (Config.getConfig().swing) {
SongPlayer.addChatMessage("§6Enabled arm swinging");
}
else {
SongPlayer.addChatMessage("§6Disabled arm swinging");
}
Config.saveConfigWithErrorHandling();
return true;
case "rotate":
Config.getConfig().rotate = !Config.getConfig().rotate;
if (Config.getConfig().rotate) {
SongPlayer.addChatMessage("§6Enabled player rotation");
}
else {
SongPlayer.addChatMessage("§6Disabled player rotation");
}
Config.saveConfigWithErrorHandling();
return true;
default:
return false;
}
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
if (!args.contains(" ")) {
return CommandSource.suggestMatching(new String[]{"swing", "rotate"}, suggestionsBuilder);
}
else {
return null;
}
}
}
private static class songItemCommand extends Command {
public String getName() {
return "songItem";

View file

@ -22,6 +22,8 @@ public class Config {
public boolean loopPlaylists = false;
public boolean shufflePlaylists = false;
public Stage.StageType stageType = Stage.StageType.DEFAULT;
public boolean swing = false;
public boolean rotate = false;
public static Config getConfig() {
if (config == null) {

View file

@ -1,6 +1,7 @@
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;
@ -31,11 +32,16 @@ public class ClientPlayNetworkHandlerMixin {
@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.PositionAndOnGround(stage.position.getX()+0.5, stage.position.getY(), stage.position.getZ()+0.5, true));
} else {
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) {

View file

@ -11,6 +11,7 @@ import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
@ -18,6 +19,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
@ -426,14 +428,39 @@ public class SongHandler {
fy += bp.getY();
fz += bp.getZ();
SongPlayer.MC.interactionManager.interactBlock(SongPlayer.MC.player, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(fx, fy, fz), Direction.UP, bp, false));
doMovements(fx, fy, fz);
}
private void attackBlock(BlockPos bp) {
SongPlayer.MC.interactionManager.attackBlock(bp, Direction.UP);
doMovements(bp.getX() + 0.5, bp.getY() + 0.5, bp.getZ() + 0.5);
}
private void stopAttack() {
SongPlayer.MC.interactionManager.cancelBlockBreaking();
}
private void doMovements(double lookX, double lookY, double lookZ) {
if (Config.getConfig().swing) {
SongPlayer.MC.player.swingHand(Hand.MAIN_HAND);
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.swingHand(Hand.MAIN_HAND);
}
}
if (Config.getConfig().rotate) {
double d = lookX - (stage.position.getX() + 0.5);
double e = lookY - (stage.position.getY() + SongPlayer.MC.player.getStandingEyeHeight());
double f = lookZ - (stage.position.getZ() + 0.5);
double g = Math.sqrt(d * d + f * f);
float pitch = MathHelper.wrapDegrees((float) (-(MathHelper.atan2(e, g) * 57.2957763671875)));
float yaw = MathHelper.wrapDegrees((float) (MathHelper.atan2(f, d) * 57.2957763671875) - 90.0f);
if (SongPlayer.fakePlayer != null) {
SongPlayer.fakePlayer.setPitch(pitch);
SongPlayer.fakePlayer.setYaw(yaw);
SongPlayer.fakePlayer.setHeadYaw(yaw);
}
SongPlayer.MC.player.networkHandler.getConnection().send(new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, true));
}
}
private void getAndSaveBuildSlot() {
buildSlot = SongPlayer.MC.player.getInventory().getSwappableHotbarSlot();
prevHeldItem = SongPlayer.MC.player.getInventory().getStack(buildSlot);