mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-19 22:41:52 +00:00
Added forceCancelDig and some other stuff
This commit is contained in:
parent
0355195cd9
commit
483269db4c
6 changed files with 32 additions and 9 deletions
10
doc/api.md
10
doc/api.md
|
|
@ -109,6 +109,7 @@
|
|||
- ["dig"](#dig)
|
||||
- ["dug"](#dug)
|
||||
- ["cancelDig"](#canceldig)
|
||||
- ["forceCancelDig"](#forcecanceldig)
|
||||
- ["breakAnimation"](#breakanimation)
|
||||
- ["placeBlock"](#placeblock)
|
||||
- ["attack"](#attack)
|
||||
|
|
@ -714,6 +715,13 @@ Default: Stop animation for all players, save stop digging
|
|||
|
||||
Cancelled: Nothing
|
||||
|
||||
#### "forceCancelDig"
|
||||
|
||||
Emitted when the server cancels a dig (currently only happens if the player mines too fast)
|
||||
- stop: Whether the digging should be cancelled because they mined too fast (Default: true)
|
||||
- start (u): Time mining started
|
||||
- time (u): How long the player has been mining
|
||||
|
||||
##### "breakAnimation"
|
||||
|
||||
Emitted when the server believes the break animation should increase (not sent by client!)
|
||||
|
|
@ -732,7 +740,7 @@ Cancelled: Nothing
|
|||
Emitted when a player places a block
|
||||
- position: Position they're attempting to place the block
|
||||
- id: Id of block being placed
|
||||
- data: Data of block being placed
|
||||
- damage: Data of block being placed
|
||||
- reference (u): Reference block that was placed on
|
||||
- direction (u): Direction vector from reference to position
|
||||
- playSound: Which sound to play (Default: true)
|
||||
|
|
|
|||
|
|
@ -20,5 +20,6 @@ module.exports = (obj) => {
|
|||
else if (cancelFunc && defaultCancel) await cancelFunc(data).catch((err)=> setTimeout(() => {throw err;},0));
|
||||
|
||||
await obj.emitThen(eventName + '_done', data, cancelled).catch((err)=> setTimeout(() => {throw err;},0));
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -95,7 +95,16 @@ module.exports.player=function(player,serv)
|
|||
{
|
||||
clearInterval(animationInterval);
|
||||
var diggingTime=new Date()-startDiggingTime;
|
||||
var stop = false;
|
||||
if(expectedDiggingTime-diggingTime<100) {
|
||||
stop = true;
|
||||
stop = player.behavior('forceCancelDig', {
|
||||
stop: true,
|
||||
start: startDiggingTime,
|
||||
time: diggingTime
|
||||
}).stop;
|
||||
}
|
||||
if(!stop) {
|
||||
player.behavior('dug', {
|
||||
position: location,
|
||||
block: currentlyDugBlock,
|
||||
|
|
@ -109,8 +118,9 @@ module.exports.player=function(player,serv)
|
|||
blockDropDeath: 60*5*1000
|
||||
}, (data) => {
|
||||
player.changeBlock(data.position,0,0);
|
||||
console.log('dropping',data.dropBlock);
|
||||
if (data.dropBlock) dropBlock(data);
|
||||
})
|
||||
}, cancelDig)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -148,7 +158,7 @@ module.exports.player=function(player,serv)
|
|||
}, (data) => {
|
||||
player.changeBlock(data.position,0,0);
|
||||
if (data.dropBlock) dropBlock(data);
|
||||
});
|
||||
}, cancelDig);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -259,7 +259,8 @@ module.exports.entity=function(entity,serv){
|
|||
|
||||
entity.collect = (collectEntity) => {
|
||||
if (entity.type != 'player'){
|
||||
serv.emit('error', 'Non-player entity (ttype ' + entity.type + ') cannot collect another entity')
|
||||
console.log('[ERROR] Non-player entity (type ' + entity.type + ') cannot collect another entity');
|
||||
console.log((new Error()).stack);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
var fs = require('fs');
|
||||
|
||||
module.exports.server = function(serv, settings) {
|
||||
serv.plugins = {};
|
||||
serv.pluginCount = 0;
|
||||
|
|
@ -23,11 +25,12 @@ module.exports.server = function(serv, settings) {
|
|||
try {
|
||||
serv.addPlugin(p, require(p), settings.plugins[p]);
|
||||
} catch (err) {
|
||||
try {
|
||||
serv.addPlugin(p, require('../../plugins/' + p), settings.plugins[p]);
|
||||
try { // Throw error if cannot find plugin
|
||||
fs.accessSync('./dist/plugins/' + p);
|
||||
} catch (err) {
|
||||
throw new Error('Cannot find plugin "' + p + '"');
|
||||
}
|
||||
serv.addPlugin(p, require('../../plugins/' + p), settings.plugins[p]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,19 +22,19 @@ module.exports.player=function(player,serv)
|
|||
direction: directionVector,
|
||||
heldItem: heldItem,
|
||||
id: heldItem.blockId,
|
||||
data: heldItem.itemDamage,
|
||||
damage: heldItem.itemDamage,
|
||||
position: placedPosition,
|
||||
reference: referencePosition,
|
||||
playSound: true,
|
||||
sound: 'dig.' + (materialToSound[blocks[heldItem.blockId].material] || 'stone'),
|
||||
}, ({direction, heldItem, position, reference, playSound, sound}) => {
|
||||
}, ({direction, heldItem, position, reference, playSound, sound, id, damage}) => {
|
||||
if (playSound) {
|
||||
serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), {
|
||||
pitch: 0.8
|
||||
});
|
||||
}
|
||||
if(heldItem.blockId!=323){
|
||||
player.changeBlock(position,heldItem.blockId,heldItem.itemDamage);
|
||||
player.changeBlock(position, id, damage);
|
||||
}else if(direction==1){
|
||||
player.setBlock(position, 63, 0);
|
||||
player._client.write('open_sign_entity', {
|
||||
|
|
|
|||
Loading…
Reference in a new issue