Class: DiamondLang::Helpers::CommandBlock

Inherits:
Block show all
Defined in:
lib/diamond-lang/helpers/command_block.rb

Constant Summary collapse

Types =
{
  chain: 'chain_command_block',
  impulse: 'command_block',
  repeating: 'repeating_command_block'
}.freeze

Instance Attribute Summary

Attributes inherited from Block

#data_value, #id, #nbt

Instance Method Summary collapse

Methods inherited from Block

#to_falling_sand, #to_s

Constructor Details

#initialize(command, type = :chain, data_value = 0, auto = true, conditional = false) ⇒ CommandBlock

Returns a new instance of CommandBlock.



15
16
17
18
19
20
21
# File 'lib/diamond-lang/helpers/command_block.rb', line 15

def initialize(command,type=:chain,data_value=0,auto=true,conditional=false)
  super Types[type], data_value, {
    Command: command.to_s,
    auto: auto
  }
  conditional = conditional
end

Instance Method Details

#conditional=(val) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/diamond-lang/helpers/command_block.rb', line 28

def conditional=(val)
  if conditional? && !val
    @data_value -= 8
  elsif !@conditional && val
    @data_value += 8
  end
end

#conditional?(data_value = @data_value) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/diamond-lang/helpers/command_block.rb', line 35

def conditional?(data_value=@data_value)
  data_value >= 8
end

#directionObject



9
10
11
# File 'lib/diamond-lang/helpers/command_block.rb', line 9

def direction
  conditional? ? @data_value - 8 : @data_value
end

#direction=(val) ⇒ Object



12
13
14
# File 'lib/diamond-lang/helpers/command_block.rb', line 12

def direction=(val)
  @data_value = val + (conditional? ? 8 : 0)
end

#typeObject



25
26
27
# File 'lib/diamond-lang/helpers/command_block.rb', line 25

def type
  Types.reverse[@id]
end

#type=(type) ⇒ Object



22
23
24
# File 'lib/diamond-lang/helpers/command_block.rb', line 22

def type=(type)
  @id = Types[type]
end