cosmetic preview

This commit is contained in:
2025-04-15 00:49:30 +02:00
parent f70a5db63c
commit deef6333fb
4 changed files with 99 additions and 17 deletions
@@ -62,13 +62,7 @@ public class Cloaks {
player.cloak = cloakName;
}
if (!cloakName.isEmpty()) {
if (Arrays.asList(ANIMATED_CLOAKS).contains(cloakName)) {
new Thread(() -> loadAnimatedCloak(uuid, cloakName + ".gif")).start();
} else {
loadStaticCloak(cloakName + ".png");
}
}
loadCloak(uuid);
}
/**
@@ -158,11 +152,6 @@ public class Cloaks {
}
}
private static void loadAnimatedCloak(String uuid, String fileName) {
// This method is now handled directly in loadCloak
throw new UnsupportedOperationException("This method should not be called directly. Use loadCloak instead.");
}
public static Identifier getCurrentCloakTexture(String uuid) {
if (!Auth.players.containsKey(uuid)) {
return null;
@@ -7,6 +7,7 @@ import org.saturnclient.saturnclient.config.Property;
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
import org.saturnclient.ui.SaturnUi;
import org.saturnclient.ui.Textures;
import org.saturnclient.ui.components.SkinPreview;
import org.saturnclient.ui.widgets.SaturnClickableImage;
import org.saturnclient.ui.widgets.SaturnClickableSprite;
import org.saturnclient.ui.widgets.SaturnImage;
@@ -101,12 +102,18 @@ public class CloaksMenu extends SaturnUi {
.setHeight(rectHeight - 10)
.setAnimations(SaturnClientConfig.getAnimations()));
draw(new SkinPreview()
.setScale(3.0f)
.setX(rectWidth - 100)
.setY(rectY + 8)
.setAnimations(SaturnClientConfig.getAnimations()));
super.init();
}
private void drawItems(int rectX, int rectY, int rectWidth, int rectHeight) {
int cloakWidth = 32;
int cloakHeight = 70;
int cloakWidth = 28;
int cloakHeight = 61;
int modX = 0;
int modY = 0;
@@ -139,7 +146,7 @@ public class CloaksMenu extends SaturnUi {
col++;
if (col < 6) {
if (col < 4) {
modX += cloakWidth + 21;
} else {
modX = 0;
@@ -6,6 +6,7 @@ import org.saturnclient.saturnclient.auth.Auth;
import org.saturnclient.saturnclient.cosmetics.Hats;
import org.saturnclient.ui.SaturnUi;
import org.saturnclient.ui.Textures;
import org.saturnclient.ui.components.SkinPreview;
import org.saturnclient.ui.widgets.SaturnClickableImage;
import org.saturnclient.ui.widgets.SaturnClickableSprite;
import org.saturnclient.ui.widgets.SaturnImage;
@@ -77,7 +78,7 @@ public class HatsMenu extends SaturnUi {
.setHeight(tabSize)
.setAnimations(SaturnClientConfig.getAnimations()));
int hatSize = 32;
int hatSize = 28;
int modX = 0;
int modY = 0;
@@ -104,7 +105,7 @@ public class HatsMenu extends SaturnUi {
col++;
if (col < 6) {
if (col < 4) {
modX += hatSize + 21;
} else {
modX = 0;
@@ -121,6 +122,12 @@ public class HatsMenu extends SaturnUi {
.setHeight(rectHeight - 10)
.setAnimations(SaturnClientConfig.getAnimations()));
draw(new SkinPreview()
.setScale(3.0f)
.setX(rectWidth - 100)
.setY(rectY + 8)
.setAnimations(SaturnClientConfig.getAnimations()));
super.init();
}
}
@@ -0,0 +1,79 @@
package org.saturnclient.ui.components;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.saturnclient.ui.SaturnWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.LivingEntity;
// If you think this code is bad, it's because it's written by Mojang
public class SkinPreview extends SaturnWidget {
public static void drawEntity(DrawContext context, int x1, int y1, int x2, int y2, int size, float f, float mouseX,
float mouseY, LivingEntity entity, float angle, boolean negativeAngle) {
float g = (float) (x1 + x2) / 2.0F;
float h = (float) (y1 + y2) / 2.0F;
context.enableScissor(0, 6, x2, y2);
float i = (float) Math.atan((double) ((g - mouseX) / 40.0F));
float j = (float) Math.atan((double) ((h - mouseY) / 40.0F));
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
float k = entity.bodyYaw;
float l = entity.getYaw();
float m = entity.getPitch();
float n = entity.prevHeadYaw;
float o = entity.headYaw;
entity.setYaw(angle);
entity.bodyYaw = angle;
entity.setPitch(-j * 20.0F);
entity.headYaw = negativeAngle ? -i * 40.0F : i * 40.0F;
entity.prevHeadYaw = entity.getHeadYaw();
entity.setCustomNameVisible(false);
float p = entity.getScale();
Vector3f vector3f = new Vector3f(0.0F, entity.getHeight() / 2.0F + f * p, 0.0F);
float q = (float) size / p;
drawEntity(context, g, h, q, vector3f, quaternionf, null, entity);
entity.setCustomNameVisible(true);
entity.bodyYaw = k;
entity.setYaw(l);
entity.setPitch(m);
entity.prevHeadYaw = n;
entity.headYaw = o;
context.disableScissor();
}
public static void drawEntity(DrawContext context, float x, float y, float size, Vector3f vector3f,
Quaternionf quaternionf, @Nullable Quaternionf quaternionf2, LivingEntity entity) {
context.getMatrices().push();
context.getMatrices().translate((double) x, (double) y, 50.0);
context.getMatrices().scale(size, size, -size);
context.getMatrices().translate(vector3f.x, vector3f.y, vector3f.z);
context.getMatrices().multiply(quaternionf);
context.draw();
DiffuseLighting.method_34742();
EntityRenderDispatcher entityRenderDispatcher = MinecraftClient.getInstance().getEntityRenderDispatcher();
entityRenderDispatcher.setRenderShadows(false);
context.draw((vertexConsumers) -> {
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F, context.getMatrices(), vertexConsumers,
15728880);
});
context.draw();
entityRenderDispatcher.setRenderShadows(true);
context.getMatrices().pop();
DiffuseLighting.enableGuiDepthLighting();
}
@Override
public void render(DrawContext context, boolean hovering, int mouseX, int mouseY) {
LivingEntity entity = MinecraftClient.getInstance().player;
if (entity != null) {
drawEntity(context, 0, 0, 75, 78, 30, 0.0625F, mouseX, mouseY, entity, -30.0f, true);
}
}
}