mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 19:20:54 +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.equipment = new Array(5);
|
||||||
this.heldItem = this.equipment[0]; // shortcut to equipment[0]
|
this.heldItem = this.equipment[0]; // shortcut to equipment[0]
|
||||||
this.isValid = true;
|
this.isValid = true;
|
||||||
|
this.metadata = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity.prototype.setEquipment = function(index, item) {
|
Entity.prototype.setEquipment = function(index, item) {
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,15 @@ function inject(serv,player)
|
||||||
|
|
||||||
function sendInitialPosition()
|
function sendInitialPosition()
|
||||||
{
|
{
|
||||||
|
player.entity.position=player.spawnPoint;
|
||||||
|
player.entity.yaw=0;
|
||||||
|
player.entity.pitch=0;
|
||||||
player._client.write('position', {
|
player._client.write('position', {
|
||||||
x: player.spawnPoint.x,
|
x: player.entity.position.x,
|
||||||
y: player.spawnPoint.y,
|
y: player.entity.position.y,
|
||||||
z: player.spawnPoint.z,
|
z: player.entity.position.z,
|
||||||
yaw: 0,
|
yaw: player.entity.yaw,
|
||||||
pitch: 0,
|
pitch: player.entity.pitch,
|
||||||
flags: 0x00
|
flags: 0x00
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -125,18 +128,16 @@ function inject(serv,player)
|
||||||
function spawnOthers()
|
function spawnOthers()
|
||||||
{
|
{
|
||||||
player.getOthers().forEach(function (otherPlayer) {
|
player.getOthers().forEach(function (otherPlayer) {
|
||||||
var spawnPoint=toFixedPosition(otherPlayer.spawnPoint);
|
|
||||||
var pos = otherPlayer.entity.position;
|
|
||||||
player._client.write('named_entity_spawn', {
|
player._client.write('named_entity_spawn', {
|
||||||
entityId: otherPlayer.entity.id,
|
entityId: otherPlayer.entity.id,
|
||||||
playerUUID: transformUuid(otherPlayer._client.uuid),
|
playerUUID: transformUuid(otherPlayer._client.uuid),
|
||||||
x: pos ? pos.x : spawnPoint.x,
|
x: otherPlayer.entity.position.x,
|
||||||
y: pos ? pos.y : spawnPoint.y,
|
y: otherPlayer.entity.position.y,
|
||||||
z: pos ? pos.z : spawnPoint.z,
|
z: otherPlayer.entity.position.z,
|
||||||
yaw: 0,
|
yaw: otherPlayer.entity.yaw,
|
||||||
pitch: 0,
|
pitch: otherPlayer.entity.pitch,
|
||||||
currentItem: 0,
|
currentItem: 0,
|
||||||
metadata: []
|
metadata: otherPlayer.entity.metadata
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -148,13 +149,13 @@ function inject(serv,player)
|
||||||
player._writeOthers('named_entity_spawn',{
|
player._writeOthers('named_entity_spawn',{
|
||||||
entityId: player.entity.id,
|
entityId: player.entity.id,
|
||||||
playerUUID: transformUuid(player._client.uuid),
|
playerUUID: transformUuid(player._client.uuid),
|
||||||
x: spawnPoint.x,
|
x: player.entity.position.x,
|
||||||
y: spawnPoint.y,
|
y: player.entity.position.y,
|
||||||
z: spawnPoint.z,
|
z: player.entity.position.z,
|
||||||
yaw: 0,
|
yaw: player.entity.yaw,
|
||||||
pitch: 0,
|
pitch: player.entity.pitch,
|
||||||
currentItem: 0,
|
currentItem: 0,
|
||||||
metadata: []
|
metadata: player.entity.metadata
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,37 @@ function toFixedPosition(p)
|
||||||
|
|
||||||
function inject(serv,player)
|
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) {
|
player._client.on('position', function (packet) {
|
||||||
var position = new vec3(packet.x, packet.y, packet.z);
|
var position = new vec3(packet.x, packet.y, packet.z);
|
||||||
var onGround = packet.onGround;
|
var onGround = packet.onGround;
|
||||||
|
|
@ -19,6 +50,7 @@ function inject(serv,player)
|
||||||
var position = new vec3(packet.x, packet.y, packet.z);
|
var position = new vec3(packet.x, packet.y, packet.z);
|
||||||
var onGround = packet.onGround;
|
var onGround = packet.onGround;
|
||||||
sendRelativePositionChange(toFixedPosition(position), onGround);
|
sendRelativePositionChange(toFixedPosition(position), onGround);
|
||||||
|
sendLook(packet.yaw,packet.pitch,packet.onGround);
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendRelativePositionChange(newPosition, onGround) {
|
function sendRelativePositionChange(newPosition, onGround) {
|
||||||
|
|
@ -31,8 +63,8 @@ function inject(serv,player)
|
||||||
x: newPosition.x,
|
x: newPosition.x,
|
||||||
y: newPosition.y,
|
y: newPosition.y,
|
||||||
z: newPosition.z,
|
z: newPosition.z,
|
||||||
yaw: 0,
|
yaw: player.entity.yaw,
|
||||||
pitch: 0,
|
pitch: player.entity.pitch,
|
||||||
onGround: onGround
|
onGround: onGround
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue