Modding 1.4.7: Custom Block Textures

In this tutorial I will show you how to add a custom texture to your Block. To do this you will have to make changes to 2 files. The first is the ClientProxy and the second is the Block file. These are the files I will start with.
ClientProxy


package tutorial;

public class ClientProxyTutorial extends CommonProxyTutorial
{
@Override
public void registerRenderThings()
{

}
}


Block


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class BlockTutorialBlock extends Block
{
public BlockTutorialBlock(int id, int texture)
{
super(id, texture, Material.cloth);
this.setCreativeTab(CreativeTabs.tabBlock);
}
}


The first thing that you will have to do is make a 256 by 256 image in an image editor. I suggest using GIMP.
The best file to use for blocks is this one.

This is simply a grid of 16 by 16 pixel blocks.
The square on the top left is index 0. One to the left is 1, the one below 0 is 16 etc.
The next thing you have to do is save it and give it a name. I named it tutorialblocks.png.

Once you have made the image you have to paste it somewhere where Eclipse can find it when it launches Minecraft. To do that you have to go to your mcp folder. In there go to jars and then bin. In there should be the Minecraft.jar. Open it with 7zip or winRar and paste in the image you have just made.
Now you have to add one line of code to your Client Proxy.


MinecraftForgeClient.preloadTexture(“/tutorialblocks.png”);


If you want to have your images in a folder for example tutorialmod it will be like this.


MinecraftForgeClient.preloadTexture(“/tutorialmod/tutorialblocks.png”);


I will not do that for the tutorial, but it is a good idea to do it inside of another folder.
So the whole Client Proxy should now look like this.


package tutorial;

import net.minecraftforge.client.MinecraftForgeClient;

public class ClientProxyTutorial extends CommonProxyTutorial
{
@Override
public void registerRenderThings()
{
MinecraftForgeClient.preloadTexture(“/tutorialblocks.png”);
}
}


Once you have done this you will have to add one method to every single block that needs to have a texture from your custom sprite sheet. The method is the same for everything though. It’s simply this.


public String getTextureFile()
    {
            return “/tutorialblocks.png”;
    }


The thing returned is simply the sprite sheet where it will load the image from.
The whole Block file should now look something like this.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class BlockTutorialBlock extends Block
{
public BlockTutorialBlock(int id, int texture)
{
super(id, texture, Material.cloth);
this.setCreativeTab(CreativeTabs.tabBlock);
}

public String getTextureFile()
    {
            return “/tutorialblocks.png”;
    }
}


You can download the new Block and Proxy file over here.

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