Skip to content

Commit

Permalink
More features!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jun 23, 2024
1 parent 8579919 commit 1aa4737
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,61 @@

import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import org.polyfrost.glintcolorizer.config.ColorSettings;
import org.polyfrost.glintcolorizer.config.GlintEffectOptions;
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.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

import java.util.HashMap;

@Mixin(RenderItem.class)
public class RenderItemMixin_GlintCustomizer {

@Unique
private final HashMap<Integer, Integer> glintColorizer$cachedColors = new HashMap<>();
@Unique private final HashMap<Integer, Integer> glintColorizer$cachedColors = new HashMap<>();

@Inject(method = "renderEffect", at = @At("HEAD"))
@Inject(
method = "renderEffect",
at = @At(
value = "HEAD"
)
)
private void glintColorizer$push(IBakedModel model, CallbackInfo ci) {
if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; }
if (glintColorizer$shouldApplyMatrix()) {
GlStateManager.pushMatrix();
}
if (!glintColorizer$shouldApplyMatrix()) { return; }
GlStateManager.pushMatrix();
}

@Inject(method = "renderEffect", at = @At("TAIL"))
@Inject(
method = "renderEffect",
at = @At(
value = "TAIL"
)
)
private void glintColorizer$pop(IBakedModel model, CallbackInfo ci) {
if (!RenderItemHook.INSTANCE.isPotionGlintEnabled()) { return; }
if (glintColorizer$shouldApplyMatrix()) {
GlStateManager.popMatrix();
}
if (glintColorizer$shouldApplyMatrix()) { return; }
GlStateManager.popMatrix();
}

@ModifyArgs(
method = "renderEffect",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V"
)
)
private void glintColorizer$modifyScale(Args args) {
if (!GlintConfig.INSTANCE.enabled) { return; }
args.set(0, glintColorizer$getModifiedScale(args.get(0)));
args.set(1, glintColorizer$getModifiedScale(args.get(1)));
args.set(2, glintColorizer$getModifiedScale(args.get(2)));
}

@ModifyArg(
Expand All @@ -49,7 +69,7 @@ public class RenderItemMixin_GlintCustomizer {
)
private float glintColorizer$modifySpeed(float speed) {
if (!GlintConfig.INSTANCE.enabled) { return speed; }
return glintColorizer$getModifiedSpeed(speed); //todo: adw
return glintColorizer$getModifiedSpeed(speed);
}

@ModifyArg(
Expand All @@ -63,7 +83,7 @@ public class RenderItemMixin_GlintCustomizer {
)
private float glintColorizer$modifyRotation(float angle) {
if (!GlintConfig.INSTANCE.enabled) { return angle; }
return glintColorizer$getModifiedRotation(angle, true); //todo: adw
return glintColorizer$getModifiedRotation(angle , true);
}

@ModifyArg(
Expand All @@ -77,7 +97,7 @@ public class RenderItemMixin_GlintCustomizer {
)
private float glintColorizer$modifyRotation2(float angle) {
if (!GlintConfig.INSTANCE.enabled) { return angle; }
return glintColorizer$getModifiedRotation(angle, false); //todo: adw
return glintColorizer$getModifiedRotation(angle, false);
}

@ModifyArg(
Expand Down Expand Up @@ -136,80 +156,91 @@ public class RenderItemMixin_GlintCustomizer {
}

@Unique
private int glintColorizer$getColor(ColorSettings settings, boolean isFirstStroke) {
private int glintColorizer$getColor(GlintEffectOptions 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) {
private float glintColorizer$getModifiedRotation(float defaultRot, boolean isFirstStroke) {
if (RenderItemHook.INSTANCE.isRenderingHeld()) {
return isFirstStroke ? GlintConfig.INSTANCE.getHeldStrokeRotOne() : GlintConfig.INSTANCE.getHeldStrokeRotTwo();
}

// 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 GlintConfig.INSTANCE.getGuiIndividualStrokes() ?
// (isFirstStroke ? GlintConfig.INSTANCE.getGuiStrokeOne().getRGB() : GlintConfig.INSTANCE.getGuiStrokeTwo().getRGB()) :
// GlintConfig.INSTANCE.getGuiColor().getRGB();
// }
//
// if (RenderItemHook.INSTANCE.isRenderingDropped()) {
// 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() ?
// (isFirstStroke ? GlintConfig.INSTANCE.getFramedStrokeOne().getRGB() : GlintConfig.INSTANCE.getFramedStrokeTwo().getRGB()) :
// GlintConfig.INSTANCE.getFramedColor().getRGB();
// }
return isFirstStroke ? GlintConfig.INSTANCE.getHeldItem().getStrokeRotOne() : GlintConfig.INSTANCE.getHeldItem().getStrokeRotTwo();
}

return color;
if (RenderItemHook.INSTANCE.isRenderingInGUI()) {
if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) {
return isFirstStroke ? GlintConfig.INSTANCE.getGuiItem().getStrokeRotOne() : GlintConfig.INSTANCE.getGuiItem().getStrokeRotTwo();
}
if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isPotionItem()) {
return isFirstStroke ? GlintConfig.INSTANCE.getShinyPots().getStrokeRotOne() : GlintConfig.INSTANCE.getShinyPots().getStrokeRotTwo();
}
return isFirstStroke ? GlintConfig.INSTANCE.getGuiItem().getStrokeRotOne() : GlintConfig.INSTANCE.getGuiItem().getStrokeRotTwo();
}

if (RenderItemHook.INSTANCE.isRenderingDropped()) {
return isFirstStroke ? GlintConfig.INSTANCE.getDroppedItem().getStrokeRotOne() : GlintConfig.INSTANCE.getDroppedItem().getStrokeRotTwo();
}

if (RenderItemHook.INSTANCE.isRenderingFramed()) {
return isFirstStroke ? GlintConfig.INSTANCE.getFramedItem().getStrokeRotOne() : GlintConfig.INSTANCE.getFramedItem().getStrokeRotTwo();
}

return defaultRot;
}

@Unique
private float glintColorizer$getModifiedSpeed(float defaultSpeed) {
if (RenderItemHook.INSTANCE.isRenderingHeld()) {
return GlintConfig.INSTANCE.getHeldItem().getSpeed() * defaultSpeed;
}

if (RenderItemHook.INSTANCE.isRenderingInGUI()) {
if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) {
return GlintConfig.INSTANCE.getGuiItem().getSpeed() * defaultSpeed;
}
if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isPotionItem()) {
return GlintConfig.INSTANCE.getShinyPots().getScale() * defaultSpeed;
}
return GlintConfig.INSTANCE.getGuiItem().getSpeed() * defaultSpeed;
}

if (RenderItemHook.INSTANCE.isRenderingDropped()) {
return GlintConfig.INSTANCE.getDroppedItem().getSpeed() * defaultSpeed;
}

if (RenderItemHook.INSTANCE.isRenderingFramed()) {
return GlintConfig.INSTANCE.getFramedItem().getSpeed() * defaultSpeed;
}

return defaultSpeed;
}

@Unique
private float glintColorizer$getModifiedSpeed(float speed) {
private float glintColorizer$getModifiedScale(float originalScale) {
if (RenderItemHook.INSTANCE.isRenderingHeld()) {
return GlintConfig.INSTANCE.getHeldSpeed() * speed;
}

// 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 GlintConfig.INSTANCE.getGuiIndividualStrokes() ?
// (isFirstStroke ? GlintConfig.INSTANCE.getGuiStrokeOne().getRGB() : GlintConfig.INSTANCE.getGuiStrokeTwo().getRGB()) :
// GlintConfig.INSTANCE.getGuiColor().getRGB();
// }
//
// if (RenderItemHook.INSTANCE.isRenderingDropped()) {
// 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() ?
// (isFirstStroke ? GlintConfig.INSTANCE.getFramedStrokeOne().getRGB() : GlintConfig.INSTANCE.getFramedStrokeTwo().getRGB()) :
// GlintConfig.INSTANCE.getFramedColor().getRGB();
// }

return speed;
return GlintConfig.INSTANCE.getHeldItem().getScale() * originalScale;
}

if (RenderItemHook.INSTANCE.isRenderingInGUI()) {
if (GlintConfig.INSTANCE.getPotionBasedColor() && RenderItemHook.INSTANCE.isPotionItem()) {
return GlintConfig.INSTANCE.getGuiItem().getScale() * originalScale;
}
if (GlintConfig.INSTANCE.getPotionGlintBackground() && RenderItemHook.INSTANCE.isPotionItem()) {
return GlintConfig.INSTANCE.getShinyPots().getScale() * originalScale;
}
return GlintConfig.INSTANCE.getGuiItem().getScale() * originalScale;
}

if (RenderItemHook.INSTANCE.isRenderingDropped()) {
return GlintConfig.INSTANCE.getDroppedItem().getScale() * originalScale;
}

if (RenderItemHook.INSTANCE.isRenderingFramed()) {
return GlintConfig.INSTANCE.getFramedItem().getScale() * originalScale;
}

return originalScale;
}

@Unique
Expand All @@ -220,9 +251,9 @@ public class RenderItemMixin_GlintCustomizer {
(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>
*/
/**
* <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 @@ -6,8 +6,8 @@
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.polyfrost.glintcolorizer.config.GlintEffectOptions;
import org.polyfrost.glintcolorizer.config.annotation.ColorEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -21,29 +21,39 @@
@Mixin(value = Config.class, remap = false)
public class ConfigMixin {

@Unique
private transient OptionPage page;
@Unique
private transient Object instance;
@Unique private transient OptionPage glintColorizer$page;
@Unique private transient Object glintColorizer$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"))
@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(
value = "HEAD"
)
)
private void capture(Object instance, Class<?> targetClass, OptionPage page, Mod mod, boolean migrate, CallbackInfo ci) {
this.instance = instance;
this.page = page;
this.glintColorizer$instance = instance;
this.glintColorizer$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")
@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)) {
glintColorizer$addOptions(page, field, instance);
glintColorizer$addOptions(glintColorizer$page, field, glintColorizer$instance);
}
return field;
}

@Unique
private void glintColorizer$addOptions(OptionPage page, Field field, Object instance) {
ColorEntry annotation = field.getAnnotation(ColorEntry.class);
ColorSettings colorSettings = (ColorSettings) ConfigUtils.getField(field, instance);
GlintEffectOptions colorSettings = (GlintEffectOptions) ConfigUtils.getField(field, instance);
BasicOption strokeOne = null;
BasicOption strokeTwo = null;
BasicOption individualStrokes = null;
Expand Down
Loading

0 comments on commit 1aa4737

Please sign in to comment.