diff --git a/build.gradle b/build.gradle index 2071d0cc..3b84bf54 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/gradle.properties b/gradle.properties index c5d435de..f210189e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 @@ -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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 17655d0e..0d184210 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/src/main/java/com/minelittlepony/common/client/gui/ITextContext.java b/src/main/java/com/minelittlepony/common/client/gui/ITextContext.java index 39826fc0..8f927f1d 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/ITextContext.java +++ b/src/main/java/com/minelittlepony/common/client/gui/ITextContext.java @@ -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; @@ -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(); } /** @@ -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); } } diff --git a/src/main/java/com/minelittlepony/common/client/gui/OutsideWorldRenderer.java b/src/main/java/com/minelittlepony/common/client/gui/OutsideWorldRenderer.java index 12c3094c..4cb7316f 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/OutsideWorldRenderer.java +++ b/src/main/java/com/minelittlepony/common/client/gui/OutsideWorldRenderer.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/common/client/gui/element/AbstractSlider.java b/src/main/java/com/minelittlepony/common/client/gui/element/AbstractSlider.java index a345237b..540297dc 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/element/AbstractSlider.java +++ b/src/main/java/com/minelittlepony/common/client/gui/element/AbstractSlider.java @@ -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; @@ -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) { diff --git a/src/main/java/com/minelittlepony/common/client/gui/element/Button.java b/src/main/java/com/minelittlepony/common/client/gui/element/Button.java index 146381e6..988461a3 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/element/Button.java +++ b/src/main/java/com/minelittlepony/common/client/gui/element/Button.java @@ -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; @@ -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); @@ -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) { diff --git a/src/main/java/com/minelittlepony/common/client/gui/element/Toggle.java b/src/main/java/com/minelittlepony/common/client/gui/element/Toggle.java index 8532b322..1a0286de 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/element/Toggle.java +++ b/src/main/java/com/minelittlepony/common/client/gui/element/Toggle.java @@ -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; /** @@ -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 diff --git a/src/main/java/com/minelittlepony/common/client/gui/sprite/ItemStackSprite.java b/src/main/java/com/minelittlepony/common/client/gui/sprite/ItemStackSprite.java index 142a1118..b359d1ba 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/sprite/ItemStackSprite.java +++ b/src/main/java/com/minelittlepony/common/client/gui/sprite/ItemStackSprite.java @@ -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)); } @@ -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; + } } } diff --git a/src/main/java/com/minelittlepony/common/client/gui/sprite/TextureSprite.java b/src/main/java/com/minelittlepony/common/client/gui/sprite/TextureSprite.java index ad32e511..930b31f0 100644 --- a/src/main/java/com/minelittlepony/common/client/gui/sprite/TextureSprite.java +++ b/src/main/java/com/minelittlepony/common/client/gui/sprite/TextureSprite.java @@ -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 { @@ -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, diff --git a/src/main/java/com/minelittlepony/common/event/SkinFilterCallback.java b/src/main/java/com/minelittlepony/common/event/SkinFilterCallback.java index 8478e73a..c4b4a7d9 100644 --- a/src/main/java/com/minelittlepony/common/event/SkinFilterCallback.java +++ b/src/main/java/com/minelittlepony/common/event/SkinFilterCallback.java @@ -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 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; } } @@ -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. * diff --git a/src/main/java/com/minelittlepony/common/mixin/MixinPlayerSkinTexture.java b/src/main/java/com/minelittlepony/common/mixin/MixinPlayerSkinTexture.java index be440b2c..621cb31e 100644 --- a/src/main/java/com/minelittlepony/common/mixin/MixinPlayerSkinTexture.java +++ b/src/main/java/com/minelittlepony/common/mixin/MixinPlayerSkinTexture.java @@ -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 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 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(); } } diff --git a/src/main/java/com/minelittlepony/common/util/Color.java b/src/main/java/com/minelittlepony/common/util/Color.java index 200bd35c..66651a3a 100644 --- a/src/main/java/com/minelittlepony/common/util/Color.java +++ b/src/main/java/com/minelittlepony/common/util/Color.java @@ -1,7 +1,6 @@ package com.minelittlepony.common.util; import net.minecraft.util.math.ColorHelper; -import net.minecraft.util.math.MathHelper; /** * Colouration Utilities @@ -11,65 +10,72 @@ public interface Color { * Returns the ALPHA channel for the given colour hex code. */ static float a(int hex) { - return ColorHelper.Argb.getAlpha(hex) / 255F; + return ColorHelper.floatFromChannel(ColorHelper.getAlpha(hex)); } /** * Returns the RED channel for the given colour hex code. */ static float r(int hex) { - return ColorHelper.Argb.getRed(hex) / 255F; + return ColorHelper.floatFromChannel(ColorHelper.getRed(hex)); } /** * Returns the GREEN channel for the given colour hex code. */ static float g(int hex) { - return ColorHelper.Argb.getGreen(hex) / 255F; + return ColorHelper.floatFromChannel(ColorHelper.getGreen(hex)); } /** * Returns the BLUE channel for the given colour hex code. */ static float b(int hex) { - return ColorHelper.Argb.getBlue(hex) / 255F; + return ColorHelper.floatFromChannel(ColorHelper.getBlue(hex)); } /** * Converts the given rgb floats on a range of 0-1 into a colour hex code. + * + * @Deprecated(since = "1.19.4", forRemoval = true) */ + @Deprecated(since = "1.19.4", forRemoval = true) static int argbToHex(float a, float r, float g, float b) { - return ColorHelper.Argb.getArgb((int)(a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255)); + return ColorHelper.fromFloats(a, r, g, b); } /** * Converts the given rbg int on a range of 0-255 into a colour hex code. + * + * @deprecated Will be removed in MC1.22 */ + @Deprecated(since = "1.19.4", forRemoval = true) static int argbToHex(int a, int r, int g, int b) { - return ColorHelper.Argb.getArgb(a, r, g, b); + return ColorHelper.getArgb(a, r, g, b); } /** * Converts a colour hex code from BGR to RGB (and back). + * + * @deprecated Will be removed in MC1.22 */ + @Deprecated static int abgrToArgb(int color) { - return ColorHelper.Argb.getArgb( - ColorHelper.Argb.getAlpha(color), - ColorHelper.Argb.getBlue(color), - ColorHelper.Argb.getGreen(color), - ColorHelper.Argb.getRed(color) + return ColorHelper.getArgb( + ColorHelper.getAlpha(color), + ColorHelper.getBlue(color), + ColorHelper.getGreen(color), + ColorHelper.getRed(color) ); } /** * Interpolates between two colours + * + * @deprecated Will be removed in MC1.22 */ + @Deprecated(since = "1.19.4", forRemoval = true) static int lerp(float delta, int from, int to) { - return argbToHex( - MathHelper.lerp(delta, a(from), a(to)), - MathHelper.lerp(delta, r(from), r(to)), - MathHelper.lerp(delta, g(from), g(to)), - MathHelper.lerp(delta, b(from), b(to)) - ); + return ColorHelper.lerp(delta, from, to); } } diff --git a/src/main/java/com/minelittlepony/common/util/registry/RegistryTypeAdapter.java b/src/main/java/com/minelittlepony/common/util/registry/RegistryTypeAdapter.java index ad575f00..a07db4fb 100644 --- a/src/main/java/com/minelittlepony/common/util/registry/RegistryTypeAdapter.java +++ b/src/main/java/com/minelittlepony/common/util/registry/RegistryTypeAdapter.java @@ -28,7 +28,7 @@ public T read(JsonReader in) throws IOException { return null; } String ls = s.toLowerCase(Locale.US); - return registry.getOrEmpty(Identifier.of(ls)).orElseGet(() -> defaultValue.apply(ls, registry)); + return registry.getOptionalValue(Identifier.of(ls)).orElseGet(() -> defaultValue.apply(ls, registry)); } }; }