Skip to content

Commit

Permalink
Add experience orb colors
Browse files Browse the repository at this point in the history
  • Loading branch information
kvverti committed Jul 23, 2019
1 parent e4e39df commit fbf9f24
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main/java/io/github/kvverti/colormatic/Colormatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<ExperienceOrbEntity> {

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class GlobalColorProperties {
private final Map<EntityType<?>, int[]> spawnEgg;
private final Map<ChatFormat, HexColor> textColor;
private final TextColor text;
private final int xpOrbTime;

private GlobalColorProperties(Settings settings) {
this.particle = settings.particle;
Expand All @@ -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<>();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -325,6 +331,7 @@ private static class Settings {
Map<String, HexColor[]> spawnegg = Collections.emptyMap();
LegacyEggColor egg;
TextColor text;
XpOrb xporb = XpOrb.DEFAULT;
}

/**
Expand All @@ -348,4 +355,10 @@ static class ButtonText {
HexColor disabled;
}
}

private static class XpOrb {
static XpOrb DEFAULT = new XpOrb();

int time = 628; // milliseconds
}
}
3 changes: 2 additions & 1 deletion src/main/resources/colormatic.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"text.DyeColorMixin",
"text.InGameHudMixin",
"world.BiomeMixin",
"world.WorldMixin"
"world.WorldMixin",
"xp.ExperienceOrbEntityRendererMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit fbf9f24

Please sign in to comment.