From 1c4bcd682d01706f860640bb816979d6ed5661e1 Mon Sep 17 00:00:00 2001 From: altrisi Date: Thu, 27 Apr 2023 18:06:57 +0200 Subject: [PATCH] Use `DyeColor`'s `textColor` for hopper counters (#1709) * Use `DyeColor`'s `textColor` for hopper counters * Remove now unused `Material2DyeName` map in `WoolTool` --- .../java/carpet/helpers/HopperCounter.java | 20 +++++++++------- src/main/java/carpet/utils/WoolTool.java | 24 ------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/main/java/carpet/helpers/HopperCounter.java b/src/main/java/carpet/helpers/HopperCounter.java index fb5dd3b0..2138541e 100644 --- a/src/main/java/carpet/helpers/HopperCounter.java +++ b/src/main/java/carpet/helpers/HopperCounter.java @@ -3,7 +3,6 @@ package carpet.helpers; import carpet.CarpetServer; import carpet.fakes.IngredientInterface; import carpet.fakes.RecipeManagerInterface; -import carpet.utils.WoolTool; import carpet.utils.Messenger; import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; @@ -79,7 +78,7 @@ public class HopperCounter * The string which is passed into {@link Messenger#m} which makes each counter name be displayed in the colour of * that counter. */ - private final String prettyColour; + private final String coloredName; /** * All the items stored within the counter, as a map of {@link Item} mapped to a {@code long} of the amount of items * stored thus far of that item type. @@ -101,7 +100,10 @@ public class HopperCounter { startTick = -1; this.color = color; - this.prettyColour = WoolTool.Material2DyeName.getOrDefault(color.getMapColor(),"w ") + color.getName(); + String hexColor = Integer.toHexString(color.getTextColor()); + if (hexColor.length() < 6) + hexColor = "0".repeat(hexColor.length() - 4) + hexColor; + this.coloredName = '#' + hexColor + ' ' + color.getName(); } /** @@ -179,31 +181,31 @@ public class HopperCounter { if (brief) { - return Collections.singletonList(Messenger.c("b"+prettyColour,"w : ","gi -, -/h, - min ")); + return Collections.singletonList(Messenger.c("b"+coloredName,"w : ","gi -, -/h, - min ")); } - return Collections.singletonList(Messenger.c(prettyColour, "w hasn't started counting yet")); + return Collections.singletonList(Messenger.c(coloredName, "w hasn't started counting yet")); } long total = getTotalItems(); if (total == 0) { if (brief) { - return Collections.singletonList(Messenger.c("b"+prettyColour,"w : ","wb 0","w , ","wb 0","w /h, ", String.format("wb %.1f ", ticks / (20.0 * 60.0)), "w min")); + return Collections.singletonList(Messenger.c("b"+coloredName,"w : ","wb 0","w , ","wb 0","w /h, ", String.format("wb %.1f ", ticks / (20.0 * 60.0)), "w min")); } - return Collections.singletonList(Messenger.c("w No items for ", prettyColour, String.format("w yet (%.2f min.%s)", + return Collections.singletonList(Messenger.c("w No items for ", coloredName, String.format("w yet (%.2f min.%s)", ticks / (20.0 * 60.0), (realTime ? " - real time" : "")), "nb [X]", "^g reset", "!/counter " + color.getName() +" reset")); } if (brief) { - return Collections.singletonList(Messenger.c("b"+prettyColour,"w : ", + return Collections.singletonList(Messenger.c("b"+coloredName,"w : ", "wb "+total,"w , ", "wb "+(total * (20 * 60 * 60) / ticks),"w /h, ", String.format("wb %.1f ", ticks / (20.0 * 60.0)), "w min" )); } List items = new ArrayList<>(); - items.add(Messenger.c("w Items for ", prettyColour, + items.add(Messenger.c("w Items for ", coloredName, "w (",String.format("wb %.2f", ticks*1.0/(20*60)), "w min"+(realTime?" - real time":"")+"), ", "w total: ", "wb "+total, "w , (",String.format("wb %.1f",total*1.0*(20*60*60)/ticks),"w /h):", "nb [X]", "^g reset", "!/counter "+color+" reset" diff --git a/src/main/java/carpet/utils/WoolTool.java b/src/main/java/carpet/utils/WoolTool.java index 4f0da908..93a682f3 100644 --- a/src/main/java/carpet/utils/WoolTool.java +++ b/src/main/java/carpet/utils/WoolTool.java @@ -38,30 +38,6 @@ public class WoolTool private static final Map Material2Dye = Arrays.stream(DyeColor.values()) .collect(Collectors.toUnmodifiableMap(DyeColor::getMapColor, Function.identity())); - /** - * A map of all the wool colours to their respective colours in the {@link Messenger#m} format so the name of the counter - * gets printed in colour. - */ - - public static final Map Material2DyeName = Map.ofEntries( - entry(MapColor.SNOW, "w "), - entry(MapColor.COLOR_ORANGE, "#F9801D "), - entry(MapColor.COLOR_MAGENTA, "m "), - entry(MapColor.COLOR_LIGHT_BLUE, "t "), - entry(MapColor.COLOR_YELLOW, "y "), - entry(MapColor.COLOR_LIGHT_GREEN, "l "), - entry(MapColor.COLOR_PINK, "#FFACCB "), - entry(MapColor.COLOR_GRAY, "f "), - entry(MapColor.COLOR_LIGHT_GRAY, "g "), - entry(MapColor.COLOR_CYAN, "c "), - entry(MapColor.COLOR_PURPLE, "p "), - entry(MapColor.COLOR_BLUE, "v "), - entry(MapColor.COLOR_BROWN, "#835432 "), - entry(MapColor.COLOR_GREEN, "e "), - entry(MapColor.COLOR_RED, "r "), - entry(MapColor.COLOR_BLACK, "k ") - ); - /** * The method which gets triggered when a player places a carpet, and decides what to do based on the carpet's colour: *