星露谷模组开发教程#7 自定义机器

首发于Enaium的个人博客


添加大型工艺品

机器也算是大型工艺品,所以我们需要先添加它的大型工艺品。

这里做一张16x32格式为png的图。

csharp 复制代码
if (e.Name.IsEquivalentTo("Data/BigCraftables"))
{
    e.Edit(assets =>
    {
        var dict = assets.AsDictionary<string, BigCraftableData>();
        dict.Data["Awesome_Orearium"] = new BigCraftableData
        {
            Name = "Awesome_Orearium",
            DisplayName = "Orearium",
            Description = "Insert a ore of your choice and it will grow copies.",
            Texture = "Awesome_Orearium"
        };
    });
}

if (e.Name.IsEquivalentTo("Awesome_Orearium"))
{
    e.LoadFromModFile<Texture2D>("assets/Orearium.png", AssetLoadPriority.Medium);
}

添加机器

Data/Machines.json中我们可以看到所有机器的信息,我们就仿照着宝石复制机做一个矿石复制机。

csharp 复制代码
if (e.Name.IsEquivalentTo("Data/Machines"))
{
    e.Edit(assets =>
    {
        var dict = assets.AsDictionary<string, MachineData>();
        dict.Data["(BC)Awesome_Orearium"] = new MachineData
        {
            OutputRules = new List<MachineOutputRule> {
                new() {
                    Id = "Default",
                    Triggers =
                    new List<MachineOutputTriggerRule>() {
                        new() {
                            Id = "OutputCollected",
                            Trigger = MachineOutputTrigger.OutputCollected,
                            RequiredCount = 1
                        },
                        new() {
                            Id = "CopperOre",
                            Trigger = MachineOutputTrigger.ItemPlacedInMachine,
                            RequiredItemId = "(O)378"
                        },
                        new() {
                            Id = "IronOre",
                            Trigger = MachineOutputTrigger.ItemPlacedInMachine,
                            RequiredItemId = "(O)380"
                        },
                        new() {
                            Id = "GoldOre",
                            Trigger = MachineOutputTrigger.ItemPlacedInMachine,
                            RequiredItemId = "(O)384"
                        },
                        new() {
                            Id = "IridiumOre",
                            Trigger = MachineOutputTrigger.ItemPlacedInMachine,
                            RequiredItemId = "(O)386"
                        }
                    },
                    OutputItem = new List<MachineItemOutput>() {
                        new() {
                            Id = "Default",
                            ItemId = "DROP_IN"
                        }
                    },
                    MinutesUntilReady = 10,
                }
            },
            ReadyTimeModifiers = new List<StardewValley.GameData.QuantityModifier>() {
                new() {
                    Id = "CopperOre",
                    Condition = "ITEM_ID Target (O)378",
                    Modification = StardewValley.GameData.QuantityModifier.ModificationType.Multiply,
                    Amount = 1
                },
                new() {
                    Id = "CopperOre",
                    Condition = "ITEM_ID Target (O)380",
                    Modification = StardewValley.GameData.QuantityModifier.ModificationType.Multiply,
                    Amount = 2
                },
                new() {
                    Id = "CopperOre",
                    Condition = "ITEM_ID Target (O)384",
                    Modification = StardewValley.GameData.QuantityModifier.ModificationType.Multiply,
                    Amount = 3
                },
                new() {
                    Id = "CopperOre",
                    Condition = "ITEM_ID Target (O)386",
                    Modification = StardewValley.GameData.QuantityModifier.ModificationType.Multiply,
                    Amount = 4
                }
            }
        };
    });
}

首先我们需要添加一个输出规则,它有一些触发器,首先是OutputCollected,它会将输出物品继续放入机器,接着是ItemPlacedInMachine它可以指定只能让机器使用某些物品,比如放入矿石,它有一个RequiredItemId属性,这表示只能放入指定的物品,这里多加了几个矿石,铜矿石、铁矿石、金矿石和铱矿石。之后是它的输出物品,它的物品ID是DROP_IN,这表示它会复制放入的物品。最后是它的准备时间,这里是10分钟。之后我们可以使用ReadyTimeModifiers属性来修改准备时间,它有一个Condition属性,比如这里使用了ITEM_ID Target (O)378,这表示如果放入的物品是铜矿石,Modification也就是修改的类型,这里是MultiplyAmount也就是修改的倍数,这里是1,所以铜矿石的准备时间是10分钟,以此类推,铁矿石是20分钟,金矿石是30分钟,铱矿石是40分钟。

添加配方

csharp 复制代码
if (e.Name.IsEquivalentTo("Data/CraftingRecipes"))
{
    e.Edit(assets =>
    {
        var dict = assets.AsDictionary<string, string>();
        dict.Data["Awesome_Orearium"] = "390 99 335 5 336 2 787 1/Home/Awesome_Orearium/true/default/";
    });
}

这里使用99个石头、5个铁锭、2个金锭和1个电池制造一个矿石复制机。

相关推荐
★YUI★14 分钟前
学习游戏制作记录(玩家掉落系统,删除物品功能和独特物品)8.17
java·学习·游戏·unity·c#
谷宇.1 小时前
【Unity3D实例-功能-拔枪】角色拔枪(二)分割上身和下身
游戏·unity·c#·游戏程序·unity3d·游戏开发·游戏编程
LZQqqqqo1 小时前
C# 中 ArrayList动态数组、List<T>列表与 Dictionary<T Key, T Value>字典的深度对比
windows·c#·list
Dm_dotnet4 小时前
Stylet启动机制详解:从Bootstrap到View显示
c#
三千道应用题5 小时前
WPF&C#超市管理系统(6)订单详情、顾客注册、商品销售排行查询和库存提示、LiveChat报表
开发语言·c#·wpf
唐青枫10 小时前
别滥用 Task.Run:C# 异步并发实操指南
c#·.net
我好喜欢你~17 小时前
C#---StopWatch类
开发语言·c#
一阵没来由的风21 小时前
拒绝造轮子(C#篇)ZLG CAN卡驱动封装应用
c#·can·封装·zlg·基础封装·轮子
一枚小小程序员哈1 天前
基于微信小程序的家教服务平台的设计与实现/基于asp.net/c#的家教服务平台/基于asp.net/c#的家教管理系统
后端·c#·asp.net
Eternity_GQM1 天前
【Word VBA Zotero 引用宏错误分析与改正指南】【解决[21–23]参考文献格式插入超链接问题】
开发语言·c#·word