class DiamondLang::OneCommand
Public Class Methods
create(*args)
click to toggle source
# 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()
click to toggle source
# File lib/diamond-lang/one_command.rb, line 3 def self.instance @@instance end
new(height=5, length=6, width=5, offset=coords(2, 2, 0), surrond=Helpers::Block.new('stained_hardened_clay', 13), output=false)
click to toggle source
# 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
Public Instance Methods
chain()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 103 def setup(c) puts "Warning: You haven't implimented a setup function." end
startup(c)
click to toggle source
# 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)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 106 def tick(c) puts "Warning: You haven't implimented a tick function." end
to_command()
click to toggle source
# 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
Private Instance Methods
add_crafting(recipes)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 151 def add_crafting(recipes) chain = CommandChain.new self @custom_crafting = Helpers::CustomCrafting.new(chain, recipes) @setup_commands.push *chain.commands end
b(*args)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 110 def b(*args) Helpers::Block.new(*args) end
colors(color)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 131 def colors(color) { white: 0, orange: 1, magenta: 2, light_blue: 3, yellow: 4, lime: 5, pink: 6, grey: 7, light_grey: 8, cyan: 9, purple: 10, blue: 11, brown: 12, green: 13, red: 14, black: 15 }.freeze[color] end
coords(*args)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 125 def coords(*args) Helpers::Coordinates.new(*args) end
e(*args)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 113 def e(*args) Helpers::Entity.new(*args) end
relative()
click to toggle source
# File lib/diamond-lang/one_command.rb, line 128 def relative coords('~', '~', '~') end
s(*args)
click to toggle source
# File lib/diamond-lang/one_command.rb, line 116 def s(*args) Helpers::TargetSelector.new(*args) end
s_self()
click to toggle source
# File lib/diamond-lang/one_command.rb, line 122 def s_self s :e, {r: 0, c: 1} end
sp()
click to toggle source
# File lib/diamond-lang/one_command.rb, line 119 def sp s :p end