|
本帖最后由 InkSoul 于 2023-6-7 10:15 编辑
我当时的实现是这样的:public static final DeferredRegister<Block> MATERIAL_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS,
CT_Main.MOD_ID);
public static final DeferredRegister<Item> MATERIAL_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS,
CT_Main.MOD_ID);
public static void init(final FMLClientSetupEvent event) {
for (var i : MaterialSet.materials) {
for (var ii = 0; ii < i.regBlocks.size(); ii++) {
var iii = ((MaterialBlock) i.regBlocks.get(ii));
i.regBlocks.set(ii, MATERIAL_BLOCKS
.register(iii.getMaterial().regName[0] + "_" + iii.getType().regName, () -> iii).get());
}
for (var ii = 0; ii < i.regItems.size(); ii++) {
var iii = ((MaterialItem) i.regItems.get(ii));
var reg = MATERIAL_ITEMS.register(iii.getMaterial().regName[0] + "_" + iii.getType().regName, () -> iii)
.get();
i.partItems.put((iii).getType(), reg);
i.regItems.set(ii, reg);
}
}
// 获取Mod事件总线
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
// 将物品与方块扔进总线
MATERIAL_ITEMS.register(bus);
MATERIAL_BLOCKS.register(bus);
}
public static List<MaterialSet> materials;
public static Map<Item, MaterialSet> vanilaItemMaterial = new HashMap<Item, MaterialSet>();
public static Map<Tag<Item>, MaterialSet> vanilaTagMaterial = new HashMap<Tag<Item>, MaterialSet>();
// ...
private static MaterialSet register(MaterialSet material){
materials.add(material);
return material;
}
public static final MaterialSet IRON;
public static final MaterialSet GOLD;
static {
IRON = register(
new MaterialSet("Iron", new Settings(0xffffff))
.addPart(PartType.BLOCK, Blocks.IRON_BLOCK)
.addPart(PartType.INGOT, Items.IRON_INGOT)
.addPart(PartType.NUGGET, Items.IRON_NUGGET)
.regPart(PartType.values())
);
GOLD = register(
new MaterialSet("Gold", new Settings(0x0f0f0f))
.addPart(PartType.BLOCK, Blocks.GOLD_BLOCK)
.addPart(PartType.INGOT, Items.GOLD_INGOT)
.addPart(PartType.NUGGET, Items.GOLD_NUGGET)
.regPart(PartType.values())
);
}
反正行不通。
|
|