Class: MinecraftApi

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = 'localhost', port = 4711) ⇒ MinecraftApi

Returns a new instance of MinecraftApi.



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

def initialize(host = 'localhost', port = 4711)
  @socket = TCPSocket.new host, port
  @world = World.new(self)
  @camera = Camera.new(self)
  @player = Player.new(self)
end

Instance Attribute Details

#cameraObject (readonly)

Returns the value of attribute camera.



11
12
13
# File 'lib/minecraft_api.rb', line 11

def camera
  @camera
end

#playerObject (readonly)

Returns the value of attribute player.



12
13
14
# File 'lib/minecraft_api.rb', line 12

def player
  @player
end

#worldObject (readonly)

Returns the value of attribute world.



10
11
12
# File 'lib/minecraft_api.rb', line 10

def world
  @world
end

Instance Method Details

#closeObject



39
40
41
# File 'lib/minecraft_api.rb', line 39

def close
  @socket.close
end

#drainObject

The other api’s have a method like this I haven’t seen it be invoked yet. Perhaps it is not needed



23
24
25
26
27
# File 'lib/minecraft_api.rb', line 23

def drain()
  while @socket.ready?
    puts "DRAINING DATA FROM SOCKET [#{@socket.gets}]"
  end
end

#send(data) ⇒ Object



29
30
31
32
# File 'lib/minecraft_api.rb', line 29

def send(data)
  drain()
  @socket.puts "#{data}"
end

#send_and_receive(data) ⇒ Object



34
35
36
37
# File 'lib/minecraft_api.rb', line 34

def send_and_receive(data)
  send(data)
  @socket.gets.chomp
end