public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            if (api.Side != EnumAppSide.Client)
            {
                return;
            }
            ICoreClientAPI capi = api as ICoreClientAPI;

            interactions = ObjectCacheUtil.GetOrCreate(api, "echoChamberBlockInteractions", () =>
            {
                List <ItemStack> echochamberStacks = new List <ItemStack>();

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    if (obj.Attributes?.IsTrue("isPlayableDisc") == true)
                    {
                        echochamberStacks.Add(new ItemStack(obj));
                    }
                }

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-bloomery-playdisc",
                        HotKeyCode = null,
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = echochamberStacks.ToArray(),
                        GetMatchingStacks = (wi, bs, es) =>
                        {
                            BlockEntityEchoChamber bee = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityEchoChamber;
                            if (bee == null || !bee.HasDisc)
                            {
                                return wi.Itemstacks;
                            }

                            return null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-bloomery-takedisc",
                        HotKeyCode = null,
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (wi, bs, es) =>
                        {
                            BlockEntityEchoChamber bee = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityEchoChamber;
                            return bee != null && bee.HasDisc;
                        }
                    }
                });
            });
        }
예제 #2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (blockSel.Position == null)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            BlockEntityEchoChamber beec = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityEchoChamber;

            if (beec != null)
            {
                beec.OnInteract(world, byPlayer);
            }

            return(true);
        }