mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-18 14:01:13 +00:00
store position as fixed point representation, fix precision problem
This commit is contained in:
parent
d544c1094d
commit
71d6c1fa8c
1 changed files with 15 additions and 8 deletions
23
app.js
23
app.js
|
|
@ -8,6 +8,13 @@ var playersConnected = [];
|
|||
var uuidToPlayer = {};
|
||||
var vec3 = require("vec3");
|
||||
|
||||
|
||||
function toFixedPosition(p)
|
||||
{
|
||||
return new vec3(Math.floor(p.x*32),Math.floor(p.y*32),Math.floor(p.z*32))
|
||||
}
|
||||
|
||||
|
||||
var options = {
|
||||
motd: settings.motd,
|
||||
'max-players': settings.maxPlayers,
|
||||
|
|
@ -150,9 +157,9 @@ server.on('login', function(client) {
|
|||
client.write('named_entity_spawn', {
|
||||
entityId: otherClient.id,
|
||||
playerUUID: transformUuid(otherClient.uuid),
|
||||
x: pos ? Math.floor(pos.x*32) : 6*32,
|
||||
y: pos ? Math.floor(pos.y*32) : 53*32,
|
||||
z: pos ? Math.floor(pos.z*32) : 6*32,
|
||||
x: pos ? pos.x : 6*32,
|
||||
y: pos ? pos.y : 53*32,
|
||||
z: pos ? pos.z : 6*32,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
currentItem: 0,
|
||||
|
|
@ -185,13 +192,13 @@ server.on('login', function(client) {
|
|||
client.on('position', function(packet) {
|
||||
var position = new vec3(packet.x,packet.y,packet.z);
|
||||
var onGround=packet.onGround;
|
||||
sendRelativePositionChange(client,position,onGround);
|
||||
sendRelativePositionChange(client,toFixedPosition(position),onGround);
|
||||
});
|
||||
|
||||
client.on('position_look', function(packet) {
|
||||
var position = new vec3(packet.x,packet.y,packet.z);
|
||||
var onGround=packet.onGround;
|
||||
sendRelativePositionChange(client,position,onGround);
|
||||
sendRelativePositionChange(client,toFixedPosition(position),onGround);
|
||||
});
|
||||
|
||||
function sendRelativePositionChange(client,newPosition,onGround) {
|
||||
|
|
@ -201,9 +208,9 @@ server.on('login', function(client) {
|
|||
getOtherClients().forEach(function (otherClient) {
|
||||
otherClient.write('rel_entity_move', {
|
||||
entityId: uuidToPlayer[client.uuid].id,
|
||||
dX: Math.floor(diff.x*32),
|
||||
dY: Math.floor(diff.y*32),
|
||||
dZ: Math.floor(diff.z*32),
|
||||
dX: diff.x,
|
||||
dY: diff.y,
|
||||
dZ: diff.z,
|
||||
onGround: onGround
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue