mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-07 12:10:46 +00:00
add metadata when placing a block, progress on #9
This commit is contained in:
parent
f0808b36e1
commit
81d6cca4f1
7 changed files with 29 additions and 27 deletions
16
doc/api.md
16
doc/api.md
|
|
@ -64,12 +64,12 @@
|
||||||
- [player.kick(reason)](#playerkickreason)
|
- [player.kick(reason)](#playerkickreason)
|
||||||
- [player.getOthers()](#playergetothers)
|
- [player.getOthers()](#playergetothers)
|
||||||
- [player.chat(message)](#playerchatmessage)
|
- [player.chat(message)](#playerchatmessage)
|
||||||
- [player.changeBlock(position,blockType)](#playerchangeblockpositionblocktype)
|
- [player.changeBlock(position,blockType,blockData)](#playerchangeblockpositionblocktypeblockdata)
|
||||||
- [player.sendBlock(position,blockType)](#playersendblockpositionblocktype)
|
- [player.sendBlock(position,blockType,blockData)](#playersendblockpositionblocktypeblockdata)
|
||||||
- [player.sendInitialPosition()](#playersendinitialposition)
|
- [player.sendInitialPosition()](#playersendinitialposition)
|
||||||
- [player.setGameMode(gameMode)](#playersetgamemodegamemode)
|
- [player.setGameMode(gameMode)](#playersetgamemodegamemode)
|
||||||
- [player.handleCommand(command)](#playerhandlecommandcommand)
|
- [player.handleCommand(command)](#playerhandlecommandcommand)
|
||||||
- [player.setBlock(position,blockType)](#playersetblockpositionblocktype)
|
- [player.setBlock(position,blockType,blockData)](#playersetblockpositionblocktypeblockdata)
|
||||||
- [player.updateHealth(health)](#playerupdatehealthhealth)
|
- [player.updateHealth(health)](#playerupdatehealthhealth)
|
||||||
- [player.changeWorld(world, opt)](#playerchangeworldworld-opt)
|
- [player.changeWorld(world, opt)](#playerchangeworldworld-opt)
|
||||||
- [player.spawnAPlayer(spawnedPlayer)](#playerspawnaplayerspawnedplayer)
|
- [player.spawnAPlayer(spawnedPlayer)](#playerspawnaplayerspawnedplayer)
|
||||||
|
|
@ -328,16 +328,16 @@ return the other players than `player`
|
||||||
|
|
||||||
sends `message` to the 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
|
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
|
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
|
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`
|
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.
|
Saves block in world and sends block update to all players of the same world.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,21 @@ module.exports=inject;
|
||||||
|
|
||||||
function inject(serv,player)
|
function inject(serv,player)
|
||||||
{
|
{
|
||||||
player.changeBlock=async (position,blockType) =>
|
player.changeBlock=async (position,blockType,blockData) =>
|
||||||
{
|
{
|
||||||
serv.players
|
serv.players
|
||||||
.filter(p => p.world==player.world)
|
.filter(p => p.world==player.world && player!=p)
|
||||||
.forEach(p => p.sendBlock(position, blockType));
|
.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",{
|
player._client.write("block_change",{
|
||||||
location:position,
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -57,9 +57,9 @@ function inject(serv, player) {
|
||||||
base.add({
|
base.add({
|
||||||
base: 'setblock',
|
base: 'setblock',
|
||||||
info: 'to put a block',
|
info: 'to put a block',
|
||||||
usage: '/setblock <x> <y> <z> <id>',
|
usage: '/setblock <x> <y> <z> <id> <data>',
|
||||||
parse(str) {
|
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;
|
if(!results) return false;
|
||||||
else return results;
|
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]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ function inject(serv,player)
|
||||||
clearInterval(animationInterval);
|
clearInterval(animationInterval);
|
||||||
var diggingTime=new Date()-startDiggingTime;
|
var diggingTime=new Date()-startDiggingTime;
|
||||||
if(expectedDiggingTime-diggingTime<100)
|
if(expectedDiggingTime-diggingTime<100)
|
||||||
player.changeBlock(location,0);
|
player.changeBlock(location,0,0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player._client.write("block_change",{
|
player._client.write("block_change",{
|
||||||
|
|
@ -88,7 +88,7 @@ function inject(serv,player)
|
||||||
|
|
||||||
function creativeDigging(location)
|
function creativeDigging(location)
|
||||||
{
|
{
|
||||||
return player.changeBlock(location,0);
|
return player.changeBlock(location,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -10,14 +10,14 @@ function inject(serv,player)
|
||||||
var directionVector=directionToVector[direction];
|
var directionVector=directionToVector[direction];
|
||||||
var placedPosition=referencePosition.plus(directionVector);
|
var placedPosition=referencePosition.plus(directionVector);
|
||||||
if(heldItem.blockId!=323){
|
if(heldItem.blockId!=323){
|
||||||
player.changeBlock(placedPosition,heldItem.blockId);
|
player.changeBlock(placedPosition,heldItem.blockId,heldItem.itemDamage);
|
||||||
}else if(direction==1){
|
}else if(direction==1){
|
||||||
player.setBlock(placedPosition, 63);
|
player.setBlock(placedPosition, 63, 0);
|
||||||
player._client.write('open_sign_entity', {
|
player._client.write('open_sign_entity', {
|
||||||
location:placedPosition
|
location:placedPosition
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
player.setBlock(placedPosition, 68);
|
player.setBlock(placedPosition, 68, 0);
|
||||||
player._client.write('open_sign_entity', {
|
player._client.write('open_sign_entity', {
|
||||||
location:placedPosition
|
location:placedPosition
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ function modpeApi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTile(x, y, z, id, damage) {
|
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) {
|
function getTile(x, y, z) {
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,14 @@ function inject(serv,{regionFolder,generation={"name":"diamond_square","options"
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
};
|
};
|
||||||
|
|
||||||
serv.setBlock = (world,position,blockType) =>
|
serv.setBlock = async (world,position,blockType,blockData) =>
|
||||||
{
|
{
|
||||||
serv.players
|
serv.players
|
||||||
.filter(p => p.world==world)
|
.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'));
|
//serv.pregenWorld(serv.overworld).then(() => serv.log('Pre-Generated Overworld'));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue