コード例 #1
0
ファイル: NetHelper.cs プロジェクト: Lanboost/MagicStorage
        public static void ReceiveStationOperation(BinaryReader reader, int sender)
        {
            if (Main.netMode != 2)
            {
                return;
            }
            int ent = reader.ReadInt32();

            if (!TileEntity.ByID.ContainsKey(ent) || !(TileEntity.ByID[ent] is TECraftingAccess))
            {
                return;
            }
            TECraftingAccess access = (TECraftingAccess)TileEntity.ByID[ent];

            Item[] stations = access.stations;
            byte   op       = reader.ReadByte();

            if (op == 0)
            {
                Item item = ItemIO.Receive(reader, true);
                access.TryDepositStation(item);
                if (item.stack > 0)
                {
                    ModPacket packet = PrepareStationResult(op);
                    ItemIO.Send(item, packet, true);
                    packet.Send(sender);
                }
            }
            else if (op == 1)
            {
                int  slot = reader.ReadByte();
                Item item = access.TryWithdrawStation(slot);
                if (!item.IsAir)
                {
                    ModPacket packet = PrepareStationResult(op);
                    ItemIO.Send(item, packet, true);
                    packet.Send(sender);
                }
            }
            else if (op == 2)
            {
                Item item = ItemIO.Receive(reader, true);
                int  slot = reader.ReadByte();
                item = access.DoStationSwap(item, slot);
                if (!item.IsAir)
                {
                    ModPacket packet = PrepareStationResult(op);
                    ItemIO.Send(item, packet, true);
                    packet.Send(sender);
                }
            }
            Point16       pos     = access.Position;
            StorageAccess modTile = TileLoader.GetTile(Main.tile[pos.X, pos.Y].type) as StorageAccess;

            if (modTile != null)
            {
                TEStorageHeart heart = modTile.GetHeart(pos.X, pos.Y);
                if (heart != null)
                {
                    SendRefreshNetworkItems(heart.ID);
                }
            }
        }