Пример #1
0
        public new CookingRecipeStack Clone()
        {
            CookingRecipeStack stack = new CookingRecipeStack()
            {
                Code = Code.Clone(),
                ResolvedItemstack = ResolvedItemstack?.Clone(),
                StackSize         = StackSize,
                Type           = Type,
                TextureMapping = (string[])TextureMapping?.Clone(),
                CookedStack    = CookedStack?.Clone()
            };

            if (Attributes != null)
            {
                stack.Attributes = Attributes.Clone();
            }

            stack.ShapeElement = ShapeElement;

            return(stack);
        }
Пример #2
0
        public override void OnLoaded(ICoreAPI api)
        {
            if (api.Side != EnumAppSide.Client)
            {
                return;
            }
            ICoreClientAPI capi = api as ICoreClientAPI;

            string createdByText = "metalmolding";

            if (Attributes?["createdByText"].Exists == true)
            {
                createdByText = Attributes["createdByText"].AsString();
            }

            if (Attributes?["drop"].Exists == true)
            {
                JsonItemStack ojstack = Attributes["drop"].AsObject <JsonItemStack>();
                if (ojstack != null)
                {
                    MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();
                    for (int i = 0; i < metals.Variants.Length; i++)
                    {
                        string        metaltype = metals.Variants[i].Code.Path;
                        string        tooltype  = LastCodePart();
                        JsonItemStack jstack    = ojstack.Clone();
                        jstack.Code.Path = jstack.Code.Path.Replace("{tooltype}", tooltype).Replace("{metal}", metaltype);

                        CollectibleObject collObj;

                        if (jstack.Type == EnumItemClass.Block)
                        {
                            collObj = api.World.GetBlock(jstack.Code);
                        }
                        else
                        {
                            collObj = api.World.GetItem(jstack.Code);
                        }

                        if (collObj == null)
                        {
                            continue;
                        }

                        JToken token;

                        if (collObj.Attributes?["handbook"].Exists != true)
                        {
                            if (collObj.Attributes == null)
                            {
                                collObj.Attributes = new JsonObject(JToken.Parse("{ handbook: {} }"));
                            }
                            else
                            {
                                token             = collObj.Attributes.Token;
                                token["handbook"] = JToken.Parse("{ }");
                            }
                        }

                        token = collObj.Attributes["handbook"].Token;
                        token["createdBy"] = JToken.FromObject(createdByText);
                    }
                }
            }


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

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    if (obj is BlockSmeltedContainer)
                    {
                        smeltedContainerStacks.Add(new ItemStack(obj));
                    }
                }

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-toolmold-pour",
                        HotKeyCode = "sneak",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = smeltedContainerStacks.ToArray(),
                        GetMatchingStacks = (wi, bs, es) =>
                        {
                            BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold;
                            return (betm != null && !betm.IsFull) ? wi.Itemstacks : null;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-toolmold-takeworkitem",
                        HotKeyCode = null,
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (wi, bs, es) =>
                        {
                            BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold;
                            return betm != null && betm.IsFull && betm.IsHardened;
                        }
                    },
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-toolmold-pickup",
                        HotKeyCode = null,
                        RequireFreeHand = true,
                        MouseButton = EnumMouseButton.Right,
                        ShouldApply = (wi, bs, es) =>
                        {
                            BlockEntityToolMold betm = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityToolMold;
                            return betm != null && betm.metalContent == null;
                        }
                    }
                });
            });
        }