Class: Minecraft

Inherits:
Object
  • Object
show all
Includes:
Block
Defined in:
lib/minecraft-pi-ruby.rb

Constant Summary

Constants included from Block

Block::AIR, Block::BED, Block::BEDROCK, Block::BEDROCK_INVISIBLE, Block::BOOKSHELF, Block::BRICK_BLOCK, Block::CACTUS, Block::CHEST, Block::CLAY, Block::COAL_ORE, Block::COBBLESTONE, Block::COBWEB, Block::CRAFTING_TABLE, Block::DIAMOND_BLOCK, Block::DIAMOND_ORE, Block::DIRT, Block::DOOR_IRON, Block::DOOR_WOOD, Block::FARMLAND, Block::FENCE, Block::FENCE_GATE, Block::FIRE, Block::FLOWER_CYAN, Block::FLOWER_YELLOW, Block::FURNACE_ACTIVE, Block::FURNACE_INACTIVE, Block::GLASS, Block::GLASS_PANE, Block::GLOWING_OBSIDIAN, Block::GLOWSTONE_BLOCK, Block::GOLD_BLOCK, Block::GOLD_ORE, Block::GRASS, Block::GRASS_TALL, Block::GRAVEL, Block::ICE, Block::IRON_BLOCK, Block::IRON_ORE, Block::LADDER, Block::LAPIS_LAZULI_BLOCK, Block::LAPIS_LAZULI_ORE, Block::LAVA, Block::LAVA_FLOWING, Block::LAVA_STATIONARY, Block::LEAVES, Block::MELON, Block::MOSS_STONE, Block::MUSHROOM_BROWN, Block::MUSHROOM_RED, Block::NETHER_REACTOR_CORE, Block::OBSIDIAN, Block::REDSTONE_ORE, Block::SAND, Block::SANDSTONE, Block::SAPLING, Block::SNOW, Block::SNOW_BLOCK, Block::STAIRS_COBBLESTONE, Block::STAIRS_WOOD, Block::STONE, Block::STONE_BRICK, Block::STONE_SLAB, Block::STONE_SLAB_DOUBLE, Block::SUGAR_CANE, Block::TNT, Block::TORCH, Block::WATER, Block::WATER_FLOWING, Block::WATER_STATIONARY, Block::WOOD, Block::WOOD_PLANKS, Block::WOOL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil) ⇒ Minecraft

Returns a new instance of Minecraft.



8
9
10
11
# File 'lib/minecraft-pi-ruby.rb', line 8

def initialize(connection = nil)
  @connection = connection
  @connection ||= Connection.new
end

Class Method Details

.control(&script) ⇒ Object Also known as: world



14
15
16
17
# File 'lib/minecraft-pi-ruby.rb', line 14

def control(&script)
  mc = self.new
  mc.instance_eval(&script)
end

Instance Method Details

#get_ground_height(x, z) ⇒ Object Also known as: ground_height



67
68
69
70
# File 'lib/minecraft-pi-ruby.rb', line 67

def get_ground_height(x,z)
  return  @connection.send_with_response "world.getHeight(#{x},#{z})"
  #return s
end

#say(message) ⇒ Object



22
23
24
# File 'lib/minecraft-pi-ruby.rb', line 22

def say(message)
  @connection.send_command "chat.post(#{message})"
end

#set_block(*args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/minecraft-pi-ruby.rb', line 32

def set_block(*args)
  command = "world.setBlock("
  case args.length
  when 2
    command = command + "#{args[0]},#{args[1]})"
  when 3
    command += "#{args[0]},#{args[1]},#{args[2]})"
  when 4
    command += "#{args[0]},#{args[1]},#{args[2]},#{args[3]})"
  when 5
    command += "#{args[0]},#{args[1]},#{args[2]},#{args[3]},#{args[4]})"
  else
    return
  end
  @connection.send_command command
end

#set_blocks(*args) ⇒ Object Also known as: make_cuboid



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/minecraft-pi-ruby.rb', line 49

def set_blocks(*args)
  command = "world.setBlocks("
  case args.length
  when 3
    command += "#{args[0]},#{args[1]},#{args[2]})"
  when 4
    command += "#{args[0]},#{args[1]},#{args[2]},#{args[3]})"
  when 7
    command += "#{args[0]},#{args[1]},#{args[2]},#{args[3]},#{args[4]},#{args[5]},#{args[6]})"
  when 8
    command += "#{args[0]},#{args[1]},#{args[2]},#{args[3]},#{args[4]},#{args[5]},#{args[6]},#{args[7]})"
  else
    return
  end
  @connection.send_command command
end

#set_camera_mode(mode) ⇒ Object



26
27
28
29
30
# File 'lib/minecraft-pi-ruby.rb', line 26

def set_camera_mode(mode)
  @connection.send_command 'camera.mode.setNormal' if mode == :normal
  @connection.send_command 'camera.mode.setFixed' if mode == :fixed
  @connection.send_command 'camera.mode.setFollow' if mode == :follow
end

#set_player_position(*args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/minecraft-pi-ruby.rb', line 73

def set_player_position(*args)
  command = "player.setPos("
  case args.length
  when 1
    command += "#{args[0].x},#{args[0].y},#{args[0].z})"
  when 3
    command += "#{args[0]},#{args[1]},#{args[2]})"
  else
    return
  end
  @connection.send_command command
end