minecraft_utils 0.1.0 → 1.0.0

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 +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ade4161dc2a89c78868302a98e54664ec94ed1a61d7f7cad45f716344ffe08cb
4
- data.tar.gz: e4bfc6cbc5ded8615131b0a230ebe8d72c43fe4d8a911405fca9a5dc8797b3d1
3
+ metadata.gz: 7c88ac42418332dadfbc407e85220306e174fe9b2cdf169e9e7ce061befda07d
4
+ data.tar.gz: b9494d9e838f4cdaacc1409c0b8cd78a16f57e8536ddc5941ff590da49bb8add
5
5
  SHA512:
6
- metadata.gz: 462b31765ee8a35e729ab3ad04a5ee5abaf6125aa0ebaaaecbc8b12ce132da9d78db6157e3ce575f915643159adfe3e8b2a634ac9440800344e2dddf774ba179
7
- data.tar.gz: 9402dad2988380246b5f9cd9f8545785361a587347e89defdd43a13f2a8ce541f82ffc56961c69649396fe3aca40159c0ecfd6335f4682c7445dec93bca21ffa
6
+ metadata.gz: 7f3b679c6f25188205339fe1c344243cf7b39ebbc33a3f6de5f5b258066492b4ebbf4639bf3fe554596d8673ec4dc6f958238552ffdb6243a4b1225876eb54c3
7
+ data.tar.gz: 30a5e0eabe2e76b2f112ad3043163fea94fd2bf3623643e9dbf469cfe905c5df8fc0dac00c92b8f6771f724209c0f1caa2406b9be73cc66e0fb73f29ccd29a46
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,7 +1,7 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl