diff --git a/gradle.properties b/gradle.properties index 625b71ac..8d794ed6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,15 +4,15 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.21.7 - yarn_mappings=1.21.7+build.6 - loader_version=0.16.14 + minecraft_version=1.21.10 + yarn_mappings=1.21.10+build.1 + loader_version=0.18.1 # Mod Properties - mod_version = 3.3.3 + mod_version = 3.3.4 maven_group = com.github.hhhzzzsss archives_base_name = song-player # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.129.0+1.21.7 + fabric_version=0.138.3+1.21.10 diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java index a4225e79..76091c0e 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java @@ -1160,7 +1160,7 @@ public boolean processCommand(String args) { Util.showChatMessage("ยง6There is nothing to clean up"); return true; } - if (MC.player.getPos().squaredDistanceTo(lastStage.getOriginBottomCenter()) > 3*3 || !lastStage.worldName.equals(Util.getWorldName())) { + if (MC.player.getEntityPos().squaredDistanceTo(lastStage.getOriginBottomCenter()) > 3*3 || !lastStage.worldName.equals(Util.getWorldName())) { String coordStr = String.format( "%d %d %d", lastStage.position.getX(), lastStage.position.getY(), lastStage.position.getZ() diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java b/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java index 9d6c0fe5..63c78af9 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java @@ -1,69 +1,95 @@ -package com.github.hhhzzzsss.songplayer; - -import com.github.hhhzzzsss.songplayer.mixin.ClientPlayNetworkHandlerAccessor; -import com.github.hhhzzzsss.songplayer.playing.SongHandler; -import com.github.hhhzzzsss.songplayer.playing.Stage; -import com.mojang.authlib.GameProfile; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.OtherClientPlayerEntity; -import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.EntityPose; -import net.minecraft.entity.player.PlayerEntity; - -import java.util.UUID; - -public class FakePlayerEntity extends OtherClientPlayerEntity { - public static final UUID FAKE_PLAYER_UUID = UUID.randomUUID(); - - ClientPlayerEntity player = SongPlayer.MC.player; - ClientWorld world = SongPlayer.MC.world; - - public FakePlayerEntity() { - super(SongPlayer.MC.world, getProfile()); - - copyStagePosAndPlayerLook(); - - getInventory().clone(player.getInventory()); - - Byte playerModel = player.getDataTracker().get(PlayerEntity.PLAYER_MODEL_PARTS); - getDataTracker().set(PlayerEntity.PLAYER_MODEL_PARTS, playerModel); - - headYaw = player.headYaw; - bodyYaw = player.bodyYaw; - - if (player.isSneaking()) { - setSneaking(true); - setPose(EntityPose.CROUCHING); - } - - capeX = getX(); - capeY = getY(); - capeZ = getZ(); - - world.addEntity(this); - } - - public void resetPlayerPosition() { - player.refreshPositionAndAngles(getX(), getY(), getZ(), getYaw(), getPitch()); - } - - public void copyStagePosAndPlayerLook() { - Stage lastStage = SongHandler.getInstance().lastStage; - if (lastStage != null) { - refreshPositionAndAngles(lastStage.position.getX()+0.5, lastStage.position.getY(), lastStage.position.getZ()+0.5, player.getYaw(), player.getPitch()); - headYaw = player.headYaw; - } - else { - copyPositionAndRotation(player); - } - } - - private static GameProfile getProfile() { - GameProfile profile = new GameProfile(FAKE_PLAYER_UUID, SongPlayer.MC.player.getGameProfile().getName()); - profile.getProperties().putAll(SongPlayer.MC.player.getGameProfile().getProperties()); - PlayerListEntry playerListEntry = new PlayerListEntry(SongPlayer.MC.player.getGameProfile(), false); - ((ClientPlayNetworkHandlerAccessor)SongPlayer.MC.getNetworkHandler()).getPlayerListEntries().put(FAKE_PLAYER_UUID, playerListEntry); - return profile; - } -} +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 com.mojang.authlib.properties.Property; +import net.minecraft.client.MinecraftClient; +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.SkinTextures; + +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.UUID; + +public class FakePlayerEntity extends OtherClientPlayerEntity { + public static final UUID FAKE_PLAYER_UUID = + UUID.nameUUIDFromBytes("songplayer:fake-player".getBytes(StandardCharsets.UTF_8)); + + ClientPlayerEntity player = SongPlayer.MC.player; + ClientWorld world = SongPlayer.MC.world; + + public FakePlayerEntity() { + super(Objects.requireNonNull(SongPlayer.MC.world), getProfile()); + + copyStagePosAndPlayerLook(); + + getInventory().clone(player.getInventory()); + + headYaw = player.headYaw; + bodyYaw = player.bodyYaw; + + if (player.isSneaking()) { + setSneaking(true); + setPose(EntityPose.CROUCHING); + } + world.addEntity(this); + } + + private static GameProfile getProfile() { + MinecraftClient mc = MinecraftClient.getInstance(); + GameProfile sessionProfile = null; + String name = "FakePlayer"; + try { + sessionProfile = mc.getSession() != null ? mc.getGameProfile() : null; + if (sessionProfile != null && sessionProfile.name() != null) { + name = sessionProfile.name(); + } + } catch (Throwable ignored) { + } + + GameProfile fakeProfile = new GameProfile(FAKE_PLAYER_UUID, name); + + try { + if (sessionProfile != null) { + var textures = sessionProfile.properties().get("textures"); + if (!textures.isEmpty()) { + for (var p : textures) { + assert p != null; + fakeProfile.properties().put("textures", new Property(p.name(), p.value(), p.signature())); + } + } + } + } catch (Throwable ignored) { + } + + return fakeProfile; + } + + public void resetPlayerPosition() { + player.refreshPositionAndAngles(getX(), getY(), getZ(), getYaw(), getPitch()); + } + + public void copyStagePosAndPlayerLook() { + Stage lastStage = SongHandler.getInstance().lastStage; + if (lastStage != null) { + refreshPositionAndAngles(lastStage.position.getX() + 0.5, lastStage.position.getY(), lastStage.position.getZ() + 0.5, player.getYaw(), player.getPitch()); + headYaw = player.headYaw; + } + else { + copyPositionAndRotation(player); + } + } + + @Override + public SkinTextures getSkin() { + MinecraftClient mc = MinecraftClient.getInstance(); + if (mc.player != null) { + return mc.player.getSkin(); + } + return super.getSkin(); + } +} diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java index 4db20b2d..df6b1e1c 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java @@ -70,7 +70,7 @@ else if (loadedText == null) { Text[] messageList = Arrays.stream(loadedMessages).map(Text::literal).toArray(Text[]::new); this.loadedText = MultilineText.create(this.textRenderer, messageList); - int loadedTextHeight = this.loadedText.count() * this.textRenderer.fontHeight; + int loadedTextHeight = this.loadedText.getLineCount() * this.textRenderer.fontHeight; addButtons(60 + loadedTextHeight + 12); loaded = true; @@ -78,10 +78,10 @@ else if (loadedText == null) { } if (loaded) { - loadedText.drawCenterWithShadow(context, this.width / 2, 60); + loadedText.draw(context, MultilineText.Alignment.CENTER,this.width / 2, 60, 20, true, 0xFFFFFF); } else { - unloadedText.drawCenterWithShadow(context, this.width / 2, 60); + unloadedText.draw(context, MultilineText.Alignment.CENTER,this.width / 2, 60, 20, true, 0xFFFFFF); } } diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java index 106f3d27..2cf3e7df 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/ClientPlayNetworkHandlerMixin.java @@ -87,7 +87,7 @@ public void onOnPlayerAbilities(PlayerAbilitiesS2CPacket packet, CallbackInfo ci } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setVelocityClient(DDD)V"), method = "onEntityVelocityUpdate", cancellable = true) + @Inject(at = @At("HEAD"), method = "onEntityVelocityUpdate(Lnet/minecraft/network/packet/s2c/play/EntityVelocityUpdateS2CPacket;)V", cancellable = true) public void onOnEntityVelocityUpdate(EntityVelocityUpdateS2CPacket packet, CallbackInfo ci) { if (!SongHandler.getInstance().isIdle() && packet.getEntityId() == SongPlayer.MC.player.getId()) { ci.cancel(); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d870c942..e893e268 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,7 +28,7 @@ "depends": { "fabricloader": ">=0.16.0", "fabric": "*", - "minecraft": "~1.21.7", + "minecraft": "~1.21.10", "java": ">=21" }, "suggests": {