From c71fca6cc633416162b2dd010c52182662ceff85 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 18 Oct 2024 16:35:18 +0200 Subject: Add custom inventory text color texture pack support --- .../mixins/ReplaceTextColorInHandledScreen.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/moe/nea/firmament/mixins/ReplaceTextColorInHandledScreen.java (limited to 'src/main/java/moe/nea/firmament') diff --git a/src/main/java/moe/nea/firmament/mixins/ReplaceTextColorInHandledScreen.java b/src/main/java/moe/nea/firmament/mixins/ReplaceTextColorInHandledScreen.java new file mode 100644 index 0000000..190fda0 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/ReplaceTextColorInHandledScreen.java @@ -0,0 +1,43 @@ +package moe.nea.firmament.mixins; + + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import moe.nea.firmament.features.texturepack.CustomTextColors; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ingame.AnvilScreen; +import net.minecraft.client.gui.screen.ingame.BeaconScreen; +import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.client.gui.screen.ingame.MerchantScreen; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin({HandledScreen.class, InventoryScreen.class, CreativeInventoryScreen.class, MerchantScreen.class, + AnvilScreen.class, BeaconScreen.class}) +public class ReplaceTextColorInHandledScreen { + + @WrapOperation( + method = "drawForeground", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/DrawContext;drawText(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;IIIZ)I"), + expect = 0) + private int replaceTextColorWithVariableShadow(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int color, boolean shadow, Operation original) { + return original.call(instance, textRenderer, text, x, y, CustomTextColors.INSTANCE.mapTextColor(text, color), shadow); + } + + @WrapOperation( + method = "drawForeground", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)I"), + expect = 0) + private int replaceTextColorWithShadow(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int color, Operation original) { + return original.call(instance, textRenderer, text, x, y, CustomTextColors.INSTANCE.mapTextColor(text, color)); + } + +} -- cgit