2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.reg;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
|
|
|
import net.minecraft.block.Block;
|
2018-10-26 12:03:42 +02:00
|
|
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public final class ModRegistry {
|
|
|
|
|
|
|
|
private static final List<IModItem> ALL_ITEMS = new ArrayList<>();
|
|
|
|
|
|
|
|
public static void addItemOrBlock(IModItem item) {
|
|
|
|
ALL_ITEMS.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void registerItem(Item item, String name, boolean addCreative) {
|
2018-10-13 20:45:32 +02:00
|
|
|
item.setTranslationKey(NaturesAura.MOD_ID + "." + name);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
item.setRegistryName(NaturesAura.MOD_ID, name);
|
|
|
|
ForgeRegistries.ITEMS.register(item);
|
|
|
|
|
2018-11-21 20:36:55 +01:00
|
|
|
if (addCreative)
|
2018-10-13 20:45:32 +02:00
|
|
|
item.setCreativeTab(NaturesAura.CREATIVE_TAB);
|
2018-11-21 20:36:55 +01:00
|
|
|
else
|
2018-10-13 20:45:32 +02:00
|
|
|
item.setCreativeTab(null);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void registerBlock(Block block, String name, ItemBlock item, boolean addCreative) {
|
2018-10-13 20:45:32 +02:00
|
|
|
block.setTranslationKey(NaturesAura.MOD_ID + "." + name);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
block.setRegistryName(NaturesAura.MOD_ID, name);
|
|
|
|
ForgeRegistries.BLOCKS.register(block);
|
|
|
|
|
|
|
|
item.setRegistryName(block.getRegistryName());
|
|
|
|
ForgeRegistries.ITEMS.register(item);
|
|
|
|
|
2018-11-21 20:36:55 +01:00
|
|
|
if (addCreative)
|
2018-10-13 20:45:32 +02:00
|
|
|
block.setCreativeTab(NaturesAura.CREATIVE_TAB);
|
2018-11-21 20:36:55 +01:00
|
|
|
else
|
2018-10-13 20:45:32 +02:00
|
|
|
block.setCreativeTab(null);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void preInit(FMLPreInitializationEvent event) {
|
|
|
|
for (IModItem item : ALL_ITEMS) {
|
2018-11-21 20:36:55 +01:00
|
|
|
if (item instanceof Item)
|
2018-10-13 20:35:18 +02:00
|
|
|
registerItem((Item) item, item.getBaseName(), item.shouldAddCreative());
|
2018-11-21 20:36:55 +01:00
|
|
|
else if (item instanceof Block) {
|
2018-10-13 20:35:18 +02:00
|
|
|
Block block = (Block) item;
|
|
|
|
|
|
|
|
ItemBlock itemBlock;
|
2018-11-21 20:36:55 +01:00
|
|
|
if (item instanceof ICustomItemBlockProvider)
|
2018-10-13 20:35:18 +02:00
|
|
|
itemBlock = ((ICustomItemBlockProvider) item).getItemBlock();
|
2018-11-21 20:36:55 +01:00
|
|
|
else
|
2018-10-13 20:35:18 +02:00
|
|
|
itemBlock = new ItemBlock(block);
|
|
|
|
|
|
|
|
registerBlock(block, item.getBaseName(), itemBlock, item.shouldAddCreative());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item instanceof IModelProvider) {
|
2018-10-26 12:03:42 +02:00
|
|
|
Map<ItemStack, ModelResourceLocation> models = ((IModelProvider) item).getModelLocations();
|
2018-11-21 20:36:55 +01:00
|
|
|
for (ItemStack stack : models.keySet())
|
2018-10-26 12:03:42 +02:00
|
|
|
NaturesAura.proxy.registerRenderer(stack, models.get(stack));
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
item.onPreInit(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void init(FMLInitializationEvent event) {
|
|
|
|
for (IModItem item : ALL_ITEMS) {
|
2018-11-21 20:36:55 +01:00
|
|
|
if (item instanceof IColorProvidingBlock)
|
2018-10-13 20:35:18 +02:00
|
|
|
NaturesAura.proxy.addColorProvidingBlock((IColorProvidingBlock) item);
|
2018-11-21 20:36:55 +01:00
|
|
|
if (item instanceof IColorProvidingItem)
|
2018-10-13 20:35:18 +02:00
|
|
|
NaturesAura.proxy.addColorProvidingItem((IColorProvidingItem) item);
|
2018-11-21 20:36:55 +01:00
|
|
|
if (item instanceof ITESRProvider)
|
|
|
|
NaturesAura.proxy.registerTESR((ITESRProvider) item);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
item.onInit(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void postInit(FMLPostInitializationEvent event) {
|
|
|
|
for (IModItem item : ALL_ITEMS) {
|
|
|
|
item.onPostInit(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|