mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-14 12:01:12 +00:00
get ticking back to server plugin (more efficient not to listen lot of time on an event)
This commit is contained in:
parent
4cefdedf75
commit
5530f7b1de
1 changed files with 17 additions and 19 deletions
|
|
@ -67,7 +67,23 @@ module.exports.server=function(serv,options) {
|
|||
world: entity.world
|
||||
});
|
||||
delete serv.entities[entity.id];
|
||||
}
|
||||
};
|
||||
|
||||
serv.on('tick', function(delta) {
|
||||
Promise.all(
|
||||
Object.keys(serv.entities).map(async (id) => {
|
||||
var entity = serv.entities[id];
|
||||
if (entity.deathTime && Date.now() - entity.bornTime >= entity.deathTime) {
|
||||
entity.destroy();
|
||||
return;
|
||||
}
|
||||
if (!entity.velocity || !entity.size) return;
|
||||
var oldPosAndOnGround = await entity.calculatePhysics(delta);
|
||||
if (!oldPosAndOnGround.oldPos.equals(new Vec3(0,0,0)))
|
||||
if (entity.type == 'mob') entity.sendPosition(oldPosAndOnGround);
|
||||
})
|
||||
).catch((err)=> setTimeout(() => {throw err;},0));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.player=function(player,serv){
|
||||
|
|
@ -145,24 +161,6 @@ module.exports.entity=function(entity,serv){
|
|||
};
|
||||
|
||||
|
||||
serv.on('tick', async function(delta) {
|
||||
if (entity.deathTime && Date.now() - entity.bornTime >= entity.deathTime) {
|
||||
entity.destroy();
|
||||
return;
|
||||
}
|
||||
if (!entity.velocity || !entity.size) return;
|
||||
var oldPosAndOnGround;
|
||||
try {
|
||||
oldPosAndOnGround = await entity.calculatePhysics(delta);
|
||||
}
|
||||
catch(err){
|
||||
setTimeout(() => {throw err;},0)
|
||||
}
|
||||
if (!oldPosAndOnGround.oldPos.equals(new Vec3(0,0,0)))
|
||||
if (entity.type == 'mob') entity.sendPosition(oldPosAndOnGround);
|
||||
});
|
||||
|
||||
|
||||
entity.on("positionChanged",() => {
|
||||
if(entity.position.distanceTo(entity.lastPositionPlayersUpdated)>2*32)
|
||||
entity.updateAndSpawn();
|
||||
|
|
|
|||
Loading…
Reference in a new issue