add new feature:

show position , health ,weather and food
This commit is contained in:
shugen002
2016-02-01 17:38:35 +08:00
parent b34486b603
commit fdc031e660
8 changed files with 107 additions and 1 deletions
+10
View File
@@ -0,0 +1,10 @@
export default (socket) => {
let ondeath = () => {
var pos = socket.mcbot.entity.position;
socket.emit('buffer:info', `You have been dead in X:${pos.x}, Y:${pos.y}, Z:${pos.z} `);
};
socket.mcbot.on('death', ondeath);
};
+12
View File
@@ -0,0 +1,12 @@
export default (socket) => {
let onHealth = () => {
var health = socket.mcbot.health || 0;
var food = socket.mcbot.food||0;
var foodSaturation = socket.mcbot.foodSaturation||0;
socket.emit('bot:health', {health:health,food:food,foodSaturation:foodSaturation});
};
socket.mcbot.on('health', onHealth);
};
+24
View File
@@ -0,0 +1,24 @@
export default (socket) => {
let onmove = () => {
var pos = socket.mcbot.entity.position;
if(movingornot(socket.mcbot.entity.velocity)){
socket.emit('bot:move', {x:pos.x.toFixed(2),y:pos.y.toFixed(2),z:pos.z.toFixed(2)});
}
};
socket.mcbot.on('move', onmove);
let onforcedMove = () => {
var pos = socket.mcbot.entity.position;
socket.emit('bot:forcedMove', {x:pos.x.toFixed(2),y:pos.y.toFixed(2),z:pos.z.toFixed(2)});
};
socket.mcbot.on('forcedMove', onforcedMove);
function movingornot(v){
if(v.x!=0) return true;
if(v.y!=0) return true;
if(v.z!=0) return true;
}
};
+13
View File
@@ -0,0 +1,13 @@
export default (socket) => {
let onRain = () => {
if (socket.mcbot.entity.isRaining){
socket.emit('buffer:info', `It started raining.`);
}else{
socket.emit('buffer:info', `It stopped raining. `);
}
};
socket.mcbot.on('spawn', onRain);
};