Skip to content

Commit

Permalink
Improve clarity of code a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed May 20, 2024
1 parent f195945 commit 6027c85
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, Integer> glintColorizer$cachedColors = new HashMap<>();
@Unique
private final HashMap<Integer, Integer> 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();
}
}
Expand All @@ -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(
Expand All @@ -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;
}

/**
* </><a href="https://github.com/RoccoDev/ShinyPots-1.8">Adapted from ShinyPots by RoccoDev under the LGPL-3.0 license.</a>
*/
@Unique
private boolean glintColorizer$shouldApplyMatrix() {
return GlintConfig.INSTANCE.getPotionGlintSize() &&
RenderItemHook.INSTANCE.isRenderingInGUI() &&
RenderItemHook.INSTANCE.isPotionItem() &&
(GlintConfig.INSTANCE.getPotionGlintForeground() || GlintConfig.INSTANCE.getPotionGlintBackground());
}

/**
* </><a href="https://github.com/RoccoDev/ShinyPots-1.8">Adapted from ShinyPots by RoccoDev under the LGPL-3.0 license.</a>
*/
@Unique
private int glintColorizer$getPotionColor(ItemStack item) {
int potionId = item.getMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
49 changes: 32 additions & 17 deletions src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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."
Expand All @@ -360,15 +375,15 @@ 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)

@Color(
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)

Expand Down

0 comments on commit 6027c85

Please sign in to comment.