mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-18 22:11:07 +00:00
Merge pull request #38 from demipixel/block_stuff
Added setBlock, sendBlock, some fixes, and /setblock
This commit is contained in:
commit
fbc9a10cef
4 changed files with 58 additions and 5 deletions
18
doc/api.md
18
doc/api.md
|
|
@ -21,6 +21,7 @@
|
|||
- [serv.createLog()](#servcreatelog)
|
||||
- [serv.log(message)](#servlogmessage)
|
||||
- [serv.broadcast(message[,color])](#servbroadcastmessagecolor)
|
||||
- [serv.setBlock(position,blockType)](#servsetblockpositionblocktype)
|
||||
- [Player](#player)
|
||||
- [Properties](#properties-1)
|
||||
- [player.entity](#playerentity)
|
||||
|
|
@ -33,9 +34,10 @@
|
|||
- ["chat" (message)](#chat-message)
|
||||
- [Methods](#methods-1)
|
||||
- [player.login()](#playerlogin)
|
||||
- [player.others()](#playerothers)
|
||||
- [player.getOthers()](#playergetothers)
|
||||
- [player.chat(message)](#playerchatmessage)
|
||||
- [player.changeBlock(position,blockType)](#playerchangeblockpositionblocktype)
|
||||
- [player.sendBlock(position,blockType)](#playersendblockpositionblocktype)
|
||||
- [player.sendInitialPosition()](#playersendinitialposition)
|
||||
- [player.spawn()](#playerspawn)
|
||||
- [player.setGameMode(gameMode)](#playersetgamemodegamemode)
|
||||
|
|
@ -113,6 +115,10 @@ logs a `message`
|
|||
|
||||
broadcasts `message` to all the players with the optional `color`.
|
||||
|
||||
#### serv.setBlock(position,blockType)
|
||||
|
||||
Saves block in world and sends block update to all players.
|
||||
|
||||
## Player
|
||||
|
||||
### Properties
|
||||
|
|
@ -153,7 +159,7 @@ Fires when the player says `message`.
|
|||
|
||||
login
|
||||
|
||||
#### player.others()
|
||||
#### player.getOthers()
|
||||
|
||||
return the other players than `player`
|
||||
|
||||
|
|
@ -165,6 +171,14 @@ sends `message` to the player
|
|||
|
||||
change the block at position `position` to `blockType`
|
||||
|
||||
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)
|
||||
|
||||
change the block at position `position` to `blockType`
|
||||
|
||||
this will not make any changes on the server's world and only sends it to the user as a "fake" or "local" block
|
||||
|
||||
#### player.sendInitialPosition()
|
||||
|
||||
send its initial position to the player
|
||||
|
|
|
|||
|
|
@ -4,12 +4,19 @@ function inject(serv,player)
|
|||
{
|
||||
function changeBlock(position,blockType)
|
||||
{
|
||||
player._writeOthers("block_change",{
|
||||
location:position,
|
||||
type:blockType<<4
|
||||
player.getOthers().forEach(function(player) {
|
||||
player.sendBlock(position, blockType);
|
||||
});
|
||||
serv.world.setBlockType(position,blockType);
|
||||
}
|
||||
|
||||
function sendBlock(position, blockType) { // Call from serv.setBlock unless you want "local" fake blocks
|
||||
player._client.write("block_change",{
|
||||
location:position,
|
||||
type:blockType<<4
|
||||
});
|
||||
}
|
||||
|
||||
player.changeBlock=changeBlock;
|
||||
player.sendBlock=sendBlock;
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
var Vec3 = require('vec3');
|
||||
|
||||
module.exports=inject;
|
||||
|
||||
function inject(serv, player, options)
|
||||
|
|
@ -11,6 +13,22 @@ function inject(serv, player, options)
|
|||
var gameMode=parseInt(results[1]);
|
||||
player.setGameMode(gameMode);
|
||||
}
|
||||
else if(results=command.match(/^setblock/)) { // Like old version which uses ids
|
||||
results = command.match(/^setblock (~|~?-?[0-9]*) (~|~?-?[0-9]*) (~|~?-?[0-9]*) ([0-9]{1,3})/);
|
||||
if(!results) {
|
||||
player.chat("Usage: /setblock <x> <y> <z> <id>");
|
||||
}
|
||||
else {
|
||||
results = results.map(function(num, i) { // parseInt paramaters
|
||||
if (num.indexOf('~') == 0) {
|
||||
return (player.entity.position[['','x', 'y', 'z'][i]]>>5) + parseInt(num.slice(1) || 0);
|
||||
}
|
||||
else
|
||||
return parseInt(num); // return parseInt>>5 if position, not id
|
||||
});
|
||||
serv.setBlock(new Vec3(results[1], results[2], results[3]), results[4]);
|
||||
}
|
||||
}
|
||||
else
|
||||
player.chat("Invalid command.");
|
||||
}
|
||||
|
|
|
|||
14
lib/serverPlugins/blocks.js
Normal file
14
lib/serverPlugins/blocks.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
module.exports=inject;
|
||||
|
||||
function inject(serv)
|
||||
{
|
||||
function setBlock(position,blockType)
|
||||
{
|
||||
serv.players.forEach(function(player){
|
||||
player.sendBlock(position, blockType);
|
||||
});
|
||||
serv.world.setBlockType(position,blockType);
|
||||
}
|
||||
|
||||
serv.setBlock = setBlock;
|
||||
}
|
||||
Loading…
Reference in a new issue