mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-18 22:11:07 +00:00
set the spawn point in spawn player plugin, send teleport packet if the position diff is too important, fix #5
This commit is contained in:
parent
34ca0aa788
commit
49e313d72b
4 changed files with 57 additions and 10 deletions
|
|
@ -52,6 +52,7 @@
|
|||
- [player.login()](#playerlogin)
|
||||
- [player.others()](#playerothers)
|
||||
- [player.chat(message)](#playerchatmessage)
|
||||
- [player.setSpawnPoint()](#playersetspawnpoint)
|
||||
- [Low level properties](#low-level-properties)
|
||||
- [player._client](#player_client)
|
||||
- [Low level methods](#low-level-methods)
|
||||
|
|
@ -242,6 +243,10 @@ return the other players than `player`
|
|||
|
||||
sends `message` to the player
|
||||
|
||||
#### player.setSpawnPoint()
|
||||
|
||||
set the spawn point of a player
|
||||
|
||||
### Low level properties
|
||||
|
||||
#### player._client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var Entity=require("../entity");
|
||||
var vec3 = require("vec3");
|
||||
|
||||
module.exports=inject;
|
||||
|
||||
|
|
@ -7,6 +8,10 @@ function transformUuid(s)
|
|||
return s.split("-").map(function(item) { return parseInt(item, 16); });
|
||||
}
|
||||
|
||||
function toFixedPosition(p)
|
||||
{
|
||||
return new vec3(Math.floor(p.x*32),Math.floor(p.y*32),Math.floor(p.z*32))
|
||||
}
|
||||
|
||||
function inject(serv,player)
|
||||
{
|
||||
|
|
@ -45,12 +50,20 @@ function inject(serv,player)
|
|||
});
|
||||
}
|
||||
|
||||
function sendSpawn()
|
||||
{
|
||||
console.log("setting spawn at "+player.spawnPoint);
|
||||
player._client.write('spawn_position',{
|
||||
"location":player.spawnPoint
|
||||
});
|
||||
}
|
||||
|
||||
function sendInitialPosition()
|
||||
{
|
||||
player._client.write('position', {
|
||||
x: 6,
|
||||
y: 53,
|
||||
z: 6,
|
||||
x: player.spawnPoint.x,
|
||||
y: player.spawnPoint.y,
|
||||
z: player.spawnPoint.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
flags: 0x00
|
||||
|
|
@ -108,13 +121,14 @@ function inject(serv,player)
|
|||
function spawn()
|
||||
{
|
||||
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 : 6 * 32,
|
||||
y: pos ? pos.y : 53 * 32,
|
||||
z: pos ? pos.z : 6 * 32,
|
||||
x: pos ? pos.x : spawnPoint.x,
|
||||
y: pos ? pos.y : spawnPoint.y,
|
||||
z: pos ? pos.z : spawnPoint.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
currentItem: 0,
|
||||
|
|
@ -122,12 +136,13 @@ function inject(serv,player)
|
|||
});
|
||||
});
|
||||
|
||||
var spawnPoint=toFixedPosition(player.spawnPoint);
|
||||
player._writeOthers('named_entity_spawn',{
|
||||
entityId: player.entity.id,
|
||||
playerUUID: transformUuid(player._client.uuid),
|
||||
x: 6 * 32,
|
||||
y: 53 * 32,
|
||||
z: 6 * 32,
|
||||
x: spawnPoint.x,
|
||||
y: spawnPoint.y,
|
||||
z: spawnPoint.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
currentItem: 0,
|
||||
|
|
@ -150,6 +165,8 @@ function inject(serv,player)
|
|||
addPlayer();
|
||||
sendLogin();
|
||||
sendMap();
|
||||
player.setSpawnPoint();
|
||||
sendSpawn();
|
||||
sendInitialPosition();
|
||||
|
||||
player.emit("spawned");
|
||||
|
|
|
|||
13
lib/playerPlugins/spawn.js
Normal file
13
lib/playerPlugins/spawn.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var vec3 = require("vec3");
|
||||
|
||||
module.exports=inject;
|
||||
|
||||
function inject(serv,player)
|
||||
{
|
||||
function setSpawnPoint()
|
||||
{
|
||||
player.spawnPoint=new vec3(6,51,6);
|
||||
}
|
||||
|
||||
player.setSpawnPoint=setSpawnPoint;
|
||||
}
|
||||
|
|
@ -24,7 +24,19 @@ function inject(serv,player)
|
|||
function sendRelativePositionChange(newPosition, onGround) {
|
||||
if (player.entity.position.distanceTo(new vec3(0, 0, 0)) != 0) {
|
||||
var diff = newPosition.minus(player.entity.position);
|
||||
if (diff.distanceTo(new vec3(0, 0, 0)) != 0) {
|
||||
if(diff.abs().x>256 || diff.abs().y>256 || diff.abs().z>256)
|
||||
{
|
||||
player._client.write('entity_teleport', {
|
||||
entityId:player.entity.id,
|
||||
x: newPosition.x,
|
||||
y: newPosition.y,
|
||||
z: newPosition.z,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
onGround: onGround
|
||||
});
|
||||
}
|
||||
else if (diff.distanceTo(new vec3(0, 0, 0)) != 0) {
|
||||
player._writeOthers('rel_entity_move', {
|
||||
entityId: player.entity.id,
|
||||
dX: diff.x,
|
||||
|
|
|
|||
Loading…
Reference in a new issue