MC Forge 1.20.1 mod开发学习笔记(战利品、标签、配方)

战利品列表loot_tables

看了源码之后,发现这些都只是数据配置的内容,不需要额外写java代码,只需要配置一下data里面的json文件就可以了。

archaeology:考古学的掉落物

blocks:方块(挖掘、破坏)掉落物

chests:战利品箱

entities:实体(击杀)掉落物

gameplay:其他的游戏交互方式的掉落物以及效果

(真好啊,不用去开发这些底层逻辑了)

其实这里面的逻辑都是一样的,类似在卡池里面抽卡

以击杀牛的掉落物为例:

pools就是抽取的池子有哪些

然后每个池子在entries中抽取rolls+bonus_rolls次,bonus_rolls是额外的抽取次数,在json文件没有写明的情况下会受到幸运值、抢夺、时运影响(不确定)

然后每个entries一般都有几个属性:name、type、functions、weight、(似乎可能有quality)

name就是物品的标签、type就是物品的类型、functions就是作用在抽取过程的函数、weight就是抽取的权重(默认为1)(计算方式就是当前weight除以所有weight之和,得到抽出该物品的概率)

以牛的掉落物为例:

首先用函数set_count设置基础的掉落数目,count可以设为数值或者函数分布

然后是在该实体属性满足is_on_fire的情况下,对掉落物进行furnace_smelt函数(也就是用熔炉煮熟牛肉)

最后是抢夺附魔,每等级额外增加0~1个。

对于方块挖掘掉落物:(以测试模组中的candy_ore为例)

首先我们模仿官方的data格式建立文件夹,战利品列表放在test_mod文件夹下

然后开始编写我们的candy_ore.json

其中type: minecraft:alternatives,表示在children中选择第一个满足条件的物品

children下面的内容结构和entries是一样的

复制代码
{
  "type": "minecraft:block",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "conditions": [
                {
                  "condition": "minecraft:match_tool",
                  "predicate": {
                    "enchantments": [
                      {
                        "enchantment": "minecraft:silk_touch",
                        "levels": {
                          "min": 1
                        }
                      }
                    ]
                  }
                }
              ],
              "name": "test_mod:candy_ore"
            },
            {
              "type": "minecraft:item",
              "functions": [
                {
                  "add": false,
                  "count": {
                    "type": "minecraft:uniform",
                    "max": 5.0,
                    "min": 2.0
                  },
                  "function": "minecraft:set_count"
                },
                {
                  "enchantment": "minecraft:fortune",
                  "formula": "minecraft:ore_drops",
                  "function": "minecraft:apply_bonus"
                },
                {
                  "function": "minecraft:explosion_decay"
                }
              ],
              "name": "minecraft:sugar"
            }
          ]
        }
      ],
      "rolls": 1.0
    }
  ]
}

其他:

对于战利品箱子,内容是在打开箱子的时候生成的

如果在entries中填写了quality字段,会根据幸运值与quality动态调整该物品的抽取权重

weight = floor(base_weight + quality * luck)

标签tags

当你在注册blocks的时候,可以添加一个.requiresCorrectToolForDrops()方法,这样会要求开采该方块的工具类型,这里的判定要求需要在tags中配置

在mineable文件夹下规定能使用不同工具进行开采的方块,例如使用镐子开采的就是pickaxe.json,在blocks文件夹下,添加needs_stone_tool.json可以添加对工具级别的要求。

目前我mod中pickaxe.json和needs_stone_tool.json内容是一样的。

复制代码
{
  "replace": false,
  "values": [
    "test_mod:candy_ore"
  ]
}

这里的replace字段表示是否替换已有的minecraft工具标签文件(当然不能替换)

对于tags中其他的内容,其实就是给物品打标签,然后代码会根据物品的标签进行一些条件判定。

配方recipes

其实这个看几个示例就明白了

type:配方类别

category:合成表分类(building、redstone、equipment、misc)(点开合成表绿色书时最左边的选项卡)

group:合成表组(绿书中左侧的配方选择框,把多类配方相似的物品放在一个组)

key:字符到物品的映射表(有序合成中使用)(只在该json中生效)(在key里面也可以使用tag,表示这一类物品都可以使用该字符表示)

pattern:合成表(有序合成中使用)(用key中的字符代表物品)(每行字符数要一样,没有物品的地方用空格代替)

result:合成台的产出,可以设定数量

show_notification:解锁配方后的右上角提示

木棍配方:

复制代码
{
  "type": "minecraft:crafting_shaped",
  "category": "misc",
  "group": "sticks",
  "key": {
    "#": {
      "tag": "minecraft:planks"
    }
  },
  "pattern": [
    "#",
    "#"
  ],
  "result": {
    "count": 4,
    "item": "minecraft:stick"
  },
  "show_notification": true
}

信标配方:(有序合成)

复制代码
{
  "type": "minecraft:crafting_shaped",
  "category": "misc",
  "key": {
    "G": {
      "item": "minecraft:glass"
    },
    "O": {
      "item": "minecraft:obsidian"
    },
    "S": {
      "item": "minecraft:nether_star"
    }
  },
  "pattern": [
    "GGG",
    "GSG",
    "OOO"
  ],
  "result": {
    "item": "minecraft:beacon"
  },
  "show_notification": true
}

下届合金锭:(无序合成,只用写ingredient)

复制代码
{
  "type": "minecraft:crafting_shapeless",
  "category": "misc",
  "group": "netherite_ingot",
  "ingredients": [
    {
      "item": "minecraft:netherite_scrap"
    },
    {
      "item": "minecraft:netherite_scrap"
    },
    {
      "item": "minecraft:netherite_scrap"
    },
    {
      "item": "minecraft:netherite_scrap"
    },
    {
      "item": "minecraft:gold_ingot"
    },
    {
      "item": "minecraft:gold_ingot"
    },
    {
      "item": "minecraft:gold_ingot"
    },
    {
      "item": "minecraft:gold_ingot"
    }
  ],
  "result": {
    "item": "minecraft:netherite_ingot"
  }
}

熔炉类型的配方:(以烧石头为例,如果type是blasting的话就是高炉,smoking烟熏炉,campfire_cooking篝火)

复制代码
{
  "type": "minecraft:smelting",
  "category": "blocks",
  "cookingtime": 200,
  "experience": 0.1,
  "ingredient": {
    "item": "minecraft:cobblestone"
  },
  "result": "minecraft:stone"
}

熔炉配方在java版MC中没法设置result的数量,这个问题好像还没修复。

锻造模板类型的配方:(以下界合金鞋子为例)

复制代码
{
  "type": "minecraft:smithing_transform",
  "addition": {
    "item": "minecraft:netherite_ingot"
  },
  "base": {
    "item": "minecraft:diamond_boots"
  },
  "result": {
    "item": "minecraft:netherite_boots"
  },
  "template": {
    "item": "minecraft:netherite_upgrade_smithing_template"
  }
}

base是要锻造的物品,addition是添加进来的物品,template是锻造模板

铁砧和附魔台似乎不是用配方这种方式进行工作的

添加模组配方的位置在resources/test_mod/recipes里面

大概写一下

测试结果:

相关推荐
追随者永远是胜利者2 小时前
(LeetCode-Hot100)461. 汉明距离
java·算法·leetcode·职场和发展·go
山岚的运维笔记2 小时前
SQL Server笔记 -- 第70章:临时表的使用
数据库·笔记·sql·microsoft·oracle·sqlserver
人道领域2 小时前
SpringBoot多环境配置实战指南
java·开发语言·spring boot·github
量子-Alex2 小时前
【强化学习】强化学习的数学原理课程笔记第三章 最优贝尔曼公式
笔记
啊阿狸不会拉杆2 小时前
《计算机视觉:模型、学习和推理》第 5 章-正态分布
人工智能·python·学习·算法·机器学习·计算机视觉·正态分布
捷利迅分享2 小时前
Android TV 4分屏独立播放电视应用完整开发方案
java
马猴烧酒.2 小时前
【JAVA算法|hot100】栈类型题目详解笔记
java·笔记
Dragon Wu2 小时前
SpringCloud 多模块下引入独立bom模块的正确架构方案
java·spring boot·后端·spring cloud·架构·springboot
知识分享小能手2 小时前
SQL Server 2019入门学习教程,从入门到精通,SQL Server 2019 安全机制 — 语法知识点及使用方法详解(18)
数据库·学习·sqlserver