Module: McBlocky::DSL
- Included in:
- Context
- Defined in:
- lib/mcblocky/dsl.rb,
lib/mcblocky/dsl/block.rb,
lib/mcblocky/dsl/commands.rb,
lib/mcblocky/dsl/selector.rb,
lib/mcblocky/dsl/container.rb,
lib/mcblocky/dsl/repeat_chain.rb,
lib/mcblocky/dsl/command_block.rb,
lib/mcblocky/dsl/impulse_chain.rb
Defined Under Namespace
Modules: Color, Facing
Classes: Block, CommandBlock, Commands, Container, ImpulseChain, PartialCommand, RepeatChain, Selector
Class Method Summary
collapse
Instance Method Summary
collapse
-
#after(&block) ⇒ Object
-
#area(x1, y1, z1, x2, y2, z2) ⇒ Object
-
#at(x, y, z, data = 0, kind = :normal, nbt = {}, &block) ⇒ Object
-
#chain(*args, &block) ⇒ Object
-
#chest(x, y, z, data = 0, &block) ⇒ Object
-
#cleanup(&block) ⇒ Object
-
#dispenser(x, y, z, data = 0, &block) ⇒ Object
-
#dropper(x, y, z, data = 0, &block) ⇒ Object
-
#fill(x1, y1, z1, x2, y2, z2, kind, data = 0) ⇒ Object
-
#furnace(x, y, z, data = 0, &block) ⇒ Object
-
#helper(*command, &block) ⇒ Object
-
#initial(&block) ⇒ Object
-
#repeat(*args, &block) ⇒ Object
-
#setblock(x, y, z, kind, data = 0, replacemode = 'replace', nbt = {}) ⇒ Object
-
#trapped_chest(x, y, z, data = 0, &block) ⇒ Object
Class Method Details
.to_json(*args) ⇒ Object
147
148
149
150
151
152
153
|
# File 'lib/mcblocky/dsl.rb', line 147
def to_json(*args)
if args.length > 1
JSON.dump(args)
else
JSON.dump(args[0])
end
end
|
.to_nbt(obj) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/mcblocky/dsl.rb', line 128
def to_nbt(obj)
case obj
when String
JSON.dump(obj)
when Fixnum, Float
obj.to_s
when Array
"[#{obj.map{|x| to_nbt x}.join(',')}]"
when Hash
pairs = obj.map do |k,v|
"#{k}:#{to_nbt v}"
end
"{#{pairs.join(',')}}"
else
raise ArgumentError, "No NBT form for #{obj}"
end
end
|
Instance Method Details
#after(&block) ⇒ Object
28
29
30
31
32
|
# File 'lib/mcblocky/dsl.rb', line 28
def after(&block)
chain = Commands.new(context, :after)
chain.instance_exec(&block)
chains << chain
end
|
#area(x1, y1, z1, x2, y2, z2) ⇒ Object
84
85
86
|
# File 'lib/mcblocky/dsl.rb', line 84
def area(x1, y1, z1, x2, y2, z2)
context.last_area = Rect.new(x1, y1, z1, x2, y2, z2)
end
|
#at(x, y, z, data = 0, kind = :normal, nbt = {}, &block) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/mcblocky/dsl.rb', line 64
def at(x, y, z, data=0, kind=:normal, nbt={}, &block)
if Symbol === data
kind = data
data = 0
end
block_kind = case kind
when :normal
'minecraft:command_block'
when :chain
'minecraft:chain_command_block'
when :repeating
'minecraft:repeating_command_block'
else
raise ArgumentError, 'Unknown command block type'
end
cblock = CommandBlock.new(context, x, y, z, data, block_kind, nbt)
cblock.instance_exec(&block)
blocks[Location.new(x, y, z)] = cblock
end
|
#chain(*args, &block) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/mcblocky/dsl.rb', line 49
def chain(*args, &block)
if Symbol === args[0]
name = args.delete_at(0)
raise NameError, 'Name already exists' if named_chains.has_key? name
end
if args.empty?
rect = context.last_area
args = [rect.x1, rect.y1, rect.z1, rect.x2, rect.y2, rect.z2]
end
chain = ImpulseChain.new(context, *args)
chain.instance_exec(&block)
chains << chain
named_chains[name] = chain if name
end
|
#chest(x, y, z, data = 0, &block) ⇒ Object
98
99
100
101
102
|
# File 'lib/mcblocky/dsl.rb', line 98
def chest(x, y, z, data=0, &block)
container = Container.new(x, y, z, 'minecraft:chest', data)
container.instance_exec(&block)
blocks[Location.new(x, y, z)] = container
end
|
#cleanup(&block) ⇒ Object
22
23
24
25
26
|
# File 'lib/mcblocky/dsl.rb', line 22
def cleanup(&block)
chain = Commands.new(context, :cleanup)
chain.instance_exec(&block)
chains << chain
end
|
#dispenser(x, y, z, data = 0, &block) ⇒ Object
110
111
112
113
114
|
# File 'lib/mcblocky/dsl.rb', line 110
def dispenser(x, y, z, data=0, &block)
container = Container.new(x, y, z, 'minecraft:dispenser', data)
container.instance_exec(&block)
blocks[Location.new(x, y, z)] = container
end
|
#dropper(x, y, z, data = 0, &block) ⇒ Object
116
117
118
119
120
|
# File 'lib/mcblocky/dsl.rb', line 116
def dropper(x, y, z, data=0, &block)
container = Container.new(x, y, z, 'minecraft:dropper', data)
container.instance_exec(&block)
blocks[Location.new(x, y, z)] = container
end
|
#fill(x1, y1, z1, x2, y2, z2, kind, data = 0) ⇒ Object
93
94
95
96
|
# File 'lib/mcblocky/dsl.rb', line 93
def fill(x1, y1, z1, x2, y2, z2, kind, data=0)
block = Block.new(nil, nil, nil, kind, data)
rects[Rect.new(x1, y1, z1, x2, y2, z2)] = block
end
|
#furnace(x, y, z, data = 0, &block) ⇒ Object
122
123
124
125
126
|
# File 'lib/mcblocky/dsl.rb', line 122
def furnace(x, y, z, data=0, &block)
container = Container.new(x, y, z, 'minecraft:furnace', data)
container.instance_exec(&block)
blocks[Location.new(x, y, z)] = container
end
|
#helper(*command, &block) ⇒ Object
12
13
14
|
# File 'lib/mcblocky/dsl.rb', line 12
def helper(*command, &block)
context.helpers << [command, block]
end
|
#initial(&block) ⇒ Object
16
17
18
19
20
|
# File 'lib/mcblocky/dsl.rb', line 16
def initial(&block)
chain = Commands.new(context, :initial)
chain.instance_exec(&block)
chains << chain
end
|
#repeat(*args, &block) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mcblocky/dsl.rb', line 34
def repeat(*args, &block)
if Symbol === args[0]
name = args.delete_at(0)
raise NameError, 'Name already exists' if named_chains.has_key? name
end
if args.empty?
rect = context.last_area
args = [rect.x1, rect.y1, rect.z1, rect.x2, rect.y2, rect.z2]
end
chain = RepeatChain.new(context, *args)
chain.instance_exec(&block)
chains << chain
named_chains[name] = chain if name
end
|
#setblock(x, y, z, kind, data = 0, replacemode = 'replace', nbt = {}) ⇒ Object
88
89
90
91
|
# File 'lib/mcblocky/dsl.rb', line 88
def setblock(x, y, z, kind, data=0, replacemode='replace', nbt={})
block = Block.new(x, y, z, kind, data, nbt)
blocks[Location.new(x, y, z)] = block
end
|
#trapped_chest(x, y, z, data = 0, &block) ⇒ Object
104
105
106
107
108
|
# File 'lib/mcblocky/dsl.rb', line 104
def trapped_chest(x, y, z, data=0, &block)
container = Container.new(x, y, z, 'minecraft:trapped_chest', data)
container.instance_exec(&block)
blocks[Location.new(x, y, z)] = container
end
|