Improved RenderScope for 1.21.4 #59

This commit is contained in:
2026-03-25 18:23:31 +01:00
parent 57da2f1181
commit 0b469e6a5a
7 changed files with 335 additions and 400 deletions
+1 -1
Submodule common updated: 6873f76c43...c72af1300a
@@ -65,8 +65,8 @@ public class RenderMixin {
ModLayout dim = hud.getDimensions(); ModLayout dim = hud.getDimensions();
scope.getMatrixStack().push(); scope.getMatrixStack().push();
scope.getMatrixStack().translate(dim.x.value, (float) dim.y.value, 0f); scope.getMatrixStack().translate(dim.x.value, (float) dim.y.value);
scope.getMatrixStack().scale(dim.scale.value, dim.scale.value, 1.0f); scope.getMatrixStack().scale(dim.scale.value, dim.scale.value);
if (dim.renderBackground) { if (dim.renderBackground) {
scope.drawRoundedRectangle(0, 0, dim.width, dim.height, scope.drawRoundedRectangle(0, 0, dim.width, dim.height,
@@ -1,59 +1,32 @@
package org.saturnclient.impl.mixins; package org.saturnclient.impl.mixins;
import org.joml.Quaternionf;
import org.saturnclient.common.ref.render.MatrixStackRef; import org.saturnclient.common.ref.render.MatrixStackRef;
import org.saturnclient.common.ref.render.QuaternionfRef;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
@Mixin(MatrixStack.class) @Mixin(MatrixStack.class)
public abstract class MatrixStackMixin implements MatrixStackRef { public abstract class MatrixStackMixin implements MatrixStackRef {
@Shadow
public abstract void translate(double x, double y, double z);
@Shadow @Shadow
public abstract void translate(float x, float y, float z); public abstract void translate(float x, float y, float z);
@Shadow @Shadow
public abstract void scale(float x, float y, float z); public abstract void scale(float x, float y, float z);
@Shadow
public abstract void multiply(Quaternionf quaternion);
@Shadow
public abstract void multiply(Quaternionf quaternion, float originX, float originY, float originZ);
@Shadow @Shadow
public abstract void push(); public abstract void push();
@Shadow @Shadow
public abstract void pop(); public abstract void pop();
@Invoker("peek")
public abstract MatrixStack.Entry peekM();
@Shadow
public abstract boolean isEmpty();
@Shadow
public abstract void loadIdentity();
@Override @Override
public void multiply(QuaternionfRef quaternion) { public void translate(float x, float y) {
this.multiply((Quaternionf) quaternion); translate(x, y, 0);
} }
@Override @Override
public void multiply(QuaternionfRef quaternion, float originX, float originY, float originZ) { public void scale(float x, float y) {
this.multiply((Quaternionf) quaternion, originX, originY, originZ); scale(x, y, 1.0f);
}
@Override
public Object peek() {
return this.peekM();
} }
} }
@@ -3,7 +3,6 @@ package org.saturnclient.impl.ui;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.saturnclient.common.ref.render.QuaternionfRef;
import org.saturnclient.saturnclient.SaturnClient; import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.ui.ElementContext; import org.saturnclient.ui.ElementContext;
import org.saturnclient.ui.RenderScope; import org.saturnclient.ui.RenderScope;
@@ -51,29 +50,30 @@ public class EntityDrawerImpl implements EntityDrawer {
public static void drawEntity(RenderScope renderScope, float x, float y, float size, Vector3f vector3f, public static void drawEntity(RenderScope renderScope, float x, float y, float size, Vector3f vector3f,
Quaternionf quaternionf, @Nullable Quaternionf quaternionf2, LivingEntity entity) { Quaternionf quaternionf, @Nullable Quaternionf quaternionf2, LivingEntity entity) {
renderScope.getMatrixStack().push(); if (renderScope instanceof RenderScopeImpl scopeImpl) {
renderScope.getMatrixStack().translate((double) x, (double) y, 50.0); scopeImpl.matrices.push();
renderScope.getMatrixStack().scale(size, size, -size); scopeImpl.matrices.translate((double) x, (double) y, 0);
renderScope.getMatrixStack().translate(vector3f.x, vector3f.y, vector3f.z); scopeImpl.matrices.scale(size, size, -size);
renderScope.getMatrixStack().multiply((QuaternionfRef) quaternionf); scopeImpl.matrices.translate(vector3f.x, vector3f.y, vector3f.z);
renderScope.draw(); scopeImpl.matrices.multiply(quaternionf);
scopeImpl.draw();
DiffuseLighting.method_34742(); DiffuseLighting.method_34742();
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher(); EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
entityRenderDispatcher.setRenderShadows(false); entityRenderDispatcher.setRenderShadows(false);
if (renderScope instanceof RenderScopeImpl r) { scopeImpl.draw((vertexConsumers) -> {
r.draw((vertexConsumers) -> {
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F, entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F,
r.matrices, vertexConsumers, scopeImpl.matrices, vertexConsumers, 15728880);
15728880);
}); });
}
renderScope.draw(); scopeImpl.draw();
entityRenderDispatcher.setRenderShadows(true); entityRenderDispatcher.setRenderShadows(true);
renderScope.getMatrixStack().pop(); scopeImpl.getMatrixStack().pop();
DiffuseLighting.enableGuiDepthLighting(); DiffuseLighting.enableGuiDepthLighting();
} }
}
@Override @Override
public void render(RenderScope renderScope, boolean negativeAngle, float angle, float scale, ElementContext ctx) { public void render(RenderScope renderScope, boolean negativeAngle, float angle, float scale, ElementContext ctx) {
LivingEntity entity = SaturnClient.client.player; LivingEntity entity = SaturnClient.client.player;
@@ -46,12 +46,18 @@ import net.minecraft.util.math.RotationAxis;
import net.minecraft.world.World; import net.minecraft.world.World;
public class RenderScopeImpl implements RenderScope { public class RenderScopeImpl implements RenderScope {
// ----------------------------
// Fields
// ----------------------------
public MatrixStack matrices; public MatrixStack matrices;
public VertexConsumerProvider.Immediate vertexConsumers; public VertexConsumerProvider.Immediate vertexConsumers;
private ScissorStack scissorStack = new ScissorStack(); private ScissorStack scissorStack = new ScissorStack();
private int opacity = 255 << 24; private int opacity = 255 << 24;
private final ItemRenderState itemRenderState; private final ItemRenderState itemRenderState;
// ----------------------------
// Constructors
// ----------------------------
public RenderScopeImpl(DrawContext context) { public RenderScopeImpl(DrawContext context) {
this(context.getMatrices(), ((DrawContextAccessor) context).getVertexConsumers()); this(context.getMatrices(), ((DrawContextAccessor) context).getVertexConsumers());
} }
@@ -63,11 +69,17 @@ public class RenderScopeImpl implements RenderScope {
this.itemRenderState = new ItemRenderState(); this.itemRenderState = new ItemRenderState();
} }
// ----------------------------
// Matrix & Transform
// ----------------------------
@Override @Override
public MatrixStackRef getMatrixStack() { public MatrixStackRef getMatrixStack() {
return (MatrixStackRef) matrices; return (MatrixStackRef) matrices;
} }
// ----------------------------
// Color & Opacity
// ----------------------------
@Override @Override
public void setOpacity(float alpha) { public void setOpacity(float alpha) {
this.opacity = (int) (alpha * 255) << 24; this.opacity = (int) (alpha * 255) << 24;
@@ -81,132 +93,12 @@ public class RenderScopeImpl implements RenderScope {
return (mixedAlpha << 24) | (color & 0x00FFFFFF); return (mixedAlpha << 24) | (color & 0x00FFFFFF);
} }
// ----------------------------
// Draw / Window Info
// ----------------------------
@Override @Override
public void drawRect(int x, int y, int width, int height, int color) { public void draw() {
if (color == 0) this.vertexConsumers.draw();
return;
color = getColor(color);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
int x1 = x;
int x2 = x + width;
int y1 = y;
int y2 = y + height;
int i;
if (x1 < x2) {
i = x1;
x1 = x2;
x2 = i;
}
if (y1 < y2) {
i = y1;
y1 = y2;
y2 = i;
}
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(RenderLayer.getGui());
vertexConsumer.vertex(matrix4f, (float) x1, (float) y1, 0).color(color);
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, 0).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 0).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0).color(color);
}
@Override
public void drawText(String text, int x, int y, int font, int color) {
drawText(1.0f, text, x, y, font, color);
}
@Override
public void drawText(float scale, String text, int x, int y, int font, int color) {
if (color == 0)
return;
if (font == 0) {
scale *= 2;
}
int i = 0;
for (String line : text.split("\n")) {
color = getColor(color);
matrices.push();
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
matrices.scale(scale, scale, 1.0f);
TextRenderer textRenderer = SaturnClient.client.textRenderer;
textRenderer.draw((Text) Fonts.setFont(line, font), 0,
font == 0 ? 1 : 7, color, false,
this.matrices.peek().getPositionMatrix(),
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
matrices.pop();
i++;
}
}
private void drawRoundedCorner(int width, int height, int radius, int color) {
int w = width * 20;
int h = height * 20;
for (int y = 0; y < h; y++) {
int startX = 0;
if (y < radius) {
double dy = radius - y - 0.5;
double dx = Math.sqrt(Math.max(0, radius * radius - dy * dy));
startX = radius - (int) dx;
}
this.drawRect(startX, y, w - startX, 1, color);
}
}
private void drawRoundedSide(int cornerWidth, int cornerHeight, int radius, int color) {
// Top
this.matrices.push();
this.matrices.scale(0.05f, 0.05f, 1.0f);
this.drawRoundedCorner(cornerWidth, cornerHeight, radius * 10, color);
this.matrices.pop();
// Bottom
this.matrices.push();
this.matrices.translate(cornerWidth, cornerHeight * 2, 0);
this.matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(90));
this.matrices.translate(0, -cornerWidth, 0);
this.matrices.scale(0.05f, 0.05f, 1.0f);
this.drawRoundedCorner(cornerHeight, cornerWidth, radius * 10, color);
this.matrices.pop();
}
@Override
public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) {
if (color == 0)
return;
radius = Math.min(radius, Math.min(width, height));
int cornerWidth = width / 2;
int cornerHeight = height / 2;
this.matrices.push();
this.matrices.translate(x, y, 0);
this.drawRoundedSide(cornerWidth, cornerHeight, radius, color);
this.matrices.translate(cornerWidth * 2, cornerHeight * 2, 0);
this.matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(180));
this.matrices.translate(0, 0, 0);
this.drawRoundedSide(cornerWidth, cornerHeight, radius, color);
this.matrices.pop();
} }
@Override @Override
@@ -219,66 +111,221 @@ public class RenderScopeImpl implements RenderScope {
return SaturnClient.client.getWindow().getScaledHeight(); return SaturnClient.client.getWindow().getScaledHeight();
} }
public void draw(Consumer<VertexConsumerProvider> drawer) {
drawer.accept(this.vertexConsumers);
this.vertexConsumers.draw();
}
// ----------------------------
// Shapes
// ----------------------------
@Override @Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height, int color) { public void drawRectangle(int x, int y, int width, int height, int color) {
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
}
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height) {
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height);
}
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
int regionWith,
int regionHeight, int textureWidth, int textureHeight) {
this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
}
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
int regionWidth,
int regionHeight, int textureWidth, int textureHeight, int color) {
this.drawTexturedQuad((Identifier) (Object) sprite, x, x + width, y, y + height,
(u + 0.0F) / (float) textureWidth,
(u + (float) regionWidth) / (float) textureWidth, (v + 0.0F) / (float) textureHeight,
(v + (float) regionHeight) / (float) textureHeight, color);
}
/* Minecraft sprites */
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int color) {
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
}
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height) {
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height);
}
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith,
int regionHeight, int textureWidth, int textureHeight) {
this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
}
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWidth,
int regionHeight, int textureWidth, int textureHeight, int color) {
this.drawTexturedQuad(sprite, x, x + width, y, y + height, (u + 0.0F) / (float) textureWidth,
(u + (float) regionWidth) / (float) textureWidth, (v + 0.0F) / (float) textureHeight,
(v + (float) regionHeight) / (float) textureHeight, color);
}
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1,
float v2, int color) {
if (sprite.toString().endsWith(".svg")) {
sprite = (Identifier) (Object) SvgTexture.getSvg(Providers.saturn.getClient(),
(IdentifierRef) (Object) sprite,
(x2 - x1) * 2, (y2 - y1) * 2);
}
if (color == 0) if (color == 0)
return; return;
color = getColor(color);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
int x1 = x;
int x2 = x + width;
int y1 = y;
int y2 = y + height;
if (x1 < x2) {
int tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 < y2) {
int tmp = y1;
y1 = y2;
y2 = tmp;
}
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(RenderLayer.getGui());
vertexConsumer.vertex(matrix4f, x1, y1, 0).color(color);
vertexConsumer.vertex(matrix4f, x1, y2, 0).color(color);
vertexConsumer.vertex(matrix4f, x2, y2, 0).color(color);
vertexConsumer.vertex(matrix4f, x2, y1, 0).color(color);
}
@Override
public void fill(int x1, int y1, int x2, int y2, int color) {
fill(x1, y1, x2, y2, 0, color);
}
public void fill(int x1, int y1, int x2, int y2, int z, int color) {
fill(RenderLayer.getGui(), x1, y1, x2, y2, z, color);
}
public void fill(RenderLayer layer, int x1, int y1, int x2, int y2, int color) {
fill(layer, x1, y1, x2, y2, 0, color);
}
public void fill(RenderLayer layer, int x1, int y1, int x2, int y2, int z, int color) {
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
if (x1 < x2) {
int tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 < y2) {
int tmp = y1;
y1 = y2;
y2 = tmp;
}
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(layer);
vertexConsumer.vertex(matrix4f, x1, y1, z).color(color);
vertexConsumer.vertex(matrix4f, x1, y2, z).color(color);
vertexConsumer.vertex(matrix4f, x2, y2, z).color(color);
vertexConsumer.vertex(matrix4f, x2, y1, z).color(color);
}
@Override
public void drawBorder(int x, int y, int width, int height, int color) {
fill(x, y, x + width, y + 1, color);
fill(x, y + height - 1, x + width, y + height, color);
fill(x, y + 1, x + 1, y + height - 1, color);
fill(x + width - 1, y + 1, x + width, y + height - 1, color);
}
@Override
public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) {
if (color == 0)
return;
radius = Math.min(radius, Math.min(width, height));
int cornerWidth = width / 2;
int cornerHeight = height / 2;
matrices.push();
matrices.translate(x, y, 0);
drawRoundedSide(cornerWidth, cornerHeight, radius, color);
matrices.translate(cornerWidth * 2, cornerHeight * 2, 0);
matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(180));
drawRoundedSide(cornerWidth, cornerHeight, radius, color);
matrices.pop();
}
// Rounded rectangle helpers
private void drawRoundedCorner(int width, int height, int radius, int color) {
int w = width * 20;
int h = height * 20;
for (int y = 0; y < h; y++) {
int startX = 0;
if (y < radius) {
double dy = radius - y - 0.5;
double dx = Math.sqrt(Math.max(0, radius * radius - dy * dy));
startX = radius - (int) dx;
}
drawRectangle(startX, y, w - startX, 1, color);
}
}
private void drawRoundedSide(int cornerWidth, int cornerHeight, int radius, int color) {
// Top
matrices.push();
matrices.scale(0.05f, 0.05f, 1.0f);
drawRoundedCorner(cornerWidth, cornerHeight, radius * 10, color);
matrices.pop();
// Bottom
matrices.push();
matrices.translate(cornerWidth, cornerHeight * 2, 0);
matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(90));
matrices.translate(0, -cornerWidth, 0);
matrices.scale(0.05f, 0.05f, 1.0f);
drawRoundedCorner(cornerHeight, cornerWidth, radius * 10, color);
matrices.pop();
}
// ----------------------------
// Text
// ----------------------------
@Override
public void drawText(String text, int x, int y, int font, int color) {
drawText(1.0f, text, x, y, font, color);
}
@Override
public void drawText(float scale, String text, int x, int y, int font, int color) {
if (color == 0)
return;
if (font == 0)
scale *= 2;
int i = 0;
for (String line : text.split("\n")) {
color = getColor(color);
matrices.push();
matrices.translate(x, y + i * Fonts.getHeight(), 0);
matrices.scale(scale, scale, 1.0f);
TextRenderer textRenderer = SaturnClient.client.textRenderer;
textRenderer.draw((Text) Fonts.setFont(line, font), 0, font == 0 ? 1 : 7, color, false,
matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
matrices.pop();
i++;
}
}
// ----------------------------
// Textures & Sprites
// ----------------------------
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height) {
drawTexture(sprite, x, y, u, v, width, height, width, height, width, height);
}
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height, int color) {
drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
}
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
int regionWidth, int regionHeight, int textureWidth, int textureHeight) {
drawTexture(sprite, x, y, u, v, width, height, regionWidth, regionHeight, textureWidth, textureHeight, -1);
}
@Override
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color) {
drawTexturedQuad((Identifier) (Object) sprite, x, x + width, y, y + height,
(u + 0.0f) / textureWidth, (u + regionWidth) / textureWidth,
(v + 0.0f) / textureHeight, (v + regionHeight) / textureHeight, color);
}
@Override
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height) {
drawSpriteStretched(sprite, x, y, width, height, -1);
}
@Override
public void drawSpriteStretched(SpriteRef saturnSprite, int x, int y, int width, int height, int color) {
Sprite sprite = (Sprite) saturnSprite;
if (color == 0)
return;
if (width != 0 && height != 0) {
drawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height,
sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), color);
}
}
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2,
float u1, float u2, float v1, float v2, int color) {
if (sprite.toString().endsWith(".svg")) {
sprite = (Identifier) (Object) SvgTexture.getSvg(Providers.saturn.getClient(),
(IdentifierRef) (Object) sprite, (x2 - x1) * 2, (y2 - y1) * 2);
}
if (color == 0)
return;
x1 *= 4; x1 *= 4;
x2 *= 4; x2 *= 4;
y1 *= 4; y1 *= 4;
@@ -288,58 +335,99 @@ public class RenderScopeImpl implements RenderScope {
matrices.push(); matrices.push();
matrices.scale(0.25f, 0.25f, 1.0f); matrices.scale(0.25f, 0.25f, 1.0f);
RenderSystem.setShaderTexture(0, sprite); RenderSystem.setShaderTexture(0, sprite);
RenderLayer renderLayer = (RenderLayer) RenderLayer.getGuiTextured(sprite); RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix(); Matrix4f matrix4f = matrices.peek().getPositionMatrix();
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer); VertexConsumer vertexConsumer = vertexConsumers.getBuffer(renderLayer);
vertexConsumer.vertex(matrix4f, (float) x1, (float) y1, 0.0F).texture(u1, v1).color(color); vertexConsumer.vertex(matrix4f, x1, y1, 0).texture(u1, v1).color(color);
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, 0.0F).texture(u1, v2).color(color); vertexConsumer.vertex(matrix4f, x1, y2, 0).texture(u1, v2).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 0.0F).texture(u2, v2).color(color); vertexConsumer.vertex(matrix4f, x2, y2, 0).texture(u2, v2).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0.0F).texture(u2, v1).color(color); vertexConsumer.vertex(matrix4f, x2, y1, 0).texture(u2, v1).color(color);
matrices.pop(); matrices.pop();
} }
// ----------------------------
// Items
// ----------------------------
@Override
public void drawItem(ItemStackRef item, int x, int y) {
drawItem(SaturnClient.client.player, SaturnClient.client.world, item, x, y, 0);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStackRef stack, int x, int y,
int seed) {
drawItem(entity, world, (ItemStack) (Object) stack, x, y, seed, 0);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed,
int z) {
if (stack.isEmpty())
return;
SaturnClient.client.getItemModelManager().update(itemRenderState, stack, ModelTransformationMode.GUI,
false, world, entity, seed);
matrices.push();
matrices.translate(x + 8, y + 8, 150 + (itemRenderState.hasDepth() ? z : 0));
try {
matrices.scale(16.0f, -16.0f, 16.0f);
boolean disableLighting = !itemRenderState.isSideLit();
if (disableLighting) {
draw();
DiffuseLighting.disableGuiDepthLighting();
}
itemRenderState.render(matrices, vertexConsumers, 15728880, OverlayTexture.DEFAULT_UV);
draw();
if (disableLighting)
DiffuseLighting.enableGuiDepthLighting();
} catch (Throwable e) {
CrashReport crashReport = CrashReport.create(e, "Rendering item");
CrashReportSection section = crashReport.addElement("Item being rendered");
section.add("Item Type", () -> String.valueOf(stack.getItem()));
section.add("Item Components", () -> String.valueOf(stack.getComponents()));
section.add("Item Foil", () -> String.valueOf(stack.hasGlint()));
throw new CrashException(crashReport);
}
matrices.pop();
}
// ----------------------------
// Scissor / Clipping
// ----------------------------
@Override @Override
public void enableScissor(int x1, int y1, int x2, int y2) { public void enableScissor(int x1, int y1, int x2, int y2) {
ScreenRect screenRect = (new ScreenRect(x1, y1, x2 - x1, y2 - y1)) ScreenRect screenRect = new ScreenRect(x1, y1, x2 - x1, y2 - y1)
.transform(this.matrices.peek().getPositionMatrix()); .transform(matrices.peek().getPositionMatrix());
this.setScissor(this.scissorStack.push(screenRect)); setScissor(scissorStack.push(screenRect));
} }
@Override @Override
public void disableScissor() { public void disableScissor() {
this.setScissor(this.scissorStack.pop()); setScissor(scissorStack.pop());
} }
@Override @Override
public boolean scissorContains(int x, int y) { public boolean scissorContains(int x, int y) {
return this.scissorStack.containsPoint(x, y); return scissorStack.containsPoint(x, y);
} }
private void setScissor(@Nullable ScreenRect rect) { private void setScissor(@Nullable ScreenRect rect) {
this.draw(); draw();
if (rect != null) { if (rect != null) {
Window window = SaturnClient.client.getWindow(); Window window = SaturnClient.client.getWindow();
int i = window.getFramebufferHeight(); int framebufferHeight = window.getFramebufferHeight();
double d = window.getScaleFactor(); double scaleFactor = window.getScaleFactor();
double e = (double) rect.getLeft() * d; RenderSystem.enableScissor(
double f = (double) i - (double) rect.getBottom() * d; (int) (rect.getLeft() * scaleFactor),
double g = (double) rect.width() * d; (int) (framebufferHeight - rect.getBottom() * scaleFactor),
double h = (double) rect.height() * d; Math.max(0, (int) (rect.width() * scaleFactor)),
RenderSystem.enableScissor((int) e, (int) f, Math.max(0, (int) g), Math.max(0, (int) h)); Math.max(0, (int) (rect.height() * scaleFactor)));
} else { } else {
RenderSystem.disableScissor(); RenderSystem.disableScissor();
} }
}
@Override
public void draw() {
this.vertexConsumers.draw();
}
public void draw(Consumer<VertexConsumerProvider> drawer) {
drawer.accept(this.vertexConsumers);
this.vertexConsumers.draw();
} }
static class ScissorStack { static class ScissorStack {
@@ -372,132 +460,4 @@ public class RenderScopeImpl implements RenderScope {
return this.stack.isEmpty() ? true : this.stack.peek().contains(p_329411_, p_333404_); return this.stack.isEmpty() ? true : this.stack.peek().contains(p_329411_, p_333404_);
} }
} }
@Override
public void drawItem(ItemStackRef item, int x, int y) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, item, x, y, 0);
}
@Override
public void drawItem(ItemStackRef stack, int x, int y, int seed) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, stack, x, y, seed);
}
@Override
public void drawItem(ItemStackRef stack, int x, int y, int seed, int z) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, (ItemStack) (Object) stack, x, y, seed, z);
}
@Override
public void drawItemWithoutEntity(ItemStackRef stack, int x, int y) {
this.drawItemWithoutEntity(stack, x, y, 0);
}
@Override
public void drawItemWithoutEntity(ItemStackRef stack, int x, int y, int seed) {
this.drawItem((LivingEntity) null, SaturnClient.client.world, stack, x, y, seed);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStackRef stack, int x, int y,
int seed) {
this.drawItem(entity, world, (ItemStack) (Object) stack, x, y, seed, 0);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed,
int z) {
if (!stack.isEmpty()) {
SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ModelTransformationMode.GUI,
false, world, entity, seed);
this.matrices.push();
this.matrices.translate((float) (x + 8), (float) (y + 8),
(float) (150 + (this.itemRenderState.hasDepth() ? z : 0)));
try {
this.matrices.scale(16.0F, -16.0F, 16.0F);
boolean bl = !this.itemRenderState.isSideLit();
if (bl) {
this.draw();
DiffuseLighting.disableGuiDepthLighting();
}
this.itemRenderState.render(this.matrices, this.vertexConsumers, 15728880, OverlayTexture.DEFAULT_UV);
this.draw();
if (bl) {
DiffuseLighting.enableGuiDepthLighting();
}
} catch (Throwable var11) {
CrashReport crashReport = CrashReport.create(var11, "Rendering item");
CrashReportSection crashReportSection = crashReport.addElement("Item being rendered");
crashReportSection.add("Item Type", () -> {
return String.valueOf(stack.getItem());
});
crashReportSection.add("Item Components", () -> {
return String.valueOf(stack.getComponents());
});
crashReportSection.add("Item Foil", () -> {
return String.valueOf(stack.hasGlint());
});
throw new CrashException(crashReport);
}
this.matrices.pop();
}
}
@Override
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height) {
this.drawSpriteStretched(sprite, x, y, width, height, -1);
}
@Override
public void drawSpriteStretched(SpriteRef saturnSprite, int x, int y, int width, int height, int color) {
Sprite sprite = (Sprite) saturnSprite;
if (color == 0)
return;
if (width != 0 && height != 0) {
this.drawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height, sprite.getMinU(), sprite.getMaxU(),
sprite.getMinV(), sprite.getMaxV(), color);
}
}
public void fill(int x1, int y1, int x2, int y2, int color) {
this.fill(x1, y1, x2, y2, 0, color);
}
public void fill(int x1, int y1, int x2, int y2, int z, int color) {
this.fill(RenderLayer.getGui(), x1, y1, x2, y2, z, color);
}
public void fill(RenderLayer layer, int x1, int y1, int x2, int y2, int color) {
this.fill(layer, x1, y1, x2, y2, 0, color);
}
public void fill(RenderLayer layer, int x1, int y1, int x2, int y2, int z, int color) {
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
int i;
if (x1 < x2) {
i = x1;
x1 = x2;
x2 = i;
}
if (y1 < y2) {
i = y1;
y1 = y2;
y2 = i;
}
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(layer);
vertexConsumer.vertex(matrix4f, (float) x1, (float) y1, (float) z).color(color);
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, (float) z).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, (float) z).color(color);
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, (float) z).color(color);
}
public void drawBorder(int x, int y, int width, int height, int color) {
this.fill(x, y, x + width, y + 1, color);
this.fill(x, y + height - 1, x + width, y + height, color);
this.fill(x, y + 1, x + 1, y + height - 1, color);
this.fill(x + width - 1, y + 1, x + width, y + height - 1, color);
}
} }
@@ -82,7 +82,7 @@ public class RenderScopeImpl implements RenderScope {
} }
@Override @Override
public void drawRect(int x, int y, int width, int height, int color) { public void drawRectangle(int x, int y, int width, int height, int color) {
if (color == 0) if (color == 0)
return; return;
color = getColor(color); color = getColor(color);
@@ -154,7 +154,7 @@ public class RenderScopeImpl implements RenderScope {
startX = radius - (int) dx; startX = radius - (int) dx;
} }
this.drawRect(startX, y, w - startX, 1, color); this.drawRectangle(startX, y, w - startX, 1, color);
} }
} }
@@ -405,7 +405,8 @@ public class RenderScopeImpl implements RenderScope {
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed, private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed,
int z) { int z) {
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ItemDisplayContext.GUI, world, entity, seed); SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ItemDisplayContext.GUI, world,
entity, seed);
this.matrices.push(); this.matrices.push();
this.matrices.translate((float) (x + 8), (float) (y + 8), this.matrices.translate((float) (x + 8), (float) (y + 8),
(float) (150 + z)); // always has depth (float) (150 + z)); // always has depth
@@ -102,7 +102,7 @@ public class RenderScopeImpl implements RenderScope {
} }
@Override @Override
public void drawRect(int x, int y, int width, int height, int color) { public void drawRectangle(int x, int y, int width, int height, int color) {
if (color == 0) if (color == 0)
return; return;
color = getColor(color); color = getColor(color);
@@ -166,7 +166,7 @@ public class RenderScopeImpl implements RenderScope {
startX = radius - (int) dx; startX = radius - (int) dx;
} }
this.drawRect(startX, y, w - startX, 1, color); this.drawRectangle(startX, y, w - startX, 1, color);
} }
} }
@@ -300,7 +300,8 @@ public class RenderScopeImpl implements RenderScope {
} }
this.state.addSimpleElement(new TexturedQuadGuiElementRenderState(RenderPipelines.GUI, this.state.addSimpleElement(new TexturedQuadGuiElementRenderState(RenderPipelines.GUI,
TextureSetup.withoutGlTexture(gpuTextureView), new Matrix3x2f(this.matrices.stack), x1, y1, x2, y2, u1, u2, TextureSetup.withoutGlTexture(gpuTextureView), new Matrix3x2f(this.matrices.stack), x1, y1, x2, y2, u1,
u2,
v1, v2, v1, v2,
color, this.scissorStack.peekLast())); color, this.scissorStack.peekLast()));
} }