Module: Fishbans::BlockEngine

Included in:
Fishbans
Defined in:
lib/block_engine.rb

Instance Method Summary collapse

Instance Method Details

#get_block(id, metadata = nil, size = 42) ⇒ ChunkyPNG::Image

Gets a block image by its ID and Metadata. Unfortunately it uses the old

block IDs rather than the new ones, so you have to memorize those
pesky integers.

Parameters:

  • id (Integer)

    The (outdated) block ID number.

  • metadata (Integer) (defaults to: nil)

    The metadata, if any, for the block.

  • size (Fixnum) (defaults to: 42)

    The size of the image to get.

Returns:

  • (ChunkyPNG::Image)

    The ChunkyPNG instance of that block image.

Raises:

  • see #get



14
15
16
17
18
19
20
# File 'lib/block_engine.rb', line 14

def get_block(id,  = nil, size = 42)
  url = "http://blocks.fishbans.com/#{id}"
  url += "-#{}" unless .nil?
  url += "/#{size}" if size != 42
  response = get(url, false)
  ChunkyPNG::Image.from_blob(response.body)
end

#get_monster(id, three = false, size = 42) ⇒ ChunkyPNG::Image

Gets the monster image by its ID.

Parameters:

  • id (Any)

    The string ID. It will automatically prefix it with “m” if that is omitted. It doesn’t matter what type it is: String or Fixnum, because it will automatically convert it to a String.

  • three (Boolean) (defaults to: false)

    Whether to get a three-dimensional monster image. The three-dimensional image is of the full monster, while the two-dimensional image is just its head.

  • size (Integer) (defaults to: 42)

    The size of the image (width) to get. For 3D images this will not be perfect just by nature of the API.

Returns:

  • (ChunkyPNG::Image)

    The ChunkyPNG instance of that monster image.

Raises:

  • see #get



33
34
35
36
37
38
39
40
41
42
# File 'lib/block_engine.rb', line 33

def get_monster(id, three = false, size = 42)
  id = id.to_s
  url = 'http://blocks.fishbans.com'
  url += "/#{id}" if id =~ /^m/
  url += "/m#{id}" if id !~ /^m/
  url += '-3d' if three
  url += "/#{size}" if size != 42
  response = get(url, false)
  ChunkyPNG::Image.from_blob(response.body)
end