mcblocky 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjMwYjg5MzQ2MjUyYWQwZmI2NjhhMDA1MTYzODNjOTA0NDI2MTBhZA==
4
+ NDNlNzBiMzQ4NDE0NDE3ODcwYjg4ZjRkM2ZmNjMyYzQ0ODE5ZjZiZQ==
5
5
  data.tar.gz: !binary |-
6
- N2I1ZTM3ZWRlN2RhYjAzNzMzZTJhNTI5MTA1ZDU4MmIzMWVhYzA0Mg==
6
+ ZWRmY2NlYzI1YjE5YzM5ZDFiMmY4NTAzNDNkZjlhN2EzZmEzN2VkZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWRmODk2MmIzODVmM2RiMzYyNzQyNDhhYTVkYjIxYTAzNzA1Njg4MTEzNWUy
10
- NjI0MmNjZTZiZTIxMDY1ODVjMzgwZjg5MWZlNjI3OTIyZjY4MTVkZTRmOTYy
11
- NjJhNmQ2NTdmMDVkNGY3M2Y0ZGI1ODUxOGJkMGM0ODQwOTNjZjk=
9
+ NGNmN2JiMjZmZDQ2YzQ0MzI2MTU5ZWU3OGZkNzIxNGQyMTJlNjQ0NTE1NjRh
10
+ ODAyNDg3MzAyMmY1NjA0ZDI1NmJlODQ5OTk3Y2Y0MzRiNGJlMDJkMTg3NWM3
11
+ ZjU1NjEyMDkyODExYjc4M2M1ZjM4OTIxODc3MjhlOWFlYTJkNjA=
12
12
  data.tar.gz: !binary |-
13
- YzdmZGQyM2FhMjRjMDAwMzlhOTFjYmUxMWJlZWUzNTkxMDBkOWQ0MjU1YTU1
14
- MzRiODdiYzhkNGQyYjc1YjFhZjMwNWU2NzhiYTFjNzMxMTYxMDliYjM0NmY5
15
- NTdjMDRjODFkYjgyY2EzZTdmZTBhYTA2NzY3Mjk1Nzc1MThhYzA=
13
+ MGQ1N2VhNDg1YjZiM2RiZTIyOWY1Y2FiYjllNmI0YjY4MTYwYjNlYjc2MWIz
14
+ ODg4OTQxZjY5ZjZkYjk4NTgwZTFkZmZmNjQ5MTJiOGM0Y2E1MDFjMjc4M2I2
15
+ M2FmZDQxODQ4N2UxMjU1MGQ1OTBlODU5ZWNhNzFmMWNmNDk5MTA=
@@ -31,7 +31,7 @@ initial do
31
31
  tellraw @a[team: 'Red'], {text: "Hello world", color: "red"}
32
32
  end
33
33
 
34
- repeat 171, 82, 242, 175, 84, 247 do
34
+ repeat :teams, 171, 82, 242, 175, 84, 242 do
35
35
  scoreboard :players, :set, @a[x: 172, y: 81, z: 236, r: 1, team: '!Red'], 'SwitchingTeam', 1
36
36
  scoreboard :players, :set, @a[x: 170, y: 81, z: 236, r: 1, team: '!Blue'], 'SwitchingTeam', 1
37
37
  execute @a[x: 170, y: 81, z: 236, r: 1, score_SwitchingTeam_min: 1], '~ ~ ~', 'scoreboard teams join Blue @p'
@@ -74,6 +74,31 @@ furnace 176, 79, 248 do
74
74
  item 'minecraft:gold_ingot'
75
75
  end
76
76
 
77
+ at 172, 79, 244 do
78
+ disable :teams
79
+ end
80
+
81
+ at 174, 79, 244 do
82
+ enable :teams
83
+ end
84
+
85
+ setblock 172, 80, 244, 'minecraft:standing_sign', 0, 'replace', {'Text1'=>'{"text":"Disable team"}', 'Text2'=>'{"text":"switcher"}'}
86
+ setblock 174, 80, 244, 'minecraft:standing_sign', 0, 'replace', {'Text1'=>'{"text":"Enable team"}', 'Text2'=>'{"text":"switcher"}'}
87
+ setblock 172, 79, 245, 'minecraft:stone_button', 3
88
+ setblock 174, 79, 245, 'minecraft:stone_button', 3
89
+
90
+ chain :hello, 171, 82, 243, 175, 84, 243 do
91
+ say 'Hello'
92
+ say 'World'
93
+ end
94
+
95
+ at 176, 79, 244 do
96
+ activate :hello
97
+ end
98
+
99
+ setblock 176, 80, 244, 'minecraft:standing_sign', 0, 'replace', {'Text1'=>'{"text":"Activate hello"}'}
100
+ setblock 176, 79, 245, 'minecraft:stone_button', 3
101
+
77
102
  after do
78
103
  # setblock 175, 79, 248, 'minecraft:standing_sign', 0, 'replace'
79
104
  # blockdata 175, 79, 248, {'Text1'=>'{"text":"hola mundo"}'}
@@ -3,6 +3,7 @@ require 'mcblocky/dsl'
3
3
  module McBlocky
4
4
  class Context
5
5
  attr_accessor :server
6
+ attr_accessor :last_area
6
7
 
7
8
  def self.run_file(file, dir=nil)
8
9
  dir = File.dirname(file) unless dir
@@ -36,6 +37,10 @@ module McBlocky
36
37
  @chains ||= []
37
38
  end
38
39
 
40
+ def named_chains
41
+ @named_chains ||= {}
42
+ end
43
+
39
44
  def blocks
40
45
  @blocks ||= {}
41
46
  end
@@ -44,10 +49,6 @@ module McBlocky
44
49
  @rects ||= {}
45
50
  end
46
51
 
47
- def areas
48
- @areas ||= []
49
- end
50
-
51
52
  def context
52
53
  self
53
54
  end
@@ -1,6 +1,7 @@
1
1
  load File.expand_path('dsl/selector.rb', File.dirname(__FILE__))
2
2
  load File.expand_path('dsl/commands.rb', File.dirname(__FILE__))
3
3
  load File.expand_path('dsl/repeat_chain.rb', File.dirname(__FILE__))
4
+ load File.expand_path('dsl/impulse_chain.rb', File.dirname(__FILE__))
4
5
  load File.expand_path('dsl/command_block.rb', File.dirname(__FILE__))
5
6
  load File.expand_path('dsl/block.rb', File.dirname(__FILE__))
6
7
  load File.expand_path('dsl/container.rb', File.dirname(__FILE__))
@@ -13,27 +14,51 @@ module McBlocky
13
14
  end
14
15
 
15
16
  def initial(&block)
16
- chain = Commands.new(:initial)
17
+ chain = Commands.new(context, :initial)
17
18
  chain.instance_exec(&block)
18
19
  chains << chain
19
20
  end
20
21
 
21
22
  def cleanup(&block)
22
- chain = Commands.new(:cleanup)
23
+ chain = Commands.new(context, :cleanup)
23
24
  chain.instance_exec(&block)
24
25
  chains << chain
25
26
  end
26
27
 
27
28
  def after(&block)
28
- chain = Commands.new(:after)
29
+ chain = Commands.new(context, :after)
29
30
  chain.instance_exec(&block)
30
31
  chains << chain
31
32
  end
32
33
 
33
- def repeat(x1, y1, z1, x2, y2, z2, &block)
34
- chain = RepeatChain.new(x1, y1, z1, x2, y2, z2)
34
+ def repeat(*args, &block)
35
+ if Symbol === args[0]
36
+ name = args.delete_at(0)
37
+ raise NameError, 'Name already exists' if named_chains.has_key? name
38
+ end
39
+ if args.empty?
40
+ rect = context.last_area
41
+ args = [rect.x1, rect.y1, rect.z1, rect.x2, rect.y2, rect.z2]
42
+ end
43
+ chain = RepeatChain.new(context, *args)
44
+ chain.instance_exec(&block)
45
+ chains << chain
46
+ named_chains[name] = chain if name
47
+ end
48
+
49
+ def chain(*args, &block)
50
+ if Symbol === args[0]
51
+ name = args.delete_at(0)
52
+ raise NameError, 'Name already exists' if named_chains.has_key? name
53
+ end
54
+ if args.empty?
55
+ rect = context.last_area
56
+ args = [rect.x1, rect.y1, rect.z1, rect.x2, rect.y2, rect.z2]
57
+ end
58
+ chain = ImpulseChain.new(context, *args)
35
59
  chain.instance_exec(&block)
36
60
  chains << chain
61
+ named_chains[name] = chain if name
37
62
  end
38
63
 
39
64
  def at(x, y, z, data=0, kind=:normal, nbt={}, &block)
@@ -51,11 +76,15 @@ module McBlocky
51
76
  else
52
77
  raise ArgumentError, 'Unknown command block type'
53
78
  end
54
- cblock = CommandBlock.new(x, y, z, data, block_kind, nbt)
79
+ cblock = CommandBlock.new(context, x, y, z, data, block_kind, nbt)
55
80
  cblock.instance_exec(&block)
56
81
  blocks[Location.new(x, y, z)] = cblock
57
82
  end
58
83
 
84
+ def area(x1, y1, z1, x2, y2, z2)
85
+ context.last_area = Rect.new(x1, y1, z1, x2, y2, z2)
86
+ end
87
+
59
88
  def setblock(x, y, z, kind, data=0, replacemode='replace', nbt={})
60
89
  block = Block.new(x, y, z, kind, data, nbt)
61
90
  blocks[Location.new(x, y, z)] = block
@@ -1,8 +1,8 @@
1
1
  module McBlocky::DSL
2
2
  class CommandBlock < Commands
3
3
  attr_reader :x, :y, :z, :block_data, :block_kind
4
- def initialize(x, y, z, facing, kind, nbt={})
5
- super(:at)
4
+ def initialize(context, x, y, z, facing, kind, nbt={})
5
+ super(context, :at)
6
6
  @x = x
7
7
  @y = y
8
8
  @z = z
@@ -1,9 +1,11 @@
1
1
  module McBlocky::DSL
2
2
  class Commands
3
+ attr_accessor :context
3
4
  attr_reader :kind
4
5
  attr_accessor :commands
5
6
 
6
- def initialize(kind, *args)
7
+ def initialize(context, kind, *args)
8
+ @context = context
7
9
  @kind = kind
8
10
  @args = args
9
11
  @commands = []
@@ -21,6 +23,27 @@ module McBlocky::DSL
21
23
  McBlocky::DSL.to_nbt(obj)
22
24
  end
23
25
 
26
+ def activate(name)
27
+ raise NameError, "No chain named #{name}" unless context.named_chains.has_key? name
28
+ raise ArgumentError, "#{name} is not an activateable chain" unless context.named_chains[name].kind == :impulse_chain
29
+ chain = context.named_chains[name]
30
+ command :blockdata, chain.rect.x1, chain.rect.y1, chain.rect.z1, '{auto:1}'
31
+ end
32
+
33
+ def enable(name)
34
+ raise NameError, "No chain named #{name}" unless context.named_chains.has_key? name
35
+ raise ArgumentError, "#{name} is not a repeat chain" unless context.named_chains[name].kind == :repeat
36
+ chain = context.named_chains[name]
37
+ command :blockdata, chain.rect.x1, chain.rect.y1, chain.rect.z1, '{auto:1}'
38
+ end
39
+
40
+ def disable(name)
41
+ raise NameError, "No chain named #{name}" unless context.named_chains.has_key? name
42
+ raise ArgumentError, "#{name} is not a repeat chain" unless context.named_chains[name].kind == :repeat
43
+ chain = context.named_chains[name]
44
+ command :blockdata, chain.rect.x1, chain.rect.y1, chain.rect.z1, '{auto:0}'
45
+ end
46
+
24
47
  COMMANDS = [:achievement, :ban, :ban_ip, :banlist, :blockdata, :clear, :clone, :debug, :defaultgamemode, :deop, :difficulty, :effect, :enchant, :entitydata, :execute, :fill, :gamemode, :gamerule, :give, :help, :kick, :kill, :list, :me, :op, :pardon, :pardon_ip, :particle, :playsound, :replaceitem, :save_all, :save_off, :save_on, :say, :scoreboard, :seed, :setblock, :setidletimeout, :setworldspawn, :spawnpoint, :spreadplayers, :stats, :stop, :summon, :tell, :tellraw, :testfor, :testforblock, :testforblocks, :time, :title, :toggledownfall, :tp, :trigger, :weather, :whitelist, :worldborder, :xp]
25
48
 
26
49
  def blockdata(*args)
@@ -30,7 +53,7 @@ module McBlocky::DSL
30
53
 
31
54
  def detect(selector, *args, &block)
32
55
  if block
33
- chain = Commands.new(:detect)
56
+ chain = Commands.new(context, :detect)
34
57
  chain.instance_exec &block
35
58
  chain.commands.each do |c|
36
59
  command :execute, selector, '~ ~ ~', :detect, *args, c
@@ -45,7 +68,7 @@ module McBlocky::DSL
45
68
  args = ['~ ~ ~']
46
69
  end
47
70
  if block
48
- chain = Commands.new(:execute)
71
+ chain = Commands.new(context, :execute)
49
72
  chain.instance_exec &block
50
73
  chain.commands.each do |c|
51
74
  command :execute, selector, *args, c
@@ -0,0 +1,9 @@
1
+ module McBlocky::DSL
2
+ class ImpulseChain < Commands
3
+ attr_reader :rect
4
+ def initialize(context, *args)
5
+ super(context, :impulse_chain)
6
+ @rect = McBlocky::Rect.new(*args)
7
+ end
8
+ end
9
+ end
@@ -1,8 +1,8 @@
1
1
  module McBlocky::DSL
2
2
  class RepeatChain < Commands
3
3
  attr_reader :rect
4
- def initialize(*args)
5
- super(:repeat)
4
+ def initialize(context, *args)
5
+ super(context, :repeat)
6
6
  @rect = McBlocky::Rect.new(*args)
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module McBlocky
2
2
  class Executor < DSL::Commands
3
3
  def self.to_commands(context, old_context=nil)
4
- executor = Executor.new(:final)
4
+ executor = Executor.new(nil, :final)
5
5
  executor.do_context(context, old_context)
6
6
  executor.commands
7
7
  end
@@ -36,20 +36,6 @@ module McBlocky
36
36
  end
37
37
  end
38
38
 
39
- if old_context
40
- old_context.areas.each do |x1, y1, z1, x2, y2, z2|
41
- fill x1, y1, z1, x2, y2, z2, 'minecraft:air'
42
- end
43
- end
44
- context.areas.each do |x1, y1, z1, x2, y2, z2|
45
- fill x1, y1, z1, x2, y1, z2, 'minecraft:stained_glass', '7'
46
- fill x1, y2, z1, x2, y2, z2, 'minecraft:stained_glass', '7'
47
- fill x1, y1, z1, x1, y2, z2, 'minecraft:stained_glass', '7'
48
- fill x2, y1, z1, x2, y2, z2, 'minecraft:stained_glass', '7'
49
- fill x1, y1, z1, x2, y2, z1, 'minecraft:stained_glass', '7'
50
- fill x1, y1, z2, x2, y2, z2, 'minecraft:stained_glass', '7'
51
- end
52
-
53
39
  rects = (old_context ? old_context.rects.keys : []) + context.rects.keys
54
40
  rects.uniq.each do |rect|
55
41
  old_block = old_context ? old_context.rects[rect] : nil
@@ -63,8 +49,13 @@ module McBlocky
63
49
  end
64
50
  end
65
51
 
66
- context.chains.select{|x|x.kind == :repeat}.each do |c|
67
- do_repeat context, c
52
+ context.chains.select{|x|[:repeat, :impulse_chain].include? x.kind}.each do |c|
53
+ case c.kind
54
+ when :repeat
55
+ do_repeat context, c
56
+ when :impulse_chain
57
+ do_impulse context, c
58
+ end
68
59
  end
69
60
 
70
61
  locations = (old_context ? old_context.blocks.keys : []) + context.blocks.keys
@@ -96,13 +87,17 @@ module McBlocky
96
87
  end
97
88
 
98
89
  def do_repeat(context, chain)
90
+ if chain.rect != @last_area
91
+ @last_area = chain.rect
92
+ @offset = 0
93
+ end
99
94
  sequence = fill_space(chain.rect)
100
- if chain.commands.length > sequence.length
95
+ if chain.commands.length + @offset > sequence.length
101
96
  raise ArgumentError, "Chain is too long for the provided space"
102
97
  end
103
98
  kind = 'minecraft:repeating_command_block'
104
99
  chain.commands.each_with_index do |c,i|
105
- cursor = sequence[i]
100
+ cursor = sequence[i+@offset]
106
101
  next_cursor = if i+1 < sequence.length
107
102
  sequence[i+1]
108
103
  else
@@ -121,10 +116,51 @@ module McBlocky
121
116
  elsif next_cursor.z - cursor.z == -1
122
117
  DSL::Facing::NORTH
123
118
  end
124
- context.blocks[cursor] = DSL::CommandBlock.new(cursor.x, cursor.y, cursor.z, facing, kind, {'auto'=>1})
119
+ context.blocks[cursor] = DSL::CommandBlock.new(context, cursor.x, cursor.y, cursor.z, facing, kind, {'auto'=>1})
125
120
  context.blocks[cursor].command c
126
121
  kind = 'minecraft:chain_command_block'
127
122
  end
123
+ @offset += self.next_power_of_two(chain.commands.length)
124
+ end
125
+
126
+ def do_impulse(context, chain)
127
+ if chain.rect != @last_area
128
+ @last_area = chain.rect
129
+ @offset = 0
130
+ end
131
+ sequence = fill_space(chain.rect)
132
+ chain.commands << "blockdata #{sequence[@offset].x} #{sequence[@offset].y} #{sequence[@offset].z} {auto:0}"
133
+ if chain.commands.length + @offset > sequence.length
134
+ raise ArgumentError, "Chain is too long for the provided space"
135
+ end
136
+ kind = 'minecraft:command_block'
137
+ nbt = {auto: 0}
138
+ chain.commands.each_with_index do |c,i|
139
+ cursor = sequence[i+@offset]
140
+ next_cursor = if i+1 < sequence.length
141
+ sequence[i+1]
142
+ else
143
+ Location.new(cursor.x, cursor.y+1, cursor.z)
144
+ end
145
+ facing = if next_cursor.x - cursor.x == 1
146
+ DSL::Facing::EAST
147
+ elsif next_cursor.x - cursor.x == -1
148
+ DSL::Facing::WEST
149
+ elsif next_cursor.y - cursor.y == 1
150
+ DSL::Facing::UP
151
+ elsif next_cursor.y - cursor.y == -1
152
+ DSL::Facing::DOWN
153
+ elsif next_cursor.z - cursor.z == 1
154
+ DSL::Facing::SOUTH
155
+ elsif next_cursor.z - cursor.z == -1
156
+ DSL::Facing::NORTH
157
+ end
158
+ context.blocks[cursor] = DSL::CommandBlock.new(context, cursor.x, cursor.y, cursor.z, facing, kind, nbt)
159
+ context.blocks[cursor].command c
160
+ kind = 'minecraft:chain_command_block'
161
+ nbt = {auto: 1}
162
+ end
163
+ @offset += self.next_power_of_two(chain.commands.length)
128
164
  end
129
165
 
130
166
  def fill_space(rect)
@@ -145,5 +181,13 @@ module McBlocky
145
181
  end
146
182
  path
147
183
  end
184
+
185
+ protected
186
+ def next_power_of_two(n)
187
+ l = Math.log(n, 2)
188
+ # ceiling
189
+ l = l.to_i + 1 if l != l.to_i
190
+ return (2**l).to_i
191
+ end
148
192
  end
149
193
  end
@@ -18,6 +18,7 @@ module McBlocky
18
18
  File.expand_path('../dsl.rb', __FILE__),
19
19
  File.expand_path('../dsl/commands.rb', __FILE__),
20
20
  File.expand_path('../dsl/repeat_chain.rb', __FILE__),
21
+ File.expand_path('../dsl/impulse_chain.rb', __FILE__),
21
22
  File.expand_path('../dsl/selector.rb', __FILE__),
22
23
  File.expand_path('../dsl/command_block.rb', __FILE__),
23
24
  File.expand_path('../dsl/block.rb', __FILE__),
@@ -1,3 +1,3 @@
1
1
  module McBlocky
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mcblocky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Limiero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-10 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,7 @@ files:
120
120
  - lib/mcblocky/dsl/command_block.rb
121
121
  - lib/mcblocky/dsl/commands.rb
122
122
  - lib/mcblocky/dsl/container.rb
123
+ - lib/mcblocky/dsl/impulse_chain.rb
123
124
  - lib/mcblocky/dsl/repeat_chain.rb
124
125
  - lib/mcblocky/dsl/selector.rb
125
126
  - lib/mcblocky/executor.rb