Fixing emote system

This commit is contained in:
2026-02-23 09:20:10 +01:00
parent 61be7c317f
commit f0966c86f3
5 changed files with 69 additions and 20 deletions
@@ -1,6 +1,7 @@
package org.saturnclient.saturnclient.client;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.saturnclient.saturnclient.SaturnClient;
@@ -8,8 +9,14 @@ import org.saturnclient.saturnclient.client.player.SaturnPlayer;
import org.saturnclient.saturnclient.cosmetics.Hats;
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
import dev.kosmx.playerAnim.api.layered.AnimationStack;
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
import dev.selimaj.session.Session;
import dev.selimaj.session.types.SessionResult;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.util.Identifier;
public class ServiceClient {
private static Session session;
@@ -53,7 +60,8 @@ public class ServiceClient {
return false;
}
ServiceMethods.AuthResponse response = session.request(ServiceMethods.Authenticate, accessToken).get();
ServiceMethods.Types.AuthResponse response = session.request(ServiceMethods.Authenticate, accessToken)
.get();
for (String availableCloak : response.cloaks()) {
Cloaks.availableCloaks.add(availableCloak);
@@ -63,6 +71,8 @@ public class ServiceClient {
Hats.availableHats.add(availableHat);
}
eventHandlers();
SaturnPlayer.set(uuid, username, new SaturnPlayer(uuid, username, response.cloak(), response.hat()));
Cloaks.loadCloak(uuid);
@@ -128,13 +138,42 @@ public class ServiceClient {
public static void emote(String emote) {
try {
session.request(ServiceMethods.Emote, emote).whenComplete((msg, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
}
});
String[] targets = { uuid.toString().replaceAll("-", "") };
session.request(ServiceMethods.Emote,
new ServiceMethods.Types.EmoteRequest(emote, targets))
.whenComplete((msg, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
}
});
} catch (Exception e) {
SaturnClient.LOGGER.error("Failed to emote (service): ", e);
}
}
public static void eventHandlers() {
session.onNotification(ServiceMethods.EmoteEvent, (l, data) -> {
return CompletableFuture.supplyAsync(() -> {
for (AbstractClientPlayerEntity player : SaturnClient.client.world.getPlayers()) {
if (player.getUuidAsString().replace("-", "").equals(data.from())) {
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(player);
if (data.emote() != null && !data.emote().isEmpty()) {
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
animationStack.removeLayer(1000);
}
animationStack.addAnimLayer(1000,
PlayerAnimationRegistry
.getAnimation(Identifier.of("saturnclient", data.emote()))
.playAnimation());
} else {
animationStack.removeLayer(1000);
}
}
}
return SessionResult.ok("");
});
});
}
}
@@ -3,11 +3,19 @@ package org.saturnclient.saturnclient.client;
import dev.selimaj.session.types.Method;
public class ServiceMethods {
public record AuthResponse(String cloak, String hat, String[] cloaks, String[] hats) {
public class Types {
public record AuthResponse(String cloak, String hat, String[] cloaks, String[] hats) {
}
public record EmoteRequest(String emote, String[] targets) {
}
public record EmoteEvent(String emote, String from) {
}
}
public static final Method<String, AuthResponse, String> Authenticate = new Method<>("auth",
String.class, AuthResponse.class, String.class);
public static final Method<String, Types.AuthResponse, String> Authenticate = new Method<>("auth",
String.class, Types.AuthResponse.class, String.class);
// Equip
public static final Method<String, String, String> SetCloak = new Method<>("set_cloak",
@@ -22,6 +30,9 @@ public class ServiceMethods {
String.class, String.class, String.class);
// Emote
public static final Method<String, String, String> Emote = new Method<>("emote",
String.class, String.class, String.class);
public static final Method<Types.EmoteRequest, String, String> Emote = new Method<>("emote",
Types.EmoteRequest.class, String.class, String.class);
public static final Method<Types.EmoteEvent, String, String> EmoteEvent = new Method<>("emote_event",
Types.EmoteEvent.class, String.class, String.class);
}
@@ -28,7 +28,7 @@ public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState,
PlayerEntityRenderState state, float limbAngle, float limbDistance) {
ItemStack headItem = state.equippedHeadStack;
SaturnPlayer player = SaturnPlayer.get(state.name);
System.out.println(state.name + "hat" + player.hat);
if (!headItem.isEmpty() || state.invisible || player == null || player.hat.isEmpty()) {
return;
}
@@ -51,7 +51,6 @@ public class Utils {
}
public static <T> T getOrNull(List<T> list, int index) {
SaturnClient.LOGGER.info("Accessing index {} in list of size {}", index, list.size());
return (index >= 0 && index < list.size()) ? list.get(index) : null;
}
@@ -63,13 +63,13 @@ public class EmoteWheel extends SaturnScreen {
if (emote == null) {
return;
}
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
animationStack.removeLayer(1000);
}
animationStack.addAnimLayer(1000,
PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient",
emote)).playAnimation());
// AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
// if (animationStack.isActive() && animationStack.getPriority() == 1000) {
// animationStack.removeLayer(1000);
// }
// animationStack.addAnimLayer(1000,
// PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient",
// emote)).playAnimation());
ServiceClient.emote(emote);
close();
}).dimensions(70, 70).centerOffset(width, height, -80 + (col * 80), -35 + (row * 80))