Jump to content

Items use last item's info


Casual Dutchman

Recommended Posts

So I made say 10 item within forge.

I made a custom Sword.

The only thing it add is a new int.

That int call the texture of the item.

 

Now all items use that info from the last item.

Last item in was 10, all items use 10.

 

It worked perfectly fine when I created it.

But it is rubbish now, I have no clue about the problem or how to fix it.

 

Please help

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

Storing in the ItemStack can either be done in 1. damagevalues or 2. NBT. As you're damagevalue probably already has been taken by how much the item is damaged you need to use NBT. And for a beginner that's quite advanced stuff.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Link to comment
Share on other sites

To create a new Item you create an instance of it, right? (

new ItemFoobar()

)

There is only this single instance of the item, so if you store data in it, it will remain consistent for all stacks that contain your item. Therefor you have to store the data in the ItemStack.

By creating an instance for every sword worked out the first time.

I made that (lets say) 10 swords, used the new int and it worked fine.

This was the result : http://minecraft.curseforge.com/mc-mods/potion-blade/

It worked all fine.

Until I opened Eclipse a next time.

I runned it and it used only the new int of the last sword.

 

I think this is really wierd.

that's why I putted it up here.

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

Post code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Post code.

Here:

I deleted some stuff that is not related to the problem.

Sword with potion

 

public class PotionSword extends ItemSword{

private Icon sword;
private Icon overlay;

private String unlocname;
private static int potionID;

public PotionSword(int id, int pot, String name, EnumToolMaterial mat)
{
	super(id, mat);
	unlocname = name;
	potionID = pot;
	this.setCreativeTab(Core.tabBlades);
	this.setUnlocalizedName(unlocname + "_" + potion[potionID]);
}

@Override
public Icon getIconFromDamageForRenderPass(int damage, int pass) {
  if(pass == 0) {
    return this.sword;
  }
  else {
    return this.overlay;
  }
}

@SideOnly(Side.CLIENT)
    public boolean requiresMultipleRenderPasses()
    {
        return true;
    }

public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase)
    {
    	par2EntityLivingBase.addPotionEffect(new PotionEffect(potionID, 100 + rand.nextInt(20)));
        par1ItemStack.damageItem(1, par3EntityLivingBase);
        return true;
    }

@Override 
public void registerIcons(IconRegister i) {

this.sword = i.registerIcon(unlocname);	
this.overlay = i.registerIcon(Core.getModid() + ":" + "overlay_" + potion[potionID]);

}
}

 

main file

 

protected static final String modID = "potionblade";

public static String getModid() {
	return modID;
}

private static int itemID = 5000;

@SidedProxy(clientSide="potionblade.Main.ClientProxy", serverSide="potionblade.Main.CommonProxy")
public static CommonProxy proxy;

@Mod.Instance(Core.modID)
public static Core instance;

public static CreativeTabs tabBlades = new CreativeTabs("tabBlades") {
	public ItemStack getIconItemStack() { return new ItemStack(WoodSwordMovespeed, 1, 0); }};

public static final Item WoodSwordMovespeed = new PotionSword(++itemID, 1, "wood_sword", EnumToolMaterial.WOOD);
public static final Item StoneSwordMovespeed = new PotionSword(++itemID, 1, "stone_sword", EnumToolMaterial.STONE);
public static final Item IronSwordMovespeed = new PotionSword(++itemID, 1, "iron_sword", EnumToolMaterial.IRON);
public static final Item GoldSwordMovespeed = new PotionSword(++itemID, 1, "gold_sword", EnumToolMaterial.GOLD);
public static final Item DiamondSwordMovespeed = new PotionSword(++itemID, 1, "diamond_sword", EnumToolMaterial.EMERALD);

public static final Item WoodSwordmoveslowdown = new PotionSword(++itemID, 2, "wood_sword", EnumToolMaterial.WOOD);
public static final Item StoneSwordmoveslowdown = new PotionSword(++itemID, 2, "stone_sword", EnumToolMaterial.STONE);
public static final Item IronSwordmoveslowdown = new PotionSword(++itemID, 2, "iron_sword", EnumToolMaterial.IRON);
public static final Item GoldSwordmoveslowdown = new PotionSword(++itemID, 2, "gold_sword", EnumToolMaterial.GOLD);
public static final Item DiamondSwordmoveslowdown = new PotionSword(++itemID, 2, "diamond_sword", EnumToolMaterial.EMERALD);

public static final Item WoodSworddamageboost = new PotionSword(++itemID, 5, "wood_sword", EnumToolMaterial.WOOD);
public static final Item StoneSworddamageboost = new PotionSword(++itemID, 5, "stone_sword", EnumToolMaterial.STONE);
public static final Item IronSworddamageboost = new PotionSword(++itemID, 5, "iron_sword", EnumToolMaterial.IRON);
public static final Item GoldSworddamageboost = new PotionSword(++itemID, 5, "gold_sword", EnumToolMaterial.GOLD);
public static final Item DiamondSworddamageboost = new PotionSword(++itemID, 5, "diamond_sword", EnumToolMaterial.EMERALD);

public static final Item WoodSwordharm = new PotionSword(++itemID, 7, "wood_sword", EnumToolMaterial.WOOD);
public static final Item StoneSwordharm = new PotionSword(++itemID, 7, "stone_sword", EnumToolMaterial.STONE);
public static final Item IronSwordharm = new PotionSword(++itemID, 7, "iron_sword", EnumToolMaterial.IRON);
public static final Item GoldSwordharm = new PotionSword(++itemID, 7, "gold_sword", EnumToolMaterial.GOLD);
public static final Item DiamondSwordharm = new PotionSword(++itemID, 7, "diamond_sword", EnumToolMaterial.EMERALD);

deleted some here, just too long

public static final Item StoneSwordWither = new PotionSword(++itemID, 20, "stone_sword", EnumToolMaterial.STONE);
public static final Item IronSwordWither = new PotionSword(++itemID, 20, "iron_sword", EnumToolMaterial.IRON);
public static final Item GoldSwordWither = new PotionSword(++itemID, 20, "gold_sword", EnumToolMaterial.GOLD);
public static final Item DiamondSwordWither = new PotionSword(++itemID, 20, "diamond_sword", EnumToolMaterial.EMERALD);

inside the load file are all the addNames and addRecipes
this is to related to the problem

The first WoodSwordmovespeed hase the wither effect to it.

but it has the potion id of 1 to it.

btw, all sowrds have the wither effect applied to them.

 

btw, Could I use the getPotionColor methode liek the one in the ItemPotion to color the overlay only?

or would it olso give the sword an extra color?

just a question, maybe someone knows?

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

private static int potionID;

 

Go learn Java.  This line is your problem and it's really easy to fix and if you knew anything about any object oriented language you'd know what the problem is.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

private static int potionID;

 

Go learn Java.  This line is your problem and it's really easy to fix and if you knew anything about any object oriented language you'd know what the problem is.

I have learned it for a bit, not very indepth or something.

 

I think I know how to fix it?

correct me if I'm wrong.

 

I need to make the potionID a non-static int.

Then I need to make a static getter for the int.

 

 

I have no time to try this out, so I'm just asking.

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

Then I need to make a static getter for the int.

 

Wat.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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