Skip to content

Commit

Permalink
1.21.2 -> 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Nov 14, 2024
1 parent 1f3f975 commit d0f0aab
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 67 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}
}
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
id 'com.modrinth.minotaur' version '2.+'
id 'org.ajoberstar.reckon' version '0.13.1'
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21-pre2
yarn_mappings=1.21-pre2+build.2
loader_version=0.15.11
fabric_version=0.99.4+1.21
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7
fabric_version=0.106.1+1.21.3

# Mod Properties
group=com.minelittlepony
Expand All @@ -15,6 +15,6 @@ org.gradle.daemon=false
description=Embedded common code used across several Mine Little Pony projects to create their GUIs.

# Publishing
minecraft_version_range=>=1.21 <1.21.3
minecraft_version_range=>=1.21.3
modrinth_loader_type=fabric
modrinth_project_id=9aNz8Zqn
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.OrderedText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;

Expand Down Expand Up @@ -38,9 +37,10 @@ default TextRenderer getFont() {
* @param zIndex The Z-index used when layering multiple elements.
*/
default void drawLabel(DrawContext context, Text text, int x, int y, int color, double zIndex) {
context.getMatrices().push();
context.getMatrices().translate(0, 0, zIndex);
getFont().draw(text, x, y, color, true, context.getMatrices().peek().getPositionMatrix(), context.getVertexConsumers(), TextRenderer.TextLayerType.SEE_THROUGH, 0, 0xF000F0);
context.getVertexConsumers().draw();
context.drawText(getFont(), text, x, y, color, false);
context.getMatrices().pop();
}

/**
Expand Down Expand Up @@ -69,12 +69,6 @@ default void drawCenteredLabel(DrawContext context, Text text, int x, int y, int
* @param color The font colour
*/
default void drawTextBlock(DrawContext context, StringVisitable text, int x, int y, int maxWidth, int color) {
for (OrderedText line : getFont().wrapLines(text, maxWidth)) {
float left = x;
getFont().draw(line, left, y, color, false, context.getMatrices().peek().getPositionMatrix(), context.getVertexConsumers(), TextRenderer.TextLayerType.SEE_THROUGH, 0, 0xF000F0);
context.getVertexConsumers().draw();

y += 9;
}
context.drawTextWrapped(getFont(), text, x, y, maxWidth, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public static BlockEntityRenderDispatcher configure(@Nullable World world) {
* @param y The top-Y position (in pixels)
*/
public static void renderStack(DrawContext context, ItemStack stack, int x, int y) {
configure(null);
try {
configure(null);
} catch (Throwable t) {}
context.drawItem(stack, x, y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;

Expand Down Expand Up @@ -148,9 +149,9 @@ protected void onDrag(double mouseX, double mouseY, double mouseDX, double mouse

@Override
protected void renderBackground(DrawContext context, MinecraftClient mc, int mouseX, int mouseY) {
context.drawGuiTexture(TEXTURES.get(false, isSelected()), getX(), getY(), getWidth(), getHeight());
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(false, isSelected()), getX(), getY(), getWidth(), getHeight());
int sliderX = getX() + (int)(value * (getWidth() - 8));
context.drawGuiTexture(TEXTURES.get(active, isSelected()), sliderX, getY(), 8, getHeight());
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(active, isSelected()), sliderX, getY(), 8, getHeight());
}

static float convertFromRange(float value, float min, float max) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.client.gui.tooltip.TooltipPositioner;
import net.minecraft.client.gui.tooltip.TooltipState;
import net.minecraft.client.gui.widget.PressableWidget;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -211,12 +212,12 @@ public boolean isMouseOver(double mouseX, double mouseY) {
@Override
public void renderWidget(DrawContext context, int mouseX, int mouseY, float tickDelta) {
MinecraftClient mc = MinecraftClient.getInstance();
context.setShaderColor(1, 1, 1, alpha);
RenderSystem.setShaderColor(1, 1, 1, alpha);
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();

renderBackground(context, mc, mouseX, mouseY);
context.setShaderColor(1, 1, 1, 1);
RenderSystem.setShaderColor(1, 1, 1, 1);

setMessage(getStyle().getText());
drawIcon(context, mouseX, mouseY, tickDelta);
Expand All @@ -231,7 +232,7 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float tick
}

protected void renderBackground(DrawContext context, MinecraftClient mc, int mouseX, int mouseY) {
context.drawGuiTexture(TEXTURES.get(active, this.isSelected()), getX(), getY(), getWidth(), getHeight());
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(active, this.isSelected()), getX(), getY(), getWidth(), getHeight());
}

protected void drawIcon(DrawContext context, int mouseX, int mouseY, float partialTicks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;

/**
Expand Down Expand Up @@ -69,9 +70,9 @@ public void onPress() {

@Override
protected void renderBackground(DrawContext context, MinecraftClient mc, int mouseX, int mouseY) {
context.drawGuiTexture(TEXTURES.get(false, isSelected()), getX(), getY(), getWidth(), getHeight());
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(false, isSelected()), getX(), getY(), getWidth(), getHeight());
int sliderX = getX() + (on ? getWidth() - 8 : 0);
context.drawGuiTexture(TEXTURES.get(active, isSelected()), sliderX, getY(), 8, getHeight());
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(active, isSelected()), sliderX, getY(), 8, getHeight());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class ItemStackSprite implements ISprite {

private int tint = 0xFFFFFFFF;

private boolean renderFailed;
private boolean needsWorld;

public ItemStackSprite setStack(ItemConvertible iitem) {
return setStack(new ItemStack(iitem));
}
Expand All @@ -32,7 +35,26 @@ public ItemStackSprite setTint(int tint) {

@Override
public void render(DrawContext context, int x, int y, int mouseX, int mouseY, float partialTicks) {
OutsideWorldRenderer.renderStack(context, stack, x + 2, y + 2);
RenderSystem.disableDepthTest();
if (renderFailed) {
return;
}

if (!needsWorld) {
try {
context.drawItem(stack, x, y);
RenderSystem.disableDepthTest();
return;
} catch (Throwable ignored) {
needsWorld = true;
}
}

try {
OutsideWorldRenderer.configure(null);
context.drawItem(stack, x, y);
RenderSystem.disableDepthTest();
} catch (Throwable ignored) {
renderFailed = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minelittlepony.common.client.gui.dimension.Bounds;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.util.Identifier;

public class TextureSprite implements ISprite {
Expand Down Expand Up @@ -48,6 +49,7 @@ public TextureSprite setTextureSize(int width, int height) {
@Override
public void render(DrawContext context, int x, int y, int mouseX, int mouseY, float partialTicks) {
context.drawTexture(
RenderLayer::getGuiTextured,
texture,
x + bounds.left, y + bounds.top,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
import net.minecraft.client.texture.NativeImage;

public interface SkinFilterCallback {
int VANILLA_SKIN_WIDTH = 64;
int VANILLA_SKIN_HEIGHT = 64;
int OLD_VANILLA_SKIN_HEIGHT = 32;

Event<SkinFilterCallback> EVENT = EventFactory.createArrayBacked(SkinFilterCallback.class, listeners -> {
return new SkinFilterCallback() {
@Override
public void processImage(NativeImage image, boolean legacy) {
public NativeImage processImage(NativeImage image, int initialWidth, int initialHeight) {
for (SkinFilterCallback event : listeners) {
event.processImage(image, legacy);
image = event.processImage(image, initialWidth, initialHeight);
}

return image;
}

@Override
public boolean shouldAllowTransparency(NativeImage image, boolean legacy) {
public boolean shouldAllowTransparency(NativeImage image, int initialWidth, int initialHeight) {
for (SkinFilterCallback event : listeners) {
if (event.shouldAllowTransparency(image, legacy)) {
if (event.shouldAllowTransparency(image, initialWidth, initialHeight)) {
return true;
}
}
Expand All @@ -27,12 +33,20 @@ public boolean shouldAllowTransparency(NativeImage image, boolean legacy) {
};
});

void processImage(NativeImage image, boolean legacy);
NativeImage processImage(NativeImage image, int initialWidth, int initialHeight);

default boolean shouldAllowTransparency(NativeImage image, boolean legacy) {
default boolean shouldAllowTransparency(NativeImage image, int initialWidth, int initialHeight) {
return true; // default is true since in most cases this is the desired effect
}

static boolean isLegacyAspectRatio(int width, int height) {
return width == height * 2;
}

static int getResolutionScale(int width, int height) {
return width / VANILLA_SKIN_WIDTH;
}

/**
* Copies a scaled section from one region to another.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,34 @@

@Mixin(PlayerSkinTexture.class)
public abstract class MixinPlayerSkinTexture extends ResourceTexture {

private MixinPlayerSkinTexture() { super(null); }

private static final String FILTER_IMAGE = "remapTexture(Lnet/minecraft/client/texture/NativeImage;)Lnet/minecraft/client/texture/NativeImage;";

private static final String STRIP_COLOR = "stripColor(Lnet/minecraft/client/texture/NativeImage;IIII)V";
private static final String STRIP_ALPHA = "stripAlpha(Lnet/minecraft/client/texture/NativeImage;IIII)V";

private static boolean isLegacy;
private static int initialWidth;
private static int initialHeight;

@Inject(method = FILTER_IMAGE, at = @At("HEAD"))
@Inject(method = "remapTexture", at = @At("HEAD"))
private void beforeUpdate(NativeImage image, CallbackInfoReturnable<NativeImage> info) {
isLegacy = image.getHeight() == 32;
initialWidth = image.getWidth();
initialHeight = image.getHeight();
}

@Inject(method = FILTER_IMAGE, at = @At("RETURN"))
@Inject(method = "remapTexture", at = @At("RETURN"))
private void update(NativeImage image, CallbackInfoReturnable<NativeImage> ci) {
// convert skins from mojang server
SkinFilterCallback.EVENT.invoker().processImage(ci.getReturnValue(), isLegacy);
ci.setReturnValue(SkinFilterCallback.EVENT.invoker().processImage(ci.getReturnValue(), initialWidth, initialHeight));
}

// Sorry, Mahjon. Input validation is good 'n all, but this interferes with our other mods.
@Inject(method = STRIP_ALPHA, at = @At("HEAD"), cancellable = true)
@Inject(method = "stripAlpha", at = @At("HEAD"), cancellable = true)
private static void cancelAlphaStrip(NativeImage image, int beginX, int beginY, int endX, int endY, CallbackInfo info) {
if (SkinFilterCallback.EVENT.invoker().shouldAllowTransparency(image, isLegacy)) {
if (SkinFilterCallback.EVENT.invoker().shouldAllowTransparency(image, initialWidth, initialHeight)) {
info.cancel();
}
}

@Inject(method = STRIP_COLOR, at = @At("HEAD"), cancellable = true)
@Inject(method = "stripColor", at = @At("HEAD"), cancellable = true)
private static void cancelColorStrip(NativeImage image, int beginX, int beginY, int endX, int endY, CallbackInfo info) {
if (SkinFilterCallback.EVENT.invoker().shouldAllowTransparency(image, isLegacy)) {
if (SkinFilterCallback.EVENT.invoker().shouldAllowTransparency(image, initialWidth, initialHeight)) {
info.cancel();
}
}
Expand Down
Loading

0 comments on commit d0f0aab

Please sign in to comment.