add player.changeBlock method, make digging work in creative mode, basic block_place functionality

This commit is contained in:
Romain Beaumont 2015-08-27 03:46:53 +02:00
parent 0b2967c5db
commit 6d13014d1c
4 changed files with 39 additions and 8 deletions

View file

@ -52,6 +52,7 @@
- [player.login()](#playerlogin)
- [player.others()](#playerothers)
- [player.chat(message)](#playerchatmessage)
- [player.changeBlock(position,blockType)](#playerchangeblockpositionblocktype)
- [Low level properties](#low-level-properties)
- [player._client](#player_client)
- [Low level methods](#low-level-methods)
@ -242,6 +243,10 @@ return the other players than `player`
sends `message` to the player
#### player.changeBlock(position,blockType)
change the block at position `position` to `blockType`
### Low level properties
#### player._client

View file

@ -0,0 +1,15 @@
module.exports=inject;
function inject(serv,player)
{
function changeBlock(position,blockType)
{
player._writeOthers("block_change",{
location:position,
type:blockType<<4
});
serv.world.setBlockType(position.x,position.y,position.z,blockType);
}
player.changeBlock=changeBlock;
}

View file

@ -4,13 +4,8 @@ function inject(serv,player)
{
// doesn't check whether the player actually wait the correct time
player._client.on("block_dig",function(packet){
if(packet.status==2)
{
player._writeOthers("block_change",{
location:packet.location,
type:0
});
serv.world.setBlockType(packet.location.x,packet.location.y,packet.location.z,0);
}
if(packet.status==2 || (packet.status==0 && player.gameMode==1))
player.changeBlock(packet.location,0);
});
}

View file

@ -0,0 +1,16 @@
var vec3 = require("vec3");
module.exports=inject;
function inject(serv,player)
{
player._client.on("block_place",function(packet){
if(packet.direction==-1) return;
var referencePosition=new vec3(packet.location.x,packet.location.y,packet.location.z);
var directionVector=directionToVector[packet.direction];
var placedPosition=referencePosition.plus(directionVector);
player.changeBlock(placedPosition,packet.heldItem.blockId);
});
}
var directionToVector=[new vec3(0,-1,0),new vec3(0,1,0),new vec3(0,0,-1),new vec3(0,0,1),new vec3(-1,0,0),new vec3(1,0,0)];