SerriniaCorp

[1.5.1]Minecraft Forge Custom Crops & Food

May 31st, 2013
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This should be in your Mod main class under the @Init method.
  2. //Note that public static Block/Item should be in your @Instance method.
  3.         public static Block Rubarb;
  4.             Rubarb = (new Rubarb(448)).setUnlocalizedName("Rubarb");
  5.             GameRegistry.registerBlock(Rubarb, "Rubarb");
  6.             LanguageRegistry.addName(Rubarb, "Rubarb");
  7.  
  8. //Edit name,ID,the BlockId's to whatever your want.
  9.  
  10.         public static Item rubarb;
  11.             rubarb = (new ItemSeedFood(452, 4, 0.3F, Rubarb.blockID, Block.tilledField.blockID)).setUnlocalizedName("mystique:Rubarb");
  12.             GameRegistry.registerItem(rubarb, "rubarb");
  13.             LanguageRegistry.addName(rubarb, "Rubarb");
  14.  
  15. //Here is the Block class for the crop.
  16. //Change package and names to what fits your mod.Also change or add imports if needed!
  17.  
  18. package erikstutorials;
  19.  
  20. import net.minecraft.block.BlockCrops;
  21. import net.minecraft.client.renderer.texture.IconRegister;
  22. import net.minecraft.item.Item;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.util.Icon;
  25. import net.minecraft.world.World;
  26. import cpw.mods.fml.relauncher.Side;
  27. import cpw.mods.fml.relauncher.SideOnly;
  28.  
  29. public class Rubarb extends BlockCrops
  30. {
  31.     @SideOnly(Side.CLIENT)
  32.     private Icon[] iconArray;
  33.  
  34.     public Rubarb(int par1)
  35.     {
  36.         super(par1);
  37.     }
  38.  
  39.     @SideOnly(Side.CLIENT)
  40.  
  41.     /**
  42.      * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
  43.      */
  44.     public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
  45.     {
  46.         if (par2 < 7)
  47.         {
  48.             if (par2 == 6)
  49.             {
  50.                 par2 = 5;
  51.             }
  52.  
  53.             return this.iconArray[par2 >> 1];
  54.         }
  55.         else
  56.         {
  57.             return this.iconArray[3];
  58.         }
  59.     }
  60.  
  61.     /**
  62.      * Generate a seed ItemStack for this crop.
  63.      */
  64.     protected int getSeedItem()
  65.     {
  66.         return Mod_Main.rubarb.itemID;
  67.     }
  68.  
  69.     /**
  70.      * Generate a crop produce ItemStack for this crop.
  71.      */
  72.     protected int getCropItem()
  73.     {
  74.         return Mod_Main.rubarb.itemID;
  75.     }
  76.  
  77.     @SideOnly(Side.CLIENT)
  78.  
  79.     /**
  80.      * When this method is called, your block should register all the icons it needs with the given IconRegister. This
  81.      * is the only chance you get to register icons.
  82.      */
  83.     public void registerIcons(IconRegister par1IconRegister)
  84.     {
  85.         this.iconArray = new Icon[4];
  86.  
  87.         for (int i = 0; i < this.iconArray.length; ++i)
  88.         {
  89.             this.iconArray[i] = par1IconRegister.registerIcon("carrots_" + i);
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment