online cosmetics
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package org.saturnclient.saturnclient.auth;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.PlayerListEntry;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public class PlayerTracker {
|
||||
private static Set<UUID> trackedPlayers = new HashSet<>();
|
||||
|
||||
public static void initialize() {
|
||||
// When client joins a server, reset tracked players
|
||||
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
|
||||
trackedPlayers.clear();
|
||||
client.execute(() -> {
|
||||
checkForNewPlayers(MinecraftClient.getInstance());
|
||||
});
|
||||
});
|
||||
|
||||
// Check for new players every tick
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> checkForNewPlayers(client));
|
||||
}
|
||||
|
||||
private static void checkForNewPlayers(MinecraftClient client) {
|
||||
if (client.getNetworkHandler() == null)
|
||||
return;
|
||||
|
||||
for (PlayerListEntry player : client.getNetworkHandler().getPlayerList()) {
|
||||
UUID playerUUID = player.getProfile().getId();
|
||||
|
||||
if (!trackedPlayers.contains(playerUUID)) {
|
||||
// A new player has joined
|
||||
onPlayerJoin(client, player);
|
||||
trackedPlayers.add(playerUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void onPlayerJoin(MinecraftClient client, PlayerListEntry player) {
|
||||
GameProfile profile = player.getProfile();
|
||||
String uuid = profile.getId().toString();
|
||||
SaturnSocket.player(profile.getName(), uuid);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SaturnParser {
|
||||
public String method = "";
|
||||
private Map<String, String> params = new HashMap<>();
|
||||
|
||||
public SaturnParser(String input) throws IOException {
|
||||
@@ -18,6 +19,8 @@ public class SaturnParser {
|
||||
throw new IOException(parts[0]);
|
||||
}
|
||||
|
||||
method = parts[0];
|
||||
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
String[] keyValue = parts[i].split("=");
|
||||
if (keyValue.length == 2) {
|
||||
@@ -39,6 +42,15 @@ public class SaturnParser {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getBool(String i) throws IOException {
|
||||
String val = params.get(i);
|
||||
if (val != null) {
|
||||
return val.equals("true");
|
||||
} else {
|
||||
throw new IOException("Parameter not found " + i);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getArray(String i) throws IOException {
|
||||
String val = params.get(i);
|
||||
if (val != null) {
|
||||
|
||||
@@ -4,14 +4,16 @@ import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||
|
||||
public class SaturnSocket {
|
||||
|
||||
private static final String server = "127.0.0.1";
|
||||
private static final String server = "77.247.92.168";
|
||||
private static final int port = 8080;
|
||||
|
||||
public static Map<String, SaturnPlayer> players = new HashMap<>();
|
||||
@@ -49,8 +51,6 @@ public class SaturnSocket {
|
||||
writer.println(accessToken);
|
||||
String response = reader.readLine();
|
||||
|
||||
SaturnClient.LOGGER.info(response);
|
||||
|
||||
SaturnParser parser = new SaturnParser(response);
|
||||
|
||||
uuid = parser.getString("uuid");
|
||||
@@ -58,7 +58,6 @@ public class SaturnSocket {
|
||||
String hat = parser.getString("hat");
|
||||
|
||||
for (String availableCloak : parser.getArray("cloaks")) {
|
||||
SaturnClient.LOGGER.info("Available cloak: " + availableCloak);
|
||||
Cloaks.availableCloaks.add(availableCloak);
|
||||
}
|
||||
|
||||
@@ -66,7 +65,8 @@ public class SaturnSocket {
|
||||
|
||||
playerNames.put(client.getSession().getUsername(), uuid);
|
||||
|
||||
// Start listening for server messages
|
||||
afterAuth();
|
||||
|
||||
startListenerThread();
|
||||
|
||||
return true;
|
||||
@@ -83,11 +83,26 @@ public class SaturnSocket {
|
||||
while (running) {
|
||||
String message = reader.readLine();
|
||||
if (message == null) {
|
||||
SaturnClient.LOGGER.error("Connection closed");
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
SaturnClient.LOGGER.info("Received: " + message);
|
||||
SaturnParser parser = new SaturnParser(message);
|
||||
|
||||
switch (parser.method) {
|
||||
case "player":
|
||||
String uuid = parser.getString("uuid");
|
||||
if (parser.getBool("saturn")) {
|
||||
String cloak = parser.getString("cloak");
|
||||
String hat = parser.getString("hat");
|
||||
players.put(uuid, new SaturnPlayer(cloak, hat));
|
||||
Cloaks.setCloakSilent(uuid, cloak);
|
||||
} else {
|
||||
playerNames.entrySet().removeIf(entry -> entry.getValue().equals(uuid));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
SaturnClient.LOGGER.error("Error reading from server", e);
|
||||
@@ -118,6 +133,10 @@ public class SaturnSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public static void afterAuth() {
|
||||
PlayerTracker.initialize();
|
||||
}
|
||||
|
||||
public static void setCloak(String cloakName) {
|
||||
try {
|
||||
writer.println("set_cloak@cloak=" + cloakName);
|
||||
@@ -125,4 +144,21 @@ public class SaturnSocket {
|
||||
SaturnClient.LOGGER.error("Request failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void player(String name, String uuid) {
|
||||
try {
|
||||
playerNames.put(name, uuid.replaceAll("-", ""));
|
||||
writer.println("player@uuid=" + uuid.replaceAll("-", ""));
|
||||
} catch (Exception e) {
|
||||
SaturnClient.LOGGER.error("Request failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void joinServer(String ip) {
|
||||
try {
|
||||
writer.println("join_server@ip=" + ip);
|
||||
} catch (Exception e) {
|
||||
SaturnClient.LOGGER.error("Request failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.saturnclient.saturnclient.cosmetics;
|
||||
|
||||
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
||||
import org.saturnclient.saturnclient.auth.SaturnSocket;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@@ -30,8 +31,8 @@ public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState,
|
||||
ItemStack headItem = state.equippedHeadStack;
|
||||
String uuid = SaturnSocket.playerNames.get(state.name);
|
||||
if (headItem.isEmpty() && uuid != null) {
|
||||
String hat = SaturnSocket.players.get(uuid).hat;
|
||||
if (hat.isEmpty()) {
|
||||
SaturnPlayer player = SaturnSocket.players.get(uuid);
|
||||
if (player == null || player.hat == null || player.hat.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState,
|
||||
|
||||
ItemStack customHat = new ItemStack(Items.STICK);
|
||||
customHat.set(DataComponentTypes.ITEM_MODEL,
|
||||
Identifier.of("saturnclient:hat_" + hat));
|
||||
Identifier.of("saturnclient:hat_" + player.hat));
|
||||
customHat.set(DataComponentTypes.EQUIPPABLE,
|
||||
EquippableComponent.builder(EquipmentSlot.HEAD).build());
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ public class ModMenu extends SaturnUi {
|
||||
SaturnScroll modsScroll = new SaturnScroll();
|
||||
|
||||
for (SaturnMod mod : ModManager.MODS) {
|
||||
SaturnClient.LOGGER.info(mod.getName());
|
||||
modsScroll.draw(
|
||||
new SaturnModComp(mod)
|
||||
.setX(modX)
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class NameTagMixin<S extends EntityRenderState> {
|
||||
@Overwrite
|
||||
public void renderLabelIfPresent(S state, Text text_o, MatrixStack matrices,
|
||||
VertexConsumerProvider vertexConsumers, int light) {
|
||||
Text text = isSaturn(state) ? Text.literal("" + "HexLeo") : text_o;
|
||||
Text text = isSaturn(state) ? Text.literal("" + text_o.getString()) : text_o;
|
||||
|
||||
Vec3d vec3d = state.nameLabelPos;
|
||||
if (vec3d != null) {
|
||||
@@ -60,7 +60,8 @@ public abstract class NameTagMixin<S extends EntityRenderState> {
|
||||
private boolean isSaturn(S state) {
|
||||
if (state instanceof PlayerEntityRenderState) {
|
||||
String name = ((PlayerEntityRenderState) state).name;
|
||||
return SaturnSocket.playerNames.containsKey(name);
|
||||
String uuid = SaturnSocket.playerNames.get(name);
|
||||
return uuid != null && SaturnSocket.players.containsKey(uuid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -13,17 +13,14 @@ import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
public class SaturnUi extends Screen {
|
||||
|
||||
private final ScheduledExecutorService scheduler =
|
||||
Executors.newSingleThreadScheduledExecutor();
|
||||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
public static MutableText text(String text) {
|
||||
return Text.literal(text).setStyle(
|
||||
Style.EMPTY.withFont(Identifier.of("saturnclient:panton"))
|
||||
);
|
||||
Style.EMPTY.withFont(Identifier.of("saturnclient:panton")));
|
||||
}
|
||||
|
||||
public List<SaturnWidget> widgets = new ArrayList<>();
|
||||
@@ -36,11 +33,10 @@ public class SaturnUi extends Screen {
|
||||
@Override
|
||||
protected void init() {
|
||||
scheduler.scheduleAtFixedRate(
|
||||
this::saturnTick,
|
||||
0,
|
||||
7,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
this::saturnTick,
|
||||
0,
|
||||
7,
|
||||
TimeUnit.MILLISECONDS);
|
||||
super.init();
|
||||
}
|
||||
|
||||
@@ -53,34 +49,32 @@ public class SaturnUi extends Screen {
|
||||
|
||||
@Override
|
||||
public void render(
|
||||
DrawContext context,
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
float delta
|
||||
) {
|
||||
DrawContext context,
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
float delta) {
|
||||
renderBackground(context, mouseX, mouseY, delta);
|
||||
|
||||
for (SaturnWidget widget : new ArrayList<>(widgets)) {
|
||||
if (!widget.visible) continue;
|
||||
if (!widget.visible)
|
||||
continue;
|
||||
|
||||
double adjustedMouseX = mouseX - widget.x;
|
||||
double adjustedMouseY = mouseY - widget.y;
|
||||
boolean isMouseInside =
|
||||
adjustedMouseX >= 0 &&
|
||||
adjustedMouseX <= (widget.width * widget.scale) &&
|
||||
adjustedMouseY >= 0 &&
|
||||
adjustedMouseY <= (widget.height * widget.scale);
|
||||
boolean isMouseInside = adjustedMouseX >= 0 &&
|
||||
adjustedMouseX <= (widget.width * widget.scale) &&
|
||||
adjustedMouseY >= 0 &&
|
||||
adjustedMouseY <= (widget.height * widget.scale);
|
||||
|
||||
MatrixStack matrices = context.getMatrices();
|
||||
matrices.push();
|
||||
matrices.translate(widget.x, widget.y, 0);
|
||||
matrices.scale(widget.scale, widget.scale, 1.0f);
|
||||
widget.render(
|
||||
context,
|
||||
isMouseInside,
|
||||
(int) (adjustedMouseX / widget.scale),
|
||||
(int) (adjustedMouseY / widget.scale)
|
||||
);
|
||||
context,
|
||||
isMouseInside,
|
||||
(int) (adjustedMouseX / widget.scale),
|
||||
(int) (adjustedMouseY / widget.scale));
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
@@ -90,29 +84,21 @@ public class SaturnUi extends Screen {
|
||||
if (button == 0) {
|
||||
for (SaturnWidget widget : new ArrayList<>(widgets)) {
|
||||
widget.focused = false;
|
||||
if (!widget.visible) continue;
|
||||
if (!widget.visible)
|
||||
continue;
|
||||
|
||||
double adjustedMouseX = mouseX - widget.x;
|
||||
double adjustedMouseY = mouseY - widget.y;
|
||||
boolean isMouseInside =
|
||||
adjustedMouseX >= 0 &&
|
||||
adjustedMouseX <= (widget.width * widget.scale) &&
|
||||
adjustedMouseY >= 0 &&
|
||||
adjustedMouseY <= (widget.height * widget.scale);
|
||||
|
||||
SaturnClient.LOGGER.info(
|
||||
"CLick mouse X: " +
|
||||
adjustedMouseX +
|
||||
", mouse Y: " +
|
||||
adjustedMouseY
|
||||
);
|
||||
boolean isMouseInside = adjustedMouseX >= 0 &&
|
||||
adjustedMouseX <= (widget.width * widget.scale) &&
|
||||
adjustedMouseY >= 0 &&
|
||||
adjustedMouseY <= (widget.height * widget.scale);
|
||||
|
||||
if (isMouseInside) {
|
||||
widget.focused = true;
|
||||
widget.click(
|
||||
(int) (adjustedMouseX / widget.scale),
|
||||
(int) (adjustedMouseY / widget.scale)
|
||||
);
|
||||
(int) (adjustedMouseX / widget.scale),
|
||||
(int) (adjustedMouseY / widget.scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +109,8 @@ public class SaturnUi extends Screen {
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
for (SaturnWidget widget : new ArrayList<>(widgets)) {
|
||||
if (!widget.visible && !widget.focused) continue;
|
||||
if (!widget.visible && !widget.focused)
|
||||
continue;
|
||||
|
||||
widget.keyPressed(keyCode, scanCode, modifiers);
|
||||
|
||||
@@ -137,36 +124,32 @@ public class SaturnUi extends Screen {
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(
|
||||
double mouseX,
|
||||
double mouseY,
|
||||
double horizontalAmount,
|
||||
double verticalAmount
|
||||
) {
|
||||
double mouseX,
|
||||
double mouseY,
|
||||
double horizontalAmount,
|
||||
double verticalAmount) {
|
||||
for (SaturnWidget widget : new ArrayList<>(widgets)) {
|
||||
double adjustedMouseX = mouseX - widget.x;
|
||||
double adjustedMouseY = mouseY - widget.y;
|
||||
boolean isMouseInside =
|
||||
adjustedMouseX >= 0 &&
|
||||
adjustedMouseX <= (widget.width * widget.scale) &&
|
||||
adjustedMouseY >= 0 &&
|
||||
adjustedMouseY <= (widget.height * widget.scale);
|
||||
boolean isMouseInside = adjustedMouseX >= 0 &&
|
||||
adjustedMouseX <= (widget.width * widget.scale) &&
|
||||
adjustedMouseY >= 0 &&
|
||||
adjustedMouseY <= (widget.height * widget.scale);
|
||||
|
||||
if (isMouseInside) {
|
||||
widget.mouseScrolled(
|
||||
(int) (adjustedMouseX / widget.scale),
|
||||
(int) (adjustedMouseY / widget.scale),
|
||||
horizontalAmount,
|
||||
verticalAmount
|
||||
);
|
||||
(int) (adjustedMouseX / widget.scale),
|
||||
(int) (adjustedMouseY / widget.scale),
|
||||
horizontalAmount,
|
||||
verticalAmount);
|
||||
}
|
||||
}
|
||||
|
||||
return super.mouseScrolled(
|
||||
mouseX,
|
||||
mouseY,
|
||||
horizontalAmount,
|
||||
verticalAmount
|
||||
);
|
||||
mouseX,
|
||||
mouseY,
|
||||
horizontalAmount,
|
||||
verticalAmount);
|
||||
}
|
||||
|
||||
private char getCharFromKey(int keyCode, int modifiers) {
|
||||
@@ -182,8 +165,8 @@ public class SaturnUi extends Screen {
|
||||
// 0-9
|
||||
if (keyCode >= GLFW.GLFW_KEY_0 && keyCode <= GLFW.GLFW_KEY_9) {
|
||||
return shift
|
||||
? ")!@#$%^&*(".charAt(keyCode - GLFW.GLFW_KEY_0)
|
||||
: (char) ('0' + (keyCode - GLFW.GLFW_KEY_0));
|
||||
? ")!@#$%^&*(".charAt(keyCode - GLFW.GLFW_KEY_0)
|
||||
: (char) ('0' + (keyCode - GLFW.GLFW_KEY_0));
|
||||
}
|
||||
|
||||
// Special characters
|
||||
@@ -209,10 +192,8 @@ public class SaturnUi extends Screen {
|
||||
for (SaturnWidget widget : widgets) {
|
||||
if (widget.visible && widget.animations != null) {
|
||||
for (SaturnAnimation animation : widget.animations) {
|
||||
if (
|
||||
animation != null &&
|
||||
tick - animation.lastTick == animation.delay
|
||||
) {
|
||||
if (animation != null &&
|
||||
tick - animation.lastTick == animation.delay) {
|
||||
if (animation.run(widget, tick)) {
|
||||
animation = null;
|
||||
} else {
|
||||
|
||||
@@ -52,7 +52,6 @@ public class SaturnFloat extends SaturnWidget {
|
||||
|
||||
@Override
|
||||
public void charTyped(char chr) {
|
||||
SaturnClient.LOGGER.info("current digit: " + chr);
|
||||
if ((Character.isDigit(chr) || chr == '.') && text.length() < 10) {
|
||||
if (text.equals("0") && cursorPosition == 1) {
|
||||
text = "" + chr;
|
||||
|
||||
@@ -52,7 +52,6 @@ public class SaturnInteger extends SaturnWidget {
|
||||
|
||||
@Override
|
||||
public void charTyped(char chr) {
|
||||
SaturnClient.LOGGER.info("current digit: " + chr);
|
||||
if (Character.isDigit(chr) && text.length() < 10) {
|
||||
if (text.equals("0") && cursorPosition == 1) {
|
||||
text = "" + chr;
|
||||
|
||||
Reference in New Issue
Block a user