Jump to content

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


SoldierW518
 Share

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.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I figured out what was wrong ... you can spot it pretty quick most likely: { "type": "minecraft:smelting", "ingredient": { "item": "minecraft:gold_nugget_ore" }, "result": "minecraft:gold_nugget", "experience": 0.25, "cookingtime": 150 }   ... so, after changing `minecraft` to `foundations` for all the custom items and all the recipes work. Well that's what copy/paste will get you. One last question about recipes, though. What does the following json key/value do in the game? "group": "copper_ingot"  
    • # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # #      102.54.94.97     rhino.acme.com          # source server #       38.25.63.10     x.acme.com              # x client host # localhost name resolution is handled within DNS itself. #    127.0.0.1       localhost #    ::1             localhost ###0.0.0.0 apps.corel.com ###0.0.0.0 mc.corel.com 0.0.0.0 origin-mc.corel.com ###0.0.0.0 iws.corel.com
    • Is there a way to create a custom map marker for a custom structure/biome (same as a vanilla mansion)?
    • I’ve scrounged the Internet for solutions and found absolutely nothing that has worked for me I have posted my code in a GitHub Repository. I bet the culprit is somewhere in the Container or TileEntity classes (Furnace packages are in blocks/coke_furnace or blocks/foundry) PS I know I’m on 1.12.2 and that it’s not supported I don’t want to update my game or my code. Lol It’s my favorite version and the most widely modded. I don’t plan to release the mod, I’m just customizing my game to my will. I’ll send it to friends but that’s it.
    • 1.19.2 With forge 43.2.4   https://mclo.gs/zCAx1MG      
  • Topics

×
×
  • Create New...

Important Information

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