diff --git a/doc/api.md b/doc/api.md index e0f84de..6f485f4 100644 --- a/doc/api.md +++ b/doc/api.md @@ -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. diff --git a/src/lib/playerPlugins/blocks.js b/src/lib/playerPlugins/blocks.js index c6dc6d3..2394d23 100644 --- a/src/lib/playerPlugins/blocks.js +++ b/src/lib/playerPlugins/blocks.js @@ -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); } \ No newline at end of file diff --git a/src/lib/playerPlugins/commands.js b/src/lib/playerPlugins/commands.js index c8b7f58..76747af 100644 --- a/src/lib/playerPlugins/commands.js +++ b/src/lib/playerPlugins/commands.js @@ -57,9 +57,9 @@ function inject(serv, player) { base.add({ base: 'setblock', info: 'to put a block', - usage: '/setblock ', + usage: '/setblock ', 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]); } }); diff --git a/src/lib/playerPlugins/digging.js b/src/lib/playerPlugins/digging.js index 93ddf9c..56aa35a 100644 --- a/src/lib/playerPlugins/digging.js +++ b/src/lib/playerPlugins/digging.js @@ -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); } } \ No newline at end of file diff --git a/src/lib/playerPlugins/placeBlock.js b/src/lib/playerPlugins/placeBlock.js index 0bf0109..ede0851 100644 --- a/src/lib/playerPlugins/placeBlock.js +++ b/src/lib/playerPlugins/placeBlock.js @@ -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 }); diff --git a/src/lib/serverPlugins/modpe.js b/src/lib/serverPlugins/modpe.js index c6c28b3..43b4a90 100644 --- a/src/lib/serverPlugins/modpe.js +++ b/src/lib/serverPlugins/modpe.js @@ -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) { diff --git a/src/lib/serverPlugins/world.js b/src/lib/serverPlugins/world.js index 1293475..0f6e31c 100644 --- a/src/lib/serverPlugins/world.js +++ b/src/lib/serverPlugins/world.js @@ -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'));