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
@@ -1,6 +1,8 @@
module.exports = function($scope, socket) {
$scope.players = [];
$scope.food=0;
$scope.health=0;
// request player list every 5000ms
setInterval(function() {
@@ -26,6 +28,11 @@ module.exports = function($scope, socket) {
socket.on('disconnect', function() {
$scope.$apply(function() {
$scope.players = [];
$scope.posx = 'no';
$scope.posy = 'no';
$scope.posz = 'no';
$scope.food=0;
$scope.health=0;
});
});
@@ -33,7 +40,34 @@ module.exports = function($scope, socket) {
socket.on('bot:disconnect', function() {
$scope.$apply(function() {
$scope.players = [];
$scope.posx = 'no';
$scope.posy = 'no';
$scope.posz = 'no';
$scope.food=0;
$scope.health=0;
});
});
socket.on('bot:move', function(data) {
$scope.$apply(function() {
$scope.posx=data.x;
$scope.posy=data.y;
$scope.posz=data.z;
});
});
socket.on('bot:forcedMove', function(data) {
$scope.$apply(function() {
$scope.posx=data.x;
$scope.posy=data.y;
$scope.posz=data.z;
});
});
socket.on('bot:health',function(data){
$scope.$apply(function() {
$scope.health=data.health;
$scope.food=data.food;
});
})
};
+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);
};
+8
View File
@@ -3,6 +3,10 @@ import login from './events/login';
import spawn from './events/spawn';
import message from './events/message';
import end from './events/end';
import death from './events/death';
import rain from './events/rain';
import health from './events/health';
import move from './events/move';
// bind all listeners to the bot
export default (socket) => {
@@ -12,5 +16,9 @@ export default (socket) => {
spawn(socket);
message(socket);
end(socket);
death(socket);
rain(socket);
move(socket);
health(socket);
};
BIN
View File
Binary file not shown.
+5
View File
@@ -1,6 +1,11 @@
<div id="buffer" ng-controller="bufferController">
<div id="players" ng-controller="playersController" ng-show="players.length" class="hidden-xs">
<div>
<span style="color:#6AC126">x:{{posx}} y:{{posy}} z:{{posz}}</span>
<br>
<span style="color:#6AC126">Health:{{health}} Food:{{food}}</span>
</div>
<div class="header">Players [{{players.length}}]</div>
<div class="body">
<ul>