Modding: Custom textures part 1

In this tutorial I will show you how to give custom textures to your blocks and items. This is a pretty hard part of modding. This is what you will need to start:
The mod file:


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import cpw.mods.fml.common.Mod;
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 
{
public static Block oreblock;

public static Item youritem;

@Init
public void load(FMLInitializationEvent event) 
{
oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);

youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);

LanguageRegistry.addName(youritem, “Your Item”);
}
}


The block file:


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Material;

public class BlockOres extends Block
{
    public BlockOres(int par1, int par2)
    {
        super(par1, par2, Material.rock);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }
}


The item file:


package Tutorial.common;

import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Item;

public class ItemTutorial extends Item
{
    public ItemTutorial(int i)
    {
        super(i);
        maxStackSize = 64;
        this.setTabToDisplayOn(CreativeTabs.tabMaterials);
    }
}


Now to add custom textures you will have to add 1 new package and 2 new files. You also have to edit all of the files you have right now.
First off make a new package in the src folder. I mean the folder above the common one. In there you have to create a package called: modname.client. For this tutorial I will name it Tutorial.client.
Now go to your mod file and add these 3 lines:


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


The whole file should now look like this.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
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 
{
public static Block oreblock;

public static Item youritem;

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

@Init
public void load(FMLInitializationEvent event) 
{
oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);

youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);

LanguageRegistry.addName(youritem, “Your Item”);

proxy.registerRenderThings();
}
}


I will now explain what this means.


@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)


clientSide is the client part of the code.
“Tutorial.client.ClientProxyTutorial” is a string (‘words’ in java) that is the location of the client sided code. This should be the name of the package and the file it needs to start.
serverSide is the server part of the code.
“Tutorial.common.CommonProxyTutorial” is a string that is the location of the general code. This is used on the client and the server. This should be the name of the package and the file it needs to start.
@SidedProxy is the file where all this get processed.


 public static CommonProxyTutorial proxy;


proxy is an object of the CommonProxyTutorial file. With this you can acces functions from inside of that class.


 proxy.registerRenderThings();


registerRenderThings() is a method you are going to create in the class that the proxy is an object from. So there will be a registerRenderThings() method in the CommonProxyTutorial class.

In the next part I will show you how to make the Proxy files.

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="">