跳到主要内容

19可疑的沙子

代码

这里是在原有的基础上增加掉落物

public class ModLootTableModifiers {
...
private static final Identifier SUSPICIOUS_SAND_ID =
new Identifier("minecraft", "archaeology/desert_pyramid");

public static void modifyLootTables() {
...
LootTableEvents.REPLACE.register((resourceManager, lootManager, id, original, source) -> {
if (SUSPICIOUS_SAND_ID.equals(id)) {
// 如果是怀疑的沙子掉落表,在原有的基础上添加金属探测器和煤砖
List<LootPoolEntry> entries = new ArrayList<>(Arrays.asList(original.pools[0].entries));
entries.add(ItemEntry.builder(ModItems.METAL_DETECTOR).build());
entries.add(ItemEntry.builder(ModItems.COAL_BRIQUETTE).build());
LootPool.Builder pool = LootPool.builder().with(entries);
return LootTable.builder().pool(pool).build();
}
return original;
});
}
}

效果

用刷子刷可疑的沙子时,会掉落金属探测器等物品

image-20240824223946114