Modding 1.5.1: Custom Block Texture

In this tutorial I will show you how to add custom textures to your block. All of the code for this tutorial is done in the Block file. This is the file I will start with.

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, Material par2Material)
       {
             super(id, par2Material);
             this.setCreativeTab(CreativeTabs.tabBlock);
       }
}

The first thing you will have to do before you can add the texture to the block is to actually make the texture and make sure it is saved correctly etc.
To do this you will have to make a 16x16 sprite for the Block. I'm not going into detail about this, because I'm no artist. However, I use GIMP to make the textures I use.
The next part is saving the file. I know much more about that, so this is what you will have to do. For a block you need to make sure that the name for the file is your unlocalized block name.png.
Then there is also the part where you need to make sure that it is in the right folder. In the newest versions of Forge for 1.5.1 Forge will load the images for you. You don't have to add any code for that like you used to in earlier versions. However, because this is automated you also have to follow a couple of rules for the folder structure where you will have to save the images. This structure goes like this.
mods/[modid]/textures/blocks/Image.png
If you follow these rules you should be able to assign a texture to your block quite easily.

Now to get those textures to load in MCP you will have to open the forge folder where you have mcp installed in. Then enter the mcp folder and then the jars folder in there. When you are there you should be able to find the Minecraft.jar. In here you will have to paste the complete folder structure.
When you have done that your textures will be loaded in for you by Forge. The next part is to actually use them in your blocks. To do this you will have to add this one simple method.

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
    {
        this.blockIcon = par1IconRegister.registerIcon(Tutorial.modid + ":" + this.getUnlocalizedName2());
    }

The only thing you have to change in here is Tutorial into whatever your mod file name is. Then your textures should load just fine in the game.
The whole file should now look like this.

package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;

public class BlockTutorialBlock extends Block
{
       public BlockTutorialBlock(int id, Material par2Material)
       {
             super(id, par2Material);
             this.setCreativeTab(CreativeTabs.tabBlock);
       }
      @SideOnly(Side.CLIENT)
       public void registerIcons(IconRegister par1IconRegister)
    {
        this.blockIcon = par1IconRegister.registerIcon(Tutorial.modid + ":" + this.getUnlocalizedName2());
    }
}

This method simply sets the blockIcon which is the Icon used to render the block to an Image located in the folder structure you made earlier. par1IconRegister.registerIcon is the method that loads this image.
In the next Block tutorials there will be more customization for the blocks.

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

18 opmerkingen:

  1. I am having problems with locating where to find the folder to save the texture at, Suggestions?

    BeantwoordenVerwijderen
    Reacties
    1. your mcp folder... src/minecraft/mods/YOURNAME/textures/blocks
      or: /items

      perhaps you have to create the mods folder

      Verwijderen
  2. Deze reactie is verwijderd door de auteur.

    BeantwoordenVerwijderen
  3. Deze reactie is verwijderd door de auteur.

    BeantwoordenVerwijderen
  4. in your mcp folder. go to src, insite that make a folder called mods, insite that make a folder named your mods name (ex. buildcraft) insite that folder make a folder called textures. insite that folder make two folders, one called blocks (with little b), and one called items (with little i). insite those you put your pictures. the pictures names need to be the exactly the same as the code says (ex. if i got a block called testblock, then i need to call the picture testblock.png (remember to make it in png format). the path will be. YOUR_MCP/src/mods/MODNAME/blocks/YOURBLOCKNAME.png or YOUR_MCP/src/mods/MODNAME/items/YOURITEMNAME.png

    BeantwoordenVerwijderen
  5. and if that does not work, open your minecraft.jar and add the files there instead:

    1. download a archive program (such as winrar or 7zip etc.)
    2. go to your mcp folder
    3. go into the folder called jars
    4. open the folder called bin
    5. in there open the file called minecraft.jar with the archive program
    6. put the mods folder in there instead

    BeantwoordenVerwijderen
  6. i have the folder in the right place and its still missing the texture

    BeantwoordenVerwijderen
    Reacties
    1. In 1.5.2 try changing the name of the texture to have a 'tile.' before the rest, like how for items your write: item.itemname. Hope that fixes your problem

      Verwijderen
  7. I am making a block similar to the furnace, that needs multiple faces. Will MCP assign them automatically or do I have to do something extra?

    BeantwoordenVerwijderen
    Reacties
    1. You will have to use a method that is (in newer versions of forge) called setIcon(int, int) one of the parameters is the side (I think first) and the other is the metadata.

      Verwijderen
  8. I got the folder working for real!
    it's MCP/src/minecraft/mods/YOURMODID/textures/blocks/NAME.png
    And with items just change blocks to items.

    After you have made this folder, you see a package called mods.YOURMODID.textures.blocks in your src folder in eclipse. You can put all the stuff there in eclipse and it still works. Hope this helped :)

    BeantwoordenVerwijderen
  9. i don't know why but minecraft don't want to load my icons :( i have this error in the console :

    [WARNING] [Minecraft-Client] TextureManager.createTexture called for file textures/blocks/mariolucky:tutorialBlock.png, but that file does not exist. Ignoring.

    my modid is mariolucky and my unlocalized block name is tutorialBlock. i put a texture in the mcp/src/minecraft/mods/mariolucky/textures/blocks folder, and i called it tutorialBlock.png. Can someone help me please !

    BeantwoordenVerwijderen
    Reacties
    1. Check the forge update tutorial. There have been some method name changes that break this tutorial.

      Verwijderen
  10. So I'm having a problem, I've made sure the names are right for my textures but when I go to run the project it only loads the first blocks texture. Any ideas? Thanks

    BeantwoordenVerwijderen
    Reacties
    1. Nevermind, I forgot to copy the file back into the minecraft.jar/mods folder.

      Verwijderen
    2. That didn't fix the error, but when I looked at the console and it showed the texture path, I saw that it said tile.crystalBlock.png. So I renamed it that with the 'tile.' and it worked.

      Verwijderen
  11. ROBLOX is driven by a growing community of over 300,000 creators who generate an infinite variety of highly immersive experiences.

    These experiences range from 3D games and competitions, to interactive adventures where players can take on new avatars to explore what it's like to be a dinosaur, a miner working a mine or an astronaut out in space.

    BeantwoordenVerwijderen