Skip to content

Commit

Permalink
Merge pull request #12 from BlazingTwist/1.19.4
Browse files Browse the repository at this point in the history
1.3.0 - support custom text colors
  • Loading branch information
BlazingTwist authored Jun 4, 2023
2 parents 3ebf4c4 + 9a4e7bd commit daad7a9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.17

# Mod Properties
mod_version = 1.2.0
mod_version = 1.3.0
maven_group = blazingtwist
archives_base_name = itemcounts

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/blazingtwist/itemcounts/config/ItemCountsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public ItemRenderConfig(boolean enabled, CountDisplayOption countOption,
public IconDisplayOption iconOption = IconDisplayOption.NEVER;
@ConfigEntry.Gui.CollapsibleObject()
public HudOffset offset = new HudOffset(0, -5, 0.75f);
@ConfigEntry.Gui.CollapsibleObject()
public HudColors colors = new HudColors();

}

public static class HudOffset {
Expand All @@ -124,6 +127,20 @@ public HudOffset(int x, int y, float textScale) {
public TextAnchorOption anchor = TextAnchorOption.CENTER;
}

public static class HudColors {
@AutoConfigConstructor
public HudColors() {
}

public boolean enableCustomColors;
@ConfigEntry.ColorPicker
public int colorItemCount = 0xffffff;
@ConfigEntry.ColorPicker
public int colorDurabilityHigh = 0x00ff00;
@ConfigEntry.ColorPicker
public int colorDurabilityLow = 0xff0000;
}

public static class ItemCountSeparationRules {
@AutoConfigConstructor
public ItemCountSeparationRules() {
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/blazingtwist/itemcounts/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import blazingtwist.itemcounts.ItemCounts;
import blazingtwist.itemcounts.config.ItemCountsConfig;
import blazingtwist.itemcounts.util.ColorHelper;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -30,6 +31,7 @@
@Environment(EnvType.CLIENT)
@Mixin(InGameHud.class)
public abstract class InGameHudMixin {

@Shadow
@Final
private MinecraftClient client;
Expand Down Expand Up @@ -70,13 +72,23 @@ private boolean renderItemText(ItemCountsConfig.ItemRenderConfig config, boolean
if (!config.durabilityOption.shouldShowDurability(stack)) {
return false;
}
text = "" + (stack.getMaxDamage() - stack.getDamage());
color = stack.getItemBarColor();
int maxDamage = stack.getMaxDamage();
int currentDamage = stack.getDamage();
text = "" + (maxDamage - currentDamage);
if (config.colors.enableCustomColors) {
float damageFraction = ((float) currentDamage) / maxDamage;
color = ColorHelper.lerpColor(damageFraction, config.colors.colorDurabilityHigh, config.colors.colorDurabilityLow);
} else {
color = stack.getItemBarColor();
}
} else {
if (!config.countOption.shouldShowCount(player, stack)) {
return false;
}
text = "" + ItemCounts.getConfig().item_count_rules.getTotalItemCount(player, stack);
if (config.colors.enableCustomColors) {
color = config.colors.colorItemCount;
}
}

renderTextAt(config, text, color, x, y, onHotbar);
Expand Down Expand Up @@ -174,4 +186,5 @@ public void onRenderHotbarItem(MatrixStack matrixStack, int x, int y, float tick

renderItemOverlay(config.hotbar_relativeToHotbarConfig, true, player, stack, x, y);
}

}
30 changes: 30 additions & 0 deletions src/main/java/blazingtwist/itemcounts/util/ColorHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package blazingtwist.itemcounts.util;

import net.minecraft.util.math.MathHelper;

public class ColorHelper {

public static int lerpColor(float delta, int fromColor, int toColor) {
int red = MathHelper.lerp(delta, getRed(fromColor), getRed(toColor));
int green = MathHelper.lerp(delta, getGreen(fromColor), getGreen(toColor));
int blue = MathHelper.lerp(delta, getBlue(fromColor), getBlue(toColor));
return setRGB(red, green, blue);
}

public static int getRed(int color) {
return (color & 0xff0000) >> 16;
}

public static int getGreen(int color) {
return (color & 0xff00) >> 8;
}

public static int getBlue(int color) {
return (color & 0xff);
}

public static int setRGB(int red, int green, int blue) {
return ((red & 0xff) << 16) | ((green & 0xff) << 8) | (blue & 0xff);
}

}
25 changes: 25 additions & 0 deletions src/main/resources/assets/itemcounts/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.offset.y": "y > 0 moves text down, y < 0 moves text up",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.offset.textScale": "Scale-factor for text",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.offset.anchor": "Anchor-position, text grows outwards from its anchor",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.colors": "Configure colors",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.colors.enableCustomColors": "Enable custom colors",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.colors.colorItemCount": "Color for counts",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.colors.colorDurabilityHigh": "Color for max durability",
"text.autoconfig.itemcounts.option.mainHand_relativeToHotbarConfig.colors.colorDurabilityLow": "Color for min durability",

"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig": "Configure overlay relative to crosshair for active item",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.enabled": "enable this overlay",
Expand All @@ -28,6 +33,11 @@
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.offset.y": "y > 0 moves text down, y < 0 moves text up",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.offset.textScale": "Scale-factor for text",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.offset.anchor": "Anchor-position, text grows outwards from its anchor",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.colors": "Configure colors",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.colors.enableCustomColors": "Enable custom colors",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.colors.colorItemCount": "Color for counts",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.colors.colorDurabilityHigh": "Color for max durability",
"text.autoconfig.itemcounts.option.mainHand_relativeToCrosshairConfig.colors.colorDurabilityLow": "Color for min durability",

"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig": "Configure overlay relative to hotbar for offhand item",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.enabled": "enable this overlay",
Expand All @@ -40,6 +50,11 @@
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.offset.y": "y > 0 moves text down, y < 0 moves text up",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.offset.textScale": "Scale-factor for text",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.offset.anchor": "Anchor-position, text grows outwards from its anchor",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.colors": "Configure colors",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.colors.enableCustomColors": "Enable custom colors",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.colors.colorItemCount": "Color for counts",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.colors.colorDurabilityHigh": "Color for max durability",
"text.autoconfig.itemcounts.option.offHand_relativeToHotbarConfig.colors.colorDurabilityLow": "Color for min durability",

"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig": "Configure overlay relative to crosshair for offhand item",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.enabled": "enable this overlay",
Expand All @@ -52,6 +67,11 @@
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.offset.y": "y > 0 moves text down, y < 0 moves text up",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.offset.textScale": "Scale-factor for text",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.offset.anchor": "Anchor-position, text grows outwards from its anchor",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.colors": "Configure colors",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.colors.enableCustomColors": "Enable custom colors",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.colors.colorItemCount": "Color for counts",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.colors.colorDurabilityHigh": "Color for max durability",
"text.autoconfig.itemcounts.option.offHand_relativeToCrosshairConfig.colors.colorDurabilityLow": "Color for min durability",

"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig": "Configure overlay relative to hotbar for hotbar items",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.enabled": "enable this overlay",
Expand All @@ -64,6 +84,11 @@
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.offset.y": "y > 0 moves text down, y < 0 moves text up",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.offset.textScale": "Scale-factor for text",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.offset.anchor": "Anchor-position, text grows outwards from its anchor",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.colors": "Configure colors",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.colors.enableCustomColors": "Enable custom colors",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.colors.colorItemCount": "Color for counts",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.colors.colorDurabilityHigh": "Color for max durability",
"text.autoconfig.itemcounts.option.hotbar_relativeToHotbarConfig.colors.colorDurabilityLow": "Color for min durability",

"text.autoconfig.itemcounts.option.item_count_rules": "Configure how items are counted",
"text.autoconfig.itemcounts.option.item_count_rules.separateNbtData": "separate item-count by item NBT tags",
Expand Down
Binary file not shown.

0 comments on commit daad7a9

Please sign in to comment.