Advertisement
Nuparu00

RegisterUtil

Apr 28th, 2018
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. package com.nuparu.sevendaystomine.util;
  2.  
  3. import com.google.common.collect.ImmutableList;
  4. import com.nuparu.sevendaystomine.init.Blocks;
  5. import com.nuparu.sevendaystomine.init.Items;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  10. import net.minecraft.client.renderer.block.statemap.DefaultStateMapper;
  11. import net.minecraft.client.renderer.block.statemap.StateMapperBase;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemBlock;
  14. import net.minecraftforge.client.model.ModelLoader;
  15. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
  16. import net.minecraftforge.fml.common.registry.GameRegistry;
  17. import net.minecraftforge.fml.relauncher.Side;
  18.  
  19. public class RegisterUtil {
  20.  
  21.     public static void registerAll(FMLPreInitializationEvent event) {
  22.         registerItems(event, Items.IRON_SCRAP, Items.BRASS_SCRAP, Items.LEAD_SCRAP, Items.EMPTY_CAN, Items.STONE_AXE,
  23.                 Items.PLANK_WOOD, Items.SMALL_STONE);
  24.         registerBlocks(event, Blocks.OAK_FRAME, Blocks.BIRCH_FRAME, Blocks.SPRUCE_FRAME, Blocks.JUNGLE_FRAME,
  25.                 Blocks.ACACIA_FRAME, Blocks.DARKOAK_FRAME, Blocks.OAK_PLANKS_REINFORCED, Blocks.BIRCH_PLANKS_REINFORCED,
  26.                 Blocks.SPRUCE_PLANKS_REINFORCED, Blocks.JUNGLE_PLANKS_REINFORCED, Blocks.ACACIA_PLANKS_REINFORCED,
  27.                 Blocks.DARKOAK_PLANKS_REINFORCED, Blocks.OAK_PLANKS_REINFORCED_IRON,
  28.                 Blocks.BIRCH_PLANKS_REINFORCED_IRON, Blocks.SPRUCE_PLANKS_REINFORCED_IRON,
  29.                 Blocks.JUNGLE_PLANKS_REINFORCED_IRON, Blocks.ACACIA_PLANKS_REINFORCED_IRON,
  30.                 Blocks.DARKOAK_PLANKS_REINFORCED_IRON, Blocks.SMALL_STONE);
  31.     }
  32.  
  33.     public static void registerBlocks(FMLPreInitializationEvent event, Block... blocks) {
  34.         for (Block block : blocks) {
  35.             final Item itemBlock = new ItemBlock(block).setRegistryName(block.getRegistryName());
  36.  
  37.             GameRegistry.register(block);
  38.             GameRegistry.register(itemBlock);
  39.             if (event.getSide() == Side.CLIENT) {
  40.                 ImmutableList<IBlockState> values = block.getBlockState().getValidStates();
  41.                 for (IBlockState state : values) {
  42.  
  43.                     StateMapperBase statemapper = new DefaultStateMapper();
  44.                     ModelLoader.setCustomModelResourceLocation(itemBlock, block.getMetaFromState(state),
  45.                             new ModelResourceLocation(block.getRegistryName(),
  46.                                     statemapper.getPropertyString(state.getProperties())));
  47.                 }
  48.             }
  49.         }
  50.     }
  51.  
  52.     public static void registerItems(FMLPreInitializationEvent event, Item... items) {
  53.         for (Item item : items) {
  54.  
  55.             GameRegistry.register(item);
  56.             if (event.getSide() == Side.CLIENT) {
  57.                 ModelLoader.setCustomModelResourceLocation(item, 0,
  58.                         new ModelResourceLocation(item.getRegistryName(), "inventory"));
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement