示例#1
0
        public override void OnTryIgniteBlockOver(EntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;

            BlockEntityPitKiln beb = byEntity.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityPitKiln;

            beb?.TryIgnite((byEntity as EntityPlayer).Player);
        }
示例#2
0
        public override EnumIgniteState OnTryIgniteBlock(EntityAgent byEntity, BlockPos pos, float secondsIgniting)
        {
            BlockEntityPitKiln beb = byEntity.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityPitKiln;

            if (!beb.CanIgnite())
            {
                return(EnumIgniteState.NotIgnitablePreventDefault);
            }



            return(secondsIgniting > 4 ? EnumIgniteState.IgniteNow : EnumIgniteState.Ignitable);
        }
示例#3
0
        public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null)
        {
            if (pos != null)
            {
                BlockEntityPitKiln beb = blockAccessor.GetBlockEntity(pos) as BlockEntityPitKiln;
                if (beb != null && beb.Lit)
                {
                    return(litKilnLightHsv);
                }
            }

            return(base.GetLightHsv(blockAccessor, pos, stack));
        }
示例#4
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            Dictionary <string, BuildStageMaterial[]> resolvedMats = new Dictionary <string, BuildStageMaterial[]>();

            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);
                    }
                }
            }

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



            var modelConfigs = Attributes["modelConfigs"].AsObject <Dictionary <string, PitKilnModelConfig> >();
            var buildMats    = Attributes["buildMats"].AsObject <Dictionary <string, JsonItemStackBuildStage[]> >();

            foreach (var val in buildMats)
            {
                resolvedMats[val.Key] = new BuildStageMaterial[val.Value.Length];

                int i = 0;
                foreach (var stack in val.Value)
                {
                    if (!stack.Resolve(api.World, "pit kiln build material", true))
                    {
                        continue;
                    }

                    resolvedMats[val.Key][i++] = new BuildStageMaterial()
                    {
                        ItemStack = stack.ResolvedItemstack, EleCode = stack.EleCode, TextureCodeReplace = stack.TextureCodeReplace, BurnTimeHours = stack.BurnTimeHours
                    };
                }
            }

            foreach (var val in modelConfigs)
            {
                if (val.Value?.BuildStages == null || val.Value.BuildMatCodes == null || val.Value.Shape?.Base == null)
                {
                    api.World.Logger.Error("Pit kiln model configs: Build stage array, build mat array or composite shape is null. Will ignore this config.");
                    continue;
                }

                if (val.Value.BuildStages.Length != val.Value.BuildMatCodes.Length)
                {
                    api.World.Logger.Error("Pit kiln model configs: Build stage array and build mat array not the same length, please fix. Will ignore this config.");
                    continue;
                }

                var   loc   = val.Value.Shape.Base.Clone().WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/");
                Shape shape = api.Assets.TryGet(loc)?.ToObject <Shape>();
                if (shape == null)
                {
                    api.World.Logger.Error("Pit kiln model configs: Shape file {0} not found. Will ignore this config.", val.Value.Shape.Base);
                    continue;
                }

                string[] stages   = val.Value.BuildStages;
                string[] matcodes = val.Value.BuildMatCodes;

                BuildStage[] resostages = new BuildStage[stages.Length];

                for (int i = 0; i < stages.Length; i++)
                {
                    BuildStageMaterial[] stacks;

                    if (!resolvedMats.TryGetValue(matcodes[i], out stacks))
                    {
                        api.World.Logger.Error("Pit kiln model configs: No such mat code " + matcodes[i] + ". Please fix. Will ignore all configs.");
                        return;
                    }

                    float miny2 = 0;
                    if (val.Value.MinHitboxY2 != null)
                    {
                        miny2 = val.Value.MinHitboxY2[GameMath.Clamp(i, 0, val.Value.MinHitboxY2.Length - 1)];
                    }

                    resostages[i] = new BuildStage()
                    {
                        ElementName = stages[i], Materials = stacks, MinHitboxY2 = miny2, MatCode = matcodes[i]
                    };
                }

                BuildStagesByBlock[val.Key] = resostages;
                ShapesByBlock[val.Key]      = shape;
            }
        }