class MinecraftPi::World

Public Class Methods

new(socket) click to toggle source
# File lib/minecraft-pi/world.rb, line 12
def initialize(socket)
  @socket = socket
  self
end

Public Instance Methods

checkpoint() click to toggle source
# File lib/minecraft-pi/world.rb, line 18
def checkpoint
  @checkpoint ||= WorldCheckpoint.new @socket
end
getBlock(x, y, z) click to toggle source
# File lib/minecraft-pi/world.rb, line 28
def getBlock(x, y, z)
  @socket.request("world.getBlock(#{x.to_i},#{y.to_i},#{z.to_i})").to_i
end
getBlockWithData(x, y, z) click to toggle source
# File lib/minecraft-pi/world.rb, line 33
def getBlockWithData(x, y, z)
  @socket
    .request("world.getBlockWithData(#{x.to_i},#{y.to_i},#{z.to_i})")
    .split(',')
    .map(&:to_i)
end
getHeight(x, z) click to toggle source
# File lib/minecraft-pi/world.rb, line 69
def getHeight(x, z)
  @socket.request("world.getHeight(#{x.to_i},#{z.to_i})").to_i
end
getPlayerIds() click to toggle source

TODO: Should return a collection

# File lib/minecraft-pi/world.rb, line 23
def getPlayerIds
  @socket.request 'world.getPlayerIds()'
end
setBlock(x, y, z, id, attempt = 1) click to toggle source
# File lib/minecraft-pi/world.rb, line 41
def setBlock(x, y, z, id, attempt = 1)
  @socket.write "world.setBlock(#{x.to_i},#{y.to_i},#{z.to_i},#{id.to_i})"
  raise SetBlockError if getBlock(x, y, z) != id
rescue SetBlockError
  STDERR.puts "retry #{attempt}"
  setBlock(x, y, z, id, attempt.to_i + 1)
end
setBlockWithData(x, y, z, id, data, attempt = 1) click to toggle source
# File lib/minecraft-pi/world.rb, line 50
def setBlockWithData(x, y, z, id, data, attempt = 1)
  @socket.write "world.setBlock(#{x.to_i},#{y.to_i},#{z.to_i},#{id.to_i},#{data.to_i})"
  raise SetBlockError if getBlockWithData(x, y, z) != [id.to_i, data.to_i]
rescue SetBlockError
  STDERR.puts "retry #{attempt}"
  setBlockWithData(x, y, z, id, data, attempt.to_i + 1)
end
setBlocks(x1, y1, z1, x2, y2, z2, id) click to toggle source
# File lib/minecraft-pi/world.rb, line 59
def setBlocks(x1, y1, z1, x2, y2, z2, id)
  @socket.write "world.setBlocks(#{x1},#{y1},#{z1},#{x2},#{y2},#{z2},#{id})"
end
setBlocksWithData(x1, y1, z1, x2, y2, z2, id, data) click to toggle source
# File lib/minecraft-pi/world.rb, line 64
def setBlocksWithData(x1, y1, z1, x2, y2, z2, id, data)
  @socket.write "world.setBlocks(#{x1.to_i},#{y1.to_i},#{z1.to_i},#{x2.to_i},#{y2.to_i},#{z2.to_i},#{id.to_i},#{data.to_i})"
end
setting(setting, status) click to toggle source
# File lib/minecraft-pi/world.rb, line 74
def setting(setting, status)
  @socket.write "world.setting(#{setting},#{status ? 1 : 0})"
end