Modding: Custom crop part 1: Basic Block

In this tutorial I will show you how to create your own crops. We will start coding in the mod file. I will start with this file.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.EnumToolMaterial;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.DungeonHooks;
import net.minecraftforge.common.EnumHelper;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
//blocks
public static Block oreblock;

public static int oreblockId = 230;

//items
public static Item youritem;
public static Item yourfood;
public static Item yoursword;
public static Item yourpick;
public static Item yourshovel;

//proxy
@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
    public static CommonProxyTutorial proxy;

//enums
static EnumToolMaterial yourtoolmaterial = EnumHelper.addToolMaterial(“yourmaterial”, 2, 500, 7F, 2, 14);

@Init
public void load(FMLInitializationEvent event)
{
//proxy
proxy.registerRenderThings();

//blocks
oreblock = new BlockOres(oreblockId, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

//metadata register
Item.itemsList[oreblockId] = new ItemBlockOres(oreblockId-256, oreblock).setItemName(“oreblock”);

//block names
LanguageRegistry.instance().addStringLocalization(“tile.oreblock.ore.name”, “Your Ore”);
LanguageRegistry.instance().addStringLocalization(“tile.oreblock.netherore.name”, “Your Nether Ore”);

//items
youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);
yourfood = new ItemTutorialFood(551, 8, true).setIconIndex(3).setItemName(“yourfood”);
yoursword = new ItemYourSword(552, yourtoolmaterial).setIconIndex(4).setItemName(“yoursword”);
yourpick = new ItemYourPick(553, yourtoolmaterial).setIconIndex(5).setItemName(“yourpick”);
yourshovel = new ItemYourShovel(554, yourtoolmaterial).setIconIndex(6).setItemName(“yourshovel”);

//item names
LanguageRegistry.addName(youritem, “Your Item”);
LanguageRegistry.addName(yourfood, “Your Food”);
LanguageRegistry.addName(yoursword, “Your Sword”);
LanguageRegistry.addName(yourpick, “Your Pickaxe”);
LanguageRegistry.addName(yourshovel, “Your Shovel”);

//dungeon
DungeonHooks.addDungeonLoot(new ItemStack(youritem), 10, 2, 5);
DungeonHooks.setDungeonLootTries(50);

//game registry
GameRegistry.registerFuelHandler(new TutorialFuel());
GameRegistry.registerWorldGenerator(new WorldgeneratorTutorial());

//recipes
GameRegistry.addRecipe(new ItemStack(yoursword), new Object[]
{
“X”, “X”, “Z”, ‘X’, youritem, ‘Z’, Item.stick
});
GameRegistry.addRecipe(new ItemStack(yourpick), new Object[]
{
“XXX”, ” Z “, ” Z “, ‘X’, youritem, ‘Z’, Item.stick
});
GameRegistry.addRecipe(new ItemStack(yourshovel), new Object[]
{
“X”, “Z”, “Z”, ‘X’, youritem, ‘Z’, Item.stick
});
}
}


To add a new crop you will have to add your own basic block first. You should use code like this.


public static Block cropblock;

cropblock = new BlockCropTutorial(231, 1).setStepSound(Block.soundGrassFootstep).setHardness(0.0F).setBlockName(“cropblock”);

GameRegistry.registerBlock(cropblock);

LanguageRegistry.addName(cropblock, “Custom Crop”);


This is just the basic code for any other block. The sound when you walk through this block is like with grass. The hardness of this block is 0.0F meaning that it can be destroyed instantly.
The whole file should now look like this.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.EnumToolMaterial;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.DungeonHooks;
import net.minecraftforge.common.EnumHelper;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
//blocks
public static Block oreblock;
public static Block cropblock;

public static int oreblockId = 230;

//items
public static Item youritem;
public static Item yourfood;
public static Item yoursword;
public static Item yourpick;
public static Item yourshovel;

//proxy
@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
    public static CommonProxyTutorial proxy;

//enums
static EnumToolMaterial yourtoolmaterial = EnumHelper.addToolMaterial(“yourmaterial”, 2, 500, 7F, 2, 14);

@Init
public void load(FMLInitializationEvent event)
{
//proxy
proxy.registerRenderThings();

//blocks
oreblock = new BlockOres(oreblockId, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);
cropblock = new BlockCropTutorial(231, 1).setStepSound(Block.soundGrassFootstep).setHardness(0.0F).setBlockName(“cropblock”);

GameRegistry.registerBlock(cropblock);

//metadata register
Item.itemsList[oreblockId] = new ItemBlockOres(oreblockId-256, oreblock).setItemName(“oreblock”);

//block names
LanguageRegistry.instance().addStringLocalization(“tile.oreblock.ore.name”, “Your Ore”);
LanguageRegistry.instance().addStringLocalization(“tile.oreblock.netherore.name”, “Your Nether Ore”);
LanguageRegistry.addName(cropblock, “Custom Crop”);

//items
youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);
yourfood = new ItemTutorialFood(551, 8, true).setIconIndex(3).setItemName(“yourfood”);
yoursword = new ItemYourSword(552, yourtoolmaterial).setIconIndex(4).setItemName(“yoursword”);
yourpick = new ItemYourPick(553, yourtoolmaterial).setIconIndex(5).setItemName(“yourpick”);
yourshovel = new ItemYourShovel(554, yourtoolmaterial).setIconIndex(6).setItemName(“yourshovel”);

//item names
LanguageRegistry.addName(youritem, “Your Item”);
LanguageRegistry.addName(yourfood, “Your Food”);
LanguageRegistry.addName(yoursword, “Your Sword”);
LanguageRegistry.addName(yourpick, “Your Pickaxe”);
LanguageRegistry.addName(yourshovel, “Your Shovel”);

//dungeon
DungeonHooks.addDungeonLoot(new ItemStack(youritem), 10, 2, 5);
DungeonHooks.setDungeonLootTries(50);

//game registry
GameRegistry.registerFuelHandler(new TutorialFuel());
GameRegistry.registerWorldGenerator(new WorldgeneratorTutorial());

//recipes
GameRegistry.addRecipe(new ItemStack(yoursword), new Object[]
{
“X”, “X”, “Z”, ‘X’, youritem, ‘Z’, Item.stick
});
GameRegistry.addRecipe(new ItemStack(yourpick), new Object[]
{
“XXX”, ” Z “, ” Z “, ‘X’, youritem, ‘Z’, Item.stick
});
GameRegistry.addRecipe(new ItemStack(yourshovel), new Object[]
{
“X”, “Z”, “Z”, ‘X’, youritem, ‘Z’, Item.stick
});
}
}


 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">