add metadata when placing a block, progress on #9

This commit is contained in:
Romain Beaumont 2015-10-26 21:32:31 +01:00
parent f0808b36e1
commit 81d6cca4f1
7 changed files with 29 additions and 27 deletions

View file

@ -64,12 +64,12 @@
- [player.kick(reason)](#playerkickreason)
- [player.getOthers()](#playergetothers)
- [player.chat(message)](#playerchatmessage)
- [player.changeBlock(position,blockType)](#playerchangeblockpositionblocktype)
- [player.sendBlock(position,blockType)](#playersendblockpositionblocktype)
- [player.changeBlock(position,blockType,blockData)](#playerchangeblockpositionblocktypeblockdata)
- [player.sendBlock(position,blockType,blockData)](#playersendblockpositionblocktypeblockdata)
- [player.sendInitialPosition()](#playersendinitialposition)
- [player.setGameMode(gameMode)](#playersetgamemodegamemode)
- [player.handleCommand(command)](#playerhandlecommandcommand)
- [player.setBlock(position,blockType)](#playersetblockpositionblocktype)
- [player.setBlock(position,blockType,blockData)](#playersetblockpositionblocktypeblockdata)
- [player.updateHealth(health)](#playerupdatehealthhealth)
- [player.changeWorld(world, opt)](#playerchangeworldworld-opt)
- [player.spawnAPlayer(spawnedPlayer)](#playerspawnaplayerspawnedplayer)
@ -328,16 +328,16 @@ return the other players than `player`
sends `message` to the player
#### player.changeBlock(position,blockType)
#### player.changeBlock(position,blockType,blockData)
change the block at position `position` to `blockType`
change the block at position `position` to `blockType` and `blockData`
this will not change the block for the user themself. It is mainly useful when a user places a block
and only needs to send it to other players on the server
#### player.sendBlock(position,blockType)
#### player.sendBlock(position,blockType,blockData)
change the block at position `position` to `blockType`
change the block at position `position` to `blockType` and `blockData`
this will not make any changes on the server's world and only sends it to the user as a "fake" or "local" block
@ -353,7 +353,7 @@ set player gameMode to `gameMode`
handle `command`
#### player.setBlock(position,blockType)
#### player.setBlock(position,blockType,blockData)
Saves block in world and sends block update to all players of the same world.

View file

@ -2,20 +2,21 @@ module.exports=inject;
function inject(serv,player)
{
player.changeBlock=async (position,blockType) =>
player.changeBlock=async (position,blockType,blockData) =>
{
serv.players
.filter(p => p.world==player.world)
.forEach(p => p.sendBlock(position, blockType));
.filter(p => p.world==player.world && player!=p)
.forEach(p => p.sendBlock(position, blockType, blockData));
return await player.world.setBlockType(position,blockType);
await player.world.setBlockType(position,blockType);
await player.world.setBlockData(position,blockData);
};
player.sendBlock = (position, blockType) => // Call from player.setBlock unless you want "local" fake blocks
player.sendBlock = (position, blockType, blockData) => // Call from player.setBlock unless you want "local" fake blocks
player._client.write("block_change",{
location:position,
type:blockType<<4
type:blockType<<4 | blockData
});
player.setBlock = (position,blockType) => serv.setBlock(player.world,position,blockType);
player.setBlock = (position,blockType,blockData) => serv.setBlock(player.world,position,blockType,blockData);
}

View file

@ -57,9 +57,9 @@ function inject(serv, player) {
base.add({
base: 'setblock',
info: 'to put a block',
usage: '/setblock <x> <y> <z> <id>',
usage: '/setblock <x> <y> <z> <id> <data>',
parse(str) {
var results = str.match(/^(~|~?-?[0-9]*) (~|~?-?[0-9]*) (~|~?-?[0-9]*) ([0-9]{1,3})/);
var results = str.match(/^(~|~?-?[0-9]*) (~|~?-?[0-9]*) (~|~?-?[0-9]*) ([0-9]{1,3}) ([0-9]{1,3})/);
if(!results) return false;
else return results;
@ -73,7 +73,7 @@ function inject(serv, player) {
}
});
player.setBlock(new Vec3(res[1], res[2], res[3]), res[4]);
player.setBlock(new Vec3(res[1], res[2], res[3]), res[4],res[5]);
}
});

View file

@ -75,7 +75,7 @@ function inject(serv,player)
clearInterval(animationInterval);
var diggingTime=new Date()-startDiggingTime;
if(expectedDiggingTime-diggingTime<100)
player.changeBlock(location,0);
player.changeBlock(location,0,0);
else
{
player._client.write("block_change",{
@ -88,7 +88,7 @@ function inject(serv,player)
function creativeDigging(location)
{
return player.changeBlock(location,0);
return player.changeBlock(location,0,0);
}
}

View file

@ -10,14 +10,14 @@ function inject(serv,player)
var directionVector=directionToVector[direction];
var placedPosition=referencePosition.plus(directionVector);
if(heldItem.blockId!=323){
player.changeBlock(placedPosition,heldItem.blockId);
player.changeBlock(placedPosition,heldItem.blockId,heldItem.itemDamage);
}else if(direction==1){
player.setBlock(placedPosition, 63);
player.setBlock(placedPosition, 63, 0);
player._client.write('open_sign_entity', {
location:placedPosition
});
}else{
player.setBlock(placedPosition, 68);
player.setBlock(placedPosition, 68, 0);
player._client.write('open_sign_entity', {
location:placedPosition
});

View file

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

View file

@ -32,13 +32,14 @@ function inject(serv,{regionFolder,generation={"name":"diamond_square","options"
return Promise.all(promises);
};
serv.setBlock = (world,position,blockType) =>
serv.setBlock = async (world,position,blockType,blockData) =>
{
serv.players
.filter(p => p.world==world)
.forEach(player => player.sendBlock(position, blockType));
.forEach(player => player.sendBlock(position, blockType, blockData));
return world.setBlockType(position,blockType);
await world.setBlockType(position,blockType);
await world.setBlockData(position,blockData);
};
//serv.pregenWorld(serv.overworld).then(() => serv.log('Pre-Generated Overworld'));