Can i use metadata with armor? and if so what changes do i make to the code?
for example:
These would be the normal calls in the main mod file for a normal armor set
public static Item armorsimpleHelmet;
public static Item armorsimplePlate;
public static Item armorsimpleLegs;
public static Item armorsimpleBoots;
public static int idsimpleHelmet;
public static int idsimplePlate;
public static int idsimpleLegs;
public static int idsimpleBoots;
@PreInit
public void preInit(FMLPreInitializationEvent event)
{
event.getModMetadata().version = "1.3.2";
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
idsimpleHelmet = Integer.parseInt(config.getOrCreateIntProperty("idsimpleHelmet", Configuration.CATEGORY_ITEM, 4100).value);
idsimplePlate = Integer.parseInt(config.getOrCreateIntProperty("idsimplePlate", Configuration.CATEGORY_ITEM, 4101).value);
idsimpleLegs = Integer.parseInt(config.getOrCreateIntProperty("idsimpleLegs", Configuration.CATEGORY_ITEM, 4102).value);
idsimpleBoots = Integer.parseInt(config.getOrCreateIntProperty("idsimpleBoots", Configuration.CATEGORY_ITEM, 4103).value);
config.save();
}
EnumArmorMaterial armorsimple = EnumHelper.addArmorMaterial("simple", 100, new int[] {1, 4, 4, 2}, 15);
int renderersimple = proxy.addArmor("simpleArmor");
armorsimpleHelmet = new SimpleItemArmor(idsimpleHelmet, armorAdven, renderersimple, 0).setItemName("armorsimpleHelmet").setIconIndex(128);;
armorsimplePlate = new SimpleItemArmor(idsimplePlate, armorAdven, renderersimple, 1).setItemName("armorsimplePlate").setIconIndex(128);;
armorsimpleLegs = new SimpleItemArmor(idsimpleLegs, armorAdven, renderersimple, 2).setItemName("armorsimpleLegs").setIconIndex(130);;
armorsimpleBoots = new SimpleItemArmor(idsimpleBoots, armorAdven, renderersimple, 3).setItemName("armorsimpleBoots").setIconIndex(131);;
LanguageRegistry.addName(armorsimpleHelmet, "simple Helmet");
LanguageRegistry.addName(armorsimplePlate, "simple Chest Plate");
LanguageRegistry.addName(armorsimpleLegs, "simple Greaves");
LanguageRegistry.addName(armorsimpleBoots, "simple Boots");
and this would be the normal Item file
public class SimpleItemArmor extends ItemArmor implements IArmorTextureProvider
{
public SimpleItemArmor(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
{
super(i, enumarmormaterial, j, k);
}
public String getTextureFile()
{
return "/SimpleItems.png";
}
public String getArmorTextureFile(ItemStack itemstack)
{
if(itemstack.itemID == Simple.armorsimpleHelmet.shiftedIndex || itemstack.itemID == Weave.armorsimplePlate.shiftedIndex || itemstack.itemID == Simple.armorsimpleBoots.shiftedIndex)
{
return "/simplearmor_1.png";
}
if(itemstack.itemID == Simple.armorsimpleLegs.shiftedIndex)
{
return "/simplearmor_2.png";
}
return "/simplearmor_1.png";
}
}
now say i wanted to have one for each color. but i wanted them to be the same other than the textures and names...
what would i do to make this happen?
each image file has a name like... "simplearmorblue_1, simplearmorblue_2"
Can i use metadata with armor? and if so what changes do i make to the code?
for example:
These would be the normal calls in the main mod file for a normal armor set
public static Item armorsimpleHelmet;
public static Item armorsimplePlate;
public static Item armorsimpleLegs;
public static Item armorsimpleBoots;
public static int idsimpleHelmet;
public static int idsimplePlate;
public static int idsimpleLegs;
public static int idsimpleBoots;
@PreInit
public void preInit(FMLPreInitializationEvent event)
{
event.getModMetadata().version = "1.3.2";
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
idsimpleHelmet = Integer.parseInt(config.getOrCreateIntProperty("idsimpleHelmet", Configuration.CATEGORY_ITEM, 4100).value);
idsimplePlate = Integer.parseInt(config.getOrCreateIntProperty("idsimplePlate", Configuration.CATEGORY_ITEM, 4101).value);
idsimpleLegs = Integer.parseInt(config.getOrCreateIntProperty("idsimpleLegs", Configuration.CATEGORY_ITEM, 4102).value);
idsimpleBoots = Integer.parseInt(config.getOrCreateIntProperty("idsimpleBoots", Configuration.CATEGORY_ITEM, 4103).value);
config.save();
}
EnumArmorMaterial armorsimple = EnumHelper.addArmorMaterial("simple", 100, new int[] {1, 4, 4, 2}, 15);
int renderersimple = proxy.addArmor("simpleArmor");
armorsimpleHelmet = new SimpleItemArmor(idsimpleHelmet, armorAdven, renderersimple, 0).setItemName("armorsimpleHelmet").setIconIndex(128);;
armorsimplePlate = new SimpleItemArmor(idsimplePlate, armorAdven, renderersimple, 1).setItemName("armorsimplePlate").setIconIndex(128);;
armorsimpleLegs = new SimpleItemArmor(idsimpleLegs, armorAdven, renderersimple, 2).setItemName("armorsimpleLegs").setIconIndex(130);;
armorsimpleBoots = new SimpleItemArmor(idsimpleBoots, armorAdven, renderersimple, 3).setItemName("armorsimpleBoots").setIconIndex(131);;
LanguageRegistry.addName(armorsimpleHelmet, "simple Helmet");
LanguageRegistry.addName(armorsimplePlate, "simple Chest Plate");
LanguageRegistry.addName(armorsimpleLegs, "simple Greaves");
LanguageRegistry.addName(armorsimpleBoots, "simple Boots");
and this would be the normal Item file
public class SimpleItemArmor extends ItemArmor implements IArmorTextureProvider
{
public SimpleItemArmor(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
{
super(i, enumarmormaterial, j, k);
}
public String getTextureFile()
{
return "/SimpleItems.png";
}
public String getArmorTextureFile(ItemStack itemstack)
{
if(itemstack.itemID == Simple.armorsimpleHelmet.shiftedIndex || itemstack.itemID == Weave.armorsimplePlate.shiftedIndex || itemstack.itemID == Simple.armorsimpleBoots.shiftedIndex)
{
return "/simplearmor_1.png";
}
if(itemstack.itemID == Simple.armorsimpleLegs.shiftedIndex)
{
return "/simplearmor_2.png";
}
return "/simplearmor_1.png";
}
}
now say i wanted to have one for each color. but i wanted them to be the same other than the textures and names...
what would i do to make this happen?
each image file has a name like... "simplearmorblue_1, simplearmorblue_2"
I'm not terribly experienced with armour, but it shouldn't be too hard to do metadata. You'll need to use getIconFromDamage and getItemNameIS to start with, but I'm not sure if there is actually a method for metadata with armour textures, I'll check it out
public static int simpleblockId = <number>;
simpleblock = new BlockSimple(simpleblockId, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName("simpleblock");
Item.itemsList[simpleblockId] = new ItemBlockSimple(simpleblockId-256, simpleblock).setItemName("simpleblock");
LanguageRegistry.instance().addStringLocalization("tile.simpleblock.simple.name", "Simple Block");
LanguageRegistry.instance().addStringLocalization("tile.simpleblock.nethersimple.name", "Simple Nether Block");
and
public class BlockSimple extends Block
public BlockSimple(int par1, int par2)
super(par1, par2, Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setRequiresSelfNotify();
public int getBlockTextureFromSideAndMetadata(int par1, int par2)
switch (par2)
case 0:
return 0;
case 1:
return 1;
default:
return 0;
}
}
public String getTextureFile()
{
return "/SimpleTextures.png";
}
public int idDropped(int par1, Random par2Random, int par3)
{
switch(par1)
{
case 0:
return Tutorial.youritem.shiftedIndex;
case 1:
return Tutorial.yourfood.shiftedIndex;
default:
return Tutorial.youritem.shiftedIndex;
}
}
public int quantityDropped(Random par1Random)
{
return par1Random.nextInt(2) + 1;
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int var4 = 0; var4 < 2; ++var4)
{
par3List.add(new ItemStack(par1, 1, var4));
}
}
}
in the block file
then made a ItemBlock file like this
public class ItemBlockSimple extends ItemBlock
{
public ItemBlockSimple(int par1, Block block)
{
super(par1);
setHasSubtypes(true);
}
public String getItemNameIS(ItemStack itemstack)
{
String name = "";
switch(itemstack.getItemDamage())
{
case 0:
{
name = "simple";
break;
}
case 1:
{
name = "nethersimple";
break;
}
default: name = "simple";
}
return getItemName() + "." + name;
}
public int getMetadata(int par1)
{
return par1;
}
}
but in this process i make the "block" into a "item" in a way to hold the data i need...
I don't know how to hold the data i put in the "block" file in the "item" file, nor do i know how to handle the
public SimpleItemArmor(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
{
super(i, enumarmormaterial, j, k);
}
public String getTextureFile()
{
return "/SimpleItems.png";
}
public String getArmorTextureFile(ItemStack itemstack)
{
if(itemstack.itemID == Simple.armorsimpleHelmet.shiftedIndex || itemstack.itemID == Simple.armorsimplePlate.shiftedIndex || itemstack.itemID == Simple.armorsimpleBoots.shiftedIndex)
{
return "/simplearmor_1.png";
}
if(itemstack.itemID == Simple.armorsimpleLegs.shiftedIndex)
{
return "/simplearmor_2.png";
}
return "/simplearmor_1.png";
}
of each "color" all in one file. I assume with if statments....
public static int simpleblockId = <number>;
simpleblock = new BlockSimple(simpleblockId, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName("simpleblock");
Item.itemsList[simpleblockId] = new ItemBlockSimple(simpleblockId-256, simpleblock).setItemName("simpleblock");
LanguageRegistry.instance().addStringLocalization("tile.simpleblock.simple.name", "Simple Block");
LanguageRegistry.instance().addStringLocalization("tile.simpleblock.nethersimple.name", "Simple Nether Block");
and
public class BlockSimple extends Block
public BlockSimple(int par1, int par2)
super(par1, par2, Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setRequiresSelfNotify();
public int getBlockTextureFromSideAndMetadata(int par1, int par2)
switch (par2)
case 0:
return 0;
case 1:
return 1;
default:
return 0;
}
}
public String getTextureFile()
{
return "/SimpleTextures.png";
}
public int idDropped(int par1, Random par2Random, int par3)
{
switch(par1)
{
case 0:
return Tutorial.youritem.shiftedIndex;
case 1:
return Tutorial.yourfood.shiftedIndex;
default:
return Tutorial.youritem.shiftedIndex;
}
}
public int quantityDropped(Random par1Random)
{
return par1Random.nextInt(2) + 1;
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int var4 = 0; var4 < 2; ++var4)
{
par3List.add(new ItemStack(par1, 1, var4));
}
}
}
in the block file
then made a ItemBlock file like this
public class ItemBlockSimple extends ItemBlock
{
public ItemBlockSimple(int par1, Block block)
{
super(par1);
setHasSubtypes(true);
}
public String getItemNameIS(ItemStack itemstack)
{
String name = "";
switch(itemstack.getItemDamage())
{
case 0:
{
name = "simple";
break;
}
case 1:
{
name = "nethersimple";
break;
}
default: name = "simple";
}
return getItemName() + "." + name;
}
public int getMetadata(int par1)
{
return par1;
}
}
but in this process i make the "block" into a "item" in a way to hold the data i need...
I don't know how to hold the data i put in the "block" file in the "item" file, nor do i know how to handle the
public SimpleItemArmor(int i, EnumArmorMaterial enumarmormaterial, int j, int k)
{
super(i, enumarmormaterial, j, k);
}
public String getTextureFile()
{
return "/SimpleItems.png";
}
public String getArmorTextureFile(ItemStack itemstack)
{
if(itemstack.itemID == Simple.armorsimpleHelmet.shiftedIndex || itemstack.itemID == Simple.armorsimplePlate.shiftedIndex || itemstack.itemID == Simple.armorsimpleBoots.shiftedIndex)
{
return "/simplearmor_1.png";
}
if(itemstack.itemID == Simple.armorsimpleLegs.shiftedIndex)
{
return "/simplearmor_2.png";
}
return "/simplearmor_1.png";
}
of each "color" all in one file. I assume with if statments....
Hi thanks for the tutorials, i'm following you.
But i've a question to you: how can i cshare my mods with my friends? When i download a mod(compatible with forge) i put it in mods folder, and it works, how can i make it?
When your mod is in working condition, run the recompile.bat program. Then run reobf.bat. You need to navigate to the folder, and copy your mod's package into a zip file, and don't forget to add the gfx folder
I tried the second tutorial but if i copy the code it give me an error:
public String getItemNameIS(ItemStack i){
try{ //Just in case of NullPointerException
return names[i.getItemDamage()];
}catch(Exception e){
return "";
}
}
near names, i downloaded the source code of the next tutorial and the code is:
public String getItemNameIS(ItemStack i){
switch(i.getItemDamage()){
case 0:return "Sapphire";
case 1:return "Amethyst";
case 2:return "Topaz";
default:return "";
}
}
I used this and it works.
And in this tutorial you forgot to say that you must add:
import net.minecraft.src.ItemStack;
In the main file.
and yes, if you go in FML page there are two download...
Yeah, I know there are issues with the second tutorial, I though I'd changed it... I'll fix it now though
sorry but i could not create this by the way if i'll need to create a new fuel i will not use metadata :|
now i've an other problem, i'm trying to generate new ore (i'm following your tutorial so i'm trying to generate BlockGEM in the world) but when i try it in the console appear this:
Warning: Texture /gfx/Blocks.png not preloaded, will cause render glitches!
Any known bug?
Don't worry, it's nothing, the textures still render fine I think it's just from having the textures in the common package
Great tutorials They are very good and i will have a look at that item meta-data code I like it Anyway can you do a liquid tuorial? Assuming the liquids can be picked up by an iron bucket. And im looking forward to that config tuorial.
Liquid tutorial will come eventually, but for now I've got to get my ore generation to behave
Great job on these tutorials. They've been immensely helpful, even though they'll probably be obsolete within the next few months... but that's beside the point.
I was wondering, is it possible to use infinite sprite indices without making a separate class for each item? I've been trying, but it always defaults to the Items.png for some reason.(But maybe I just have my textures in the wrong place... they're in MCP\eclipse\Minecraft\bin\mytextures.) I have some items in my mod that don't do much and I feel it would be a waste to make a class for each one rather than just having them in my main class.
Again, thanks for these.
Rollback Post to RevisionRollBack
PLEASE! Learn to use spoiler tags, especially when posting crash reports: [spoiler]YOUR TEXT HERE[ /spoiler]
Great job on these tutorials. They've been immensely helpful, even though they'll probably be obsolete within the next few months... but that's beside the point.
I was wondering, is it possible to use infinite sprite indices without making a separate class for each item? I've been trying, but it always defaults to the Items.png for some reason.(But maybe I just have my textures in the wrong place... they're in MCP\eclipse\Minecraft\bin\mytextures.) I have some items in my mod that don't do much and I feel it would be a waste to make a class for each one rather than just having them in my main class.
Again, thanks for these.
If you want to, you can just add classes to the end of your mod class, but it might start to get slightly long There is another way it could work easily, but I'll have to think it over a bit. The textures have to go in the common folder
Shouldn't take too long now that I've decided that there is no easy way to smelt with metadata
Does that mean all items/blocks that you want to be smelted cannot use metadata?
No, it's easy enough to have the output with metadata, but it doesn't look like it's going to be simple to have metadata input :/
for example:
These would be the normal calls in the main mod file for a normal armor set
and this would be the normal Item file
now say i wanted to have one for each color. but i wanted them to be the same other than the textures and names...
what would i do to make this happen?
each image file has a name like... "simplearmorblue_1, simplearmorblue_2"
"Building a better tomorrow one dream at a time…" [ 一度に1つの夢より良い明日を構築する
I'm not terribly experienced with armour, but it shouldn't be too hard to do metadata. You'll need to use getIconFromDamage and getItemNameIS to start with, but I'm not sure if there is actually a method for metadata with armour textures, I'll check it out
in the main file
and
in the block file
then made a ItemBlock file like this
but in this process i make the "block" into a "item" in a way to hold the data i need...
I don't know how to hold the data i put in the "block" file in the "item" file, nor do i know how to handle the
of each "color" all in one file. I assume with if statments....
like that and repeat for each type then put a "default" at the end....
"Building a better tomorrow one dream at a time…" [ 一度に1つの夢より良い明日を構築する
I prefer switch statements for metadata textures... For the armour texture itself you can switch the itemstack's getItemDamage() method
Thanks,
Brennan
When your mod is in working condition, run the recompile.bat program. Then run reobf.bat. You need to navigate to the folder, and copy your mod's package into a zip file, and don't forget to add the gfx folder
Shouldn't be too long, just a bit busy with exams at the moment
Yeah, I know there are issues with the second tutorial, I though I'd changed it... I'll fix it now though
At the if statement, add
You could also have a switch statement inside the if statement switching the item damage
Sorry, when I have *** I mean your own object, so for my example, *** would be the metadata you need, and by item I meant fuel, sorry for being vague
Don't worry, it's nothing, the textures still render fine I think it's just from having the textures in the common package
Probably
Liquid tutorial will come eventually, but for now I've got to get my ore generation to behave
Which import is broken and what is the error?
I was wondering, is it possible to use infinite sprite indices without making a separate class for each item? I've been trying, but it always defaults to the Items.png for some reason.(But maybe I just have my textures in the wrong place... they're in MCP\eclipse\Minecraft\bin\mytextures.) I have some items in my mod that don't do much and I feel it would be a waste to make a class for each one rather than just having them in my main class.
Again, thanks for these.
PLEASE! Learn to use spoiler tags, especially when posting crash reports: [spoiler]YOUR TEXT HERE[ /spoiler]
If you want to, you can just add classes to the end of your mod class, but it might start to get slightly long There is another way it could work easily, but I'll have to think it over a bit. The textures have to go in the common folder