class CraftingTable::Item

A class representing a single item. An item, in this case, can be any block, tool, loot etc.

@author Michael Senn <morrolan@morrolan.ch> @since 0.1

Attributes

damage_value[R]
item_id[R]
name[R]

Public Class Methods

new(name, item_id, damage_value = 0) click to toggle source

Create a new Item.

@example Spruce Wood

item = Item.new('Spruce Wood', 17, 1)

@example Glass

item = Item.new('Glass', 20, :any)

@param [String] name The item’s name. @param [Integer, Symbol] damage_value The item’s damage / meta value. @param [Integer] item_id The item’s ID.

# File lib/crafting_table/item.rb, line 24
def initialize(name, item_id, damage_value = 0)
  @name, @item_id, @damage_value = name, item_id, damage_value
end

Public Instance Methods

==(other) click to toggle source

Compare two items for equality.

Two items are considered equal, if their name, item ID and damage value are equal.

@param [Item] other Item which to compare for equality. @return [Boolean] Whether the two items are equal.

# File lib/crafting_table/item.rb, line 34
def ==(other)
  name == other.name && item_id == other.item_id && damage_value == other.damage_value
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash() click to toggle source

Return reasonable hash value of this item.

@since 0.2

@return [Integer] Hash of item’s name, id and damage value.

# File lib/crafting_table/item.rb, line 45
def hash
  [name, item_id, damage_value].hash
end
identifier() click to toggle source

Return a unique identifier of this item. The identifier is an array, containing its ID and damage value

@since 0.2

@return [Array<Integer>] Unique identifier of this item.

# File lib/crafting_table/item.rb, line 55
def identifier
  [item_id, damage_value]
end