Files
saturnclient/src/main/java/org/saturnclient/impl/ui/EntityDrawerImpl.java
T
selimaj-devandclaude af27907356 Build every version with Mojang mappings instead of Yarn
Minecraft ships unobfuscated from 26.1, and 1.21.11 has the last Yarn
release, so the shared src/ has to use Mojang's names before newer
versions can be added (#39).

Each version's sources were migrated with Loom's migrateMappings and
merged back into src/, so code that is only active on other versions
is migrated too. Where Mojang's names differ between 1.21.x versions,
src/ uses the newest ones: Stonecutter replacements swap in the older
Identifier/ResourceLocation and Avatar/Player renderer names, and
version comments cover the few package moves and renamed methods.

The fog mixin now targets setupFog on every version. Yarn's applyFog
named two methods from 1.21.6 on, so it also applied to updateBuffer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-30 17:39:14 +02:00

176 lines
7.2 KiB
Java

package org.saturnclient.impl.ui;
// Entities in the UI are drawn through the GUI render state from 1.21.6, and straight into vertex
// consumers before. This file has one implementation for each side.
//? if >=1.21.6 {
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.ui.RenderScope;
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
//? if >=1.21.9 {
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
//?} else
//import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.state.EntityRenderState;
import net.minecraft.world.entity.LivingEntity;
public class EntityDrawerImpl implements EntityDrawer {
@Override
public boolean render(RenderScope renderScope, int width, int height, float yaw) {
LivingEntity entity = SaturnClient.client.player;
if (entity == null) {
return false;
}
// The player is about 1.8 blocks tall; leave some room above and below.
drawEntity(renderScope, 0, 0, width, height, (int) (height / 2.2F), 0.0625F, yaw, entity);
return true;
}
// Draws the entity in the box, turned by yaw degrees (0 faces the viewer) with its head straight.
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, int size, float scale,
float yaw, LivingEntity entity) {
renderScope.enableScissor(x1, y1, x2, y2);
Quaternionf quaternionf = (new Quaternionf()).rotateZ((float) Math.PI);
Quaternionf quaternionf2 = new Quaternionf();
float j = entity.yBodyRot;
float k = entity.getYRot();
float l = entity.getXRot();
float m = entity.yHeadRotO;
float n = entity.yHeadRot;
entity.yBodyRot = 180.0F + yaw;
entity.setYRot(180.0F + yaw);
entity.setXRot(0.0F);
entity.yHeadRot = entity.getYRot();
entity.yHeadRotO = entity.getYRot();
float o = entity.getScale();
Vector3f vector3f = new Vector3f(0.0F, entity.getBbHeight() / 2.0F + scale * o, 0.0F);
float p = (float) size / o;
drawEntity(renderScope, x1, y1, x2, y2, p, vector3f, quaternionf, quaternionf2, entity);
entity.yBodyRot = j;
entity.setYRot(k);
entity.setXRot(l);
entity.yHeadRotO = m;
entity.yHeadRot = n;
renderScope.disableScissor();
}
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, float scale,
Vector3f translation, Quaternionf rotation, @Nullable Quaternionf overrideCameraAngle,
LivingEntity entity) {
//? if >=1.21.9 {
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
//?} else
//EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
EntityRenderer<? super LivingEntity, ?> entityRenderer = entityRenderDispatcher.getRenderer(entity);
EntityRenderState entityRenderState = entityRenderer.createRenderState(entity, 1.0F);
//? if <1.21.11
//entityRenderState.hitboxesRenderState = null;
if (renderScope instanceof RenderScopeImpl i)
i.addEntity(entityRenderState, scale, translation, rotation, overrideCameraAngle, x1, y1, x2, y2);
}
}
//?} else {
/*import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.ui.RenderScope;
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
import com.mojang.blaze3d.platform.Lighting;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.LivingEntity;
public class EntityDrawerImpl implements EntityDrawer {
// Draws the entity in the box, turned by yaw degrees (0 faces the viewer) with its head straight.
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, int size, float f,
float yaw, LivingEntity entity) {
float g = (float) (x1 + x2) / 2.0F;
float h = (float) (y1 + y2) / 2.0F;
renderScope.enableScissor(x1, y1, x2, y2);
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
float k = entity.yBodyRot;
float l = entity.getYRot();
float m = entity.getXRot();
//? if >=1.21.5
float n = entity.yHeadRotO;
//? if <1.21.5
//float n = entity.yHeadRotO;
float o = entity.yHeadRot;
entity.setYRot(180.0F + yaw);
entity.yBodyRot = 180.0F + yaw;
entity.setXRot(0.0F);
entity.yHeadRot = entity.getYRot();
//? if >=1.21.5
entity.yHeadRotO = entity.getYHeadRot();
//? if <1.21.5
//entity.yHeadRotO = entity.getYHeadRot();
entity.setCustomNameVisible(false);
float p = entity.getScale();
Vector3f vector3f = new Vector3f(0.0F, entity.getBbHeight() / 2.0F + f * p, 0.0F);
float q = (float) size / p;
drawEntity(renderScope, g, h, q, vector3f, quaternionf, null, entity);
entity.setCustomNameVisible(true);
entity.yBodyRot = k;
entity.setYRot(l);
entity.setXRot(m);
//? if >=1.21.5
entity.yHeadRotO = n;
//? if <1.21.5
//entity.yHeadRotO = n;
entity.yHeadRot = o;
renderScope.disableScissor();
}
public static void drawEntity(RenderScope renderScope, float x, float y, float size, Vector3f vector3f,
Quaternionf quaternionf, @Nullable Quaternionf quaternionf2, LivingEntity entity) {
if (renderScope instanceof RenderScopeImpl scopeImpl) {
scopeImpl.matrices.pushPose();
scopeImpl.matrices.translate((double) x, (double) y, 0);
scopeImpl.matrices.scale(size, size, -size);
scopeImpl.matrices.translate(vector3f.x, vector3f.y, vector3f.z);
scopeImpl.matrices.mulPose(quaternionf);
scopeImpl.draw();
//? if >=1.21.5
Lighting.setupForFlatItems();
//? if <1.21.5
//Lighting.setupForEntityInInventory();
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
entityRenderDispatcher.setRenderShadow(false);
scopeImpl.draw((vertexConsumers) -> {
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F,
scopeImpl.matrices, vertexConsumers, 15728880);
});
scopeImpl.draw();
entityRenderDispatcher.setRenderShadow(true);
scopeImpl.getMatrixStack().pop();
Lighting.setupFor3DItems();
}
}
@Override
public boolean render(RenderScope renderScope, int width, int height, float yaw) {
LivingEntity entity = SaturnClient.client.player;
if (entity == null) {
return false;
}
// The player is about 1.8 blocks tall; leave some room above and below.
drawEntity(renderScope, 0, 0, width, height, (int) (height / 2.2F), 0.0625F, yaw, entity);
return true;
}
}
*///?}