Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

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.

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

 

  • Author

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.

  • Author

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.

EntityItem holds the ItemStack. Damage it before spawn in world.

 

Most likely, the method you are overriding doesn't exist any more.

 

 

  • Author

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.