Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (87 sloc) 1.914 kB
6e1c68f @danielribeiro roller coaster the sine!
authored
1 #!/usr/bin/env ruby
2 require 'plotting_example'
3
4 class RollerCoaster
5 attr_accessor :size
6 attr_reader :height
7
8 def initialize(regionFile)
9 @z = padding
10 @x = padding
11 @y = 1
12 @size = 3 * 16
13 @height = 127
14 @regionFile = regionFile
15 @region = Region.fromFile(regionFile)
16 end
17
18 # for uniform plots
19 def plotWith(fillBlock, &block)
20 plot block, proc { |b| b.name = fillBlock}
21 end
22
23 def plot(function, fillFunction)
24 cube = getCube
25 middlePointX = length / 2
26 middlePointZ = width / 2
27 centeredF = proc do |x, z|
28 function.call(x - middlePointX, z - middlePointZ).ceil
29 end
30 cube.each do |b, z, x, y|
31 fxz = centeredF.call(x, z)
32 if y == fxz
33 args = [b, z, x, y].take(fillFunction.arity)
34 fillFunction.call *args
35 end
36 if x == xRail
37 onRail fxz, b, z, x, y, centeredF
38 end
39 end
40 end
41
42 def onRail(fxz, b, z, x, y, centeredF)
43 cur = fxz + 1
44 if cur == y
45 b.name = :powered_rail
46 before = centeredF.call(x, z - 1)
47 after = centeredF.call(x, z + 1)
48 if before > fxz
49 b.data = 4
50 elsif fxz < after
51 b.data = 5
52 else
53 b.data = 0
54 end
55 b.data |= 8
56 elsif fxz - 1 == y
57 b.name = :redstone_torch_on
58 elsif fxz - 2 == y
59 b.name = :gold
60 end
61 end
62
63 def save
64 @region.exportToFile @regionFile
65 end
66
67 protected
68 def getCube
69 @region.cube @z, @x, @y, :width => width, :length => length, :height => height
70 end
71
72 def padding
73 5
74 end
75
76 def xRail
77 42
78 end
79
80 def width
81 32 * 16 - 2 * padding
82 end
83
84 def length
85 5 * 16 - 2 * padding
86 end
87 end
88
89 if __FILE__ == $0
90 puts "Starting"
91 reg = '/home/daniel/.minecraft/saves/LowDirt/region/r.0.0.mcr'
92 p = RollerCoaster.new reg
93 p.plotWith :gold do |x, z|
94 Math.sin(Math.sqrt((x** 2 + z ** 2)) / 16) * 10 + 30
95 end
96 puts 'exporting'
97 p.save
98 puts 'done'
99 end
Something went wrong with that request. Please try again.