Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
164 changes: 95 additions & 69 deletions src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ 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;
}
}

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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"depends": {
"fabricloader": ">=0.16.0",
"fabric": "*",
"minecraft": "~1.21.7",
"minecraft": "~1.21.10",
"java": ">=21"
},
"suggests": {
Expand Down