Minecraft 1.12.2模组开发(十二) 战利品 (loot)

我们本次对击杀怪物掉落战利品进行设置

1.在 util.handler 包中新建 LootTableHandler 类

cr1.png

在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;
    }

cr2.png

3.在resource中新建 loot_table 包 -> 在loot_table包中新建 entities 包

cr3.png

4.打开 战利品制作网站进行掉落物的相关设置:

战利品(掉落物)制作网站

自定义你的战利品信息

cr4.png

将自动生成的代码全部复制

cr5.png

在loot_tables/entities 下新建.json文件,把代码全部放进去

cr6.png

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
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

保存文件 -> 运行游戏

cr7.png

击杀怪物后,怪物掉落腐肉

cr8.png

你可以通过修改json文件中"weight"的大小来增加各种物品的掉率~
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay_fearless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值