|
| 1 | +package org.polyfrost.glintcolorizer.mixin; |
| 2 | + |
| 3 | +import net.minecraft.client.renderer.GlStateManager; |
| 4 | +import net.minecraft.client.renderer.entity.RenderItem; |
| 5 | +import net.minecraft.client.resources.model.IBakedModel; |
| 6 | +import net.minecraft.potion.PotionHelper; |
| 7 | +import org.polyfrost.glintcolorizer.config.GlintConfig; |
| 8 | +import org.polyfrost.glintcolorizer.config.GlintOptions; |
| 9 | +import org.polyfrost.glintcolorizer.GlintMetadata; |
| 10 | +import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.Unique; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.ModifyArg; |
| 15 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 17 | + |
| 18 | +@Mixin(RenderItem.class) |
| 19 | +public class GlintCustomizer_RenderItem_Mixin { |
| 20 | + |
| 21 | + @Inject(method = "renderEffect", at = @At("HEAD")) |
| 22 | + private void pushMatrix(IBakedModel model, CallbackInfo ci) { |
| 23 | + GlStateManager.pushMatrix(); |
| 24 | + } |
| 25 | + |
| 26 | + @Inject(method = "renderEffect", at = @At("TAIL")) |
| 27 | + private void popMatrix(IBakedModel model, CallbackInfo ci) { |
| 28 | + GlStateManager.popMatrix(); |
| 29 | + } |
| 30 | + |
| 31 | + @Redirect(method = "renderEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V")) |
| 32 | + private void modifyScale(float x, float y, float z) { |
| 33 | + if (!GlintConfig.INSTANCE.enabled) { |
| 34 | + GlStateManager.scale(x, y, z); |
| 35 | + } else { |
| 36 | + float scaleFactor = GlintMetadata.getRenderingOptions().getScale(); |
| 37 | + GlStateManager.scale(x * scaleFactor, y * scaleFactor, z * scaleFactor); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @ModifyArg(method = "renderEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V"), index = 0) |
| 42 | + private float modifySpeed(float speed) { |
| 43 | + if (!GlintConfig.INSTANCE.enabled) { |
| 44 | + return speed; |
| 45 | + } |
| 46 | + return GlintMetadata.getRenderingOptions().getSpeed(); |
| 47 | + } |
| 48 | + |
| 49 | + @ModifyArg(method = "renderEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;rotate(FFFF)V", ordinal = 0), index = 0) |
| 50 | + private float modifyFirstStrokeRotation(float angle) { |
| 51 | + if (!GlintConfig.INSTANCE.enabled) { |
| 52 | + return angle; |
| 53 | + } |
| 54 | + return GlintMetadata.getRenderingOptions().getFirstStrokeRotation(); |
| 55 | + } |
| 56 | + |
| 57 | + @ModifyArg(method = "renderEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;rotate(FFFF)V", ordinal = 1), index = 0) |
| 58 | + private float modifySecondStrokeRotation(float angle) { |
| 59 | + if (!GlintConfig.INSTANCE.enabled) { |
| 60 | + return angle; |
| 61 | + } |
| 62 | + return GlintMetadata.getRenderingOptions().getSecondStrokeRotation(); |
| 63 | + } |
| 64 | + |
| 65 | + @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) |
| 66 | + private int modifyFirstStrokeColor(int color) { |
| 67 | + return glc$getColor(color, true); |
| 68 | + } |
| 69 | + |
| 70 | + @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) |
| 71 | + private int modifySecondStrokeColor(int color) { |
| 72 | + return glc$getColor(color, false); |
| 73 | + } |
| 74 | + |
| 75 | + @Unique |
| 76 | + private int glc$getColor(int color, boolean firstStroke) { |
| 77 | + if (!GlintConfig.INSTANCE.enabled) { |
| 78 | + return color; |
| 79 | + } |
| 80 | + GlintOptions options = GlintMetadata.getRenderingOptions(); |
| 81 | + if (options instanceof GlintOptions.ShinyPots) { |
| 82 | + GlintOptions.ShinyPots potsOptions = (GlintOptions.ShinyPots) options; |
| 83 | + if (potsOptions.usePotionBasedColor()) { |
| 84 | + int potionId = GlintMetadata.getRenderingItemMetadata(); |
| 85 | + return PotionHelper.getLiquidColor(potionId, false) | 0xFF000000; |
| 86 | + } |
| 87 | + } |
| 88 | + if (options.useIndividualStrokes()) { |
| 89 | + return firstStroke ? options.getStrokeOneColor().getRgba() : options.getStrokeTwoColor().getRgba(); |
| 90 | + } else return options.getGlintColor().getRgba(); |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments