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.

When you are done you should go back to the tutorials list here.

9 opmerkingen:

  1. I did everything correctly, But It gave me a black screen.

    BeantwoordenVerwijderen
  2. "The square on the top left is index 0. One to the left is 1, the one below 0 is 16 etc.
    The next"

    you meant one to the right didnt you? Dont want to bitch just asking because it confused me

    BeantwoordenVerwijderen
  3. Eclipse doesn't give any errors, but MC crashes upon startup :/

    Something has happened though, and it is in my main mod file, where I have GameRegistry.registerBlock(tutblock);
    Eclipse has put a line through 'registerBlock' and if I hover over it it says @Deprecated.
    Any ideas?

    BeantwoordenVerwijderen
    Reacties
    1. MC might be crashing because the texture might not be loaded properly (Make sure you have the correct slashes, file path, file extension, etc). The strikeout on registerBlock is because the method changed a bit. Check out Wuppy's "Updating to 1.4.6" tutorial.

      Verwijderen
    2. Thanks, I've got rid of the strikeout. MC still crashes, and the errors look like its something to do with the proxy. Will go and double check I have done that correctly ;)

      Verwijderen
  4. Deze reactie is verwijderd door de auteur.

    BeantwoordenVerwijderen
  5. It said the texture is not preloaded when i test it. Help!

    BeantwoordenVerwijderen
  6. ROBLOX is driven by a growing player base of over 300,000 creators who generate an infinite variety of highly immersive experiences.

    These experiences range from 3D games and contests, to interactive adventures where players can take on new personas discovering what it's like to be a dinosaur, a miner working a mine or an astronaut on a space exploration.

    BeantwoordenVerwijderen