Prevent players from spawning underground

Fixes #76
This commit is contained in:
Drew DeVault 2015-07-01 16:12:59 -06:00
parent bbc405f902
commit bda2e11885
2 changed files with 14 additions and 0 deletions

View File

@ -20,6 +20,8 @@ namespace TrueCraft.Core.Logic.Blocks
public override string DisplayName { get { return "Air"; } }
public override BoundingBox? BoundingBox { get { return null; } }
public override Tuple<int, int> GetTextureMap(byte metadata)
{
return new Tuple<int, int>(0, 0);

View File

@ -5,6 +5,7 @@ using TrueCraft.API.Networking;
using TrueCraft.Core.Networking.Packets;
using TrueCraft.API;
using TrueCraft.Core.Entities;
using TrueCraft.API.World;
namespace TrueCraft.Handlers
{
@ -41,6 +42,17 @@ namespace TrueCraft.Handlers
if (!remoteClient.Load())
remoteClient.Entity.Position = remoteClient.World.SpawnPoint;
// Make sure they don't spawn in the ground
var collision = new Func<bool>(() =>
{
var feet = client.World.GetBlockID((Coordinates3D)client.Entity.Position);
var head = client.World.GetBlockID((Coordinates3D)(client.Entity.Position + Vector3.Up));
var feetBox = server.BlockRepository.GetBlockProvider(feet).BoundingBox;
var headBox = server.BlockRepository.GetBlockProvider(head).BoundingBox;
return feetBox != null || headBox != null;
});
while (collision())
client.Entity.Position += Vector3.Up;
// Send setup packets
remoteClient.QueuePacket(new LoginResponsePacket(0, 0, Dimension.Overworld));