public override bool OnPlayerRightClick(IPlayer byPlayer, BlockSelection blockSel) { if (byPlayer?.Entity?.Controls?.Sneak == true) { ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (hotbarSlot?.Itemstack?.Item is ItemPostParchmentUnwritten) { hotbarSlot.TakeOut(1); hotbarSlot.MarkDirty(); if (byPlayer.Entity.World is IServerWorldAccessor) { if (this.networkId == null) { TradingPostLocation post = new TradingPostLocation(); post.PostId = this.blockEnityId; post.BlockPosition = blockSel.Position; this.networkId = Api.ModLoader.GetModSystem <TradeRoutesSystem>().TradeRoutesHandler.CreateOrAddLocation(byPlayer as IServerPlayer, post); this.SyncToNetworkInventory(); } ItemPostParchmentWritten writtenPaper = byPlayer.Entity.World.GetItem(new AssetLocation("traderoutesdeluxe:post_parchment_written")) as ItemPostParchmentWritten; ItemStack stack = new ItemStack(writtenPaper, 1); stack.Attributes.SetString("networkId", networkId); if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true)) { byPlayer.Entity.World.SpawnItemEntity(stack, byPlayer.Entity.Pos.XYZ.Add(0, 0.5, 0)); } return(true); } } if (hotbarSlot?.Itemstack?.Item is ItemPostParchmentWritten) { this.networkId = hotbarSlot.Itemstack.Attributes.GetString("networkId"); if (this.networkId == null) { return(false); } if (byPlayer.Entity.World is IServerWorldAccessor) { TradingPostLocation post = new TradingPostLocation(); post.PostId = this.blockEnityId; post.BlockPosition = blockSel.Position; Api.ModLoader.GetModSystem <TradeRoutesSystem>().TradeRoutesHandler.CreateOrAddLocation(byPlayer as IServerPlayer, post, this.networkId); } this.SyncFromNetworkInventory(Api); return(true); } } else { if (this.networkId != null && Api.World is IServerWorldAccessor) { byte[] localInventory = ByteBuilder.InventoryByteBuilder(this.inventory, "BlockEntityTradingPost", DialogTitle); ((ICoreServerAPI)Api).Network.SendBlockEntityPacket( (IServerPlayer)byPlayer, Pos.X, Pos.Y, Pos.Z, (int)EnumBlockContainerPacketId.OpenInventory, localInventory ); byPlayer.InventoryManager.OpenInventory(this.inventory); } } return(true); }