From 6027c853b9e4d45b44d30edd5c5be2d0c6ce86b0 Mon Sep 17 00:00:00 2001 From: Mixces Date: Sun, 19 May 2024 22:55:53 -0500 Subject: [PATCH] Improve clarity of code a little. --- .../RenderItemMixin_GlintCustomizer.java | 91 +++++++++---------- .../mixin/RenderItemMixin_ShinyEffect.java | 15 +-- .../glintcolorizer/GlintColorizer.kt | 3 + .../glintcolorizer/config/GlintConfig.kt | 49 ++++++---- 4 files changed, 87 insertions(+), 71 deletions(-) diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java index 1ce4f0e..b15796f 100644 --- a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_GlintCustomizer.java @@ -15,37 +15,25 @@ 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<>(); + @Unique + private final HashMap glintColorizer$cachedColors = new HashMap<>(); - @Inject( - method = "renderEffect", - at = @At( - value = "HEAD" - ) - ) + @Inject(method = "renderEffect", at = @At("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.getPotionGlintForeground() || GlintConfig.INSTANCE.getPotionGlintBackground())) { + if (glintColorizer$shouldApplyMatrix()) { GlStateManager.pushMatrix(); } } - @Inject( - method = "renderEffect", - at = @At( - value = "TAIL" - ) - ) + @Inject(method = "renderEffect", at = @At("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.getPotionGlintForeground() || GlintConfig.INSTANCE.getPotionGlintBackground())) { + if (glintColorizer$shouldApplyMatrix()) { GlStateManager.popMatrix(); } } @@ -61,26 +49,7 @@ public class RenderItemMixin_GlintCustomizer { ) private int glintColorizer$modifyColor1(int color) { if (!GlintConfig.INSTANCE.enabled) { return color; } - if (RenderItemHook.INSTANCE.isRenderingHeld()) { - return GlintConfig.INSTANCE.getHeldIndividualStrokes() ? GlintConfig.INSTANCE.getHeldStrokeOne().getRGB() : GlintConfig.INSTANCE.getHeldColor().getRGB(); - } - if (RenderItemHook.INSTANCE.isRenderingInGUI()) { - if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) { - return glintColorizer$getPotionColor(Objects.requireNonNull(RenderItemHook.INSTANCE.getItemStack())); - } - if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isPotionItem()) { - return GlintConfig.INSTANCE.getShinyIndividualStrokes() ? GlintConfig.INSTANCE.getShinyStrokeOne().getRGB() : GlintConfig.INSTANCE.getShinyColor().getRGB(); - } else { - return GlintConfig.INSTANCE.getGuiIndividualStrokes() ? GlintConfig.INSTANCE.getGuiStrokeOne().getRGB() : GlintConfig.INSTANCE.getGuiColor().getRGB(); - } - } - if (RenderItemHook.INSTANCE.isRenderingDropped()) { - return GlintConfig.INSTANCE.getDroppedIndividualStrokes() ? GlintConfig.INSTANCE.getDroppedStrokeOne().getRGB() : GlintConfig.INSTANCE.getDroppedColor().getRGB(); - } - if (RenderItemHook.INSTANCE.isRenderingFramed()) { - return GlintConfig.INSTANCE.getFramedIndividualStrokes() ? GlintConfig.INSTANCE.getFramedStrokeOne().getRGB() : GlintConfig.INSTANCE.getFramedColor().getRGB(); - } - return color; + return glintColorizer$getModifiedColor(color, true); } @ModifyArg( @@ -94,31 +63,57 @@ public class RenderItemMixin_GlintCustomizer { ) private int glintColorizer$modifyColor2(int color) { if (!GlintConfig.INSTANCE.enabled) { return color; } + return glintColorizer$getModifiedColor(color, false); + } + + @Unique + private int glintColorizer$getModifiedColor(int color, boolean isFirstStroke) { if (RenderItemHook.INSTANCE.isRenderingHeld()) { - return GlintConfig.INSTANCE.getHeldIndividualStrokes() ? GlintConfig.INSTANCE.getHeldStrokeTwo().getRGB() : GlintConfig.INSTANCE.getHeldColor().getRGB(); + return GlintConfig.INSTANCE.getHeldIndividualStrokes() ? + (isFirstStroke ? GlintConfig.INSTANCE.getHeldStrokeOne().getRGB() : GlintConfig.INSTANCE.getHeldStrokeTwo().getRGB()) : + GlintConfig.INSTANCE.getHeldColor().getRGB(); } + if (RenderItemHook.INSTANCE.isRenderingInGUI()) { if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) { - return glintColorizer$getPotionColor(Objects.requireNonNull(RenderItemHook.INSTANCE.getItemStack())); + return glintColorizer$getPotionColor(RenderItemHook.INSTANCE.getItemStack()); } if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isPotionItem()) { - return GlintConfig.INSTANCE.getShinyIndividualStrokes() ? GlintConfig.INSTANCE.getShinyStrokeTwo().getRGB() : GlintConfig.INSTANCE.getShinyColor().getRGB(); - } else { - return GlintConfig.INSTANCE.getGuiIndividualStrokes() ? GlintConfig.INSTANCE.getGuiStrokeTwo().getRGB() : GlintConfig.INSTANCE.getGuiColor().getRGB(); + return GlintConfig.INSTANCE.getShinyIndividualStrokes() ? + (isFirstStroke ? GlintConfig.INSTANCE.getShinyStrokeOne().getRGB() : GlintConfig.INSTANCE.getShinyStrokeTwo().getRGB()) : + GlintConfig.INSTANCE.getShinyColor().getRGB(); } + return GlintConfig.INSTANCE.getGuiIndividualStrokes() ? + (isFirstStroke ? GlintConfig.INSTANCE.getGuiStrokeOne().getRGB() : GlintConfig.INSTANCE.getGuiStrokeTwo().getRGB()) : + GlintConfig.INSTANCE.getGuiColor().getRGB(); } + if (RenderItemHook.INSTANCE.isRenderingDropped()) { - return GlintConfig.INSTANCE.getDroppedIndividualStrokes() ? GlintConfig.INSTANCE.getDroppedStrokeTwo().getRGB() : GlintConfig.INSTANCE.getDroppedColor().getRGB(); + return GlintConfig.INSTANCE.getDroppedIndividualStrokes() ? + (isFirstStroke ? GlintConfig.INSTANCE.getDroppedStrokeOne().getRGB() : GlintConfig.INSTANCE.getDroppedStrokeTwo().getRGB()) : + GlintConfig.INSTANCE.getDroppedColor().getRGB(); } + if (RenderItemHook.INSTANCE.isRenderingFramed()) { - return GlintConfig.INSTANCE.getFramedIndividualStrokes() ? GlintConfig.INSTANCE.getFramedStrokeTwo().getRGB() : GlintConfig.INSTANCE.getFramedColor().getRGB(); + return GlintConfig.INSTANCE.getFramedIndividualStrokes() ? + (isFirstStroke ? GlintConfig.INSTANCE.getFramedStrokeOne().getRGB() : GlintConfig.INSTANCE.getFramedStrokeTwo().getRGB()) : + GlintConfig.INSTANCE.getFramedColor().getRGB(); } + return color; } - /** - * Adapted from ShinyPots by RoccoDev under the LGPL-3.0 license. - */ + @Unique + private boolean glintColorizer$shouldApplyMatrix() { + return GlintConfig.INSTANCE.getPotionGlintSize() && + RenderItemHook.INSTANCE.isRenderingInGUI() && + RenderItemHook.INSTANCE.isPotionItem() && + (GlintConfig.INSTANCE.getPotionGlintForeground() || GlintConfig.INSTANCE.getPotionGlintBackground()); + } + + /** + * Adapted from ShinyPots by RoccoDev under the LGPL-3.0 license. + */ @Unique private int glintColorizer$getPotionColor(ItemStack item) { int potionId = item.getMetadata(); diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java index bca9ca9..0dde9f0 100644 --- a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_ShinyEffect.java @@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +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.Redirect; @@ -56,7 +57,7 @@ public abstract class RenderItemMixin_ShinyEffect { ) private void glintColorizer$onRenderModel(ItemStack stack, IBakedModel model, CallbackInfo ci) { if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } - if ((GlintConfig.INSTANCE.getPotionGlintForeground() || GlintConfig.INSTANCE.getPotionGlintBackground()) && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem() && stack.hasEffect()) { + if ((GlintConfig.INSTANCE.getPotionGlintForeground() || GlintConfig.INSTANCE.getPotionGlintBackground()) && glintColorizer$isValidItem(stack)) { renderEffect(model); } } @@ -71,7 +72,7 @@ public abstract class RenderItemMixin_ShinyEffect { ) private void glintColorizer$onRenderModel2(ItemStack stack, IBakedModel model, CallbackInfo ci) { if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; } - if (GlintConfig.INSTANCE.getPotionGlintBackground() && !GlintConfig.INSTANCE.getPotionGlintForeground() && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem() && stack.hasEffect()) { + if (GlintConfig.INSTANCE.getPotionGlintBackground() && !GlintConfig.INSTANCE.getPotionGlintForeground() && glintColorizer$isValidItem(stack)) { RenderItem instance = (RenderItem) (Object) this; SecondGlintHandler.renderEffect(instance, model, textureManager, RES_ITEM_GLINT); } @@ -86,10 +87,7 @@ public abstract class RenderItemMixin_ShinyEffect { ) private boolean glintColorizer$disableRenderEffect(ItemStack instance) { if (RenderItemHook.INSTANCE.isPotionGlintEnabled() && RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem()) { - if (GlintConfig.INSTANCE.getPotionGlintForeground()) { - return false; - } - return !GlintConfig.INSTANCE.getPotionGlintBackground(); + return !GlintConfig.INSTANCE.getPotionGlintForeground() && !GlintConfig.INSTANCE.getPotionGlintBackground(); } return instance.hasEffect(); } @@ -110,4 +108,9 @@ public abstract class RenderItemMixin_ShinyEffect { } } + @Unique + private boolean glintColorizer$isValidItem(ItemStack stack) { + return RenderItemHook.INSTANCE.isRenderingInGUI() && RenderItemHook.INSTANCE.isPotionItem() && stack.hasEffect(); + } + } diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt index bb3709b..ce167d4 100644 --- a/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/GlintColorizer.kt @@ -1,5 +1,6 @@ package org.polyfrost.glintcolorizer +import cc.polyfrost.oneconfig.config.core.ConfigUtils import cc.polyfrost.oneconfig.utils.commands.CommandManager import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent @@ -19,6 +20,8 @@ object GlintColorizer { const val VER: String = "@VER@" const val ID: String = "@ID@" + val path = "${ConfigUtils.getProfileDir().absolutePath}/${ID}/caches/" + @Mod.EventHandler fun onInit(event: FMLInitializationEvent?) { GlintConfig diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt index 58656d1..5f01806 100644 --- a/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt @@ -35,6 +35,7 @@ object GlintConfig : Config( droppedColor = OneColor(defaultColor) framedColor = OneColor(defaultColor) shinyColor = OneColor(defaultColor) + armorColor = OneColor(defaultColor) /* Individual Strokes Colors */ heldStrokeOne = OneColor(defaultColor) heldStrokeTwo = OneColor(defaultColor) @@ -61,7 +62,7 @@ object GlintConfig : Config( category = "Global", subcategory = "Color Configuration", text = "Reset", - description = "Resets ALL custom shiny pots settings" + description = "Resets ALL custom shiny pots settings." ) var resetShinyPots: Runnable = (Runnable { Minecraft.getMinecraft().displayGuiScreen(null) @@ -122,7 +123,7 @@ object GlintConfig : Config( }) @Switch( - name = "Modify glint strokes individually", + name = "Modify Strokes Individually", category = "Held Item Glint Color", ) var heldIndividualStrokes: Boolean = false @@ -137,14 +138,14 @@ object GlintConfig : Config( @Color( name = "Stroke 1 Color", category = "Held Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the first stroke of the enchantment glint effect." ) var heldStrokeOne: OneColor = OneColor(defaultColor) @Color( name = "Stroke 2 Color", category = "Held Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the second stroke of the enchantment glint effect." ) var heldStrokeTwo: OneColor = OneColor(defaultColor) @@ -166,7 +167,7 @@ object GlintConfig : Config( }) @Switch( - name = "Modify glint strokes individually", + name = "Modify Strokes Individually", category = "GUI Item Glint Color", ) var guiIndividualStrokes: Boolean = false @@ -181,14 +182,14 @@ object GlintConfig : Config( @Color( name = "Stroke 1 Color", category = "GUI Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the first stroke of the enchantment glint effect." ) var guiStrokeOne: OneColor = OneColor(defaultColor) @Color( name = "Stroke 2 Color", category = "GUI Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the second stroke of the enchantment glint effect." ) var guiStrokeTwo: OneColor = OneColor(defaultColor) @@ -210,7 +211,7 @@ object GlintConfig : Config( }) @Switch( - name = "Modify glint strokes individually", + name = "Modify Strokes Individually", category = "Dropped Item Glint Color", ) var droppedIndividualStrokes: Boolean = false @@ -225,14 +226,14 @@ object GlintConfig : Config( @Color( name = "Stroke 1 Color", category = "Dropped Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the first stroke of the enchantment glint effect." ) var droppedStrokeOne: OneColor = OneColor(defaultColor) @Color( name = "Stroke 2 Color", category = "Dropped Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the second stroke of the enchantment glint effect." ) var droppedStrokeTwo: OneColor = OneColor(defaultColor) @@ -254,7 +255,7 @@ object GlintConfig : Config( }) @Switch( - name = "Modify glint strokes individually", + name = "Modify Strokes Individually", category = "Framed Item Glint Color", ) var framedIndividualStrokes: Boolean = false @@ -269,18 +270,32 @@ object GlintConfig : Config( @Color( name = "Stroke 1 Color", category = "Framed Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the first stroke of the enchantment glint effect." ) var framedStrokeOne: OneColor = OneColor(defaultColor) @Color( name = "Stroke 2 Color", category = "Framed Item Glint Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the second stroke of the enchantment glint effect." ) var framedStrokeTwo: OneColor = OneColor(defaultColor) /* Armor */ + @Button( + name = "Reset Armor Glint", + category = "Armor Glint Color", + subcategory = "Color Configuration", + text = "Reset", + description = "Resets ALL custom glint colors." + ) + var resetArmor: Runnable = (Runnable { + Minecraft.getMinecraft().displayGuiScreen(null) + armorColor = OneColor(defaultColor) + GlintConfig.save() + openGui() + }) + @Color( name = "Armor Glint Color", category = "Armor Glint Color", @@ -342,14 +357,14 @@ object GlintConfig : Config( var potionBasedColor: Boolean = false @Switch( - name = "Modify glint strokes individually", + name = "Modify the Shiny Effect's Strokes Individually", category = "Shiny Pots", subcategory = "Color" ) var shinyIndividualStrokes: Boolean = false @Color( - name = "Shiny Effect Glint Color", + name = "Shiny Glint Effect Color", category = "Shiny Pots", subcategory = "Color", description = "Modifies the color of the enchantment glint." @@ -360,7 +375,7 @@ object GlintConfig : Config( name = "Stroke 1 Color", category = "Shiny Pots", subcategory = "Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the first stroke of the shiny glint effect." ) var shinyStrokeOne: OneColor = OneColor(defaultColor) @@ -368,7 +383,7 @@ object GlintConfig : Config( name = "Stroke 2 Color", category = "Shiny Pots", subcategory = "Color", - description = "Modifies one of the enchantment glint stroke colors." + description = "Modifies the second stroke of the shiny glint effect." ) var shinyStrokeTwo: OneColor = OneColor(defaultColor)