public override void OnReceivedServerPacket(int packetid, byte[] data) { IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World; if (packetid == (int)EnumBlockContainerPacketId.OpenInventory) { if (invDialog != null) { if (invDialog?.IsOpened() == true) { invDialog.TryClose(); } invDialog?.Dispose(); invDialog = null; return; } string dialogClassName; string dialogTitle; int cols; TreeAttribute tree = new TreeAttribute(); using (MemoryStream ms = new MemoryStream(data)) { BinaryReader reader = new BinaryReader(ms); dialogClassName = reader.ReadString(); dialogTitle = reader.ReadString(); cols = reader.ReadByte(); tree.FromBytes(reader); } Inventory.FromTreeAttributes(tree); Inventory.ResolveBlocksOrItems(); invDialog = new GuiDialogBlockEntityInventory(dialogTitle, Inventory, Pos, cols, Api as ICoreClientAPI); Block block = Api.World.BlockAccessor.GetBlock(Pos); string os = block.Attributes?["openSound"]?.AsString(); string cs = block.Attributes?["closeSound"]?.AsString(); AssetLocation opensound = os == null ? null : AssetLocation.Create(os, block.Code.Domain); AssetLocation closesound = cs == null ? null : AssetLocation.Create(cs, block.Code.Domain); invDialog.OpenSound = opensound ?? this.OpenSound; invDialog.CloseSound = closesound ?? this.CloseSound; invDialog.TryOpen(); } if (packetid == (int)EnumBlockEntityPacketId.Close) { clientWorld.Player.InventoryManager.CloseInventory(Inventory); if (invDialog?.IsOpened() == true) { invDialog?.TryClose(); } invDialog?.Dispose(); invDialog = null; } }
public override void OnReceivedServerPacket(int packetid, byte[] data) { IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World; if (packetid == (int)EnumBlockContainerPacketId.OpenInventory) { if (invDialog != null) { invDialog.TryClose(); invDialog = null; return; } using (MemoryStream ms = new MemoryStream(data)) { BinaryReader reader = new BinaryReader(ms); string dialogClassName = reader.ReadString(); string dialogTitle = reader.ReadString(); int cols = reader.ReadByte(); TreeAttribute tree = new TreeAttribute(); tree.FromBytes(reader); Inventory.FromTreeAttributes(tree); Inventory.ResolveBlocksOrItems(); invDialog = new GuiDialogBlockEntityInventory(dialogTitle, Inventory, pos, cols, api as ICoreClientAPI); invDialog.TryOpen(); } } if (packetid == (int)EnumBlockContainerPacketId.CloseInventory) { clientWorld.Player.InventoryManager.CloseInventory(Inventory); invDialog?.TryClose(); invDialog = null; } }