mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-11 10:31:08 +00:00
don't spawn in water, fix #63
This commit is contained in:
parent
908054dca1
commit
0ea7fcf40d
3 changed files with 28 additions and 5 deletions
|
|
@ -157,6 +157,7 @@ module.exports.player=function(player,serv)
|
|||
}
|
||||
|
||||
addPlayer();
|
||||
await player.findSpawnPoint();
|
||||
sendLogin();
|
||||
await player.sendMap();
|
||||
player.sendSpawnPosition();
|
||||
|
|
|
|||
|
|
@ -9,14 +9,36 @@ module.exports.server=function(serv,settings)
|
|||
{
|
||||
serv.gameMode=settings.gameMode;
|
||||
|
||||
serv.getSpawnPoint = () => new Vec3(randomInt(5,20),81,randomInt(5,20));
|
||||
async function findSpawnZone(world,initialPoint)
|
||||
{
|
||||
var point=initialPoint;
|
||||
while((await (world.getBlockType(point)))==0)
|
||||
point=point.offset(0,-1,0);
|
||||
while(true)
|
||||
{
|
||||
var p=await world.getBlockType(point);
|
||||
if(p.type!=8 && p.type!=9)
|
||||
break;
|
||||
point=point.offset(1,0,0);
|
||||
}
|
||||
while((await world.getBlockType(point))!=0)
|
||||
point = point.offset(0, 1, 0);
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
serv.getSpawnPoint = async (world) => {
|
||||
return await findSpawnZone(world,new Vec3(randomInt(0,30),81,randomInt(0,30)));
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
module.exports.player=function(player,serv)
|
||||
module.exports.player=async function(player,serv)
|
||||
{
|
||||
player.gameMode=serv.gameMode;
|
||||
player.spawnPoint=serv.getSpawnPoint();
|
||||
player.findSpawnPoint=async () => {
|
||||
player.spawnPoint=await serv.getSpawnPoint(player.world);
|
||||
};
|
||||
player._client.on('settings',({viewDistance}) => {
|
||||
player.view=viewDistance;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -143,8 +143,7 @@ module.exports.player=function(player,serv,settings) {
|
|||
player.changeWorld = async (world, opt) => {
|
||||
if(player.world == world) return Promise.resolve();
|
||||
opt = opt || {};
|
||||
player.world = world;
|
||||
player.world = world;
|
||||
player.world = world
|
||||
player.loadedChunks={};
|
||||
if (typeof opt.gamemode != 'undefined') player.gameMode = opt.gamemode;
|
||||
player._client.write("respawn",{
|
||||
|
|
@ -153,6 +152,7 @@ module.exports.player=function(player,serv,settings) {
|
|||
gamemode: opt.gamemode || player.gameMode,
|
||||
levelType:'default'
|
||||
});
|
||||
await player.findSpawnPoint();
|
||||
player.position=player.spawnPoint.toFixedPosition();
|
||||
player.sendSpawnPosition();
|
||||
player.updateAndSpawn();
|
||||
|
|
|
|||
Loading…
Reference in a new issue