Class: RubyCraft::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycraft/block.rb

Overview

A minecraft block. Its position is given by a coord[x, z, y]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blockType, data = 0) ⇒ Block

Returns a new instance of Block.



8
9
10
11
# File 'lib/rubycraft/block.rb', line 8

def initialize(blockType, data = 0)
  @blockType = blockType
  @data = 0
end

Instance Attribute Details

#block_typeObject

Returns the value of attribute block_type.



7
8
9
# File 'lib/rubycraft/block.rb', line 7

def block_type
  @block_type
end

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/rubycraft/block.rb', line 7

def data
  @data
end

#posObject

Returns the value of attribute pos.



7
8
9
# File 'lib/rubycraft/block.rb', line 7

def pos
  @pos
end

Class Method Details

.[](key) ⇒ Object



21
22
23
# File 'lib/rubycraft/block.rb', line 21

def self.[](key)
  new BlockType[key]
end

.get(key) ⇒ Object



13
14
15
# File 'lib/rubycraft/block.rb', line 13

def self.get(key)
  new BlockType.get key
end

.of(key) ⇒ Object



17
18
19
# File 'lib/rubycraft/block.rb', line 17

def self.of(key)
  self[key]
end

Instance Method Details

#blockColorObject



34
35
36
# File 'lib/rubycraft/block.rb', line 34

def blockColor
  BlockColor.typeColor[@data]
end

#colorObject



30
31
32
# File 'lib/rubycraft/block.rb', line 30

def color
  BlockColor.typeColor[@data].name
end

#color=(color) ⇒ Object



26
27
28
# File 'lib/rubycraft/block.rb', line 26

def color=(color)
  @data = BlockColor::InvertedColor[color]
end

#idObject



46
47
48
# File 'lib/rubycraft/block.rb', line 46

def id
  @blockType.id
end

#id=(id) ⇒ Object

sets block type by id



61
62
63
64
# File 'lib/rubycraft/block.rb', line 61

def id=(id)
  return if id == id
  @blockType = BlockType.get id
end

#is(name) ⇒ Object



38
39
40
# File 'lib/rubycraft/block.rb', line 38

def is(name)
  self.name == name.to_s
end

#nameObject



42
43
44
# File 'lib/rubycraft/block.rb', line 42

def name
  @blockType.name
end

#name=(newName) ⇒ Object

sets block type by name



55
56
57
58
# File 'lib/rubycraft/block.rb', line 55

def name=(newName)
  return if name == newName.to_s
  @blockType = BlockType[newName]
end

#transparentObject



50
51
52
# File 'lib/rubycraft/block.rb', line 50

def transparent
  @blockType.transparent
end

#xObject



74
75
76
# File 'lib/rubycraft/block.rb', line 74

def x
  pos[0]
end

#yObject



66
67
68
# File 'lib/rubycraft/block.rb', line 66

def y
  pos[2]
end

#zObject



70
71
72
# File 'lib/rubycraft/block.rb', line 70

def z
  pos[1]
end