Exemplo n.º 1
0
 public <BLOCK extends Block> BLOCK newBlock(
     String name, Class<BLOCK> cls, Class itemClass, String title) {
   try {
     int id = config.getBlock(name, 4095).getInt();
     Constructor<BLOCK> ctor = cls.getConstructor(int.class);
     BLOCK block = ctor.newInstance(id);
     String qualName = assetKey + ":" + name;
     block.setUnlocalizedName(qualName);
     // block.func_111022_d(qualName.toLowerCase()); // Set default icon name
     // block.func_111022_d(qualName); // Set default icon name
     block.setTextureName(qualName); // Set default icon name
     GameRegistry.registerBlock(block, itemClass);
     if (title != null) {
       LanguageRegistry.addName(block, title);
       if (clientSide) {
         // System.out.printf("%s: BaseMod.newBlock: %s: creative tab = %s\n",
         //	this, block.getUnlocalizedName(), block.getCreativeTabToDisplayOn());
         if (block.getCreativeTabToDisplayOn() == null && !title.startsWith("["))
           block.setCreativeTab(CreativeTabs.tabMisc);
       }
     }
     if (block instanceof IBlock) registeredBlocks.add((IBlock) block);
     return block;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 2
0
 Object createGuiElement(Class cls, EntityPlayer player, World world, int x, int y, int z) {
   try {
     try {
       if (debugGui)
         System.out.printf(
             "BaseMod.createGuiElement: Invoking create method of %s for %s in %s\n",
             cls, player, world);
       return cls.getMethod(
               "create", EntityPlayer.class, World.class, int.class, int.class, int.class)
           .invoke(null, player, world, x, y, z);
     } catch (NoSuchMethodException e) {
       if (debugGui)
         System.out.printf("BaseMod.createGuiElement: Invoking constructor of %s\n", cls);
       return cls.getConstructor(EntityPlayer.class, World.class, int.class, int.class, int.class)
           .newInstance(player, world, x, y, z);
     }
   } catch (Exception e) {
     Throwable cause = e.getCause();
     System.out.printf("BaseMod.createGuiElement: %s: %s\n", e, cause);
     if (cause != null) cause.printStackTrace();
     else e.printStackTrace();
     // throw new RuntimeException(e);
     return null;
   }
 }
Exemplo n.º 3
0
 public <ITEM extends Item> ITEM newItem(String name, Class<ITEM> cls, String title) {
   try {
     int id = config.getItem(name, 31743).getInt();
     Constructor<ITEM> ctor = cls.getConstructor(int.class);
     ITEM item = ctor.newInstance(id);
     String qualName = assetKey + ":" + name;
     item.setUnlocalizedName(qualName);
     // item.func_111206_d(qualName.toLowerCase()); // Set default icon name
     // item.func_111206_d(qualName); // Set default icon name
     item.setTextureName(qualName); // Set default icon name
     LanguageRegistry.addName(item, title);
     if (clientSide) {
       if (item.getCreativeTab() == null) item.setCreativeTab(CreativeTabs.tabMisc);
     }
     // System.out.printf("BaseMod.newItem: %s unlocalizedName = %s title = %s\n",
     //	item, item.getUnlocalizedName(), title);
     return item;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }