Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

oops

  • Loading branch information...
commit 586488d4ea008c5a7e4e5adecc88ad86c6a2a0a1 1 parent b66aa33
Eric Schoffstall authored
Showing with 36 additions and 16 deletions.
  1. +2 −12 examples/watchBase.coffee
  2. +33 −3 lib/main.coffee
  3. +1 −1  package.json
14 examples/watchBase.coffee
View
@@ -1,9 +1,5 @@
minebot = require '../'
-process.env.MC_USER = "Bomb"
-process.env.MC_EMAIL = "contra@maricopa.edu"
-process.env.MC_PASS = "coding2424"
-
client = minebot.createClient
#host: "mc.diamcraft.com"
host: "mc.toxicterritory.org"
@@ -30,13 +26,7 @@ client.on 'nonSpokenChat', (msg, raw) ->
console.log "[Chat] #{raw}"
client.on 'radarChange', ->
- #console.log client.entity
- #console.log Object.keys(client.radar).length
-
-client.on 'inventoryUpdate', ->
- console.log client.entity.inventory
- console.log client.entity.quickBar
- console.log client.entity.equipment
- client.hold 8
+ console.log client.radar
+
module.exports = client
36 lib/main.coffee
View
@@ -2,14 +2,44 @@ mineflayer = require 'mineflayer'
radar = (c, opt) ->
c.radar ?= {}
+
+ c.nearestPlayer = -> c.nearest (v) -> v.type is 'player'
+ c.nearestPlayerWithinRange = ->
+ p = c.nearestPlayer()
+ (if p.withinRange then p else null)
+
+ c.nearestMobWithinRange = ->
+ p = c.nearestMob()
+ return (if p.withinRange then p else null)
+
+ c.nearestMob = -> c.nearest (v) -> v.type is 'mob'
+
+ c.nearestObjectWithinRange = ->
+ p = c.nearestObject()
+ return (if p.withinRange then p else null)
+
+ c.nearestObject = -> c.nearest (v) -> v.type is 'object'
+
+ c.nearestWithinRange = (fn) ->
+ p = c.nearest fn
+ return (if p.withinRange then p else null)
+
+ c.nearest = (fn) ->
+ fn ?= -> true
+ radar = (v for k,v of c.radar when fn(v))
+ [nearest] = radar.sort (a,b) -> a.distance-b.distance
+ return nearest
+
updateRadar = (type, entity) ->
- return unless entity.type is 'player'
+ return if entity.id is c.entity.id
if type is 'remove'
- delete c.radar[entity.username]
+ delete c.radar[entity.id]
c.emit 'radarRemove', entity
else
- c.radar[entity.username] = c.entity.position.distanceTo entity.position
+ entity.distance = c.entity.position.distanceTo entity.position
+ entity.withinRange = entity.distance <= 6
+ c.radar[entity.id] = entity
c.emit 'radarMove', entity if type is 'move'
c.emit 'radarSpawn', entity if type is 'spawn'
2  package.json
View
@@ -9,7 +9,7 @@
"dependencies":{
"coffee-script":"*",
- "mineflayer":"*"
+ "mineflayer":"git://github.com/Contra/mineflayer.git"
Andrew Kelley
andrewrk added a note

You can use npm version numbers. I've been keeping good documentation of updates: https://github.com/superjoe30/mineflayer/blob/master/doc/history.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
},
"devDependencies":{
"mocha":"*",
Andrew Kelley

You can use npm version numbers. I've been keeping good documentation of updates: https://github.com/superjoe30/mineflayer/blob/master/doc/history.md

Please sign in to comment.
Something went wrong with that request. Please try again.