Adding Javadocs to CounterCommand.java and relevant files (#838)

* adding class javadoc

Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
This commit is contained in:
Ghoulboyandgnembon authored and GitHub committed 2021-05-17 19:32:57 -03:00
1 parent 7380580a3e
commit 7536edc2b9
6 files changed
+135 -1

No files matched your search

@@ -42,9 +42,22 @@ import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
/**
* The actual object residing in each hopper counter which makes them count the items and saves them. There is one for each
* colour in MC.
*/
public class HopperCounter
{
/**
* A map of all the {@link HopperCounter} counters.
*/
public static final Map<DyeColor, HopperCounter> COUNTERS;
/**
* The default display colour of each item, which makes them look nicer when printing the counter contents to the chat
*/
public static final TextColor WHITE = TextColor.fromFormatting(Formatting.WHITE);
static
@@ -57,10 +70,29 @@ public class HopperCounter
COUNTERS = Maps.immutableEnumMap(counterMap);
}
/**
* The counter's colour, determined by the colour of wool it's pointing into
*/
public final DyeColor color;
/**
* 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;
/**
* 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.
*/
private final Object2LongMap<Item> counter = new Object2LongLinkedOpenHashMap<>();
/**
* The starting tick of the counter, used to calculate in-game time. Only initialised when the first item enters the
* counter
*/
private long startTick;
/**
* The starting millisecond of the counter, used to calculate IRl time. Only initialised when the first item enters
* the counter
*/
private long startMillis;
// private PubSubInfoProvider<Long> pubSubProvider;
@@ -71,6 +103,11 @@ public class HopperCounter
this.prettyColour = WoolTool.Material2DyeName.getOrDefault(color.getMaterialColor(),"w ") + color.getName();
}
/**
* Method used to add items to the counter. Note that this is when the {@link HopperCounter#startTick} and
* {@link HopperCounter#startMillis} variables are initialised, so you can place the counters and then start the farm
* after all the collection is sorted out.
*/
public void add(MinecraftServer server, ItemStack stack)
{
if (startTick < 0)
@@ -83,6 +120,9 @@ public class HopperCounter
// pubSubProvider.publish();
}
/**
* Resets the counter, clearing its items but keeping the clock running.
*/
public void reset(MinecraftServer server)
{
counter.clear();
@@ -91,6 +131,10 @@ public class HopperCounter
// pubSubProvider.publish();
}
/**
* Resets all counters, clearing their items.
* @param fresh Whether or not to start the clocks going immediately or later.
*/
public static void resetAll(MinecraftServer server, boolean fresh)
{
for (HopperCounter counter : COUNTERS.values())
@@ -100,6 +144,9 @@ public class HopperCounter
}
}
/**
* Prints all the counters to chat, nicely formatted, and you can choose whether to diplay in in game time or IRL time
*/
public static List<BaseText> formatAll(MinecraftServer server, boolean realtime)
{
List<BaseText> text = new ArrayList<>();
@@ -120,6 +167,10 @@ public class HopperCounter
return text;
}
/**
* Prints a single counter's contents and timings to chat, with the option to keep it short (so no item breakdown,
* only rates). Again, realtime displays IRL time as opposed to in game time.
*/
public List<BaseText> format(MinecraftServer server, boolean realTime, boolean brief)
{
long ticks = Math.max(realTime ? (System.currentTimeMillis() - startMillis) / 50 : server.getWorld(World.OVERWORLD).getTime() - startTick, 1); //OW
@@ -172,6 +223,10 @@ public class HopperCounter
return items;
}
/**
* Converts a colour to have a low brightness and uniform colour, so when it prints the items in different colours
* it's not too flashy and bright, but enough that it's not dull to look at.
*/
public static int appropriateColor(int color)
{
if (color == 0) return MaterialColor.WHITE.color;
@@ -184,6 +239,10 @@ public class HopperCounter
return (r << 16) + (g << 8) + b;
}
/**
* Maps items that don't get a good block to reference for colour, or those that colour is wrong to a number of blocks, so we can get their colours easily with the
* {@link Block#getDefaultMaterialColor()} method as these items have those same colours.
*/
private static final ImmutableMap<Item, Block> DEFAULTS = new ImmutableMap.Builder<Item, Block>()
.put(Items.DANDELION, Blocks.YELLOW_WOOL)
.put(Items.POPPY, Blocks.RED_WOOL)
@@ -269,6 +328,9 @@ public class HopperCounter
//.put(Items.,Blocks.)
.build();
/**
* Gets the colour to print an item in when printing its count in a hopper counter.
*/
public static TextColor fromItem(Item item)
{
if (DEFAULTS.containsKey(item)) return TextColor.fromRgb(appropriateColor(DEFAULTS.get(item).getDefaultMaterialColor().color));
@@ -292,6 +354,10 @@ public class HopperCounter
return null;
}
/**
* Guesses the item's colour from the item itself. It first calls {@link HopperCounter#fromItem} to see if it has a
* valid colour there, if not just makes a guess, and if that fails just returns null
*/
public static TextColor guessColor(Item item)
{
TextColor direct = fromItem(item);
@@ -319,6 +385,9 @@ public class HopperCounter
return null;
}
/**
* Returns the hopper counter from the colour name, if not null
*/
public static HopperCounter getCounter(String color)
{
try
@@ -332,6 +401,9 @@ public class HopperCounter
}
}
/**
* The total number of items in the counter
*/
public long getTotalItems()
{
return counter.isEmpty()?0:counter.values().stream().mapToLong(Long::longValue).sum();