Add more to "dug" behavior and add "breakAnimation" behavior

This commit is contained in:
DemiPixel 2015-11-23 16:12:51 -08:00
parent 565309846b
commit 6a9281c195
2 changed files with 69 additions and 26 deletions

View file

@ -690,6 +690,12 @@ Cancelled: Stop them from digging
Emitted when a player finishes digging something (or a player in creative breaks a block)
- position: Position of block dug
- block (u): Block dug
- dropBlock: Should it drop a block object (Default: false in creative, otherwise true)
- blockDropPosition: Where block is dropped (Default: center of block)
- blockDropWorld: World block is dropped in (Default is the world the player/block is in)
- blockDropVelocity: The velocity the block has when dropped (Default: random)
- blockDropId: ID of the block dropped
- blockDropDamage: Damage of the block dropped
Default: Save new block as air, sends to all nearby players
@ -705,6 +711,19 @@ Default: Stop animation for all players, save stop digging
Cancelled: Nothing
##### "breakAnimation"
Emitted when the server believes the break animation should increase (not sent by client!)
- position: Position of block being updated
- state: New state being changed to
- lastState (u): Last state of block
- start (u): When mining started
- timePassed (u): How long between start and now
Default: Send animation to everyone
Cancelled: Nothing
#### "placeBlock"
Emitted when a player places a block

View file

@ -21,12 +21,7 @@ module.exports.player=function(player,serv)
return startDigging(position);
}, cancelDig);
else if(status==2)
player.behavior('dug', { // Finish dig survival
position: pos,
block: block
}, ({position}) => {
return completeDigging(position);
}, cancelDig);
completeDigging(position);
else if(status==1)
player.behavior('cancelDig', { // Cancel dig survival
position: pos,
@ -35,12 +30,7 @@ module.exports.player=function(player,serv)
return cancelDigging(position);
});
else if(status==0 && player.gameMode==1)
player.behavior('dug', { // Start/finish dig creative
position: pos,
block: block
}, ({position}) => {
return creativeDigging(position);
}, cancelDig);
return creativeDigging(position);
})
.catch((err)=> setTimeout(() => {throw err;},0))
});
@ -73,12 +63,20 @@ module.exports.player=function(player,serv)
newDestroyState=newDestroyState>9 ? 9 : newDestroyState;
if(newDestroyState!=lastDestroyState)
{
lastDestroyState=newDestroyState;
player._writeOthersNearby("block_break_animation",{
"entityId":currentAnimationId,
"location":location,
"destroyStage":newDestroyState
});
player.behavior('breakAnimation', {
lastState: lastDestroyState,
state: newDestroyState,
start: startDigging,
timePassed: currentDiggingTime,
position: location
}, ({lastState, state}) => {
lastDestroyState=state;
player._writeOthersNearby("block_break_animation",{
"entityId":currentAnimationId,
"location":location,
"destroyStage":state
});
})
}
}
}
@ -98,13 +96,19 @@ module.exports.player=function(player,serv)
clearInterval(animationInterval);
var diggingTime=new Date()-startDiggingTime;
if(expectedDiggingTime-diggingTime<100) {
player.changeBlock(location,0,0);
// Drop block
serv.spawnObject(2, player.world, location.offset(0.5, 0.5, 0.5), {
velocity: new Vec3(Math.random()*4 - 2, Math.random()*2 + 2, Math.random()*4 - 2),
itemId: currentlyDugBlock.type,
itemDamage: currentlyDugBlock.metadata
});
player.behavior('dug', {
position: location,
block: currentlyDugBlock,
dropBlock: true,
blockDropPosition: location.offset(0.5, 0.5, 0.5),
blockDropWorld: player.world,
blockDropVelocity: new Vec3(Math.random()*4 - 2, Math.random()*2 + 2, Math.random()*4 - 2),
blockDropId: currentlyDugBlock.type,
blockDropDamage: currentlyDugBlock.metadata
}, (data) => {
player.changeBlock(data.position,0,0);
if (data.dropBlock) dropBlock(data);
})
}
else
{
@ -115,10 +119,30 @@ module.exports.player=function(player,serv)
}
}
function dropBlock({blockDropPosition, blockDropWorld, blockDropVelocity, blockDropId, blockDropDamage}) {
serv.spawnObject(2, blockDropWorld, blockDropPosition, {
velocity: blockDropVelocity,
itemId: blockDropId,
itemDamage: blockDropDamage
});
}
function creativeDigging(location)
{
return player.changeBlock(location,0,0);
player.behavior('dug', {
position: location,
block: currentlyDugBlock,
dropBlock: true,
blockDropPosition: location.offset(0.5, 0.5, 0.5),
blockDropWorld: player.world,
blockDropVelocity: new Vec3(Math.random()*4 - 2, Math.random()*2 + 2, Math.random()*4 - 2),
blockDropId: currentlyDugBlock.type,
blockDropDamage: currentlyDugBlock.metadata
}, (data) => {
player.changeBlock(data.position,0,0);
if (data.dropBlock) dropBlock(data);
});
}
};