Skip to content

Commit

Permalink
i gotchu
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jun 2, 2024
1 parent 13ad58e commit 5b23684
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 288 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ val shade: Configuration by configurations.creating {

// Configures the output directory for when building from the `src/resources` directory.
sourceSets {
val dummy by creating
main {
dummy.compileClasspath += compileClasspath
compileClasspath += dummy.output
output.setResourcesDir(java.classesDirectory)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package cc.polyfrost.oneconfig.internal.config.annotations;

public @interface Option {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import org.polyfrost.glintcolorizer.config.ColorSettings;
import org.polyfrost.glintcolorizer.config.GlintConfig;
import org.polyfrost.glintcolorizer.hook.RenderItemHook;
import net.minecraft.client.renderer.GlStateManager;
Expand Down Expand Up @@ -110,40 +111,37 @@ public class RenderItemMixin_GlintCustomizer {
@Unique
private int glintColorizer$getModifiedColor(int color, boolean isFirstStroke) {
if (RenderItemHook.INSTANCE.isRenderingHeld()) {
return GlintConfig.INSTANCE.getHeldIndividualStrokes() ?
(isFirstStroke ? GlintConfig.INSTANCE.getHeldStrokeOne().getRGB() : GlintConfig.INSTANCE.getHeldStrokeTwo().getRGB()) :
GlintConfig.INSTANCE.getHeldColor().getRGB();
return glintColorizer$getColor(GlintConfig.INSTANCE.getHeldItem(), isFirstStroke);
}

if (RenderItemHook.INSTANCE.isRenderingInGUI()) {
if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) {
return glintColorizer$getPotionColor(RenderItemHook.INSTANCE.getItemStack());
}
if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isPotionItem()) {
return GlintConfig.INSTANCE.getShinyIndividualStrokes() ?
(isFirstStroke ? GlintConfig.INSTANCE.getShinyStrokeOne().getRGB() : GlintConfig.INSTANCE.getShinyStrokeTwo().getRGB()) :
GlintConfig.INSTANCE.getShinyColor().getRGB();
return glintColorizer$getColor(GlintConfig.INSTANCE.getShinyPots(), isFirstStroke);
}
return GlintConfig.INSTANCE.getGuiIndividualStrokes() ?
(isFirstStroke ? GlintConfig.INSTANCE.getGuiStrokeOne().getRGB() : GlintConfig.INSTANCE.getGuiStrokeTwo().getRGB()) :
GlintConfig.INSTANCE.getGuiColor().getRGB();
return glintColorizer$getColor(GlintConfig.INSTANCE.getGuiItem(), isFirstStroke);
}

if (RenderItemHook.INSTANCE.isRenderingDropped()) {
return GlintConfig.INSTANCE.getDroppedIndividualStrokes() ?
(isFirstStroke ? GlintConfig.INSTANCE.getDroppedStrokeOne().getRGB() : GlintConfig.INSTANCE.getDroppedStrokeTwo().getRGB()) :
GlintConfig.INSTANCE.getDroppedColor().getRGB();
return glintColorizer$getColor(GlintConfig.INSTANCE.getDroppedItem(), isFirstStroke);
}

if (RenderItemHook.INSTANCE.isRenderingFramed()) {
return GlintConfig.INSTANCE.getFramedIndividualStrokes() ?
(isFirstStroke ? GlintConfig.INSTANCE.getFramedStrokeOne().getRGB() : GlintConfig.INSTANCE.getFramedStrokeTwo().getRGB()) :
GlintConfig.INSTANCE.getFramedColor().getRGB();
return glintColorizer$getColor(GlintConfig.INSTANCE.getFramedItem(), isFirstStroke);
}

return color;
}

@Unique
private int glintColorizer$getColor(ColorSettings settings, boolean isFirstStroke) {
return settings.getIndividualStrokes() ?
(isFirstStroke ? settings.getStrokeOneColor().getRGB() : settings.getStrokeTwoColor().getRGB()) :
settings.getGlintColor().getRGB();
}

@Unique
private float glintColorizer$getModifiedRotation(float color, boolean isFirstStroke) {
if (RenderItemHook.INSTANCE.isRenderingHeld()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.polyfrost.glintcolorizer.mixin.oneconfig;

import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.config.elements.OptionPage;
import cc.polyfrost.oneconfig.internal.config.annotations.Option;
import org.polyfrost.glintcolorizer.config.ColorEntry;
import org.polyfrost.glintcolorizer.config.ColorSettings;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;

@Mixin(value = Config.class, remap = false)
public class ConfigMixin {

@Unique
private transient OptionPage page;
@Unique
private transient Object instance;

@Inject(method = "generateOptionList(Ljava/lang/Object;Ljava/lang/Class;Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/config/data/Mod;Z)V", at = @At("HEAD"))
private void capture(Object instance, Class<?> targetClass, OptionPage page, Mod mod, boolean migrate, CallbackInfo ci) {
this.instance = instance;
this.page = page;
}

@ModifyVariable(method = "generateOptionList(Ljava/lang/Object;Ljava/lang/Class;Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/config/data/Mod;Z)V", at = @At(value = "LOAD", ordinal = 0), name = "field")
private Field generate(Field field) {
if (field.isAnnotationPresent(ColorEntry.class)) {
addOptions(page, field, instance);
}
return field;
}

@Unique
private void addOptions(OptionPage page, Field field, Object instance) {
ColorEntry annotation = field.getAnnotation(ColorEntry.class);
ColorSettings colorSettings = (ColorSettings) ConfigUtils.getField(field, instance);
for (BasicOption option : glintColorizer$getClassOptions(colorSettings)) {
ConfigUtils.getSubCategory(page, annotation.category(), option.subcategory).options.add(option);
}
}

@Unique
private static ArrayList<BasicOption> glintColorizer$getClassOptions(Object object) {
ArrayList<BasicOption> options = new ArrayList<>();
ArrayList<Field> fields = ConfigUtils.getClassFields(object.getClass());
for (Field field : fields) {
Option option = ConfigUtils.findAnnotation(field, Option.class);
if (option == null) continue;
options.add(ConfigUtils.getOption(option, field, object));
}
return options;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.polyfrost.glintcolorizer.config

@Target(AnnotationTarget.FIELD)
annotation class ColorEntry(val category: String = "General")
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.polyfrost.glintcolorizer.config

import cc.polyfrost.oneconfig.config.annotations.*
import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.polyfrost.oneconfig.config.core.OneColor

class ColorSettings {

@Button(
name = "Reset Held Glint Colors",
subcategory = "Configuration",
text = "Reset",
description = "Resets ALL custom glint colors."
)
var resetColor = Runnable {
reset(false)
}

@Switch(
name = "Modify Strokes Individually",
subcategory = "Color"
)
var individualStrokes = false

@Color(
name = "Glint Color",
subcategory = "Color",
description = "Modifies the color of the enchantment glint."
)
var glintColor = OneColor(GlintConfig.defaultColor)

@Color(
name = "Stroke 1 Color",
subcategory = "Color",
description = "Modifies the first stroke of the enchantment glint effect."
)
var strokeOneColor = OneColor(GlintConfig.defaultColor)

@Color(
name = "Stroke 2 Color",
subcategory = "Color",
description = "Modifies the second stroke of the enchantment glint effect."
)
var strokeTwoColor = OneColor(GlintConfig.defaultColor)

fun reset(resetAll: Boolean) {
val target = ColorSettings()
val newFields = ConfigUtils.getClassFields(target::class.java)
val fields = ConfigUtils.getClassFields(this::class.java)
for (i in 0 until fields.size) {
if (!resetAll && fields[i].type != OneColor::class.java) continue
fields[i].set(this, ConfigUtils.getField(newFields[i], target))
}
}

}
Loading

0 comments on commit 5b23684

Please sign in to comment.