From fbf9f24cc1d3049bacfc46ab6e996432b0cfb765 Mon Sep 17 00:00:00 2001 From: Thalia Nero Date: Mon, 22 Jul 2019 22:28:06 -0400 Subject: [PATCH] Add experience orb colors --- .../github/kvverti/colormatic/Colormatic.java | 3 + .../xp/ExperienceOrbEntityRendererMixin.java | 87 +++++++++++++++++++ .../properties/GlobalColorProperties.java | 13 +++ src/main/resources/colormatic.mixins.json | 3 +- 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/kvverti/colormatic/mixin/xp/ExperienceOrbEntityRendererMixin.java diff --git a/src/main/java/io/github/kvverti/colormatic/Colormatic.java b/src/main/java/io/github/kvverti/colormatic/Colormatic.java index 8e3131e..ace2aea 100644 --- a/src/main/java/io/github/kvverti/colormatic/Colormatic.java +++ b/src/main/java/io/github/kvverti/colormatic/Colormatic.java @@ -62,6 +62,8 @@ public class Colormatic implements ClientModInitializer { new LinearColormapResource(new Identifier(MODID, "colormap/lavadrop.png")); public static final LinearColormapResource DURABILITY_COLORS = new LinearColormapResource(new Identifier(MODID, "colormap/durability.png")); + public static final LinearColormapResource EXPERIENCE_ORB_COLORS = + new LinearColormapResource(new Identifier(MODID, "colormap/xporb.png")); public static final CustomBiomeColormapsResource CUSTOM_BLOCK_COLORS = new CustomBiomeColormapsResource(new Identifier(MODID, "colormap/custom")); public static final GlobalLightmapResource LIGHTMAP_PROPS = @@ -85,6 +87,7 @@ public void onInitializeClient() { client.registerReloadListener(MYCELIUM_PARTICLE_COLORS); client.registerReloadListener(LAVA_DROP_COLORS); client.registerReloadListener(DURABILITY_COLORS); + client.registerReloadListener(EXPERIENCE_ORB_COLORS); client.registerReloadListener(CUSTOM_BLOCK_COLORS); client.registerReloadListener(LIGHTMAP_PROPS); // Note: we don't register this as a reload listener here because it diff --git a/src/main/java/io/github/kvverti/colormatic/mixin/xp/ExperienceOrbEntityRendererMixin.java b/src/main/java/io/github/kvverti/colormatic/mixin/xp/ExperienceOrbEntityRendererMixin.java new file mode 100644 index 0000000..7dfaaf0 --- /dev/null +++ b/src/main/java/io/github/kvverti/colormatic/mixin/xp/ExperienceOrbEntityRendererMixin.java @@ -0,0 +1,87 @@ +/* + * Colormatic + * Copyright (C) 2019 Thalia Nero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +package io.github.kvverti.colormatic.mixin.xp; + +import io.github.kvverti.colormatic.Colormatic; + +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.ExperienceOrbEntityRenderer; +import net.minecraft.entity.ExperienceOrbEntity; +import net.minecraft.util.math.MathHelper; + +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * Controls experience orb color pulses. + */ +@Mixin(ExperienceOrbEntityRenderer.class) +public abstract class ExperienceOrbEntityRendererMixin extends EntityRenderer { + + private ExperienceOrbEntityRendererMixin() { + super(null); + } + + @Unique + private boolean custom; + + @Unique + private int customRed; + + @Unique + private int customGreen; + + @Unique + private int customBlue; + + @Inject(method = "method_3966", at = @At("HEAD")) + private void onRenderSetColor(ExperienceOrbEntity entity, double x, double y, double z, float eh, float partialTicks, CallbackInfo info) { + if(Colormatic.EXPERIENCE_ORB_COLORS.hasCustomColormap()) { + custom = true; + float ticksPerCycle = Colormatic.COLOR_PROPS.getProperties().getXpOrbTime() / 50.0f; + float frac = (1 - MathHelper.cos((entity.renderTicks + partialTicks) * (float)(2 * Math.PI) / ticksPerCycle)) / 2; + int color = Colormatic.EXPERIENCE_ORB_COLORS.getColorFraction(frac); + customRed = (color >> 16) & 0xff; + customGreen = (color >> 8) & 0xff; + customBlue = color & 0xff; + } else { + custom = false; + } + } + + @Redirect( + method = "method_3966", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/render/BufferBuilder;color(IIII)Lnet/minecraft/client/render/BufferBuilder;" + ) + ) + private BufferBuilder proxyColor(BufferBuilder self, int r, int g, int b, int a) { + if(custom) { + r = customRed; + g = customGreen; + b = customBlue; + } + return self.color(r, g, b, a); + } +} diff --git a/src/main/java/io/github/kvverti/colormatic/properties/GlobalColorProperties.java b/src/main/java/io/github/kvverti/colormatic/properties/GlobalColorProperties.java index 376b8f7..1d660cc 100644 --- a/src/main/java/io/github/kvverti/colormatic/properties/GlobalColorProperties.java +++ b/src/main/java/io/github/kvverti/colormatic/properties/GlobalColorProperties.java @@ -63,6 +63,7 @@ public class GlobalColorProperties { private final Map, int[]> spawnEgg; private final Map textColor; private final TextColor text; + private final int xpOrbTime; private GlobalColorProperties(Settings settings) { this.particle = settings.particle; @@ -77,6 +78,7 @@ private GlobalColorProperties(Settings settings) { this.banner = settings.banner; this.map = settings.map; this.spawnEgg = collateSpawnEggColors(settings); + this.xpOrbTime = settings.xporb.time; if(settings.text != null) { TextColor text = settings.text; this.textColor = new HashMap<>(); @@ -243,6 +245,10 @@ public int getText(ChatFormat color) { return getColor(color, textColor); } + public int getXpOrbTime() { + return xpOrbTime; + } + public enum ColoredParticle implements StringIdentifiable { WATER("water"), PORTAL("portal"); @@ -325,6 +331,7 @@ private static class Settings { Map spawnegg = Collections.emptyMap(); LegacyEggColor egg; TextColor text; + XpOrb xporb = XpOrb.DEFAULT; } /** @@ -348,4 +355,10 @@ static class ButtonText { HexColor disabled; } } + + private static class XpOrb { + static XpOrb DEFAULT = new XpOrb(); + + int time = 628; // milliseconds + } } diff --git a/src/main/resources/colormatic.mixins.json b/src/main/resources/colormatic.mixins.json index 4a3e473..245e385 100644 --- a/src/main/resources/colormatic.mixins.json +++ b/src/main/resources/colormatic.mixins.json @@ -31,7 +31,8 @@ "text.DyeColorMixin", "text.InGameHudMixin", "world.BiomeMixin", - "world.WorldMixin" + "world.WorldMixin", + "xp.ExperienceOrbEntityRendererMixin" ], "injectors": { "defaultRequire": 1