Skip to content
Browse files

falling and walking on flat ground

  • Loading branch information...
1 parent e6c8ece commit d23c2e66fa6373a8a031db5e715932995e1cbe29 @ryantm committed Jul 16, 2012
Showing with 28 additions and 13 deletions.
  1. +23 −12 lib/redstone_bot/bots/david_bot.rb
  2. +4 −0 lib/redstone_bot/entity_tracker.rb
  3. +1 −1 test/config.rb
View
35 lib/redstone_bot/bots/david_bot.rb
@@ -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
@@ -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
@@ -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
View
4 lib/redstone_bot/entity_tracker.rb
@@ -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)
View
2 test/config.rb
@@ -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.
Something went wrong with that request. Please try again.