mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-04 10:40:42 +00:00
add player.changeBlock method, make digging work in creative mode, basic block_place functionality
This commit is contained in:
parent
0b2967c5db
commit
6d13014d1c
4 changed files with 39 additions and 8 deletions
|
|
@ -52,6 +52,7 @@
|
||||||
- [player.login()](#playerlogin)
|
- [player.login()](#playerlogin)
|
||||||
- [player.others()](#playerothers)
|
- [player.others()](#playerothers)
|
||||||
- [player.chat(message)](#playerchatmessage)
|
- [player.chat(message)](#playerchatmessage)
|
||||||
|
- [player.changeBlock(position,blockType)](#playerchangeblockpositionblocktype)
|
||||||
- [Low level properties](#low-level-properties)
|
- [Low level properties](#low-level-properties)
|
||||||
- [player._client](#player_client)
|
- [player._client](#player_client)
|
||||||
- [Low level methods](#low-level-methods)
|
- [Low level methods](#low-level-methods)
|
||||||
|
|
@ -242,6 +243,10 @@ return the other players than `player`
|
||||||
|
|
||||||
sends `message` to the player
|
sends `message` to the player
|
||||||
|
|
||||||
|
#### player.changeBlock(position,blockType)
|
||||||
|
|
||||||
|
change the block at position `position` to `blockType`
|
||||||
|
|
||||||
### Low level properties
|
### Low level properties
|
||||||
|
|
||||||
#### player._client
|
#### player._client
|
||||||
|
|
|
||||||
15
lib/playerPlugins/blocks.js
Normal file
15
lib/playerPlugins/blocks.js
Normal 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;
|
||||||
|
}
|
||||||
|
|
@ -4,13 +4,8 @@ function inject(serv,player)
|
||||||
{
|
{
|
||||||
// doesn't check whether the player actually wait the correct time
|
// doesn't check whether the player actually wait the correct time
|
||||||
player._client.on("block_dig",function(packet){
|
player._client.on("block_dig",function(packet){
|
||||||
if(packet.status==2)
|
if(packet.status==2 || (packet.status==0 && player.gameMode==1))
|
||||||
{
|
player.changeBlock(packet.location,0);
|
||||||
player._writeOthers("block_change",{
|
|
||||||
location:packet.location,
|
|
||||||
type:0
|
|
||||||
});
|
|
||||||
serv.world.setBlockType(packet.location.x,packet.location.y,packet.location.z,0);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
16
lib/playerPlugins/placeBlock.js
Normal file
16
lib/playerPlugins/placeBlock.js
Normal 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)];
|
||||||
Loading…
Reference in a new issue