
Smart Recipes
你觉得《Minecraft》的标准合成格式太无聊了吗?或者,你是否希望让游戏变得更加基于事件驱动,就像《泰拉瑞亚》那样?如果是的话,Smart Recipes 正是你所需要的!通过我们全新的条件合成格式,打造属于你自己的独特体验!
格式
如果你更喜欢看实际示例而不是文字解释,可以直接跳到 示例 部分。但别忘了稍后回过头来查看 条件 和 重载条件 部分。
条件格式
Smart Recipes 模组扩展了 原版合成格式。理解原版格式的工作原理至关重要,否则以下的说明可能无法让你理解。
该模组在合成格式中引入了一个新的 smart_recipes:conditions 属性。它与战利品表中的条件有些相似。让我们仔细看看:
"smart_recipes:conditions": []
此属性用于决定合成何时加载。如果指定了多个条件,则必须全部满足。
"smart_recipes:conditions": [
{
"condition": "conditionName0",
"args": [
// 传递给名为 `conditionName0` 的条件的参数。
4,
"2"
]
},
{
"condition": "conditionName1",
"args": [
// 传递给名为 `conditionName1` 的条件的参数。
"foo"
]
}
]
这个示例与通常编写战利品表条件的方式完全相同。但我认为它们过于冗长。让我们看看如何改进我们的条件。
// 让我们将这种条件声明:
{
"condition": "conditionName1",
"args": [
"foo"
]
}
// 改为这样:
"conditionName1": ["foo"]
好多了,不是吗?
"smart_recipes:conditions": [
{
"conditionName0": [4, "2"]
},
{
"conditionName1": ["foo"]
}
]
这比之前更好了,但还有改进的空间。让我们将条件合并到一个对象中:
"smart_recipes:conditions": [
{
"conditionName0": [4, "2"],
"conditionName1": ["foo"]
}
]
最后,如果数组只包含一个对象,Smart Recipes 模组允许你省略其声明。最终结果如下:
"smart_recipes:conditions": {
"conditionName0": [4, "2"],
"conditionName1": "foo"
}
需要注意的是,Smart Recipes 可以解析上述所有示例,因此你可以选择自己喜欢的风格。
重载条件格式
重载条件允许在不同情况下重新评估合成条件。如果你的合成依赖于天气、时间和其他易变实体,这将非常有用。
这个过程出乎意料地简单。你只需要提供你的合成所依赖的重载条件名称即可:
"smart_recipes:reload_conditions": [
"weather_changed",
"time_changed"
]
条件
false
不需要参数,始终返回 false。
"smart_recipes:conditions": [
"false"
]
true
不需要参数,始终返回 true。
"smart_recipes:conditions": [
"true"
]
or 和 any
如果任何指定的条件返回 true,则返回 true。
"smart_recipes:conditions": {
"or": [
{ "false": {} },
false,
"true"
]
}
and 和 all
如果所有指定的条件都返回 true,则返回 true。
"smart_recipes:conditions": {
"and": {
"true": {},
"false": null
}
}
not 和 none
如果没有指定的条件返回 true,则返回 true。
"smart_recipes:conditions": {
"not": {
"false": null
}
}
is_hardcore
不需要参数,如果服务器处于极限模式(Hardcore),则返回 true。
"smart_recipes:conditions": {
"not": "is_hardcore"
}
is_peaceful_difficulty
不需要参数,如果当前难度为和平(Peaceful),则返回 true。
"smart_recipes:conditions": {
"or": [
"is_peaceful_difficulty",
"is_hardcore"
]
}
is_easy_difficulty
不需要参数,如果当前难度为简单(Easy),则返回 true。
"smart_recipes:conditions": {
"not": ["is_easy_difficulty"]
}
is_normal_difficulty
不需要参数,如果当前难度为普通(Normal),则返回 true。
"smart_recipes:conditions": "is_normal_difficulty"
is_hard_difficulty
不需要参数,如果当前难度为困难(Hard),则返回 true。
"smart_recipes:conditions": {
"is_hard_difficulty": null
}
difficulty_check
如果指定的值之一与当前难度匹配,则返回 true。
"smart_recipes:conditions": {
"difficulty_check": [
0, // 和平难度对应的序号
1, // 简单难度对应的序号
2, // 普通难度对应的序号
3, // 困难难度对应的序号
"peaceful",
"easy",
"normal",
"HarD" // 不区分大小写
]
}
is_survival
无需参数,如果默认游戏模式为生存模式则返回 true。
"smart_recipes:conditions": "is_survival"
is_creative
无需参数,如果默认游戏模式为创造模式则返回 true。
"smart_recipes:conditions": ["is_creative"]
is_adventure
无需参数,如果默认游戏模式为冒险模式则返回 true。
"smart_recipes:conditions": {
"is_adventure": {}
}
is_spectator
无需参数,如果默认游戏模式为旁观者模式则返回 true。
"smart_recipes:conditions": {
"not": "is_spectator"
}
gamemode_check
如果指定的值之一与默认游戏模式匹配,则返回 true。
"smart_recipes:conditions": {
"gamemode_check": [
0, // 生存模式对应的序号
1, // 创造模式对应的序号
2, // 冒险模式对应的序号
3, // 旁观者模式对应的序号
"survival",
"creative",
"adventure",
"SpEcTaToR" // 不区分大小写
]
}
weather_check
如果指定的字符串之一与当前主世界维度中的天气匹配,则返回 true。
"smart_recipes:conditions": {
"weather_check": [
"clear", // 天气晴朗
"rain", // 正在下雨或雷暴
"thunder" // 正在雷暴
]
}
time_check
如果指定的字符串之一与当前主世界维度中的时间匹配,则返回 true。
"smart_recipes:conditions": {
"time_check": [
"day", // 从 1000 到 12999 刻
"noon", // 从 5000 到 6999 刻
"sunset", // 从 11000 到 12999 刻
"midnight", // 从 17000 到 18999 刻
"sunrise", // 从 22000 到 23999 刻
"night" // 从 13000 到 23999 刻,以及从 0 到 999 刻
]
}
players_online
如果所有指定的玩家都在线,则返回 true。
"smart_recipes:conditions": {
"players_online": [
"Notch",
"Dinnerbone",
"jeb_"
]
}
blocks_registered
如果所有指定的方块都已注册,则返回 true。
"smart_recipes:conditions": {
"blocks_registered": [
"stone",
"minecraft:dirt",
"aether:aether_dirt"
]
}
items_registered
如果所有指定的物品都已注册,则返回 true。
"smart_recipes:conditions": {
"items_registered": [
"stone",
"minecraft:dirt",
"aether:aether_dirt"
]
}
block_entities_registered
如果所有指定的方块实体都已注册,则返回 true。
"smart_recipes:conditions": {
"block_entities_registered": [
"furnance",
"minecraft:chest",
"aether:incubator"
]
}
entries_registered
如果所有指定的注册表条目都已注册,则返回 true。
"smart_recipes:conditions": {
"entries_registered": [
{
"registry": "block",
"entry": "stone"
},
"minecraft:dirt", // `registry` 的默认值为 "block"
{
"registry": "item",
"entry": "aether:incubator"
},
{
"entry": "air" // `registry` 的默认值为 "block"
}
]
}
fabric:mods_loaded
如果所有指定的模组都已加载,则返回 true。
"smart_recipes:conditions": {
"fabric:mods_loaded": [
{
"id": "smart-recipes",
"version": "1.0"
},
"fabric-transfer-api-v1", // `version` 的默认值为 "*"
{
"id": "fabric-command-api-v1" // `version` 的默认值为 "*"
}
]
}
重载条件
player_joined 和 player_disconnected
当玩家加入或断开连接时重新加载配方。
"smart_recipes:conditions": {
"not": {
"players_online": "Nickname"
}
},
"smart_recipes:reload_conditions": [
"player_joined",
"player_disconnected"
]
difficulty_changed
当当前难度发生变化时重新加载配方。
"smart_recipes:conditions": "is_easy_difficulty",
"smart_recipes:reload_conditions": "difficulty_changed"
gamemode_changed
当默认游戏模式发生变化时重新加载配方。
"smart_recipes:conditions": {
"gamemode_check": [
"survival",
"creative"
]
},
"smart_recipes:reload_conditions": ["gamemode_changed"]
weather_changed
当当前天气发生变化时重新加载配方。
"smart_recipes:conditions": {
"weather_check": "thunder"
},
"smart_recipes:reload_conditions": "weather_changed"
time_changed
当当前时间发生变化时重新加载配方。
"smart_recipes:conditions": {
"time_check": [
"noon",
"midnight"
]
},
"smart_recipes:reload_conditions": [
"time_changed"
]
示例
考虑以下场景:我们要添加一个简化的 TNT 合成配方:
{
"type": "minecraft:crafting_shaped",
"pattern": [
"# X",
" ",
"X #"
],
"key": {
"#": {
"item": "minecraft:sand"
},
"X": {
"item": "minecraft:gunpowder"
}
},
"result": {
"item": "minecraft:tnt"
}
}
现在,让我们添加一些条件。我们的目标如下:
- 此配方仅在
midnight(午夜)和 sunrise(日出)时可用,因为没人会在大白天制作爆炸物。
- 此配方仅在
weather is clear(天气晴朗)时可用,以防止火药受潮。
- 当
Vladimir 在线时,此配方应 not(不)可用,因为我们不信任 Vladimir 使用致命武器。
- 此配方仅在
hard(困难)难度下可用,因为……为什么不呢?
是时候将我们的计划付诸行动了:
{
// 与上面相同的部分,这里没什么有趣的
"type": "minecraft:crafting_shaped",
"pattern": [
"# X",
" ",
"X #"
],
"key": {
"#": {
"item": "minecraft:sand"
},
"X": {
"item": "minecraft:gunpowder"
}
},
"result": {
"item": "minecraft:tnt"
},
// 乐趣从这里开始。
// 我们需要在
// `conditions` 部分描述加载此配方的条件。如果指定了多个条件,则必须全部满足。
"smart_recipes:conditions": {
// #1
"time_check": [
"midnight",
"sunrise"
],
// #2
// 注意 `weather_check` 通常需要一个数组(就像 `time_check` 一样),
// 但由于我们只需要传递一个值,因此可以省略数组声明。
"weather_check": "clear",
// #3
"not": {
// 我们也可以在这里省略数组声明,但
// 我保留它只是为了展示它是可选的。
"players_online": ["Vladimir"]
},
// #4
// 可以替换为:
// - `"is_hard_difficulty": null`
// - `"is_hard_difficulty"`(在数组中)
// - `{ "condition": "is_hard_difficulty" }`(在数组中)
// - `{ "condition": "difficulty_check", "args": ["hard"] }`(在数组中)
"difficulty_check": "hard"
},
// 默认情况下,条件仅在服务器启动时进行评估。
// 因此,如果我们希望保持配方与实际
// 游戏状态同步,我们需要添加 `reload_conditions`。
"smart_recipes:reload_conditions": [
// #1
// 时间变化时重新加载配方。
"time_changed",
// #2
// 天气变化时重新加载配方。
"weather_changed",
// #3
// 玩家加入或断开连接服务器时重新加载配方。
// 我将来可能会将这两者合并为一个。
"player_joined",
"player_disconnected",
// #4
// 难度变化时重新加载配方。
// 老实说,我认为你并不需要它,
// 因为在大多数服务器上难度是锁定的,
// 所以仅在服务器启动时评估基于难度的条件是可以的。
"difficulty_changed"
]
}
安装
要求:
- Minecraft
>=1.17.x
- Fabric Loader
>=0.11.3
- Fabric API
>=0.35.0
你可以从以下位置下载模组:
作为依赖项使用
你可以在你的模组中包含 Smart Recipes,以便使用新的条件格式,而无需玩家单独下载它。
build.gradle:
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modImplementation "maven.modrinth:smart-recipes:${project.smart_recipes_version}"
}
gradle.properties:
smart_recipes_version=/* latest version goes here */
从源代码构建
要求:
Linux/MacOS
git clone https://github.com/Kir-Antipov/smart-recipes.git
cd smart-recipes
chmod +x ./gradlew
./gradlew build
cd build/libs
Windows
git clone https://github.com/Kir-Antipov/smart-recipes.git
cd smart-recipes
gradlew build
cd build/libs

Smart Recipes
Do you find the standard Minecraft recipe format boring? Or maybe you wish to make the game more event-based, like Terraria? If so, Smart Recipes is what you need! Craft your own unique experience with our new conditional recipe format!
Format
If you prefer a practical example over explanations, feel free to skip directly to the Example section. However, don't forget to revisit the Conditions and Reload Conditions sections later.
Conditions Format
The Smart Recipes mod extends the vanilla recipe format. It's crucial to understand how the vanilla format works; otherwise, the following descriptions may not make sense.
This mod introduces a new smart_recipes:conditions property to the recipe format. It's somewhat similar to the conditions in loot tables. Let's take a closer look it:
"smart_recipes:conditions": []
This property determines conditions for the recipe to be loaded. If multiple conditions are specified, all must pass.
"smart_recipes:conditions": [
{
"condition": "conditionName0",
"args": [
// Arguments to be passed to some condition named `conditionName0`.
4,
"2"
]
},
{
"condition": "conditionName1",
"args": [
// Arguments to be passed to some condition named `conditionName1`.
"foo"
]
}
]
This example is identical to how conditions in loot tables are usually written. However, I find them too verbose. Let's explore how we can improve our conditions.
// Let's turn this condition declaration:
{
"condition": "conditionName1",
"args": [
"foo"
]
}
// Into this one:
"conditionName1": ["foo"]
Much better, don't you think?
"smart_recipes:conditions": [
{
"conditionName0": [4, "2"]
},
{
"conditionName1": ["foo"]
}
]
This is even better than before, but there is still some room for imporvement. Let's consolidate our conditions into a single object:
"smart_recipes:conditions": [
{
"conditionName0": [4, "2"],
"conditionName1": ["foo"]
}
]
Finally, if an array contains only one object, the Smart Recipes mod allows you to omit its declaration. Here's the final result:
"smart_recipes:conditions": {
"conditionName0": [4, "2"],
"conditionName1": "foo"
}
I should note that Smart Recipes can parse every single one of the examples above, so you can choose the style you prefer.
Reload Conditions Format
Reload conditions allow recipe conditions to be re-evaluated on different occasions. It can be useful if your recipe relies on weather, time and/or other volatile entities.
This process is surprisingly straightforward. All you need to do is provide the names of the reload conditions that your recipe depends on:
"smart_recipes:reload_conditions": [
"weather_changed",
"time_changed"
]
Conditions
false
Doesn't require arguments, always returns false.
"smart_recipes:conditions": [
"false"
]
true
Doesn't require arguments, always returns true.
"smart_recipes:conditions": [
"true"
]
or and any
Return true if any of the specified conditions returns true.
"smart_recipes:conditions": {
"or": [
{ "false": {} },
false,
"true"
]
}
and and all
Return true if all the specified conditions return true.
"smart_recipes:conditions": {
"and": {
"true": {},
"false": null
}
}
not and none
Return true if none of the specified conditions return true.
"smart_recipes:conditions": {
"not": {
"false": null
}
}
is_hardcore
Doesn't require arguments, returns true if the server is in Hardcore mode.
"smart_recipes:conditions": {
"not": "is_hardcore"
}
is_peaceful_difficulty
Doesn't require arguments, returns true if the current difficulty is Peaceful.
"smart_recipes:conditions": {
"or": [
"is_peaceful_difficulty",
"is_hardcore"
]
}
is_easy_difficulty
Doesn't require arguments, returns true if the current difficulty is Easy.
"smart_recipes:conditions": {
"not": ["is_easy_difficulty"]
}
is_normal_difficulty
Doesn't require arguments, returns true if the current difficulty is Normal.
"smart_recipes:conditions": "is_normal_difficulty"
is_hard_difficulty
Doesn't require arguments, returns true if the current difficulty is Hard.
"smart_recipes:conditions": {
"is_hard_difficulty": null
}
difficulty_check
Returns true if one of the specified values matches the current difficulty.
"smart_recipes:conditions": {
"difficulty_check": [
0, // Ordinal number of the Peaceful difficulty
1, // Ordinal number of the Easy difficulty
2, // Ordinal number of the Normal difficulty
3, // Ordinal number of the Hard difficulty
"peaceful",
"easy",
"normal",
"HarD" // Case doesn't matter
]
}
is_survival
Doesn't require arguments, returns true if the default gamemode is Survival.
"smart_recipes:conditions": "is_survival"
is_creative
Doesn't require arguments, returns true if the default gamemode is Creative.
"smart_recipes:conditions": ["is_creative"]
is_adventure
Doesn't require arguments, returns true if the default gamemode is Adventure.
"smart_recipes:conditions": {
"is_adventure": {}
}
is_spectator
Doesn't require arguments, returns true if the default gamemode is Spectator.
"smart_recipes:conditions": {
"not": "is_spectator"
}
gamemode_check
Returns true if one of the specified values matches the default gamemode.
"smart_recipes:conditions": {
"gamemode_check": [
0, // Ordinal number of the Survival gamemode
1, // Ordinal number of the Creative gamemode
2, // Ordinal number of the Adventure gamemode
3, // Ordinal number of the Spectator gamemode
"survival",
"creative",
"adventure",
"SpEcTaToR" // Case doesn't matter
]
}
weather_check
Returns true if one of the specified strings matches the current weather in the Overworld dimension.
"smart_recipes:conditions": {
"weather_check": [
"clear", // Weather is clear
"rain", // It's raining or thundering
"thunder" // It's thundering
]
}
time_check
Returns true if one of the specified strings matches the current time in the Overworld dimension.
"smart_recipes:conditions": {
"time_check": [
"day", // from 1000 to 12999 ticks
"noon", // from 5000 to 6999 ticks
"sunset", // from 11000 to 12999 ticks
"midnight", // from 17000 to 18999 ticks
"sunrise", // from 22000 to 23999 ticks
"night" // from 13000 to 23999 ticks, from 0 to 999 ticks
]
}
players_online
Returns true if all the specified players are online.
"smart_recipes:conditions": {
"players_online": [
"Notch",
"Dinnerbone",
"jeb_"
]
}
blocks_registered
Returns true if all the specified blocks are registered.
"smart_recipes:conditions": {
"blocks_registered": [
"stone",
"minecraft:dirt",
"aether:aether_dirt"
]
}
items_registered
Returns true if all the specified items are registered.
"smart_recipes:conditions": {
"items_registered": [
"stone",
"minecraft:dirt",
"aether:aether_dirt"
]
}
block_entities_registered
Returns true if all the specified block entities are registered.
"smart_recipes:conditions": {
"block_entities_registered": [
"furnance",
"minecraft:chest",
"aether:incubator"
]
}
entries_registered
Returns true if all the specified registry entries are registered.
"smart_recipes:conditions": {
"entries_registered": [
{
"registry": "block",
"entry": "stone"
},
"minecraft:dirt", // `registry`'s default value is "block",
{
"registry": "item",
"entry": "aether:incubator"
},
{
"entry": "air" // `registry`'s default value is "block",
}
]
}
fabric:mods_loaded
Returns true if all the specified mods are loaded.
"smart_recipes:conditions": {
"fabric:mods_loaded": [
{
"id": "smart-recipes",
"version": "1.0"
},
"fabric-transfer-api-v1", // `version`'s default value is "*"
{
"id": "fabric-command-api-v1" // `version`'s default value is "*"
}
]
}
Reload Conditions
player_joined and player_disconnected
Reload recipes when player joins to/disconnects from the server.
"smart_recipes:conditions": {
"not": {
"players_online": "Nickname"
}
},
"smart_recipes:reload_conditions": [
"player_joined",
"player_disconnected"
]
difficulty_changed
Reloads recipes when the current difficulty changes.
"smart_recipes:conditions": "is_easy_difficulty",
"smart_recipes:reload_conditions": "difficulty_changed"
gamemode_changed
Reloads recipes when the default gamemode changes.
"smart_recipes:conditions": {
"gamemode_check": [
"survival",
"creative"
]
},
"smart_recipes:reload_conditions": ["gamemode_changed"]
weather_changed
Reloads recipes when the current weather changes.
"smart_recipes:conditions": {
"weather_check": "thunder"
},
"smart_recipes:reload_conditions": "weather_changed"
time_changed
Reloads recipes when the current time changes.
"smart_recipes:conditions": {
"time_check": [
"noon",
"midnight"
]
},
"smart_recipes:reload_conditions": [
"time_changed"
]
Example
Consider a scenario where we want to add a simplified TNT recipe:
{
"type": "minecraft:crafting_shaped",
"pattern": [
"# X",
" ",
"X #"
],
"key": {
"#": {
"item": "minecraft:sand"
},
"X": {
"item": "minecraft:gunpowder"
}
},
"result": {
"item": "minecraft:tnt"
}
}
Now, let's add some conditions. Here are our objectives:
- This recipe should only be available at
midnight and sunrise, because nobody crafts explosives in the light of day.
- The recipe should only be available when the
weather is clear, to prevent the gunpowder from getting damp.
- The recipe should
not be available when Vladimir is online, as we don't trust Vladimir with deadly weapons.
- The recipe should only be available on the
hard difficulty, because... why not?
Time to put our plan into action:
{
// The same part as above, nothing interesting to see here
"type": "minecraft:crafting_shaped",
"pattern": [
"# X",
" ",
"X #"
],
"key": {
"#": {
"item": "minecraft:sand"
},
"X": {
"item": "minecraft:gunpowder"
}
},
"result": {
"item": "minecraft:tnt"
},
// Here's where the fun begins.
// We need to describe our conditions for this recipe to be loaded in the
// `conditions` section. If multiple conditions are specified, all must pass.
"smart_recipes:conditions": {
// #1
"time_check": [
"midnight",
"sunrise"
],
// #2
// Note that `weather_check` usually consumes an array (just like `time_check` does),
// but since we need to pass only one value, it can be omitted.
"weather_check": "clear",
// #3
"not": {
// We can omit an array declaration here too, but
// I left it just to show that it's not necessary.
"players_online": ["Vladimir"]
},
// #4
// Can be replaced with:
// - `"is_hard_difficulty": null`
// - `"is_hard_difficulty"` (in arrays)
// - `{ "condition": "is_hard_difficulty" }` (in arrays)
// - `{ "condition": "difficulty_check", "args": ["hard"] }` (in arrays)
"difficulty_check": "hard"
},
// By default, conditions are evaluated only when the server starts.
// So, if we want to keep our recipes up-to-date with the actual
// state of the game, we need to add `reload_conditions`.
"smart_recipes:reload_conditions": [
// #1
// Reloads the recipe when time changes.
"time_changed",
// #2
// Reloads the recipe when weather changes.
"weather_changed",
// #3
// These reload the recipe when a player joins or disconnects from the server.
// I may combine these two into a single one in the future.
"player_joined",
"player_disconnected",
// #4
// Reloads the recipe when difficulty changes.
// To be honest, I don't think you really need it,
// because difficulty is locked on most servers,
// so it's fine to evaluate difficulty-based conditions
// only on server start.
"difficulty_changed"
]
}
Installation
Requirements:
- Minecraft
>=1.17.x
- Fabric Loader
>=0.11.3
- Fabric API
>=0.35.0
You can download the mod from:
Using as a Dependency
You can include Smart Recipes in your mod to use the new conditional format without requiring players to download it separately.
build.gradle:
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modImplementation "maven.modrinth:smart-recipes:${project.smart_recipes_version}"
}
gradle.properties:
smart_recipes_version=/* latest version goes here */
Building from sources
Requirements:
Linux/MacOS
git clone https://github.com/Kir-Antipov/smart-recipes.git
cd smart-recipes
chmod +x ./gradlew
./gradlew build
cd build/libs
Windows
git clone https://github.com/Kir-Antipov/smart-recipes.git
cd smart-recipes
gradlew build
cd build/libs
评论 0
登录后参与评分
还没有评论,来抢沙发吧