跳到主要内容

11标签

工具类

/**
* @author houyunfei
*/
public class ModTags {
public static class Blocks {

public static final TagKey<Block> METAL_DETECTOR_DETECTABLE_BLOCKS = createTag("metal_detector_detectable_blocks");

public static TagKey<Block> createTag(String name) {
return TagKey.of(RegistryKeys.BLOCK, Identifier.of(DemoMod1.MOD_ID, name));
}
}

public static class Items {
public static TagKey<Item> createTag(String name) {
return TagKey.of(RegistryKeys.ITEM, Identifier.of(DemoMod1.MOD_ID, name));
}
}

}

修改我们之前金属探测器的代码:

private boolean isValuableBlock(BlockState state) {
// return state.isOf(Blocks.IRON_ORE) || state.isOf(Blocks.DIAMOND_ORE);
return state.isIn(ModTags.Blocks.METAL_DETECTOR_DETECTABLE_BLOCKS);
}

这样就可以使用多个标签了

最后还需要在resource/data/tutorialmod/tags/blocks/metal_detector_detectable_blocks.json中添加:

{
"replace": false,
"values": [
"tutorialmod:ruby_ore",
"#minecraft:gold_ores",
"#minecraft:emerald_ores",
"#minecraft:redstone_ores",
"#minecraft:lapis_ores",
"#minecraft:diamond_ores",
"#minecraft:iron_ores",
"#minecraft:copper_ores",
"#minecraft:coal_ores"
]
}

效果

image-20240824084939951