minecraft_utils 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/coords +17 -16
  3. data/bin/stacks +38 -13
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ade4161dc2a89c78868302a98e54664ec94ed1a61d7f7cad45f716344ffe08cb
4
- data.tar.gz: e4bfc6cbc5ded8615131b0a230ebe8d72c43fe4d8a911405fca9a5dc8797b3d1
3
+ metadata.gz: 4ff9a21f2a355dadea7f4fe3c1d421195c6dbc0db21d53e3c218b387bd2b78e0
4
+ data.tar.gz: 86ca4f6330e09e2b26158be214949bf20275f42696b1f119836a7e329ae492cf
5
5
  SHA512:
6
- metadata.gz: 462b31765ee8a35e729ab3ad04a5ee5abaf6125aa0ebaaaecbc8b12ce132da9d78db6157e3ce575f915643159adfe3e8b2a634ac9440800344e2dddf774ba179
7
- data.tar.gz: 9402dad2988380246b5f9cd9f8545785361a587347e89defdd43a13f2a8ce541f82ffc56961c69649396fe3aca40159c0ecfd6335f4682c7445dec93bca21ffa
6
+ metadata.gz: 4ee62536fdc027efe8b7ef92f42116306918454cd7e9f1d3921a5b12701599c0a02c498c007ffedb37c8bb77e92c69c852eb397f23dfb606f36223998e3b4adb
7
+ data.tar.gz: bb5e536e9192048278cccf5019279b05f6e5b63f2543050db2b63f4d9d733eeeb983fb2846465695761db4e2646f0c9f3bca5e9b4e5272c906da3719183cf747
data/bin/coords CHANGED
@@ -1,24 +1,25 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require "optparse"
4
-
5
- ARGV.push "-h" if ARGV.empty?
6
-
7
- options = {}
8
- location = "Nether"
9
- OptionParser.new do |opts|
10
- opts.banner = "Usage: coords [options] X Z"
3
+ # TODO: OptionParser is breaking negative number support.
4
+ # Is there a better way to do this?
5
+ if ARGV.empty? or ["-h", "--help"].include? ARGV[0]
6
+ puts "Usage: coords [-o] X Z"
7
+ puts
8
+ puts " [-o] calculates nether -> overworld coordinates"
9
+ exit 0
10
+ end
11
11
 
12
- opts.on("-o", "--overworld",
13
- "calculates nether -> overworld coordinates") do |o|
14
- options[:overworld] = o
15
- location = "Overworld"
16
- end
17
- end.parse!
12
+ if ARGV.include? "-o"
13
+ overworld = true
14
+ location = "Overworld"
15
+ ARGV.delete "-o"
16
+ else
17
+ location = "Nether"
18
+ end
18
19
 
19
20
  # Try and find 2 valid numbers in the args.
20
21
  # They could run `coords 550 fuck you 700` for all I care.
21
- case (coords = ARGV.grep(/^\d+$/).map &:to_i).size
22
+ case (coords = ARGV.grep(/^-?\d+$/).map &:to_i).size
22
23
  when 3
23
24
  # If they give XYZ, strip the Y
24
25
  coords -= [coords[1]]
@@ -31,7 +32,7 @@ end
31
32
 
32
33
  # Transform the coordinates
33
34
  x, z = coords.map do |c|
34
- if options[:overworld]
35
+ if overworld
35
36
  c * 8
36
37
  else
37
38
  (c / 8.0).round
data/bin/stacks CHANGED
@@ -8,10 +8,6 @@ options = {}
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: stacks [options] AMOUNT [STACK SIZE=64]"
10
10
 
11
- opts.on("-s", "--shulkers", "prints amount of shulker boxes to fill") do |o|
12
- options[:shulkers] = o
13
- end
14
-
15
11
  opts.on("-d", "--dye",
16
12
  "prints amount of dye needed for stained glass or concrete") do |o|
17
13
  options[:dye] = o
@@ -28,28 +24,57 @@ unless ARGV[1].nil? or ARGV[1].match? /^\d+$/
28
24
  exit 1
29
25
  end
30
26
 
27
+ # Returns an array [stacks, blocks]
31
28
  def calc_stacks(n, stack_size=64)
32
- stacks = (n / stack_size).floor
33
- return [stacks, n - (stacks * stack_size)]
29
+ [stacks = (n / stack_size).floor, n - (stacks * stack_size)]
34
30
  end
35
31
 
36
- amount = ARGV[0].to_i
37
- stacks, blocks = calc_stacks(amount, ARGV[1].nil? ? 64 : ARGV[1].to_i)
32
+ # Get proper pluralization
33
+ #
34
+ # pluralize 1, "stack" #=> "1 stack"
35
+ # pluralize 3, "stack" #=> "3 stacks"
36
+ def pluralize(n, str)
37
+ "#{n} #{str + (n == 1 ? "" : "s")}"
38
+ end
39
+
40
+ # Create an intelligent output, i.e. don't print something like "0 blocks"
41
+ def get_output(stacks, blocks, put_shulkers=false)
42
+ s = ""
43
+ put_stacks, put_blocks = stacks.nonzero?, blocks.nonzero?
44
+
45
+ if put_shulkers
46
+ s += pluralize boxes = (stacks / 27).floor, "shulker"
47
+
48
+ # Strip the necessary # of stacks off the count.
49
+ stacks -= boxes * 27
50
+ put_stacks = stacks.nonzero?
38
51
 
39
- puts "#{stacks} stacks, #{blocks} blocks"
52
+ s += ", " if put_stacks or put_blocks
53
+ end
54
+
55
+ if put_stacks
56
+ s += pluralize stacks, "stack"
57
+ s += ", " if put_blocks
58
+ end
59
+
60
+ s += pluralize blocks, "block" if put_blocks
40
61
 
41
- if options[:shulkers]
42
- boxes = (stacks / 27).floor
43
- puts "#{boxes} shulkers, #{stacks-(boxes * 27)} stacks, #{blocks} blocks"
62
+ s
44
63
  end
45
64
 
65
+ exit 0 if (amount = ARGV[0].to_i).zero?
66
+ stacks, blocks = calc_stacks(amount, ARGV[1].nil? ? 64 : ARGV[1].to_i)
67
+
68
+ puts get_output stacks, blocks
69
+ puts get_output stacks, blocks, true if stacks >= 27
70
+
46
71
  if options[:dye]
47
72
  dye = (amount / 8.0).ceil
48
73
  print "Dye needed: #{dye}"
49
74
 
50
75
  if dye > 64
51
76
  stacks, blocks = calc_stacks dye
52
- print " (#{stacks} stacks, #{blocks} blocks)"
77
+ print " (#{get_output stacks, blocks, stacks >= 27})"
53
78
  end
54
79
 
55
80
  puts
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minecraft_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-26 00:00:00.000000000 Z
11
+ date: 2023-04-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Tools for calculating stacks of items and Nether coordinates.
14
14
  email: vinny.diehl@gmail.com
@@ -24,13 +24,13 @@ homepage: https://github.com/vinnydiehl/minecraft_utils
24
24
  licenses:
25
25
  - MIT
26
26
  metadata: {}
27
- post_install_message:
27
+ post_install_message:
28
28
  rdoc_options: []
29
29
  require_paths:
30
30
  - lib
31
31
  required_ruby_version: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: '2.0'
36
36
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -39,8 +39,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  requirements: []
42
- rubygems_version: 3.1.3
43
- signing_key:
42
+ rubygems_version: 3.4.10
43
+ signing_key:
44
44
  specification_version: 4
45
45
  summary: A simple set of calculator tools for Minecraft.
46
46
  test_files: []