public override void TeleportToDouble(double x, double y, double z, Action onTeleported = null) { Teleporting = true; ICoreServerAPI sapi = this.World.Api as ICoreServerAPI; if (sapi != null) { sapi.WorldManager.LoadChunkColumnPriority((int)ServerPos.X / World.BlockAccessor.ChunkSize, (int)ServerPos.Z / World.BlockAccessor.ChunkSize, new ChunkLoadOptions() { OnLoaded = () => { Pos.SetPos(x, y, z); ServerPos.SetPos(x, y, z); PreviousServerPos.SetPos(-99, -99, -99); PositionBeforeFalling.Set(x, y, z); Pos.Motion.Set(0, 0, 0); if (this is EntityPlayer) { sapi.Network.BroadcastEntityPacket(EntityId, 1, SerializerUtil.Serialize(ServerPos.XYZ)); IServerPlayer player = this.Player as IServerPlayer; int chunksize = World.BlockAccessor.ChunkSize; player.CurrentChunkSentRadius = 0; sapi.Event.RegisterCallback((bla) => { if (player.ConnectionState == EnumClientState.Offline) { return; } if (!sapi.WorldManager.HasChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player)) { sapi.WorldManager.SendChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player, false); } // Oherwise we get an endlessly looping exception spam and break the server player.CurrentChunkSentRadius = 0; }, 50); } WatchedAttributes.SetInt("positionVersionNumber", WatchedAttributes.GetInt("positionVersionNumber", 0) + 1); onTeleported?.Invoke(); Teleporting = false; }, }); } }
public override void FromBytes(BinaryReader reader, bool forClient) { base.FromBytes(reader, forClient); if (WatchedAttributes != null) { string inventoryID = WatchedAttributes.GetString("invid"); int qslots = WatchedAttributes.GetInt("qslots", 0); Inventory = new InventoryGeneric(qslots, inventoryID, Api); Inventory.FromTreeAttributes(WatchedAttributes); if (Api != null) { Inventory.ResolveBlocksOrItems(); } } }