mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-19 06:21:08 +00:00
Merge branch 'newlook'
This commit is contained in:
commit
32b957cc60
3 changed files with 55 additions and 21 deletions
|
|
@ -16,6 +16,7 @@ function Entity(id) {
|
|||
this.equipment = new Array(5);
|
||||
this.heldItem = this.equipment[0]; // shortcut to equipment[0]
|
||||
this.isValid = true;
|
||||
this.metadata = [];
|
||||
}
|
||||
|
||||
Entity.prototype.setEquipment = function(index, item) {
|
||||
|
|
|
|||
|
|
@ -62,12 +62,15 @@ function inject(serv,player)
|
|||
|
||||
function sendInitialPosition()
|
||||
{
|
||||
player.entity.position=player.spawnPoint;
|
||||
player.entity.yaw=0;
|
||||
player.entity.pitch=0;
|
||||
player._client.write('position', {
|
||||
x: player.spawnPoint.x,
|
||||
y: player.spawnPoint.y,
|
||||
z: player.spawnPoint.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
x: player.entity.position.x,
|
||||
y: player.entity.position.y,
|
||||
z: player.entity.position.z,
|
||||
yaw: player.entity.yaw,
|
||||
pitch: player.entity.pitch,
|
||||
flags: 0x00
|
||||
});
|
||||
}
|
||||
|
|
@ -125,18 +128,16 @@ function inject(serv,player)
|
|||
function spawnOthers()
|
||||
{
|
||||
player.getOthers().forEach(function (otherPlayer) {
|
||||
var spawnPoint=toFixedPosition(otherPlayer.spawnPoint);
|
||||
var pos = otherPlayer.entity.position;
|
||||
player._client.write('named_entity_spawn', {
|
||||
entityId: otherPlayer.entity.id,
|
||||
playerUUID: transformUuid(otherPlayer._client.uuid),
|
||||
x: pos ? pos.x : spawnPoint.x,
|
||||
y: pos ? pos.y : spawnPoint.y,
|
||||
z: pos ? pos.z : spawnPoint.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
x: otherPlayer.entity.position.x,
|
||||
y: otherPlayer.entity.position.y,
|
||||
z: otherPlayer.entity.position.z,
|
||||
yaw: otherPlayer.entity.yaw,
|
||||
pitch: otherPlayer.entity.pitch,
|
||||
currentItem: 0,
|
||||
metadata: []
|
||||
metadata: otherPlayer.entity.metadata
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -148,13 +149,13 @@ function inject(serv,player)
|
|||
player._writeOthers('named_entity_spawn',{
|
||||
entityId: player.entity.id,
|
||||
playerUUID: transformUuid(player._client.uuid),
|
||||
x: spawnPoint.x,
|
||||
y: spawnPoint.y,
|
||||
z: spawnPoint.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
x: player.entity.position.x,
|
||||
y: player.entity.position.y,
|
||||
z: player.entity.position.z,
|
||||
yaw: player.entity.yaw,
|
||||
pitch: player.entity.pitch,
|
||||
currentItem: 0,
|
||||
metadata: []
|
||||
metadata: player.entity.metadata
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,37 @@ function toFixedPosition(p)
|
|||
|
||||
function inject(serv,player)
|
||||
{
|
||||
player._client.on('look', function(packet) {
|
||||
sendLook(packet.yaw,packet.pitch,packet.onGround)
|
||||
});
|
||||
|
||||
// float (degrees) --> byte (1/256 "degrees")
|
||||
function conv(f){
|
||||
var b = (f % 360) * 256 / 360;
|
||||
if (b < -128) b += 256;
|
||||
else if (b > 127) b -= 256;
|
||||
return Math.floor(b);
|
||||
}
|
||||
function sendLook(yaw,pitch,onGround)
|
||||
{
|
||||
var convYaw=conv(yaw);
|
||||
var convPitch=conv(pitch);
|
||||
if (convYaw == player.entity.yaw && convPitch == player.entity.pitch) return;
|
||||
player._writeOthers("entity_look", {
|
||||
entityId: player.entity.id,
|
||||
yaw: convYaw,
|
||||
pitch: convPitch,
|
||||
onGround: onGround
|
||||
});
|
||||
player.entity.yaw = convYaw;
|
||||
player.entity.pitch = convPitch;
|
||||
player.entity.onGround = onGround;
|
||||
player._writeOthers("entity_head_rotation", {
|
||||
entityId: player.entity.id,
|
||||
headYaw: convYaw
|
||||
});
|
||||
}
|
||||
|
||||
player._client.on('position', function (packet) {
|
||||
var position = new vec3(packet.x, packet.y, packet.z);
|
||||
var onGround = packet.onGround;
|
||||
|
|
@ -19,6 +50,7 @@ function inject(serv,player)
|
|||
var position = new vec3(packet.x, packet.y, packet.z);
|
||||
var onGround = packet.onGround;
|
||||
sendRelativePositionChange(toFixedPosition(position), onGround);
|
||||
sendLook(packet.yaw,packet.pitch,packet.onGround);
|
||||
});
|
||||
|
||||
function sendRelativePositionChange(newPosition, onGround) {
|
||||
|
|
@ -31,8 +63,8 @@ function inject(serv,player)
|
|||
x: newPosition.x,
|
||||
y: newPosition.y,
|
||||
z: newPosition.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
yaw: player.entity.yaw,
|
||||
pitch: player.entity.pitch,
|
||||
onGround: onGround
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue