void DoRespawn() { if (!game.World.HasBlocks) { return; } LocalPlayer p = (LocalPlayer)entity; Vector3 spawn = p.Spawn; if (game.World.IsValidPos(Vector3I.Floor(spawn))) { FindHighestFree(ref spawn); } spawn.Y += 2 / 16f; LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, p.SpawnRotY, p.SpawnHeadX, false); entity.SetLocation(update, false); entity.Velocity = Vector3.Zero; // Update onGround, otherwise if 'respawn' then 'space' is pressed, you still jump into the air if onGround was true before AABB bb = entity.Bounds; bb.Min.Y -= 0.01f; bb.Max.Y = bb.Min.Y; entity.onGround = entity.TouchesAny(bb, touchesAnySolid); }
protected static void MoveInDirection(Entity source, Vector3 dir) { double yawRad, pitchRad; Utils.GetHeading(dir, out yawRad, out pitchRad); float yaw = (float)(yawRad * Utils.Rad2Deg), pitch = (float)(pitchRad * Utils.Rad2Deg); LocationUpdate update = LocationUpdate.MakePosAndOri(dir, yaw, pitch, true); source.SetLocation(update, false); }
void DoRespawn() { if (!game.World.HasBlocks) { return; } Vector3 spawn = Spawn; Vector3I P = Vector3I.Floor(spawn); AABB bb; // Spawn player at highest solid position to match vanilla Minecraft classic // Only when player can noclip, since this can let you 'clip' to above solid blocks if (Hacks.CanNoclip && game.World.IsValidPos(P)) { bb = AABB.Make(spawn, Size); for (int y = P.Y; y <= game.World.Height; y++) { float spawnY = Respawn.HighestFreeY(game, ref bb); if (spawnY == float.NegativeInfinity) { BlockID block = game.World.GetPhysicsBlock(P.X, y, P.Z); float height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0; spawn.Y = y + height + Entity.Adjustment; break; } bb.Min.Y += 1; bb.Max.Y += 1; } } spawn.Y += 2 / 16f; LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, SpawnRotY, SpawnHeadX, false); SetLocation(update, false); Velocity = Vector3.Zero; // Update onGround, otherwise if 'respawn' then 'space' is pressed, you still jump into the air if onGround was true before bb = Bounds; bb.Min.Y -= 0.01f; bb.Max.Y = bb.Min.Y; onGround = TouchesAny(bb, touchesAnySolid); }
void DoRespawn() { LocalPlayer p = (LocalPlayer)entity; Vector3 spawn = p.Spawn; if (game.World.IsValidPos(Vector3I.Floor(spawn))) { FindHighestFree(ref spawn); } spawn.Y += 2 / 16f; LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, p.SpawnYaw, p.SpawnPitch, false); entity.SetLocation(update, false); entity.Velocity = Vector3.Zero; // Update onGround, otherwise if 'respawn' then 'space' is pressed, you still jump into the air if onGround was true before AABB bb = entity.Bounds; bb.Min.Y -= 0.01f; bb.Max.Y = bb.Min.Y; entity.onGround = entity.TouchesAny(bb, b => game.BlockInfo.Collide[b] == CollideType.Solid); }