Skip to content

Commit

Permalink
falling and walking on flat ground
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantm committed Jul 17, 2012
1 parent e6c8ece commit d23c2e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
35 changes: 23 additions & 12 deletions lib/redstone_bot/bots/david_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def setup
end

waypoint = [99, 70, 230]
@body.debug = true
@body.on_position_update do
#move_to(waypoint)
fall
move_to(waypoint)
end


Expand All @@ -34,10 +35,15 @@ def setup
# tmphax_find_path
#end
when Packet::ChatMessage
waypoint[2] += 1 if p.message == "<RyanTM> n"
waypoint[2] -= 1 if p.message == "<RyanTM> s"
waypoint[2] -= 1 if p.message == "<RyanTM> n"
waypoint[2] += 1 if p.message == "<RyanTM> s"
waypoint[0] += 1 if p.message == "<RyanTM> e"
waypoint[0] -= 1 if p.message == "<RyanTM> w"
if p.message == "<RyanTM> h"
me = @entity_tracker.player("RyanTM")
puts me.inspect
waypoint = me.position.to_a
end
puts p.inspect
when Packet::Disconnect
exit 2
Expand All @@ -59,29 +65,34 @@ def inspect
to_s
end

def find_ground(chunk_tracker, position)
x,y,z = position.to_a
puts position.inspect
def find_ground
x,y,z = @body.position.to_a
y.ceil.downto(0).each do |_|
if (chunk_tracker.block_type([x,_,z]).solid?)
puts "#{x} #{_} #{z} #{@chunk_tracker.block_type([x,_,z])}"
if (@chunk_tracker.block_type([x.to_i,_,z.to_i]).solid?)
return _+1
end
end
end

def fall
ground = find_ground(@chunk_tracker,@body.position)
ground = find_ground
puts "GROUND: #{ground}"
if (@body.position[1] != ground)
@body.position += Vector[0,0.5,0]
if (@body.position[1] > ground)
@body.position -= Vector[0,0.5,0]
@body.stance = @body.position[1] + 1.62
end
if ((@body.position[1] - ground).abs < 0.5)
@body.position = Vector[@body.position[0],ground,@body.position[2]]
@body.stance = @body.position[1] + 1.62
end
end

def move_to(waypoint)
speed = 0.5
waypoint = Vector[*waypoint]
speed = 10
waypoint = Vector[*waypoint]
dir = waypoint - @body.position
dir = Vector[dir[0],0,dir[2]]
if dir.norm < 0.2
puts "success"
return
Expand Down
4 changes: 4 additions & 0 deletions lib/redstone_bot/entity_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def debug_entities
end
nil
end

def player(name)
entities.values.find { |entity| entity.name == name and entity.class == Player }
end

protected
def update_entity_position_absolute(p)
Expand Down
2 changes: 1 addition & 1 deletion test/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
USERNAME = 'DavidBot'
USERNAME = 'RyanBot'
HOSTNAME = '192.168.11.84' #'iprefermuffins.com'
PORT = 25565

0 comments on commit d23c2e6

Please sign in to comment.