Class: DiamondLang::OneCommand
- Defined in:
- lib/diamond-lang/one_command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #chain ⇒ Object
- #cleanup(c) ⇒ Object
- #create_commands(c) ⇒ Object
-
#initialize(height = 5, length = 6, width = 5, offset = coords(2, 2, 0), surrond = Helpers::Block.new('stained_hardened_clay', 13), output = false) ⇒ OneCommand
constructor
A new instance of OneCommand.
- #setup(c) ⇒ Object
- #startup(c) ⇒ Object
- #tick(c) ⇒ Object
- #to_command ⇒ Object
Constructor Details
#initialize(height = 5, length = 6, width = 5, offset = coords(2, 2, 0), surrond = Helpers::Block.new('stained_hardened_clay', 13), output = false) ⇒ OneCommand
Returns a new instance of OneCommand.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/diamond-lang/one_command.rb', line 10 def initialize(height=5, length=6, width=5, offset=coords(2, 2, 0), surrond=Helpers::Block.new('stained_hardened_clay', 13), output=false) @output = output @height = height # y @width = width # z @length = (length / 2).floor * 2 # x puts "WARNING: The length of your command block needs to be even. Rounding down to #{@length}." unless length.even? @offset = offset.freeze @corner1 = coords("~#{@offset.x}", "~#{@offset.y}", "~#{@offset.z}").freeze @corner2 = coords("~#{@offset.x._value + @length}", "~#{@offset.y._value + @height}", "~#{@offset.z._value + @width}").freeze @surrond = surrond @setup_commands = [] @tick_commands = [] @custom_crafting = nil end |
Class Method Details
.create(*args) ⇒ Object
6 7 8 9 |
# File 'lib/diamond-lang/one_command.rb', line 6 def self.create(*args) @@instance = self.new(*args) puts @@instance.to_command.to_s.gsub(/\\?"(\w+?)\\?":/, '\1:').gsub(/(\\?"\w+?)\s(\\?":)/, '\1\2') end |
.instance ⇒ Object
3 4 5 |
# File 'lib/diamond-lang/one_command.rb', line 3 def self.instance @@instance end |
Instance Method Details
#chain ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/diamond-lang/one_command.rb', line 87 def chain chain = CommandChain.new self startup chain setup chain chain.commands.push *@setup_commands create_commands chain cleanup chain chain end |
#cleanup(c) ⇒ Object
29 30 31 32 33 |
# File 'lib/diamond-lang/one_command.rb', line 29 def cleanup(c) c.setblock "~ ~ ~1 command_block 0 replace {Command:fill ~ ~-1 ~-1 ~ ~ ~ air}" c.setblock "~ ~-1 ~1 redstone_block" c.kill e('MinecartCommandBlock').selector({r: 1}) end |
#create_commands(c) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/diamond-lang/one_command.rb', line 34 def create_commands(c) chain = CommandChain.new self chain.commands.push *@tick_commands if @custom_crafting @custom_crafting.tick chain end tick chain commands = [] chain.commands.each do |command| if command.chain command.chain.each do |con_command| con_command = con_command.to_block con_command.conditional = true commands.push command.to_block, con_command end else commands.push command.to_block end end command_lines = commands.each_slice(@length - 1).each_with_index.map do |line, z| direction = z.even? ? 5 : 4 line.map! do |c| c.direction = direction c end end command_levels = command_lines.each_slice(@width - 1).each_with_index.map do |level, y| level = level.map! do |line| line.last.direction = y.even? ? 3 : 2 line end level.last.last.direction = 1 level = level.each_with_index.map do |line, z| z.even? ? line : line.reverse end y.even? ? level : level.reverse end command_levels.first.first.first.type = :repeating raise Errors::TooSmall if command_levels.to_a.length > (@height - 1) command_levels.each_with_index do |level, y| level.each_with_index do |line, z| z += @width - 1 - level.length if y.odd? line.each_with_index do |command, x| x += @length - 1 - line.length unless y.odd? == z.odd? c.setblock coords( "~#{x + @corner1.x._value + 1}", "~#{y + @corner1.y._value + 1}", "~#{z + @corner1.z._value + 1}" ), command.to_s(:replace) end end end end |
#setup(c) ⇒ Object
103 104 105 |
# File 'lib/diamond-lang/one_command.rb', line 103 def setup(c) puts "Warning: You haven't implimented a setup function." end |
#startup(c) ⇒ Object
25 26 27 28 |
# File 'lib/diamond-lang/one_command.rb', line 25 def startup(c) c.gamerule(:commandBlockOutput, @output) c.fill @corner1.to_s, @corner2.to_s, @surrond.to_s, 'hollow' if @surrond end |
#tick(c) ⇒ Object
106 107 108 |
# File 'lib/diamond-lang/one_command.rb', line 106 def tick(c) puts "Warning: You haven't implimented a tick function." end |
#to_command ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/diamond-lang/one_command.rb', line 96 def to_command activator_rail = b('activator_rail').to_falling_sand redstone_block = b('redstone_block').to_falling_sand activator_rail.passengers.push *chain.to_minecarts redstone_block.passengers << activator_rail redstone_block.summon coords('~', '~1', '~') end |