Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,24 @@ The script is used to compose complex JQL queries from a JSON-encoded dictionary
It will enclose the expansion of sub-queries in parentheses while expanding, in order to ensure the original precedence.

In order to use one query inside another, use the sub-query's name in brackets inside the outer query. See sample.json for an example.

## How Many Do I Need?
The minecraft/hmdin script is basically a counting formatter that can help you keep track of large item quantities in Minecraft.
By default, it will print a human-readable listing of all nonzero "units of quantity" necessary to amass the specified amount of items.

You can specify a nonstandard stack size (e.g. 16 for eggs or similar) using `--stack-size`.

python hmdin.py 256 --stack_size=16
> 256 items are 16 stacks

python hmdin.py 256
> 255 items are 3 stacks and 63 items

python hmdin.py 2000
> 2000 items are 1 chest, 4 stacks and 16 items

The actual helper/split functions are:

hmdin(count, stack_size=64, container_size=27) # will return the tuple of <chests>, <stacks>, <items>
pretty_print(chests, stacks, items) # will format the list of items as human readable (without prefix), e.g. "3 chests and 14 items"
csv_print(chests, stacks, items, separator=",") #will format the list of all three items for CSV output, e.g. comma-separated
40 changes: 40 additions & 0 deletions minecraft/hmdin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import argparse
import sys

def hmdin(count, stack_size=64, container_size=27):
i = count % stack_size
s_raw = count // stack_size
s = s_raw % container_size
c = s_raw // container_size
return c, s, i

def pretty_print_kind(count, name):
return f"{count} {name}{'' if count == 1 else 's'}"

def pretty_print(chests, stacks, items):
components = []
if chests > 0:
components.append(pretty_print_kind(chests, "chest"))
if stacks > 0:
components.append(pretty_print_kind(stacks, "stack"))
if items > 0 or len(components) == 0:
components.append(pretty_print_kind(items, "item"))
if len(components) == 1:
return components[0]
return ", ".join(components[:-1]) + " and " + components[-1]

def csv_print(chests, stacks, items, separator=","):
return separator.join(chests, stacks, items)

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("count", help="Number of items to evaluate", type=int)
parser.add_argument("--stack_size", help="Stack size of the respective item", type=int, default=64)
parser.add_argument("--as_csv", action="store_true")
args = parser.parse_args()
printer = csv_print if args.as_csv else pretty_print
if args.count < 0:
print(f"-{pretty_print_kind(-args.count, 'item')} {'are' if args.count != 1 else 'is'} imaginary.")
sys.exit(1)
print(f"{pretty_print_kind(args.count, 'item')} {'are' if args.count != 1 else 'is'} {printer(*hmdin(args.count, args.stack_size))}.")