2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.reg;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
|
|
|
import net.minecraft.block.Block;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
|
|
|
import net.minecraft.item.ItemGroup;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.item.Item;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.item.BlockItem;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.potion.Effect;
|
2018-10-13 20:35:18 +02:00
|
|
|
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<>();
|
|
|
|
|
2018-11-29 17:58:47 +01:00
|
|
|
public static void add(IModItem item) {
|
2018-10-13 20:35:18 +02:00
|
|
|
ALL_ITEMS.add(item);
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private static void registerPotion(Effect potion, String name) {
|
2018-11-29 17:58:47 +01:00
|
|
|
potion.setPotionName("potion." + NaturesAura.MOD_ID + "." + name + ".name");
|
|
|
|
|
|
|
|
potion.setRegistryName(NaturesAura.MOD_ID, name);
|
|
|
|
ForgeRegistries.POTIONS.register(potion);
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private static void registerItem(Item item, String name, ItemGroup tab) {
|
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-29 17:58:47 +01:00
|
|
|
item.setCreativeTab(tab);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private static void registerBlock(Block block, String name, BlockItem item, ItemGroup tab) {
|
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);
|
|
|
|
|
2018-11-23 17:11:35 +01:00
|
|
|
if (item != null) {
|
|
|
|
item.setRegistryName(block.getRegistryName());
|
|
|
|
ForgeRegistries.ITEMS.register(item);
|
|
|
|
}
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2018-11-29 18:02:45 +01:00
|
|
|
block.setCreativeTab(tab);
|
2018-11-29 17:58:47 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private static ItemGroup getTab(IModItem item) {
|
2018-11-29 17:58:47 +01:00
|
|
|
if (item instanceof ICreativeItem)
|
|
|
|
return ((ICreativeItem) item).getTabToAdd();
|
|
|
|
return null;
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void preInit(FMLPreInitializationEvent event) {
|
|
|
|
for (IModItem item : ALL_ITEMS) {
|
2018-11-29 17:58:47 +01:00
|
|
|
if (item instanceof Item) {
|
|
|
|
registerItem((Item) item, item.getBaseName(), getTab(item));
|
|
|
|
} else if (item instanceof Block) {
|
2018-10-13 20:35:18 +02:00
|
|
|
Block block = (Block) item;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockItem 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
|
2019-10-20 22:30:49 +02:00
|
|
|
itemBlock = new BlockItem(block);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2018-11-29 17:58:47 +01:00
|
|
|
registerBlock(block, item.getBaseName(), itemBlock, getTab(item));
|
2019-10-20 22:30:49 +02:00
|
|
|
} else if (item instanceof Effect)
|
|
|
|
registerPotion((Effect) item, item.getBaseName());
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|