Build 1.21.5 with Stonecutter from the shared src/
1.21.5 is the first version before the 1.21.6 GUI rewrite, which moved GUI drawing from vertex consumers and a MatrixStack to render states and a 2D Matrix3x2fStack. - RenderScopeImpl and EntityDrawerImpl have two whole implementations, one per side of 1.21.6 (a single >=1.21.6 / else split), instead of conditionals scattered through them. Callers use RenderScopeImpl(context) in every version; 1.21.5's did the same thing through its (matrices, vertexConsumers) constructor. - MatrixStackMixin (MatrixStack as a MatrixStackRef) is real before 1.21.6 and empty from 1.21.6, registered everywhere like NametagsMixin. - DrawContextAccessor exposes the vertex consumers before 1.21.6 and the GUI render state from it. - Smaller changes: fog (BackgroundRenderer vs FogRenderer), the end portal texture arguments (ShaderUtils, now a flat three-way chain), the status effect sprite manager, and getIconId only from 1.21.6. Features 1.21.6+ lacks stay on 1.21.5, with a TODO: the title panorama behind Saturn screens and the background blur (screen.backgroundBlur, see #23). The 1.21.5 jar differs from the old one only in the helpers from earlier steps, the RenderScopeImpl(context) calls, the empty SaturnRenderState and unused Matrix3x2fStackRef, and 1.21.5's dead NameTagMixin (never registered) being gone. 1.21.6-1.21.11 only gain the empty MatrixStackMixin and its impl.mixins.json entry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -31,13 +31,20 @@ public class ShaderUtils {
|
||||
RenderSetup.builder(END_GATEWAY_PIPELINE)
|
||||
.texture("Sampler0", AbstractEndPortalBlockEntityRenderer.SKY_TEXTURE)
|
||||
.texture("Sampler1", AbstractEndPortalBlockEntityRenderer.PORTAL_TEXTURE).build());
|
||||
//?} else {
|
||||
//?} else if >=1.21.6 {
|
||||
/*public static final RenderLayer END_GATEWAY = RenderLayer.of("end_gateway", 1536, false, false,
|
||||
END_GATEWAY_PIPELINE,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(Textures.create().add(EndPortalBlockEntityRenderer.SKY_TEXTURE, false)
|
||||
.add(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false).build())
|
||||
.build(false));
|
||||
*///?} else {
|
||||
/*public static final RenderLayer END_GATEWAY = RenderLayer.of("end_gateway", 1536, false, false,
|
||||
END_GATEWAY_PIPELINE,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(Textures.create().add(EndPortalBlockEntityRenderer.SKY_TEXTURE, false, false)
|
||||
.add(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false, false).build())
|
||||
.build(false));
|
||||
*///?}
|
||||
|
||||
public static RenderLayer getRenderLayer(IdentifierRef texture) {
|
||||
|
||||
+6
@@ -1,13 +1,19 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
//? if >=1.21.6 {
|
||||
import net.minecraft.client.render.fog.FogRenderer;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.BackgroundRenderer;
|
||||
|
||||
import org.saturnclient.mod.mods.NoFogMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
//? if >=1.21.6 {
|
||||
@Mixin(FogRenderer.class)
|
||||
//?} else
|
||||
//@Mixin(BackgroundRenderer.class)
|
||||
public class BackgroundRendererMixin {
|
||||
// fog
|
||||
@ModifyVariable(method = "applyFog", at = @At("HEAD"), ordinal = 0, argsOnly = true)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
//? if <1.21.6 {
|
||||
/*import org.joml.Quaternionfc;
|
||||
import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
*///?}
|
||||
|
||||
/**
|
||||
* Makes MatrixStack a MatrixStackRef, for GUI drawing before 1.21.6. From 1.21.6 the GUI uses a 2D
|
||||
* Matrix3x2fStack (Matrix3x2fStackRef) instead, so this mixin is empty but stays registered, keeping
|
||||
* impl.mixins.json the same for every version.
|
||||
*/
|
||||
@Mixin(MatrixStack.class)
|
||||
//? if <1.21.6 {
|
||||
/*public abstract class MatrixStackMixin implements MatrixStackRef {
|
||||
@Shadow
|
||||
public abstract void push();
|
||||
|
||||
@Shadow
|
||||
public abstract void pop();
|
||||
|
||||
@Shadow
|
||||
public abstract void translate(float x, float y, float z);
|
||||
|
||||
@Shadow
|
||||
public abstract void scale(float x, float y, float z);
|
||||
|
||||
@Shadow
|
||||
public abstract void multiply(Quaternionfc quaternion);
|
||||
|
||||
@Shadow
|
||||
public abstract void multiply(Quaternionfc quaternion, float originX, float originY, float originZ);
|
||||
|
||||
@Override
|
||||
public void translate(float x, float y) {
|
||||
translate(x, y, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scale(float x, float y) {
|
||||
scale(x, y, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle, float originX, float originY, float originZ) {
|
||||
multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(angle), originX, originY, originZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle) {
|
||||
multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(angle));
|
||||
}
|
||||
}
|
||||
*///?} else
|
||||
public abstract class MatrixStackMixin {}
|
||||
@@ -34,16 +34,21 @@ public abstract class StatusEffectMixin implements EffectRef {
|
||||
// 1.21.9 changed the GUI atlas, so newer versions draw the effect's texture (getIconId) instead.
|
||||
//? if >=1.21.9 {
|
||||
return null;
|
||||
//?} else
|
||||
//?} else if >=1.21.6 {
|
||||
//return (SpriteRef) SaturnClient.client.getGuiAtlasManager().getSprite((InGameHud.getEffectTexture(getEffectType())));
|
||||
//?} else
|
||||
//return (SpriteRef) SaturnClient.client.getStatusEffectSpriteManager().getSprite(getEffectType());
|
||||
}
|
||||
|
||||
// Before 1.21.6 there's no InGameHud.getEffectTexture; getIcon's sprite is used there instead.
|
||||
//? if >=1.21.6 {
|
||||
@Override
|
||||
public IdentifierRef getIconId() {
|
||||
Identifier id = InGameHud.getEffectTexture(getEffectType());
|
||||
|
||||
return IdentifierRef.of(id.getNamespace(), "textures/" + id.getPath() + ".png");
|
||||
}
|
||||
//?}
|
||||
|
||||
@Override
|
||||
public String getInfiniteText() {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
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;
|
||||
@@ -75,3 +78,88 @@ public class EntityDrawerImpl implements EntityDrawer {
|
||||
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.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
|
||||
|
||||
import net.minecraft.client.render.DiffuseLighting;
|
||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class EntityDrawerImpl implements EntityDrawer {
|
||||
public static void drawEntity(RenderScope renderScope, 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;
|
||||
renderScope.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.lastHeadYaw;
|
||||
float o = entity.headYaw;
|
||||
entity.setYaw(angle);
|
||||
entity.bodyYaw = angle;
|
||||
entity.setPitch(-(j * 20.0F));
|
||||
entity.headYaw = negativeAngle ? (i * 40.0F) + 180f : -(i * 40.0F);
|
||||
entity.lastHeadYaw = 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(renderScope, g, h, q, vector3f, quaternionf, null, entity);
|
||||
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.bodyYaw = k;
|
||||
entity.setYaw(l);
|
||||
entity.setPitch(m);
|
||||
entity.lastHeadYaw = n;
|
||||
entity.headYaw = 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.push();
|
||||
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.multiply(quaternionf);
|
||||
scopeImpl.draw();
|
||||
DiffuseLighting.disableGuiDepthLighting();
|
||||
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
|
||||
|
||||
entityRenderDispatcher.setRenderShadows(false);
|
||||
scopeImpl.draw((vertexConsumers) -> {
|
||||
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F,
|
||||
scopeImpl.matrices, vertexConsumers, 15728880);
|
||||
});
|
||||
|
||||
scopeImpl.draw();
|
||||
entityRenderDispatcher.setRenderShadows(true);
|
||||
scopeImpl.getMatrixStack().pop();
|
||||
DiffuseLighting.enableGuiDepthLighting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope renderScope, boolean negativeAngle, float angle, float scale, ElementContext ctx) {
|
||||
LivingEntity entity = SaturnClient.client.player;
|
||||
if (entity != null) {
|
||||
drawEntity(renderScope, 0, 0, 75, 78, 30, 0.0625F, ctx.mouseX / scale, ctx.mouseY / scale, entity, angle,
|
||||
negativeAngle);
|
||||
}
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.saturnclient.impl.ui;
|
||||
|
||||
// 1.21.6 rewrote GUI rendering: render states and a 2D matrix stack (Matrix3x2fStack) instead of
|
||||
// drawing into vertex consumers with a MatrixStack. This file has one implementation for each side.
|
||||
//? if >=1.21.6 {
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Objects;
|
||||
@@ -361,4 +364,416 @@ public class RenderScopeImpl implements RenderScope {
|
||||
overrideCameraAngle, adjustedX1, adjustedY1, adjustedX2, adjustedY2, adjustedScale,
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
}
|
||||
}
|
||||
//?} else {
|
||||
/*import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.asset.SpriteRef;
|
||||
import org.saturnclient.common.ref.game.ItemStackRef;
|
||||
import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.resources.Fonts;
|
||||
import org.saturnclient.ui.resources.SvgTexture;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.font.TextRenderer.TextLayerType;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.ScreenRect;
|
||||
import net.minecraft.client.render.DiffuseLighting;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.ItemRenderState;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemDisplayContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import net.minecraft.util.crash.CrashReportSection;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RenderScopeImpl implements RenderScope {
|
||||
// ----------------------------
|
||||
// Fields
|
||||
// ----------------------------
|
||||
public MatrixStack matrices;
|
||||
public VertexConsumerProvider.Immediate vertexConsumers;
|
||||
private ScissorStack scissorStack = new ScissorStack();
|
||||
private int opacity = 255 << 24;
|
||||
private final ItemRenderState itemRenderState;
|
||||
|
||||
// ----------------------------
|
||||
// Constructors
|
||||
// ----------------------------
|
||||
public RenderScopeImpl(DrawContext context) {
|
||||
this(context.getMatrices(), ((DrawContextAccessor) context).getVertexConsumers());
|
||||
}
|
||||
|
||||
public RenderScopeImpl(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers) {
|
||||
this.matrices = matrices;
|
||||
this.vertexConsumers = vertexConsumers;
|
||||
this.scissorStack = new ScissorStack();
|
||||
this.itemRenderState = new ItemRenderState();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Matrix & Transform
|
||||
// ----------------------------
|
||||
@Override
|
||||
public MatrixStackRef getMatrixStack() {
|
||||
return (MatrixStackRef) matrices;
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Color & Opacity
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void setOpacity(float alpha) {
|
||||
this.opacity = (int) (alpha * 255) << 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(int color) {
|
||||
int originalAlpha = (color >>> 24) & 0xFF;
|
||||
int newAlpha = (opacity >>> 24) & 0xFF;
|
||||
int mixedAlpha = (originalAlpha * newAlpha) / 255;
|
||||
return (mixedAlpha << 24) | (color & 0x00FFFFFF);
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Draw / Window Info
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void draw() {
|
||||
this.vertexConsumers.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowWidth() {
|
||||
return SaturnClient.client.getWindow().getScaledWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowHeight() {
|
||||
return SaturnClient.client.getWindow().getScaledHeight();
|
||||
}
|
||||
|
||||
public void draw(Consumer<VertexConsumerProvider> drawer) {
|
||||
drawer.accept(this.vertexConsumers);
|
||||
this.vertexConsumers.draw();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Shapes
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void drawRectangle(int x, int y, int width, int height, int color) {
|
||||
if (color == 0)
|
||||
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);
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// 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((IdentifierRef) (Object) sprite, (x2 - x1) * 2,
|
||||
(y2 - y1) * 2);
|
||||
}
|
||||
if (color == 0)
|
||||
return;
|
||||
|
||||
x1 *= 4;
|
||||
x2 *= 4;
|
||||
y1 *= 4;
|
||||
y2 *= 4;
|
||||
color = getColor(color);
|
||||
|
||||
matrices.push();
|
||||
matrices.scale(0.25f, 0.25f, 1.0f);
|
||||
RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite);
|
||||
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
|
||||
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, 0).texture(u1, v1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, 0).texture(u1, v2).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, 0).texture(u2, v2).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, 0).texture(u2, v1).color(color);
|
||||
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, ItemDisplayContext.GUI, world, entity,
|
||||
seed);
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
SaturnClient.client.getItemModelManager().clearAndUpdate(this.itemRenderState, stack,
|
||||
ItemDisplayContext.GUI, world,
|
||||
entity, seed);
|
||||
this.matrices.push();
|
||||
this.matrices.translate((float) (x + 8), (float) (y + 8), (float) (150 + z));
|
||||
|
||||
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 throwable) {
|
||||
CrashReport crashReport = CrashReport.create(throwable, "Rendering item");
|
||||
CrashReportSection crashReportSection = crashReport.addElement("Item being rendered");
|
||||
crashReportSection.add("Item Type", () -> String.valueOf(stack.getItem()));
|
||||
crashReportSection.add("Item Components", () -> String.valueOf(stack.getComponents()));
|
||||
crashReportSection.add("Item Foil", () -> String.valueOf(stack.hasGlint()));
|
||||
throw new CrashException(crashReport);
|
||||
}
|
||||
|
||||
this.matrices.pop();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Scissor / Clipping
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void enableScissor(int x1, int y1, int x2, int y2) {
|
||||
ScreenRect screenRect = new ScreenRect(x1, y1, x2 - x1, y2 - y1)
|
||||
.transform(matrices.peek().getPositionMatrix());
|
||||
setScissor(scissorStack.push(screenRect));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableScissor() {
|
||||
setScissor(scissorStack.pop());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scissorContains(int x, int y) {
|
||||
return scissorStack.containsPoint(x, y);
|
||||
}
|
||||
|
||||
private void setScissor(@Nullable ScreenRect rect) {
|
||||
draw();
|
||||
if (rect != null) {
|
||||
Window window = SaturnClient.client.getWindow();
|
||||
int framebufferHeight = window.getFramebufferHeight();
|
||||
double scaleFactor = window.getScaleFactor();
|
||||
RenderSystem.enableScissor(
|
||||
(int) (rect.getLeft() * scaleFactor),
|
||||
(int) (framebufferHeight - rect.getBottom() * scaleFactor),
|
||||
Math.max(0, (int) (rect.width() * scaleFactor)),
|
||||
Math.max(0, (int) (rect.height() * scaleFactor)));
|
||||
} else {
|
||||
RenderSystem.disableScissor();
|
||||
}
|
||||
}
|
||||
|
||||
static class ScissorStack {
|
||||
private final Deque<ScreenRect> stack = new ArrayDeque<>();
|
||||
|
||||
public ScreenRect push(ScreenRect p_281812_) {
|
||||
ScreenRect screenrectangle = this.stack.peekLast();
|
||||
if (screenrectangle != null) {
|
||||
ScreenRect screenrectangle1 = Objects.requireNonNullElse(p_281812_.intersection(screenrectangle),
|
||||
ScreenRect.empty());
|
||||
this.stack.addLast(screenrectangle1);
|
||||
return screenrectangle1;
|
||||
} else {
|
||||
this.stack.addLast(p_281812_);
|
||||
return p_281812_;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ScreenRect pop() {
|
||||
if (this.stack.isEmpty()) {
|
||||
throw new IllegalStateException("Scissor stack underflow");
|
||||
} else {
|
||||
this.stack.removeLast();
|
||||
return this.stack.peekLast();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsPoint(int p_329411_, int p_333404_) {
|
||||
return this.stack.isEmpty() ? true : this.stack.peek().contains(p_329411_, p_333404_);
|
||||
}
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
|
||||
@@ -16,6 +16,11 @@ import net.minecraft.client.gui.RotatingCubeMapRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
//? if >=1.21.9
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
//? if <1.21.6 {
|
||||
/*import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.util.Pool;
|
||||
*///?}
|
||||
import net.minecraft.client.texture.ResourceTexture;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.text.Text;
|
||||
@@ -32,6 +37,8 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
ROTATING_PANORAMA_RENDERER = new RotatingCubeMapRenderer(PANORAMA_RENDERER);
|
||||
}
|
||||
|
||||
//? if <1.21.6
|
||||
//private final Pool pool = new Pool(3);
|
||||
public final SaturnScreen screen;
|
||||
|
||||
public static void preload(MinecraftClient client) {
|
||||
@@ -55,6 +62,8 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
screen.init();
|
||||
}
|
||||
|
||||
//? if <1.21.6
|
||||
//@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
if (screen.start == null) {
|
||||
@@ -65,10 +74,28 @@ public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
mouseX *= 2;
|
||||
mouseY *= 2;
|
||||
|
||||
// TODO: the panorama and the background blur (screen.backgroundBlur) are only drawn before
|
||||
// 1.21.6 so far. See also issue #23.
|
||||
if (client.world == null && client.getCurrentServerEntry() == null) {
|
||||
// ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, true);
|
||||
//? if <1.21.6
|
||||
//ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, screen.backgroundOpacity, delta);
|
||||
}
|
||||
|
||||
//? if <1.21.6 {
|
||||
/*PostEffectProcessor postEffectProcessor = this.client.getShaderLoader().loadPostEffect(
|
||||
Identifier.ofVanilla("blur"),
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
|
||||
if (postEffectProcessor != null) {
|
||||
float radius = screen.backgroundBlur * Math.min((float) elapsed / 700, 1.0f);
|
||||
postEffectProcessor.render(
|
||||
this.client.getFramebuffer(),
|
||||
this.pool,
|
||||
pass -> pass.setUniform("Radius", radius)
|
||||
);
|
||||
}
|
||||
*///?}
|
||||
|
||||
RenderScope renderScope = new RenderScopeImpl(context);
|
||||
|
||||
screen.render(renderScope, mouseX, mouseY, delta, elapsed);
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
package org.saturnclient.saturnclient.mixin;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
//? if >=1.21.6 {
|
||||
import net.minecraft.client.gui.render.state.GuiRenderState;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(DrawContext.class)
|
||||
public interface DrawContextAccessor {
|
||||
//? if >=1.21.6 {
|
||||
@Accessor("state")
|
||||
GuiRenderState getState();
|
||||
//?} else {
|
||||
/*@Accessor("vertexConsumers")
|
||||
VertexConsumerProvider.Immediate getVertexConsumers();
|
||||
*///?}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"client": [
|
||||
"IdentifierMixin",
|
||||
"ItemStackMixin",
|
||||
"MatrixStackMixin",
|
||||
"MinecraftClientMixin",
|
||||
"QuaternionfMixin",
|
||||
"WindowMixin",
|
||||
|
||||
Reference in New Issue
Block a user