Fixing emote system
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.saturnclient.saturnclient.client;
|
package org.saturnclient.saturnclient.client;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
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.Hats;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
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.Session;
|
||||||
|
import dev.selimaj.session.types.SessionResult;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||||
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ServiceClient {
|
public class ServiceClient {
|
||||||
private static Session session;
|
private static Session session;
|
||||||
@@ -53,7 +60,8 @@ public class ServiceClient {
|
|||||||
return false;
|
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()) {
|
for (String availableCloak : response.cloaks()) {
|
||||||
Cloaks.availableCloaks.add(availableCloak);
|
Cloaks.availableCloaks.add(availableCloak);
|
||||||
@@ -63,6 +71,8 @@ public class ServiceClient {
|
|||||||
Hats.availableHats.add(availableHat);
|
Hats.availableHats.add(availableHat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventHandlers();
|
||||||
|
|
||||||
SaturnPlayer.set(uuid, username, new SaturnPlayer(uuid, username, response.cloak(), response.hat()));
|
SaturnPlayer.set(uuid, username, new SaturnPlayer(uuid, username, response.cloak(), response.hat()));
|
||||||
|
|
||||||
Cloaks.loadCloak(uuid);
|
Cloaks.loadCloak(uuid);
|
||||||
@@ -128,7 +138,11 @@ public class ServiceClient {
|
|||||||
|
|
||||||
public static void emote(String emote) {
|
public static void emote(String emote) {
|
||||||
try {
|
try {
|
||||||
session.request(ServiceMethods.Emote, emote).whenComplete((msg, throwable) -> {
|
String[] targets = { uuid.toString().replaceAll("-", "") };
|
||||||
|
|
||||||
|
session.request(ServiceMethods.Emote,
|
||||||
|
new ServiceMethods.Types.EmoteRequest(emote, targets))
|
||||||
|
.whenComplete((msg, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -137,4 +151,29 @@ public class ServiceClient {
|
|||||||
SaturnClient.LOGGER.error("Failed to emote (service): ", 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;
|
import dev.selimaj.session.types.Method;
|
||||||
|
|
||||||
public class ServiceMethods {
|
public class ServiceMethods {
|
||||||
|
public class Types {
|
||||||
public record AuthResponse(String cloak, String hat, String[] cloaks, String[] hats) {
|
public record AuthResponse(String cloak, String hat, String[] cloaks, String[] hats) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Method<String, AuthResponse, String> Authenticate = new Method<>("auth",
|
public record EmoteRequest(String emote, String[] targets) {
|
||||||
String.class, AuthResponse.class, String.class);
|
}
|
||||||
|
|
||||||
|
public record EmoteEvent(String emote, String from) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Method<String, Types.AuthResponse, String> Authenticate = new Method<>("auth",
|
||||||
|
String.class, Types.AuthResponse.class, String.class);
|
||||||
|
|
||||||
// Equip
|
// Equip
|
||||||
public static final Method<String, String, String> SetCloak = new Method<>("set_cloak",
|
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);
|
String.class, String.class, String.class);
|
||||||
|
|
||||||
// Emote
|
// Emote
|
||||||
public static final Method<String, String, String> Emote = new Method<>("emote",
|
public static final Method<Types.EmoteRequest, String, String> Emote = new Method<>("emote",
|
||||||
String.class, String.class, String.class);
|
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) {
|
PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
||||||
ItemStack headItem = state.equippedHeadStack;
|
ItemStack headItem = state.equippedHeadStack;
|
||||||
SaturnPlayer player = SaturnPlayer.get(state.name);
|
SaturnPlayer player = SaturnPlayer.get(state.name);
|
||||||
System.out.println(state.name + "hat" + player.hat);
|
|
||||||
if (!headItem.isEmpty() || state.invisible || player == null || player.hat.isEmpty()) {
|
if (!headItem.isEmpty() || state.invisible || player == null || player.hat.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getOrNull(List<T> list, int index) {
|
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;
|
return (index >= 0 && index < list.size()) ? list.get(index) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,13 +63,13 @@ public class EmoteWheel extends SaturnScreen {
|
|||||||
if (emote == null) {
|
if (emote == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
|
// AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
|
||||||
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
// if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
||||||
animationStack.removeLayer(1000);
|
// animationStack.removeLayer(1000);
|
||||||
}
|
// }
|
||||||
animationStack.addAnimLayer(1000,
|
// animationStack.addAnimLayer(1000,
|
||||||
PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient",
|
// PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient",
|
||||||
emote)).playAnimation());
|
// emote)).playAnimation());
|
||||||
ServiceClient.emote(emote);
|
ServiceClient.emote(emote);
|
||||||
close();
|
close();
|
||||||
}).dimensions(70, 70).centerOffset(width, height, -80 + (col * 80), -35 + (row * 80))
|
}).dimensions(70, 70).centerOffset(width, height, -80 + (col * 80), -35 + (row * 80))
|
||||||
|
|||||||
Reference in New Issue
Block a user