Added forceCancelDig and some other stuff

This commit is contained in:
DemiPixel 2015-11-23 19:27:35 -08:00
parent 0355195cd9
commit 483269db4c
6 changed files with 32 additions and 9 deletions

View file

@ -109,6 +109,7 @@
- ["dig"](#dig) - ["dig"](#dig)
- ["dug"](#dug) - ["dug"](#dug)
- ["cancelDig"](#canceldig) - ["cancelDig"](#canceldig)
- ["forceCancelDig"](#forcecanceldig)
- ["breakAnimation"](#breakanimation) - ["breakAnimation"](#breakanimation)
- ["placeBlock"](#placeblock) - ["placeBlock"](#placeblock)
- ["attack"](#attack) - ["attack"](#attack)
@ -714,6 +715,13 @@ Default: Stop animation for all players, save stop digging
Cancelled: Nothing 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" ##### "breakAnimation"
Emitted when the server believes the break animation should increase (not sent by client!) 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 Emitted when a player places a block
- position: Position they're attempting to place the block - position: Position they're attempting to place the block
- id: Id of block being placed - 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 - reference (u): Reference block that was placed on
- direction (u): Direction vector from reference to position - direction (u): Direction vector from reference to position
- playSound: Which sound to play (Default: true) - playSound: Which sound to play (Default: true)

View file

@ -20,5 +20,6 @@ module.exports = (obj) => {
else if (cancelFunc && defaultCancel) await cancelFunc(data).catch((err)=> setTimeout(() => {throw err;},0)); 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)); await obj.emitThen(eventName + '_done', data, cancelled).catch((err)=> setTimeout(() => {throw err;},0));
return data;
} }
} }

View file

@ -95,7 +95,16 @@ module.exports.player=function(player,serv)
{ {
clearInterval(animationInterval); clearInterval(animationInterval);
var diggingTime=new Date()-startDiggingTime; var diggingTime=new Date()-startDiggingTime;
var stop = false;
if(expectedDiggingTime-diggingTime<100) { if(expectedDiggingTime-diggingTime<100) {
stop = true;
stop = player.behavior('forceCancelDig', {
stop: true,
start: startDiggingTime,
time: diggingTime
}).stop;
}
if(!stop) {
player.behavior('dug', { player.behavior('dug', {
position: location, position: location,
block: currentlyDugBlock, block: currentlyDugBlock,
@ -109,8 +118,9 @@ module.exports.player=function(player,serv)
blockDropDeath: 60*5*1000 blockDropDeath: 60*5*1000
}, (data) => { }, (data) => {
player.changeBlock(data.position,0,0); player.changeBlock(data.position,0,0);
console.log('dropping',data.dropBlock);
if (data.dropBlock) dropBlock(data); if (data.dropBlock) dropBlock(data);
}) }, cancelDig)
} }
else else
{ {
@ -148,7 +158,7 @@ module.exports.player=function(player,serv)
}, (data) => { }, (data) => {
player.changeBlock(data.position,0,0); player.changeBlock(data.position,0,0);
if (data.dropBlock) dropBlock(data); if (data.dropBlock) dropBlock(data);
}); }, cancelDig);
} }
}; };

View file

@ -259,7 +259,8 @@ module.exports.entity=function(entity,serv){
entity.collect = (collectEntity) => { entity.collect = (collectEntity) => {
if (entity.type != 'player'){ 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; return;
} }

View file

@ -1,3 +1,5 @@
var fs = require('fs');
module.exports.server = function(serv, settings) { module.exports.server = function(serv, settings) {
serv.plugins = {}; serv.plugins = {};
serv.pluginCount = 0; serv.pluginCount = 0;
@ -23,11 +25,12 @@ module.exports.server = function(serv, settings) {
try { try {
serv.addPlugin(p, require(p), settings.plugins[p]); serv.addPlugin(p, require(p), settings.plugins[p]);
} catch (err) { } catch (err) {
try { try { // Throw error if cannot find plugin
serv.addPlugin(p, require('../../plugins/' + p), settings.plugins[p]); fs.accessSync('./dist/plugins/' + p);
} catch (err) { } catch (err) {
throw new Error('Cannot find plugin "' + p + '"'); throw new Error('Cannot find plugin "' + p + '"');
} }
serv.addPlugin(p, require('../../plugins/' + p), settings.plugins[p]);
} }
} }

View file

@ -22,19 +22,19 @@ module.exports.player=function(player,serv)
direction: directionVector, direction: directionVector,
heldItem: heldItem, heldItem: heldItem,
id: heldItem.blockId, id: heldItem.blockId,
data: heldItem.itemDamage, damage: heldItem.itemDamage,
position: placedPosition, position: placedPosition,
reference: referencePosition, reference: referencePosition,
playSound: true, playSound: true,
sound: 'dig.' + (materialToSound[blocks[heldItem.blockId].material] || 'stone'), sound: 'dig.' + (materialToSound[blocks[heldItem.blockId].material] || 'stone'),
}, ({direction, heldItem, position, reference, playSound, sound}) => { }, ({direction, heldItem, position, reference, playSound, sound, id, damage}) => {
if (playSound) { if (playSound) {
serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), { serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), {
pitch: 0.8 pitch: 0.8
}); });
} }
if(heldItem.blockId!=323){ if(heldItem.blockId!=323){
player.changeBlock(position,heldItem.blockId,heldItem.itemDamage); player.changeBlock(position, id, damage);
}else if(direction==1){ }else if(direction==1){
player.setBlock(position, 63, 0); player.setBlock(position, 63, 0);
player._client.write('open_sign_entity', { player._client.write('open_sign_entity', {