Skip to main content
Version: 1.20.x

全局战利品修改器生成

可以通过子类化GlobalLootModifierProvider并实现#start来为模组生成全局战利品修改器(GLM)。每个GLM都可以通过调用#add并指定要序列化的修改器和修改器实例的名称来添加生成。实现后,该提供者必须被添加DataGenerator中。

// 在模组事件总线上
@SubscribeEvent
public void gatherData(GatherDataEvent event) {
event.getGenerator().addProvider(
// 告诉生成器仅在生成服务端资源时运行
event.includeServer(),
output -> new MyGlobalLootModifierProvider(output, MOD_ID)
);
}

// 在某个GlobalLootModifierProvider#start中
this.add("example_modifier", new ExampleModifier(
new LootItemCondition[] {
WeatherCheck.weather().setRaining(true).build() // 当下雨时执行
},
"val1",
10,
Items.DIRT
));