public override void OnTryIgniteBlockOver(EntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            BlockEntityCharcoalPit becp = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCharcoalPit;

            if (becp != null && !becp.Lit)
            {
                becp.IgniteNow();
            }

            handling = EnumHandling.PreventDefault;
        }
        public override EnumIgniteState OnTryIgniteBlock(EntityAgent byEntity, BlockPos pos, float secondsIgniting)
        {
            BlockEntityCharcoalPit becp = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCharcoalPit;

            if (becp == null || becp.Lit)
            {
                return(EnumIgniteState.NotIgnitablePreventDefault);
            }

            return(secondsIgniting > 3 ? EnumIgniteState.IgniteNow : EnumIgniteState.Ignitable);
        }
        public bool TryConstruct(IWorldAccessor world, BlockPos pos, CollectibleObject obj, IPlayer player)
        {
            int stage = Stage;

            if (obj.Attributes?.IsTrue("firepitConstructable") != true)
            {
                return(false);
            }

            if (stage == 5)
            {
                return(false);
            }

            if (stage == 4 && world.BlockAccessor.GetBlock(pos.DownCopy()).Code.Path.Equals("firewoodpile"))
            {
                Block charcoalPitBlock = world.GetBlock(new AssetLocation("charcoalpit"));
                if (charcoalPitBlock != null)
                {
                    world.BlockAccessor.SetBlock(charcoalPitBlock.BlockId, pos);

                    BlockEntityCharcoalPit be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCharcoalPit;
                    be?.Init(player);

                    (player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                    return(true);
                }
            }

            Block block = world.GetBlock(CodeWithParts(NextStageCodePart));

            world.BlockAccessor.ExchangeBlock(block.BlockId, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
            if (block.Sounds != null)
            {
                world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z, player);
            }

            if (stage == 4)
            {
                BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);
                if (be is BlockEntityFirepit)
                {
                    ((BlockEntityFirepit)be).inventory[0].Itemstack = new ItemStack(obj, 4);
                }
            }

            (player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

            return(true);
        }
        public bool TryConstruct(IWorldAccessor world, BlockPos pos, CollectibleObject obj, IPlayer player)
        {
            int stage = Stage;

            if (obj.Attributes?["firepitConstructable"]?.AsBool(false) != true)
            {
                return(false);
            }

            CombustibleProperties combprops = obj.CombustibleProps;

            if (stage == 5)
            {
                return(false);
            }

            if (stage == 4 && world.BlockAccessor.GetBlock(pos.DownCopy()).Code.Path.Equals("firewoodpile"))
            {
                Block charcoalPitBlock = world.GetBlock(new AssetLocation("charcoalpit"));
                if (charcoalPitBlock != null)
                {
                    world.BlockAccessor.SetBlock(charcoalPitBlock.BlockId, pos);

                    BlockEntityCharcoalPit be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCharcoalPit;
                    be?.Init(player);

                    return(true);
                }
            }

            Block block = world.GetBlock(CodeWithParts(NextStageCodePart));

            world.BlockAccessor.ExchangeBlock(block.BlockId, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
            if (block.Sounds != null)
            {
                world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z, player);
            }

            if (stage == 4)
            {
                BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);
                if (be is BlockEntityFirepit)
                {
                    ((BlockEntityFirepit)be).igniteWithFuel(combprops, 4);
                }
            }

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

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

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    string firstCodePart = obj.FirstCodePart();

                    if (obj is Block && (obj as Block).HasBehavior <BlockBehaviorCanIgnite>() || obj is ItemFirestarter)
                    {
                        List <ItemStack> stacks = obj.GetHandBookStacks(api as ICoreClientAPI);
                        if (stacks != null)
                        {
                            canIgniteStacks.AddRange(stacks);
                        }
                    }
                }

                return(new WorldInteraction[]
                {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-firepit-ignite",
                        MouseButton = EnumMouseButton.Right,
                        HotKeyCode = "sneak",
                        Itemstacks = canIgniteStacks.ToArray(),
                        GetMatchingStacks = (wi, bs, es) => {
                            BlockEntityCharcoalPit becp = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityCharcoalPit;
                            if (becp?.Lit == false)
                            {
                                return wi.Itemstacks;
                            }
                            return null;
                        }
                    }
                });
            });
        }