serv.setBlock -> player.setBlock

This commit is contained in:
Romain Beaumont 2015-10-25 21:24:37 +01:00
parent e3b7ad569b
commit c2b1424743
7 changed files with 21 additions and 25 deletions

View file

@ -186,10 +186,6 @@ logs a `message`
broadcasts `message` to all the players with the optional `color`.
#### serv.setBlock(position,blockType)
Saves block in world and sends block update to all players.
#### serv.getPlayer(username)
Returns player object with that username or, if no such player is on the server, null.
@ -349,6 +345,10 @@ set player gameMode to `gameMode`
handle `command`
#### player.setBlock(position,blockType)
Saves block in world and sends block update to all players of the same world.
#### player.updateHealth(health)
update the player health.

View file

@ -4,19 +4,29 @@ function inject(serv,player)
{
async function changeBlock(position,blockType)
{
player.getNearby().forEach(function(p) {
serv.players.filter(p => p.world==player.world).forEach(function(p) {
p.sendBlock(position, blockType);
});
return await player.world.setBlockType(position,blockType);
}
function sendBlock(position, blockType) { // Call from serv.setBlock unless you want "local" fake blocks
function sendBlock(position, blockType) { // Call from player.setBlock unless you want "local" fake blocks
player._client.write("block_change",{
location:position,
type:blockType<<4
});
}
function setBlock(position,blockType)
{
player.getNearby().forEach(function(player){
player.sendBlock(position, blockType);
});
return player.world.setBlockType(position,blockType);
}
player.setBlock = setBlock;
player.changeBlock=changeBlock;
player.sendBlock=sendBlock;
}

View file

@ -73,7 +73,7 @@ function inject(serv, player) {
}
});
serv.setBlock(new Vec3(res[1], res[2], res[3]), res[4]);
player.setBlock(new Vec3(res[1], res[2], res[3]), res[4]);
}
});

View file

@ -12,12 +12,12 @@ function inject(serv,player)
if(packet.heldItem.blockId!=323){
player.changeBlock(placedPosition,packet.heldItem.blockId);
}else if(packet.direction==1){
serv.setBlock(placedPosition, 63);
player.setBlock(placedPosition, 63);
player._client.write('open_sign_entity', {
location:placedPosition
});
}else{
serv.setBlock(placedPosition, 68);
player.setBlock(placedPosition, 68);
player._client.write('open_sign_entity', {
location:placedPosition
});

View file

@ -1,14 +0,0 @@
module.exports=inject;
function inject(serv)
{
function setBlock(position,blockType)
{
serv.players.forEach(function(player){
player.sendBlock(position, blockType);
});
return serv.world.setBlockType(position,blockType);
}
serv.setBlock = setBlock;
}

View file

@ -22,5 +22,5 @@ function inject(serv,settings)
return serv.players.filter(function(player) {
return player.world == loc.world && player.entity.position.distanceTo(loc.position) <= loc.radius;
});
}
};
}

View file

@ -52,7 +52,7 @@ function modpeApi() {
}
function setTile(x, y, z, id, damage) {
server.setBlock(new vec3(x, y, z), id);
player.setBlock(new vec3(x, y, z), id);
}
function getTile(x, y, z) {