Advertisement
Guest User

Untitled

a guest
Jun 18th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. package com.mightydanp.eot.core.handler;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Set;
  5. import java.util.function.Function;
  6.  
  7. import javax.annotation.Nullable;
  8.  
  9. import com.mightydanp.eot.Eot;
  10. import com.mightydanp.eot.block.ModBlocks;
  11. import com.mightydanp.eot.item.ItemBasicOre;
  12. import com.mightydanp.eot.item.ItemEssenceOre;
  13. import com.mightydanp.eot.item.ItemMagicalStone;
  14. import com.mightydanp.eot.item.ModItems;
  15. import com.mightydanp.eot.lib.BlockStrings;
  16. import com.mightydanp.eot.lib.ItemStrings;
  17. import com.mightydanp.eot.lib.References;
  18.  
  19. import net.minecraftforge.client.model.ModelLoader;
  20. import net.minecraftforge.fml.common.registry.GameRegistry;
  21. import net.minecraft.block.Block;
  22. import net.minecraft.client.Minecraft;
  23. import net.minecraft.client.renderer.block.model.ModelBakery;
  24. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  25. import net.minecraft.creativetab.CreativeTabs;
  26. import net.minecraft.item.Item;
  27. import net.minecraft.item.ItemBlock;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.item.crafting.FurnaceRecipes;
  30. import net.minecraft.util.ResourceLocation;
  31. import net.minecraftforge.oredict.OreDictionary;
  32.  
  33. public class RegistryHandler {
  34.  
  35. public static final Set<Block> BLOCKS = new HashSet<>();
  36.  
  37. public static Item registerItem(Item item, String name) {
  38. GameRegistry.register(item.setRegistryName(name));
  39. return item;
  40. }
  41.  
  42. public static Item registerItemWithState(Item item, String name, int numberOfItemStates, String[] itemItemStates) {
  43. GameRegistry.register(item.setRegistryName(name));
  44. final String blockStates[] = itemItemStates;
  45. for (int i=0; i < numberOfItemStates; i++){
  46. ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation(References.MODID + ":" + name + "_" + itemItemStates[i]));
  47. }
  48. return item;
  49. }
  50.  
  51. public static void renderItem(Item item, String name) {
  52. Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(References.RESOURCESPREFIX + name, "inventory"));
  53. }
  54.  
  55. public static void renderItemWithItemState(Item item, String name, int meta, String[] file) {
  56. Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(References.RESOURCESPREFIX + name + "_" + file, "inventory"));
  57. }
  58.  
  59. public static Block registerBlock(Block block, String name, CreativeTabs tab) {
  60. GameRegistry.register(block, new ResourceLocation(name, name));
  61. return block;
  62. }
  63.  
  64. protected static <BLOCK extends Block> BLOCK registerBlock(BLOCK block, @Nullable Function<BLOCK, ItemBlock> itemFactory) {
  65. GameRegistry.register(block);
  66.  
  67. if (itemFactory != null) {
  68. final ItemBlock itemBlock = itemFactory.apply(block);
  69.  
  70. GameRegistry.register(itemBlock.setRegistryName(block.getRegistryName()));
  71. }
  72.  
  73. BLOCKS.add(block);
  74. return block;
  75. }
  76. public static void renderBlock(Block block, String name) {
  77. Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(References.RESOURCESPREFIX + name.substring(5), "inventory"));
  78. }
  79.  
  80. public static <BLOCK extends Block> BLOCK registerBlockState(BLOCK block, String name, @Nullable Function<BLOCK, ItemBlock> itemFactory, int numberOfBlockStates, String[] blockBlockStates) {
  81. GameRegistry.register(block, new ResourceLocation(name, name));
  82. if (itemFactory != null) {
  83. final ItemBlock itemBlock = itemFactory.apply(block);
  84.  
  85. GameRegistry.register(itemBlock.setRegistryName(block.getRegistryName()));
  86. }
  87.  
  88. final String blockStates[] = blockBlockStates;
  89. for (int i=0; i < numberOfBlockStates; i++){
  90. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), i, new ModelResourceLocation(References.MODID + ":" + name + "_" + blockStates[i]));
  91. }
  92. BLOCKS.add(block);
  93. return block;
  94. }
  95.  
  96. public static void renderBlockWithBlockState(Block block, String name, int meta, String[] file){
  97. Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), meta, new ModelResourceLocation(References.RESOURCESPREFIX + name.substring(5) + file, "inventory"));
  98. }
  99.  
  100. public static void registerOreDictionaryforBlock(Block block, String name) {
  101. OreDictionary.registerOre(block.getUnlocalizedName(), block);
  102. }
  103.  
  104. public static void registerOreDictionaryforItem(Item item, String name) {
  105. OreDictionary.registerOre(name, item);
  106. }
  107.  
  108. public static void registerOreDictionaryforMetadataBlock(Block Block, int meta, String name) {
  109. OreDictionary.registerOre(name, new ItemStack(Block, 1, meta));
  110. }
  111.  
  112. public static void registerOreDictionaryforMetadataItem(Item Item, int meta, String name) {
  113. OreDictionary.registerOre(name, new ItemStack(Item, 1, meta));
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement