Jump to content

[Solved] Metadata Blocks not registering the names and textures correctly.


SoldierW518

Recommended Posts

I've been working on my new mod More Tools and I've ran into a bump. Whenever I make a Block MetaData Value the Block names aren't registered and the textures aren't all registered. The only thing I get in the console is what I entered in which is that there was an Invalid metadata for fortile.advancedWoodPlanks.

 

moretools.java

package soldierw518.moretools;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;



@Mod(modid = moretools.mod_id, name = moretools.mod_name, version = moretools.mod_version)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class moretools
{
public static final String mod_id = "MoreTools";
public static final String mod_name = "More Tools";
public static final String mod_version = "Alpha 1.4 (Build #005)";

public static Block advancedWoodPlanks;

@PreInit
public void load(FMLPreInitializationEvent event)
{

}

@Init
public void load(FMLInitializationEvent event)
{
	advancedWoodPlanks = new BlockAdvancedWoodPlanks(4000, Material.wood).setUnlocalizedName("advancedWoodPlanks");
	GameRegistry.registerBlock(advancedWoodPlanks, ItemAdvancedWoodPlanks.class, mod_id + (advancedWoodPlanks.getUnlocalizedName().substring(5)));

	LanguageRegistry.addName(new ItemStack(advancedWoodPlanks, 1, 0), "Advanced Oak Wooden Planks");
	LanguageRegistry.addName(new ItemStack(advancedWoodPlanks, 1, 1), "Advanced Spruce Wooden Planks");
	LanguageRegistry.addName(new ItemStack(advancedWoodPlanks, 1, 2), "Advanced Birch Wooden Planks");
	LanguageRegistry.addName(new ItemStack(advancedWoodPlanks, 1, 3), "Advanced Jungle Wooden Planks");
}

@PostInit
public void load(FMLPostInitializationEvent event)
{

}
}

Blocks.java

package soldierw518.moretools;

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

public void registerIcons(IconRegister par1IconRegister)
{
	this.blockIcon = par1IconRegister.registerIcon(moretools.mod_id + ":" + (this.getUnlocalizedName().substring(5)));
}
}

BlockAdvancedWoodPlanks.java

package soldierw518.moretools;

import java.util.List;

import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;


public class BlockAdvancedWoodPlanks extends Blocks
{
public BlockAdvancedWoodPlanks(int id, Material par2Material)
{
	super(id, par2Material);
}

@SideOnly(Side.CLIENT)
private Icon[] icons;

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
	icons = new Icon[4];

	for(int i = 0; i < icons.length; i++)
	{
		icons[i] = par1IconRegister.registerIcon(moretools.mod_id + ":" + (this.getUnlocalizedName().substring(5)) + i);
	}
}

@SideOnly(Side.CLIENT)
public Icon getIcon(int par1, int par2)
{
	switch(par2)
	{
		case 0:
				return icons[0];
		case 1:
		{
			switch (par1)
			{
				case 0:
						return icons[1];
				case 1:
						return icons[2];
				default:
						return icons[3];
			}
		}
		default:
		{
			System.out.println("Invalid metadata for" + this.getUnlocalizedName());
			return icons[0];
		}
	}
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
	for(int j = 0; j < icons.length; j++)
	{
		par3List.add(new ItemStack(par1, 1, j));
	}
}
}

ItemAdvancedWoodPlanks.java

package soldierw518.moretools;

import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;



public class ItemAdvancedWoodPlanks extends ItemBlock
{
public ItemAdvancedWoodPlanks(int par1)
{
	super(par1);
	setHasSubtypes(true);
}

public String getUnlocalizedName(ItemStack itemstack)
{
	String name = "";
	switch(itemstack.getItemDamage())
	{
		case 0:
		{
			name = "world";
				break;
		}
		case 1:
		{
			name = "nether";
			break;
		}
		default: name = "broken";
	}
	return getUnlocalizedName() + "." + name;
}

public int getMetadata(int par1)
{
	return par1;
}
}

 

Any help would be greatly appreciated.

 

Thank you very much for Reading,

 

- Justin (SoldierW518)

Link to comment
Share on other sites

hello it seems that your Block class is wrong cant tell where but here is my working code that you can take a look at:

 

    @SideOnly(Side.CLIENT)
    private Icon[] iconArray;
    
    public Icon getIcon(int par1, int par2)
    {
        return this.iconArray[par2 % this.iconArray.length];
    }
    
    public int damageDropped(int par1)
    {
        return par1;
    }
    @SuppressWarnings("unchecked")
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, @SuppressWarnings("rawtypes") List par3List)
    {
        for (int var4 = 0; var4 < 15; ++var4)
        {
            par3List.add(new ItemStack(par1, 1, var4));
        }
    }
   @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister par1IconRegister)
    {
        this.iconArray = new Icon[16];

        for (int i = 0; i < this.iconArray.length; ++i)
        {
            this.iconArray[i] = par1IconRegister.registerIcon(Reference.MOD_ID + ":" + this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".")+1)+ i);
      

 

ofc you need to change 15 to 3 in my var4

Link to comment
Share on other sites

Thank you very much for the reply but this still didn't solve my problem now the textures load and everything but now my the block with the id of 4000:2 isn't even listed in the creative tabs and the blocks with the id of 4000:2 and 4000:3 still have the same name.

 

Here is my improved code based off of yours:

package soldierw518.moretools;

import java.util.List;

import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;


public class BlockAdvancedWoodPlanks extends Blocks
{
public BlockAdvancedWoodPlanks(int id, Material par2Material)
{
	super(id, par2Material);
}

@SideOnly(Side.CLIENT)
private Icon[] iconArray;

public Icon getIcon(int par1, int par2)
{
	return this.iconArray[par2 % this.iconArray.length];
}

public int damageDropped(int par1)
{
	return par1;
}

@SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, @SuppressWarnings("rawtypes") List par3List)
{
	for(int var4 = 0; var4 < 3; ++var4)
	{
		par3List.add(new ItemStack(par1, 1, var4));
	}
}

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
	this.iconArray = new Icon[4];

	for(int i = 0; i < this.iconArray.length; ++i)
	{
		this.iconArray[i] = par1IconRegister.registerIcon(moretools.mod_id + ":" + this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".")+1) + i);
	}
}
}

 

Thank you very much for reading,

 

- Justin (SoldierW518)

Link to comment
Share on other sites

Thank you very much for the reply but this still didn't solve my problem now the textures load and everything but now my the block with the id of 4000:2 isn't even listed in the creative tabs and the blocks with the id of 4000:2 and 4000:3 still have the same name.

 

Here is my improved code based off of yours:

package soldierw518.moretools;

import java.util.List;

import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;


public class BlockAdvancedWoodPlanks extends Blocks
{
public BlockAdvancedWoodPlanks(int id, Material par2Material)
{
	super(id, par2Material);
}

@SideOnly(Side.CLIENT)
private Icon[] iconArray;

public Icon getIcon(int par1, int par2)
{
	return this.iconArray[par2 % this.iconArray.length];
}

public int damageDropped(int par1)
{
	return par1;
}

@SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, @SuppressWarnings("rawtypes") List par3List)
{
	for(int var4 = 0; var4 < 3; ++var4)
	{
		par3List.add(new ItemStack(par1, 1, var4));
	}
}

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
	this.iconArray = new Icon[4];

	for(int i = 0; i < this.iconArray.length; ++i)
	{
		this.iconArray[i] = par1IconRegister.registerIcon(moretools.mod_id + ":" + this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".")+1) + i);
	}
}
}

 

Thank you very much for reading,

 

- Justin (SoldierW518)

 

where you do super(id, par2Material); just add:

this.setCreativetab([your tab]

Link to comment
Share on other sites

I added that in my Blocks.java class which the BlockAdvancedWoodPlanks.java class extends. So, it does show 3 of the 4 that I made. So far it shows 4000:0, 4000:1, 4000:2, but just not 4000:3. And 4000:2 and 4000:3 show the same name which is what 4000:3 is suppose to be.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.