Background
攻略Factorio

异星工厂 制作MOD教程 异星工厂怎么制作MOD

W
wuyan
4/3/2014

在游戏的根目录下,先创建一个名为 mods 的文件夹。随后在 mods 内再创建一个 MyMods 文件夹,用于存放自己的 MOD 代码。

在 MyMods 目录下,用记事本或任何代码编辑器新建 info.json,文件内容如下: { "name": "MyMods", "author": "MyMods", "version": "0.0.1", "title": "MyMods", "homepage": "http://www..com", "description": "MyMods", "dependencies": ["base"] } 这个文件是 MOD 的基本信息声明,告诉游戏此 MOD 的基本属性。

接下来在 MyMods 里新建 Items 文件夹(可以随意命名),把 Factorio 官方目录里 \Factorio\data\base\prototypes\item\demo-mining-tools.lua 复制到 Items 文件夹下。 随后在 MyMods 根目录下再创建 data.lua,写入: -- Items require("Items.demo-mining-tools") data.lua 用来加载其它脚本文件。

demo-mining-tools.lua 的核心内容是定义一个矿物工具(如铁镐): data:extend({ { type = "mining-tool", name = "iron-axe", icon = "__base__/graphics/icons/iron-axe.png", flags = {"goes-to-main-inventory"}, action = { type = "direct", action_delivery = { type = "instant", target_effects = { {type = "damage", damage = {amount = 5, type = "physical"}} } } }, durability = 4000, subgroup = "tool", order = "a[mining]-a[iron-axe]", speed = 2.5, stack_size = 32 } }) 这里 durability 表示耐久度,speed 是采矿速度,后面可以根据需求自行修改。

为了演示如何添加新物品,创建 MyMods\Items\MineralResource.lua,内容示例: data:extend({ { type = "item", name = "coal", icon = "__base__/graphics/icons/coal.png", flags = {"goes-to-main-inventory"}, fuel_value = "8MJ", subgroup = "raw-material", order = "b[coal]", stack_size = 64 }, { type = "item", name = "PrimaryCompressCoal", icon = "__base__/graphics/icons/coal.png", flags = {"goes-to-main-inventory"}, fuel_value = "16MJ", subgroup = "intermediate-product", order = "b[coal]", stack_size = 128 }, { type = "item", name = "AdvancedCompressCoal", icon = "__base__/graphics/icons/coal.png", flags = {"goes-to-main-inventory"}, fuel_value = "32MJ", subgroup = "intermediate-product", order = "b[coal]", stack_size = 256 }, { type = "item", name = "Coke", icon = "__base__/graphics/icons/coal.png", flags = {"goes-to-main-inventory"}, fuel_value = "64MJ", subgroup = "intermediate-product", order = "b[coal]", stack_size = 256 } })

随后在 MyMods\locale\ch\ItemNames.cfg 里给新物品命名,示例: [item-name] coal = 煤矿 PrimaryCompressCoal = 初压煤 AdvancedCompressCoal = 高压煤 Coke = 焦煤

接下来写配方文件 MyMods\Recipe\ItemRecipe.lua: data:extend({ { type = "recipe", name = "PrimaryCompressCoal", ingredients = {{"coal", 1}}, result = "PrimaryCompressCoal" }, { type = "recipe", name = "AdvancedCompressCoal", ingredients = {{"PrimaryCompressCoal", 1}}, result = "AdvancedCompressCoal" }, { type = "recipe", name = "Coke", ingredients = {{"AdvancedCompressCoal", 1}}, result = "Coke" } })

最后在 MyMods\data.lua 里一次性加载所有脚本文件: -- Items require("Items.MineralResource") -- Recipes require("Recipe.ItemRecipe")

Article Image