remixz/minecraft-pi

Callbacks registered multiple times

zhuowei opened this issue · 2 comments

When I use the callbacks with Minecraft.eventsBlockHits, the callback is called multiple times.
I also get this warning:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
    at Socket.<anonymous> (events.js:133:17)
    at Minecraft.sendReceive (/home/zhuowei/Documents/winprogress/mine/pocket/pi2/node_modules/minecraft-pi/lib/minecraft.js:50:21)
    at Minecraft.eventsBlockHits (/home/zhuowei/Documents/winprogress/mine/pocket/pi2/node_modules/minecraft-pi/lib/minecraft.js:167:17)
    at Object.runGameLoop [as _onTimeout] (/home/zhuowei/Documents/winprogress/mine/pocket/pi2/connect4.js:59:6)
    at Timer.ontimeout (timers.js:84:39)

I had to workaround it by only passing in the callback in the first call:

        mc.eventsBlockHits(hasRegisteredThiseffinhandler? function() {}: handleEvents);
        hasRegisteredThiseffinhandler = true;

Odd. I'm actually looking for proper documentation into eventsBlockHits, and I haven't got to test it. I'm thinking it's a different sort of call than a simple return of data. I'll look into this soon, as I'm working on 0.3.0. Thank you!

Check my program out: https://github.com/zhuowei/MCPIScripts A working Connect 4 game with your Node API.

For documentation, look at how the Java API handles events.
Basically, as far as I know:
x,y,z,blockFace,entityId|x,y,z,blockFace,entityId
where blockFace is a notchian block face as documented on http://mc.kev009.com/Protocol#Player_Digging_.280x0E.29

I've only tested this against my own implementation of the Minecraft Pi API at https://github.com/zhuowei/RaspberryJuice , so I'm not sure if this is correct.