Use DyeColor's textColor for hopper counters (#1709)

* Use `DyeColor`'s `textColor` for hopper counters

* Remove now unused `Material2DyeName` map in `WoolTool`
This commit is contained in:
altrisi authored and GitHub committed 2023-04-27 18:06:57 +02:00
1 parent 00ee45d59b
commit 1c4bcd682d
2 files changed
+11 -33

No files matched your search

@@ -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<Component> 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"
-24
View File
@@ -38,30 +38,6 @@ public class WoolTool
private static final Map<MapColor,DyeColor> 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<MapColor,String> 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:
* <ul>