我们本次对击杀怪物掉落战利品进行设置
1.在 util.handler 包中新建 LootTableHandler 类
在LootTableHandler.java中进行编辑:
package com.Joy187.newmod.util.handlers;
import com.Joy187.newmod.util.Reference;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTableList;
public class LootTableHandler {
//添加你想要产生掉落物的生物
public static final ResourceLocation RA3 = LootTableList.register(new ResourceLocation(Reference.Mod_ID ,"ra3"));
}
2.在 EntityRA3.java (第7讲中创建) 中添加注册表函数
@Override
protected ResourceLocation getLootTable()
{
return LootTableHandler.RA3;
}
3.在resource中新建 loot_table 包 -> 在loot_table包中新建 entities 包
4.打开 战利品制作网站进行掉落物的相关设置:
自定义你的战利品信息
将自动生成的代码全部复制
在loot_table/entities 下新建.json文件,把代码全部放进去
ra3.json代码:
{
"pools": [
{
"name": "main",
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:rotten_flesh",
"weight": 10,
"functions": [
{
"function": "set_count",
"count": {
"min": 0,
"max": 2
}
},
{
"function": "looting_enchant",
"count": {
"min": 0,
"max": 1
}
}
]
},
{
"type": "item",
"weight": 1,
"name": "joymod:labor_shovel",
"functions": [
{
"function": "set_damage",
"damage": {
"min": 17,
"max": 29
}
},
{
"function": "enchant_randomly",
"enchantments": [
"smite",
"knockback"
]
}
]
}
]
},
{
"name": "pool1",
"conditions": [
{
"condition": "killed_by_player"
},
{
"condition": "random_chance_with_looting",
"chance": 0.025,
"looting_multiplier": 0.01
}
],
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:bone",
"weight": 1
},
{
"type": "item",
"name": "minecraft:bread",
"weight": 1
},
{
"type": "item",
"name": "minecraft:flint",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {
"min": 0,
"max": 3
}
},
{
"function": "looting_enchant",
"count": {
"min": 0,
"max": 1
}
}
]
}
]
}
]
}
保存文件 -> 运行游戏
击杀怪物后,怪物掉落腐肉