minecraft_utils 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/coords +17 -16
- data/bin/stacks +38 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c88ac42418332dadfbc407e85220306e174fe9b2cdf169e9e7ce061befda07d
|
4
|
+
data.tar.gz: b9494d9e838f4cdaacc1409c0b8cd78a16f57e8536ddc5941ff590da49bb8add
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
4
|
-
|
5
|
-
ARGV.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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(
|
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
|
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
|
-
|
37
|
-
|
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
|
-
|
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
|
-
|
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 " (#{
|
77
|
+
print " (#{get_output stacks, blocks, stacks >= 27})"
|
53
78
|
end
|
54
79
|
|
55
80
|
puts
|