From f3aa1c26ebdbe6d4a6cdd358599deec1b580e224 Mon Sep 17 00:00:00 2001 From: Mixces Date: Mon, 6 May 2024 23:32:58 -0500 Subject: [PATCH] Overhaul part 1! :eyes: --- gradle.properties | 2 +- root.gradle.kts | 8 +- settings.gradle.kts | 6 +- .../glintcolorizer/GlintColorizer.java | 36 ----- .../glintcolorizer/RenderItemHook.java | 8 - .../glintcolorizer/command/GlintCommand.java | 17 -- .../glintcolorizer/config/GlintConfig.java | 53 ------ .../mixin/ForgeHooksClientMixin.java | 25 +++ .../mixin/LayerArmorBaseMixin.java | 23 ++- .../mixin/OverflowGlintHandlerMixin.java | 33 ---- .../glintcolorizer/mixin/RenderItemMixin.java | 96 ----------- .../RenderItemMixin_GlintCustomizer.java | 136 ++++++++++++++++ .../mixin/RenderItemMixin_ShinyEffect.java | 141 ++++++++++++++++ .../mixin/accessor/RenderItemAccessor.java | 13 ++ .../glintcolorizer/GlintColorizer.kt | 32 ++++ .../glintcolorizer/command/GlintCommand.kt | 19 +++ .../glintcolorizer/config/GlintConfig.kt | 153 ++++++++++++++++++ .../glintcolorizer/hook/RenderItemHook.kt | 42 +++++ src/main/resources/mixins.glintcolorizer.json | 8 +- 19 files changed, 586 insertions(+), 265 deletions(-) delete mode 100644 src/main/java/org/polyfrost/glintcolorizer/GlintColorizer.java delete mode 100644 src/main/java/org/polyfrost/glintcolorizer/RenderItemHook.java delete mode 100644 src/main/java/org/polyfrost/glintcolorizer/command/GlintCommand.java delete mode 100644 src/main/java/org/polyfrost/glintcolorizer/config/GlintConfig.java create mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/ForgeHooksClientMixin.java delete mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/OverflowGlintHandlerMixin.java delete mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin.java create mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java create mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java create mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/accessor/RenderItemAccessor.java create mode 100644 src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt create mode 100644 src/main/kotlin/org/polyfrost/glintcolorizer/command/GlintCommand.kt create mode 100644 src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt create mode 100644 src/main/kotlin/org/polyfrost/glintcolorizer/hook/RenderItemHook.kt diff --git a/gradle.properties b/gradle.properties index 101317e..865b155 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ mod_name = GlintColorizer mod_id = glintcolorizer -mod_version = 1.0.2 +mod_version = 1.1.2 mod_archives_name = GlintColorizer # Gradle Configuration -- DO NOT TOUCH THESE VALUES. diff --git a/root.gradle.kts b/root.gradle.kts index 6246bdf..14f143c 100644 --- a/root.gradle.kts +++ b/root.gradle.kts @@ -5,7 +5,9 @@ plugins { } preprocess { - "1.12.2-forge"(11202, "srg") { - "1.8.9-forge"(10809, "srg", rootProject.file("versions/1.12.2-1.8.9.txt")) - } +// "1.12.2-forge"(11202, "srg") { + "1.8.9-forge"(10809, "srg", +// rootProject.file("versions/1.12.2-1.8.9.txt") + ) +// } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 5c72efc..2c255f2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,8 +20,10 @@ rootProject.buildFileName = "root.gradle.kts" // Adds all of our build target versions to the classpath if we need to add version-specific code. listOf( - "1.8.9-forge", // Update this if you want to remove/add a version, along with `build.gradle.kts` and `root.gradle.kts`. - "1.12.2-forge" + "1.8.9-forge" +// , + // Update this if you want to remove/add a version, along with `build.gradle.kts` and `root.gradle.kts`. +// "1.12.2-forge" ).forEach { version -> include(":$version") project(":$version").apply { diff --git a/src/main/java/org/polyfrost/glintcolorizer/GlintColorizer.java b/src/main/java/org/polyfrost/glintcolorizer/GlintColorizer.java deleted file mode 100644 index 7157f24..0000000 --- a/src/main/java/org/polyfrost/glintcolorizer/GlintColorizer.java +++ /dev/null @@ -1,36 +0,0 @@ -//#if MODERN==0 || FABRIC==1 -package org.polyfrost.glintcolorizer; - -import cc.polyfrost.oneconfig.utils.commands.CommandManager; -import org.polyfrost.glintcolorizer.config.GlintConfig; - -//#if MODERN==0 -import net.minecraftforge.fml.common.Mod; -import org.polyfrost.glintcolorizer.command.GlintCommand; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -//#endif - -//#if MODERN==0 -@Mod(modid = GlintColorizer.ID, name = GlintColorizer.NAME, version = GlintColorizer.VER) -//#endif -public class GlintColorizer { - public static final String NAME = "@NAME@", VER = "@VER@", ID = "@ID@"; - public static GlintConfig config; - - //#if MODERN==0 - @Mod.EventHandler - public void onInit(FMLInitializationEvent event) - //#else - //$$ public void onInit() - //#endif - { - //#if MODERN==1 - //$$ onPreInit(); - //#endif - //#if MODERN==0 - CommandManager.INSTANCE.registerCommand(new GlintCommand()); - //#endif - config = new GlintConfig(); - } -} -//#endif \ No newline at end of file diff --git a/src/main/java/org/polyfrost/glintcolorizer/RenderItemHook.java b/src/main/java/org/polyfrost/glintcolorizer/RenderItemHook.java deleted file mode 100644 index e008f8c..0000000 --- a/src/main/java/org/polyfrost/glintcolorizer/RenderItemHook.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.polyfrost.glintcolorizer; - -import net.minecraft.item.ItemStack; - -public class RenderItemHook { - public static ItemStack itemStack = null; - public static boolean isRenderingGUI = false; -} diff --git a/src/main/java/org/polyfrost/glintcolorizer/command/GlintCommand.java b/src/main/java/org/polyfrost/glintcolorizer/command/GlintCommand.java deleted file mode 100644 index a2122bc..0000000 --- a/src/main/java/org/polyfrost/glintcolorizer/command/GlintCommand.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.polyfrost.glintcolorizer.command; - -//#if MODERN==0 - -import cc.polyfrost.oneconfig.utils.commands.annotations.Command; -import cc.polyfrost.oneconfig.utils.commands.annotations.Main; -import org.polyfrost.glintcolorizer.GlintColorizer; - -@Command(value = "glintcolorizer", description = "Glint Colorizer commands") -public class GlintCommand { - - @Main - public void handle() { - GlintColorizer.config.openGui(); - } -} -//#endif \ No newline at end of file diff --git a/src/main/java/org/polyfrost/glintcolorizer/config/GlintConfig.java b/src/main/java/org/polyfrost/glintcolorizer/config/GlintConfig.java deleted file mode 100644 index e71757c..0000000 --- a/src/main/java/org/polyfrost/glintcolorizer/config/GlintConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -//#if MODERN==0 || FABRIC==1 -package org.polyfrost.glintcolorizer.config; - -import cc.polyfrost.oneconfig.config.Config; -import cc.polyfrost.oneconfig.config.annotations.*; -import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.ModType; -import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator; -import org.polyfrost.glintcolorizer.GlintColorizer; -import net.minecraft.client.Minecraft; - -import java.io.File; - -public class GlintConfig extends Config { - - @Color( - name = "Enchantment Glint Color" - ) - public static OneColor color = new OneColor(-8372020); - - @Switch( - name = "Shiny Potions" - ) - public static boolean potionGlint; - - @Dropdown( - name = "Potion Glint Type", - options = {"Background Only", "All"} - ) - public static int potionGlintType = 0; - - @Button( - name = "Reset Color", - text = "Reset" - ) - Runnable reset = (() -> { - Minecraft.getMinecraft().displayGuiScreen(null); - color = new OneColor(-8372020); - GlintColorizer.config.save(); - GlintColorizer.config.openGui(); - }); - - @Exclude private static final File oldModDir = new File(new File("./W-OVERFLOW"), GlintColorizer.NAME); - - public GlintConfig() { - super(new Mod(GlintColorizer.NAME, ModType.UTIL_QOL, "/glintcolorizer_dark.svg", new VigilanceMigrator(new File(oldModDir, GlintColorizer.ID + ".toml").getPath())), GlintColorizer.ID + ".json"); - initialize(); - - addDependency("potionGlintType", "potionGlint"); - } -} -//#endif \ No newline at end of file diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/ForgeHooksClientMixin.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/ForgeHooksClientMixin.java new file mode 100644 index 0000000..0222c19 --- /dev/null +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/ForgeHooksClientMixin.java @@ -0,0 +1,25 @@ +package org.polyfrost.glintcolorizer.mixin; + +import org.polyfrost.glintcolorizer.hook.RenderItemHook; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraftforge.client.ForgeHooksClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = ForgeHooksClient.class, remap = false) +public class ForgeHooksClientMixin { + + @Inject( + method = "handleCameraTransforms", + at = @At( + value = "HEAD" + ) + ) + private static void glintColorizer$setCameraTransform(IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType, CallbackInfoReturnable cir) { + RenderItemHook.INSTANCE.setTransformType(cameraTransformType); + } + +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/LayerArmorBaseMixin.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/LayerArmorBaseMixin.java index e0d5d56..4c0489d 100644 --- a/src/main/java/org/polyfrost/glintcolorizer/mixin/LayerArmorBaseMixin.java +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/LayerArmorBaseMixin.java @@ -10,22 +10,19 @@ @Mixin(value = LayerArmorBase.class, priority = Integer.MIN_VALUE) public class LayerArmorBaseMixin { - private static final String RENDER_GLINT = - //#if MC<=10809 - "renderGlint"; - //#else - //$$ "renderEnchantedGlint"; - //#endif - @ModifyArgs(method = RENDER_GLINT, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V")) - private - //#if MC>=11200 - //$$ static - //#endif - void modifyColor(Args args) { - int color = GlintConfig.color.getRGB(); + @ModifyArgs( + method = "renderGlint", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V" + ) + ) + private void glintColorizer$modifyArmorColor(Args args) { + int color = GlintConfig.INSTANCE.getArmorColor().getRGB(); args.set(0, (float) ColorUtils.getRed(color) / 255); args.set(1, (float) ColorUtils.getGreen(color) / 255); args.set(2, (float) ColorUtils.getBlue(color) / 255); } + } diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/OverflowGlintHandlerMixin.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/OverflowGlintHandlerMixin.java deleted file mode 100644 index ba8f967..0000000 --- a/src/main/java/org/polyfrost/glintcolorizer/mixin/OverflowGlintHandlerMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.polyfrost.glintcolorizer.mixin; - -import org.polyfrost.glintcolorizer.RenderItemHook; -import org.polyfrost.glintcolorizer.config.GlintConfig; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.item.ItemPotion; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Pseudo -@Mixin(targets = {"org.polyfrost.overflowanimations.handlers.GlintHandler", "cc.polyfrost.overflowanimations.handlers.GlintHandler", "cc.woverflow.overflowanimations.GlintHandler"}) -public class OverflowGlintHandlerMixin { - - @Dynamic("OverflowAnimations") - @ModifyConstant(method = "renderGlint", constant = @Constant(intValue = -8372020)) - private static int modifyGlint(int constant) { - return GlintConfig.color.getRGB(); - } - - @Dynamic("OverflowAnimations") - @Redirect(method = "renderGlint", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;depthFunc(I)V")) - private static void shouldDepthFunc(int factor) { - if (RenderItemHook.isRenderingGUI && RenderItemHook.itemStack.getItem() instanceof ItemPotion && GlintConfig.potionGlint) { - return; - } - GlStateManager.depthFunc(factor); - } -} diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin.java deleted file mode 100644 index ed2b49f..0000000 --- a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.polyfrost.glintcolorizer.mixin; - -import org.polyfrost.glintcolorizer.RenderItemHook; -import org.polyfrost.glintcolorizer.config.GlintConfig; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.resources.model.IBakedModel; -import net.minecraft.item.ItemPotion; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(RenderItem.class) -public abstract class RenderItemMixin { - @Unique - private static final String IBAKEDMODEL = - //#if MC<11200 - "net/minecraft/client/resources/model/IBakedModel"; - //#else - //$$ "net/minecraft/client/renderer/block/model/IBakedModel"; - //#endif - - @Unique - private static final String RENDERITEM = - //#if MC<11200 - "net/minecraft/client/renderer/entity/RenderItem"; - //#else - //$$ "net/minecraft/client/renderer/RenderItem"; - //#endif - - @Unique - private static final String renderItemIntoGui = - //#if MC<11200 - "renderItemIntoGUI"; - //#else - //$$ "renderItemModelIntoGUI"; - //#endif - @Shadow - protected abstract void renderEffect(IBakedModel model); - - @ModifyConstant(method = "renderEffect", constant = @Constant(intValue = -8372020)) - private int modifyGlint(int constant) { - return GlintConfig.color.getRGB(); - } - - @Inject(method = renderItemIntoGui, at = @At("HEAD")) - private void setGUIRenderingTrue(ItemStack stack, int x, int y, - //#if MC>=10800 - //$$ IBakedModel model, - //#endif - CallbackInfo ci) { - RenderItemHook.isRenderingGUI = true; - } - - @Inject(method = renderItemIntoGui, at = @At("TAIL")) - private void setGUIRenderingFalse(ItemStack stack, int x, int y, - //#if MC>=10800 - //$$ IBakedModel model, - //#endif - CallbackInfo ci) { - RenderItemHook.isRenderingGUI = false; - } - - @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;L" + IBAKEDMODEL + ";)V", at = @At("HEAD")) - private void getItemRendering(ItemStack stack, IBakedModel model, CallbackInfo ci) { - RenderItemHook.itemStack = stack; - } - - @Redirect(method = "renderEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;depthFunc(I)V")) - private void shouldDepthFunc(int factor) { - if (RenderItemHook.itemStack.getItem() instanceof ItemPotion && GlintConfig.potionGlint) { - if (RenderItemHook.isRenderingGUI || GlintConfig.potionGlintType == 1) { - return; - } - } - GlStateManager.depthFunc(factor); - } - - @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;L" + IBAKEDMODEL + ";)V", at = @At(value = "INVOKE", target = "L" + RENDERITEM + ";renderModel(L" + IBAKEDMODEL + ";Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) - private void onRenderModel(ItemStack stack, IBakedModel model, CallbackInfo ci) { - if (stack.getItem() instanceof ItemPotion && GlintConfig.potionGlint && RenderItemHook.isRenderingGUI) { - renderEffect(model); - } - } - - @Redirect(method = "renderItem(Lnet/minecraft/item/ItemStack;L" + IBAKEDMODEL + ";)V", at = @At(value = "INVOKE", target = "L" + RENDERITEM + ";renderEffect(L" + IBAKEDMODEL + ";)V")) - private void shouldRender(RenderItem instance, IBakedModel model, ItemStack stack, IBakedModel model2) { - if (RenderItemHook.isRenderingGUI && stack.getItem() instanceof ItemPotion && GlintConfig.potionGlint && GlintConfig.potionGlintType == 0) { - return; - } - renderEffect(model); - } -} diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java new file mode 100644 index 0000000..12e8ed5 --- /dev/null +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java @@ -0,0 +1,136 @@ +package org.polyfrost.glintcolorizer.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import org.polyfrost.glintcolorizer.config.GlintConfig; +import org.polyfrost.glintcolorizer.hook.RenderItemHook; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.resources.model.IBakedModel; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.HashMap; +import java.util.Objects; + +@Mixin(RenderItem.class) +public class RenderItemMixin_GlintCustomizer { + + @Unique private HashMap glintColorizer$cachedColors = new HashMap<>(); + + @Inject( + method = "renderEffect", + at = @At( + value = "HEAD" + ) + ) + private void glintColorizer$push(IBakedModel model, CallbackInfo ci) { + if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } + if (GlintConfig.INSTANCE.getPotionGlintSize() && RenderItemHook.INSTANCE.isRenderingInGUI() && + RenderItemHook.INSTANCE.isPotionItem() && GlintConfig.INSTANCE.getPotionGlintBackground()) { + GlStateManager.pushMatrix(); + } + } + + @Inject( + method = "renderEffect", + at = @At( + value = "TAIL" + ) + ) + private void glintColorizer$pop(IBakedModel model, CallbackInfo ci) { + if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } + if (GlintConfig.INSTANCE.getPotionGlintSize() && RenderItemHook.INSTANCE.isRenderingInGUI() && + RenderItemHook.INSTANCE.isPotionItem() && GlintConfig.INSTANCE.getPotionGlintBackground()) { + GlStateManager.popMatrix(); + } + } + + @ModifyArg( + method = "renderEffect", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderModel(Lnet/minecraft/client/resources/model/IBakedModel;I)V", + ordinal = 0 + ), + index = 1 + ) + private int glintColorizer$modifyColor1(int color) { + if (!GlintConfig.INSTANCE.enabled) { return color; } + if (RenderItemHook.INSTANCE.isRenderingHeld()) { + return GlintConfig.INSTANCE.getHeldColor().getRGB(); + } + if (RenderItemHook.INSTANCE.isRenderingInGUI()) { + if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) { + return glintColorizer$getPotionColor(Objects.requireNonNull(RenderItemHook.INSTANCE.getItemStack())); + } + return GlintConfig.INSTANCE.getGUIcolor().getRGB(); + } + if (RenderItemHook.INSTANCE.isRenderingDropped()) { + return GlintConfig.INSTANCE.getDroppedColor().getRGB(); + } + if (RenderItemHook.INSTANCE.isRenderingFramed()) { + return GlintConfig.INSTANCE.getFramedColor().getRGB(); + } + return color; + +// return GlintConfig.individualStrokes ? GlintConfig.strokeOne.getRGB() : GlintConfig.color.getRGB(); + } + + @ModifyArg( + method = "renderEffect", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderModel(Lnet/minecraft/client/resources/model/IBakedModel;I)V", + ordinal = 1 + ), + index = 1 + ) + private int glintColorizer$modifyColor2(int color) { + if (!GlintConfig.INSTANCE.enabled) { return color; } + if (RenderItemHook.INSTANCE.isRenderingHeld()) { + return GlintConfig.INSTANCE.getHeldColor().getRGB(); + } + if (RenderItemHook.INSTANCE.isRenderingInGUI()) { + if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) { + return glintColorizer$getPotionColor(Objects.requireNonNull(RenderItemHook.INSTANCE.getItemStack())); + } + return GlintConfig.INSTANCE.getGUIcolor().getRGB(); + } + if (RenderItemHook.INSTANCE.isRenderingDropped()) { + return GlintConfig.INSTANCE.getDroppedColor().getRGB(); + } + if (RenderItemHook.INSTANCE.isRenderingFramed()) { + return GlintConfig.INSTANCE.getFramedColor().getRGB(); + } + return color; +// return GlintConfig.INSTANCE.getIndividualStrokes() ? GlintConfig.INSTANCE.getStrokeTwo().getRGB() : GlintConfig.INSTANCE.getColor().getRGB(); + } + + /** + * Adapted from ShinyPots by RoccoDev under the LGPL-3.0 license. + */ + @Unique + private int glintColorizer$getPotionColor(ItemStack item) { + int potionId = item.getMetadata(); + Integer cached = glintColorizer$cachedColors.get(potionId); + if (cached != null) { + return cached; + } else { + int color = Items.potionitem.getColorFromItemStack(item, 0) | 0xFF000000; + glintColorizer$cachedColors.put(potionId, color); + return color; + } + } + +// @Unique +// private void glintColorizer$configColors() { +// +// } + +} diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java new file mode 100644 index 0000000..82dbc70 --- /dev/null +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java @@ -0,0 +1,141 @@ +package org.polyfrost.glintcolorizer.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.ResourceLocation; +import org.polyfrost.glintcolorizer.config.GlintConfig; +import org.polyfrost.glintcolorizer.hook.RenderItemHook; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderItem.class) +public abstract class RenderItemMixin_ShinyEffect { + + @Shadow protected abstract void renderEffect(IBakedModel model); + + @Shadow @Final private static ResourceLocation RES_ITEM_GLINT; + + @Shadow @Final private TextureManager textureManager; + + @Shadow protected abstract void renderModel(IBakedModel model, int color); + + @Inject( + method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", + at = @At( + "HEAD" + ) + ) + private void glintColorizer$setItemRendering(ItemStack stack, IBakedModel model, CallbackInfo ci) { + RenderItemHook.INSTANCE.setItemStack(stack); + } + + @Redirect( + method = "renderEffect", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/GlStateManager;depthFunc(I)V" + ) + ) + private void glintColorizer$disableDepthFunc(int factor) { + if (RenderItemHook.INSTANCE.shouldSkipGlintRendering()) { + GlStateManager.depthFunc(factor); + } + } + + @Inject( + method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderModel(Lnet/minecraft/client/resources/model/IBakedModel;Lnet/minecraft/item/ItemStack;)V" + ) + ) + private void glintColorizer$onRenderModel(ItemStack stack, IBakedModel model, CallbackInfo ci) { + if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } + if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem() && stack.hasEffect()) { + renderEffect(model); + } + } + + @Inject( + method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderModel(Lnet/minecraft/client/resources/model/IBakedModel;Lnet/minecraft/item/ItemStack;)V", + shift = At.Shift.AFTER + ) + ) + private void glintColorizer$onRenderModel2(ItemStack stack, IBakedModel model, CallbackInfo ci) { + if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } + if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem() && stack.hasEffect()) { + GlStateManager.pushMatrix(); + GlStateManager.depthMask(false); + GlStateManager.depthFunc(514); + GlStateManager.disableLighting(); + GlStateManager.blendFunc(768, 1); + this.textureManager.bindTexture(RES_ITEM_GLINT); + GlStateManager.matrixMode(5890); + GlStateManager.pushMatrix(); + GlStateManager.scale(8.0f, 8.0f, 8.0f); + float f = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0f / 8.0f; + GlStateManager.translate(f, 0.0f, 0.0f); + GlStateManager.rotate(-50.0f, 0.0f, 0.0f, 1.0f); + this.renderModel(model, GlintConfig.INSTANCE.getGUIcolor().getRGB()); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.scale(8.0f, 8.0f, 8.0f); + float f1 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0f / 8.0f; + GlStateManager.translate(-f1, 0.0f, 0.0f); + GlStateManager.rotate(10.0f, 0.0f, 0.0f, 1.0f); + this.renderModel(model, GlintConfig.INSTANCE.getGUIcolor().getRGB()); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(5888); + GlStateManager.blendFunc(770, 771); + GlStateManager.enableLighting(); + GlStateManager.depthFunc(515); + GlStateManager.depthMask(true); + this.textureManager.bindTexture(TextureMap.locationBlocksTexture); + GlStateManager.popMatrix(); + } + } + + @Redirect( + method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/resources/model/IBakedModel;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/item/ItemStack;hasEffect()Z" + ) + ) + private boolean glintColorizer$disableRenderEffect(ItemStack instance) { + if (RenderItemHook.INSTANCE.isPotionGlintEnabled() && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem()) { + return !GlintConfig.INSTANCE.getPotionGlintBackground(); + } + return instance.hasEffect(); + } + + @Inject( + method = "renderEffect", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/texture/TextureManager;bindTexture(Lnet/minecraft/util/ResourceLocation;)V", + ordinal = 0 + ) + ) + private void glintColorizer$fullSlotSize(IBakedModel model, CallbackInfo ci) { + if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } + if (GlintConfig.INSTANCE.getPotionGlintSize() && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem()) { + GlStateManager.scale(1.25, 1.25, 1.25); + GlStateManager.translate(-0.1, -0.1, 0.0); + } + } + +} diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/accessor/RenderItemAccessor.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/accessor/RenderItemAccessor.java new file mode 100644 index 0000000..c399b26 --- /dev/null +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/accessor/RenderItemAccessor.java @@ -0,0 +1,13 @@ +package org.polyfrost.glintcolorizer.mixin.accessor; + +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.resources.model.IBakedModel; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(RenderItem.class) +public interface RenderItemAccessor { + + @Invoker void invokeRenderModel(IBakedModel model, int color); + +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt new file mode 100644 index 0000000..bb3709b --- /dev/null +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt @@ -0,0 +1,32 @@ +package org.polyfrost.glintcolorizer + +import cc.polyfrost.oneconfig.utils.commands.CommandManager +import net.minecraftforge.fml.common.Mod +import net.minecraftforge.fml.common.event.FMLInitializationEvent +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent +import org.polyfrost.glintcolorizer.command.GlintCommand +import org.polyfrost.glintcolorizer.config.GlintConfig + +@Mod( + modid = GlintColorizer.ID, + name = GlintColorizer.NAME, + version = GlintColorizer.VER, + modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter" +) +object GlintColorizer { + + const val NAME: String = "@NAME@" + const val VER: String = "@VER@" + const val ID: String = "@ID@" + + @Mod.EventHandler + fun onInit(event: FMLInitializationEvent?) { + GlintConfig + } + + @Mod.EventHandler + fun postInit(event: FMLPostInitializationEvent?) { + CommandManager.INSTANCE.registerCommand(GlintCommand()) + } + +} diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/command/GlintCommand.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/command/GlintCommand.kt new file mode 100644 index 0000000..73bb2ef --- /dev/null +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/command/GlintCommand.kt @@ -0,0 +1,19 @@ +package org.polyfrost.glintcolorizer.command + +import cc.polyfrost.oneconfig.utils.commands.annotations.Command +import cc.polyfrost.oneconfig.utils.commands.annotations.Main +import org.polyfrost.glintcolorizer.GlintColorizer +import org.polyfrost.glintcolorizer.config.GlintConfig + +@Command( + value = GlintColorizer.ID, + description = "Access the " + GlintColorizer.NAME + " GUI." +) +class GlintCommand { + + @Main + fun handle() { + GlintConfig.openGui() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt new file mode 100644 index 0000000..893dc73 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt @@ -0,0 +1,153 @@ +package org.polyfrost.glintcolorizer.config + +import cc.polyfrost.oneconfig.config.Config +import cc.polyfrost.oneconfig.config.annotations.* +import cc.polyfrost.oneconfig.config.core.OneColor +import cc.polyfrost.oneconfig.config.data.Mod +import cc.polyfrost.oneconfig.config.data.ModType +import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator +import net.minecraft.client.Minecraft +import org.polyfrost.glintcolorizer.GlintColorizer +import java.io.File + +object GlintConfig : Config( + Mod( + GlintColorizer.NAME, ModType.UTIL_QOL, "/glintcolorizer_dark.svg", VigilanceMigrator( + File(File(File("./W-OVERFLOW"), GlintColorizer.NAME), GlintColorizer.ID + ".toml").path + ) + ), GlintColorizer.ID + ".json" +) { + + @Button( + name = "Reset Color", + category = "Color", + subcategory = "Color Configuration", + text = "Reset", + description = "Resets ALL custom glint colors." + ) + var reset: Runnable = (Runnable { + Minecraft.getMinecraft().displayGuiScreen(null) + strokeOne = OneColor(-8372020) + strokeTwo = OneColor(-8372020) + GlintConfig.save() + openGui() + }) + + @Button( + name = "Sync Armor Glint With Item Glint", + category = "Color", + subcategory = "Color Configuration", + text = "Sync", + description = "Syncs the armor glint color with the item glint color." + ) + var syncAtoI: Runnable = (Runnable { + Minecraft.getMinecraft().displayGuiScreen(null) + strokeOne = OneColor(-8372020) + strokeTwo = OneColor(-8372020) + save() + openGui() + }) + + @Button( + name = "Sync Item Glint With Armor Glint", + category = "Color", + subcategory = "Color Configuration", + text = "Sync", + description = "Syncs the item glint color with the armor glint color ." + ) + var syncItoA: Runnable = (Runnable { + Minecraft.getMinecraft().displayGuiScreen(null) + strokeOne = OneColor(-8372020) + strokeTwo = OneColor(-8372020) + save() + openGui() + }) + + @Switch( + name = "Modify glint strokes invidiually", + category = "Color" + ) + var individualStrokes: Boolean = false + + @Color( + name = "Held Item Glint Color", + category = "Color", + description = "Modifies the color of the enchantment glint." + ) + var heldColor: OneColor = OneColor(-8372020) + + @Color( + name = "GUI Item Glint Color", + category = "Color", + description = "Modifies the color of the enchantment glint." + ) + var gUIcolor: OneColor = OneColor(-8372020) + + @Color( + name = "Dropped Item Glint Color", + category = "Color", + description = "Modifies the color of the enchantment glint." + ) + var droppedColor: OneColor = OneColor(-8372020) + + @Color( + name = "Framed Item Glint Color", + category = "Color", + description = "Modifies the color of the enchantment glint." + ) + var framedColor: OneColor = OneColor(-8372020) + + @Color( + name = "Armor Glint Color", + category = "Color", + description = "Modifies the color of the enchantment glint." + ) + var armorColor: OneColor = OneColor(-8372020) + + @Color( + name = "Stroke 1 Color", + category = "Color", + description = "Modifies one of the enchantment glint stroke colors." + ) + var strokeOne: OneColor = OneColor(-8372020) + + @Color( + name = "Stroke 2 Color", + category = "Color", + description = "Modifies one of the enchantment glint stroke colors." + ) + var strokeTwo: OneColor = OneColor(-8372020) + + @Switch( + name = "Shiny Potions", + category = "Shiny Pots" + ) + var potionGlint: Boolean = false + + @Checkbox( + name = "Render Over Full Slot", + category = "Shiny Pots" + ) + var potionGlintSize: Boolean = false + + @Checkbox( + name = "Background Slot Only", + category = "Shiny Pots" + ) + var potionGlintBackground: Boolean = false + + @Switch( + name = "Potion Color Based Glint", + category = "Shiny Pots" + ) + var potionBasedColor: Boolean = false + + init { + initialize() + + addDependency("potionGlintType", "potionGlint") + addDependency("strokeOne", "individualStrokes") + addDependency("strokeTwo", "individualStrokes") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/hook/RenderItemHook.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/hook/RenderItemHook.kt new file mode 100644 index 0000000..7fd058b --- /dev/null +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/hook/RenderItemHook.kt @@ -0,0 +1,42 @@ +package org.polyfrost.glintcolorizer.hook + +import net.minecraft.client.renderer.block.model.ItemCameraTransforms +import net.minecraft.item.ItemPotion +import net.minecraft.item.ItemStack +import org.polyfrost.glintcolorizer.config.GlintConfig +import java.util.* + +object RenderItemHook { + + var itemStack: ItemStack? = null + + var transformType: ItemCameraTransforms.TransformType? = null + + private val playerTransforms: EnumSet = EnumSet.of( + ItemCameraTransforms.TransformType.FIRST_PERSON, + ItemCameraTransforms.TransformType.THIRD_PERSON + ) + + fun shouldSkipGlintRendering(): Boolean { + return !isPotionGlintEnabled || !isRenderingInGUI || !isPotionItem + } + + val isPotionGlintEnabled: Boolean + get() = GlintConfig.potionGlint && GlintConfig.enabled + + val isPotionItem: Boolean + get() = itemStack!!.item is ItemPotion && itemStack!!.hasEffect() + + val isRenderingHeld: Boolean + get() = playerTransforms.contains(transformType) + + val isRenderingInGUI: Boolean + get() = transformType == ItemCameraTransforms.TransformType.GUI + + val isRenderingDropped: Boolean + get() = transformType == ItemCameraTransforms.TransformType.GROUND + + val isRenderingFramed: Boolean + get() = transformType == ItemCameraTransforms.TransformType.FIXED + +} diff --git a/src/main/resources/mixins.glintcolorizer.json b/src/main/resources/mixins.glintcolorizer.json index 895c87a..02db05e 100644 --- a/src/main/resources/mixins.glintcolorizer.json +++ b/src/main/resources/mixins.glintcolorizer.json @@ -1,12 +1,14 @@ { - "compatibilityLevel": "${java_level}", + "compatibilityLevel": "JAVA_8", "minVersion": "0.7", "package": "org.polyfrost.glintcolorizer.mixin", "refmap": "mixins.${id}.refmap.json", "mixins": [ + "accessor.RenderItemAccessor", + "ForgeHooksClientMixin", "LayerArmorBaseMixin", - "OverflowGlintHandlerMixin", - "RenderItemMixin" + "RenderItemMixin_GlintCustomizer", + "RenderItemMixin_ShinyEffect" ], "verbose": true } \ No newline at end of file