Jump to content

Tool meta data


ashtonr12
 Share

Recommended Posts

How do you get the dmg of a tool in the players hand? i know how to check what tool it is but not the dmg vaule of it?

On a completely unrelated note ;) how do you spawn a tool with a dmg value? i know how to spawn fully repaired ones, like this;

 

ItemStack wsword = new ItemStack(Item.swordDiamond);
             EntityItem entityitem = new EntityItem(par1World, (double)par2 + d0, (double)par3 + d1, (double)par4 + d2, wsword);
             entityitem.delayBeforeCanPickup = 10;
             par1World.spawnEntityInWorld(entityitem);}

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

ok so i have done weapon.getItemDamage();

how do i now use this figure?

could i make it an int? then use the int elsewhere? sorry i am unfamiliar with this method :/

 

also the setdamage for an item only works when the player is holding the item? or i don't know how to use it in my spawn entity code, if which is the case can you provide an example so that i understand what you mean?

 

in the mean time i will keep experimenting :)

 

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

ItemStack sword = new ItemStack(Item.swordDiamond);//this is only for the example, most of the time, you get an unknown ItemStack from methods 
int oldDmg = sword.getItemDamage();//lets get the damage...it is 0 in our example case
//you may want to check max damage value too before...
sword.setItemDamage(oldDmg+1);//increasing the damage by 1

 

Link to comment
Share on other sites

ok great that answers half my problem :D

 

now how do i spawn a damaged tool? before the player picks it up so preferable i you can spawn the item with the dmg data or spawn  it and immediately dmg it or something ??

 

EDIT- cant get the stupid extra health thing to work

public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
    {
     World world = par3EntityLiving.worldObj;
      if (world.isRemote)
      {
       return true;
      }
      else{
      int dmg = par1ItemStack.getItemDamage();
      par1ItemStack.setItemDamage(dmg+500);
      }
         return true;
    }

 

dunno why i have been fiddling with it for most of this hour, im going to bed now, help on either how to spawn a damaged tool entity or how to fix or replace the above code would be great :) ill read it in the morning.

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

1) still no idea how to spawn a damaged sword entity? do i have to spawn it with some extra data?

2) trying to make this sword gain health when used, why is it not working?

public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
    {
     World world = par3EntityLiving.worldObj;
      if (world.isRemote)
      {
       return true;
      }
      else{
      int dmg = par1ItemStack.getItemDamage();
      par1ItemStack.setItemDamage(dmg+500);
      }
         return true;
    }

 

EDIT- i tried putting System.out.println("stuff); in parts of the code above (in the sword class) and it didnt print anything so is it possible its skipping or ignoring the method or somthing??

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

i wish i was as not dumb as you xD thanks for all your help so far :)

 

i think you are right on both counts i have one what i wanted with the damaging entities and will try and find a replacement method before i ask for your help again, probs be back  in like 5-10 mins max. jokes xD

Use examples, i have aspergers.

Examples make sense to me.

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

 Share



×
×
  • Create New...

Important Information

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