mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-07 12:10:46 +00:00
Fix tp, updatePosition, and tests
This commit is contained in:
parent
9b0970b291
commit
b7aea8251f
5 changed files with 21 additions and 14 deletions
|
|
@ -40,5 +40,7 @@ class MCServer extends EventEmitter {
|
||||||
this._server.on('error', error => this.emit('error',error));
|
this._server.on('error', error => this.emit('error',error));
|
||||||
this._server.on('listening', () => this.emit('listening',this._server.socketServer.address().port));
|
this._server.on('listening', () => this.emit('listening',this._server.socketServer.address().port));
|
||||||
this.emit('asap');
|
this.emit('asap');
|
||||||
|
|
||||||
|
process.on('unhandledRejection', err => this.emit('error',err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,14 +19,16 @@ module.exports = (obj) => {
|
||||||
await obj.emitThen(eventName, data, cancelled, cancelCount).catch((err)=> setTimeout(() => {throw err;},0));
|
await obj.emitThen(eventName, data, cancelled, cancelCount).catch((err)=> setTimeout(() => {throw err;},0));
|
||||||
|
|
||||||
if (!hiddenCancelled && !cancelled) {
|
if (!hiddenCancelled && !cancelled) {
|
||||||
resp = await func(data).catch((err)=> setTimeout(() => {throw err;},0));
|
resp = func(data);
|
||||||
|
if (resp instanceof Promise) resp = await resp.catch((err)=> setTimeout(() => {throw err;},0));
|
||||||
if (typeof resp == 'undefined') resp = true;
|
if (typeof resp == 'undefined') resp = true;
|
||||||
} else if (cancelFunc && defaultCancel) {
|
} else if (cancelFunc && defaultCancel) {
|
||||||
resp = await cancelFunc(data).catch((err)=> setTimeout(() => {throw err;},0));
|
resp = cancelFunc(data);
|
||||||
|
if (resp instanceof Promise) resp = await resp.catch((err)=> setTimeout(() => {throw err;},0));
|
||||||
if (typeof resp == 'undefined') resp = false;
|
if (typeof resp == 'undefined') resp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 resp;
|
return resp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -20,7 +20,7 @@ module.exports.server=function(serv,options) {
|
||||||
}
|
}
|
||||||
if (!entity.velocity || !entity.size) return;
|
if (!entity.velocity || !entity.size) return;
|
||||||
var posAndOnGround = await entity.calculatePhysics(delta);
|
var posAndOnGround = await entity.calculatePhysics(delta);
|
||||||
if (entity.type == 'mob') entity.sendPosition(posAndOnGround);
|
if (entity.type == 'mob') entity.sendPosition(posAndOnGround.position, posAndOnGround.onGround);
|
||||||
})
|
})
|
||||||
).catch((err)=> setTimeout(() => {throw err;},0));
|
).catch((err)=> setTimeout(() => {throw err;},0));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,15 @@ module.exports.player = (player, serv) => {
|
||||||
let z = serv.posFromString(args[2], player.position.z / 32);
|
let z = serv.posFromString(args[2], player.position.z / 32);
|
||||||
|
|
||||||
player.teleport(new Vec3(x, y, z));
|
player.teleport(new Vec3(x, y, z));
|
||||||
|
|
||||||
} else if(args.length === 4) {
|
} else if(args.length === 4) {
|
||||||
let entities_from = player.selectorString(args[0]);
|
let entities_from = player.selectorString(args[0]);
|
||||||
|
|
||||||
let x = serv.posFromString(args[1], player_from.x / 32);
|
entities_from.forEach(e => e.teleport(new Vec3(
|
||||||
let y = serv.posFromString(args[2], player_from.y / 32);
|
serv.posFromString(args[1], e.position.x / 32),
|
||||||
let z = serv.posFromString(args[3], player_from.z / 32);
|
serv.posFromString(args[2], e.position.y / 32),
|
||||||
|
serv.posFromString(args[3], e.position.z / 32)
|
||||||
entities_from.forEach(e => e.teleport(new Vec3(x, y, z)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -64,17 +64,19 @@ module.exports.player=function(player)
|
||||||
};
|
};
|
||||||
|
|
||||||
player.teleport = async (position) => {
|
player.teleport = async (position) => {
|
||||||
var notCancelled = await player.sendSelfPosition(position.scaled(32).floored(), false, true);
|
var notCancelled = await player.sendPosition(position.scaled(32).floored(), false, true);
|
||||||
if (notCancelled) player.sendSelfPosition();
|
if (notCancelled) player.sendSelfPosition();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.entity=function(entity,serv){
|
module.exports.entity=function(entity,serv){
|
||||||
entity.sendPosition = (position, onGround, teleport=false) => {
|
entity.sendPosition = (position, onGround, teleport=false) => {
|
||||||
|
if (typeof position == 'undefined') throw new Error('undef');
|
||||||
if (entity.position.equals(position) && entity.onGround == onGround) return Promise.resolve();
|
if (entity.position.equals(position) && entity.onGround == onGround) return Promise.resolve();
|
||||||
return entity.behavior(teleport ? 'teleport' : 'move', {
|
return entity.behavior('move', {
|
||||||
position: position,
|
position: position,
|
||||||
onGround: onGround
|
onGround: onGround,
|
||||||
|
teleport: teleport
|
||||||
}, ({position,onGround}) => {
|
}, ({position,onGround}) => {
|
||||||
var diff = position.minus(entity.position);
|
var diff = position.minus(entity.position);
|
||||||
if(diff.abs().x>127 || diff.abs().y>127 || diff.abs().z>127)
|
if(diff.abs().x>127 || diff.abs().y>127 || diff.abs().z>127)
|
||||||
|
|
@ -87,7 +89,7 @@ module.exports.entity=function(entity,serv){
|
||||||
pitch: entity.pitch,
|
pitch: entity.pitch,
|
||||||
onGround: onGround
|
onGround: onGround
|
||||||
});
|
});
|
||||||
else if (diff.distanceTo(new Vec3(0, 0, 0)) != 0) serv._writeOthersNearby('rel_entity_move', {
|
else if (diff.distanceTo(new Vec3(0, 0, 0)) != 0) entity._writeOthersNearby('rel_entity_move', {
|
||||||
entityId: entity.id,
|
entityId: entity.id,
|
||||||
dX: diff.x,
|
dX: diff.x,
|
||||||
dY: diff.y,
|
dY: diff.y,
|
||||||
|
|
@ -119,7 +121,7 @@ module.exports.entity=function(entity,serv){
|
||||||
};
|
};
|
||||||
|
|
||||||
entity.teleport = (pos) => { // Overwritten in players inject above
|
entity.teleport = (pos) => { // Overwritten in players inject above
|
||||||
entity.sendPosition(entity.position, false, true);
|
entity.sendPosition(pos.scaled(32), false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addVelocityWithMax(current, newVel, max) {
|
function addVelocityWithMax(current, newVel, max) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue