Fixed fake player bugs and made it copy crouching

This commit is contained in:
hhhzzzsss 2023-06-18 12:34:18 -05:00
parent c032f4d5ae
commit d2e8a5c1fa
3 changed files with 30 additions and 2 deletions

View file

@ -2,17 +2,23 @@ package com.github.hhhzzzsss.songplayer;
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
import com.github.hhhzzzsss.songplayer.playing.Stage;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.RunArgs;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Uuids;
import java.util.UUID;
public class FakePlayerEntity extends OtherClientPlayerEntity {
ClientPlayerEntity player = SongPlayer.MC.player;
ClientWorld world = SongPlayer.MC.world;
public FakePlayerEntity() {
super(SongPlayer.MC.world, SongPlayer.MC.player.getGameProfile());
super(SongPlayer.MC.world, new GameProfile(UUID.randomUUID(), SongPlayer.MC.player.getGameProfile().getName()));
copyStagePosAndPlayerLook();
@ -24,6 +30,11 @@ public class FakePlayerEntity extends OtherClientPlayerEntity {
headYaw = player.headYaw;
bodyYaw = player.bodyYaw;
if (player.isSneaking()) {
setSneaking(true);
setPose(EntityPose.CROUCHING);
}
capeX = getX();
capeY = getY();
capeZ = getZ();
@ -40,7 +51,6 @@ public class FakePlayerEntity extends OtherClientPlayerEntity {
if (stage != null) {
refreshPositionAndAngles(stage.position.getX()+0.5, stage.position.getY(), stage.position.getZ()+0.5, player.getYaw(), player.getPitch());
headYaw = player.headYaw;
bodyYaw = player.bodyYaw;
}
else {
copyPositionAndRotation(player);

View file

@ -5,8 +5,11 @@ 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.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.PlayerRespawnS2CPacket;
@ -35,6 +38,19 @@ public class ClientPlayNetworkHandlerMixin {
}
ci.cancel();
}
else if (packet instanceof ClientCommandC2SPacket) {
ClientCommandC2SPacket.Mode mode = ((ClientCommandC2SPacket) packet).getMode();
if (SongPlayer.fakePlayer != null) {
if (mode == ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY) {
SongPlayer.fakePlayer.setSneaking(true);
SongPlayer.fakePlayer.setPose(EntityPose.CROUCHING);
}
else if (mode == ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY) {
SongPlayer.fakePlayer.setSneaking(false);
SongPlayer.fakePlayer.setPose(EntityPose.STANDING);
}
}
}
}
@Inject(at = @At("HEAD"), method = "sendChatMessage(Ljava/lang/String;)V", cancellable=true)

View file

@ -6,6 +6,7 @@ import com.github.hhhzzzsss.songplayer.song.Song;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@ -37,6 +38,7 @@ 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));
}
public void checkBuildStatus(Song song) {