Jump to content

Recommended Posts

Posted

Hello,

 

I'm trying to create a new Bow that instead of using arrows, it consumes energy from a crystal orb (item from the mod). I've hit a roadblock trying to figure out how to "damage" the orb every time the bow shoots. I've searched practically everywhere, but I cannot find a good tutorial on how one might go about that. I'm wondering if anyone else out there has encountered this or if they could offer any advice.

 

Edit: I'm relatively new with modding, but have some programming experience, mostly C#.

 

Here is the Bow.class:

 

  Reveal hidden contents

 

 

And the Crystal Orb.class:

 

  Reveal hidden contents

 

 

Any help would be greatly appreciated! I've been stuck on this for a few days now.

Posted

Put this in your onPlayerStoppedUsing method to damage the itemstack.

 

ItemStack itemstack;
for (int index = 0; index < player.inventory.getSizeInventory() && (itemstack != null ? itemstack.getItem() == YourModClass.youritem) ; index++) { //You could use 35 instead of the size here but i like it that way.
    itemstack = player.inventory.getStackInSlot(index);
}
if (itemstack != null && itemstack.getItem() == YourModClass.youritem) {
    if (itemStack.attemptDamageItem(1, rand)) {
        itemStack.stackSize--;
        if (itemStack.stackSize < 0)                  //This will consume your item once it breaks.
            itemStack.stackSize = 0;
        itemStack.setItemDamage(0);
        itemStack = null;
    }
}

 

EDIT: You might need to return the Item to the players Inverntory

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Thanks! I'll try it out and see how it works.

 

Edit:

Okay, after modifying you solution to match my class

 

  Reveal hidden contents

 

 

I get the following error:

 

"The operator && is undefined for the argument type(s) boolean, Object&Serializable&Comparable<?>"

 

This is what its underlining:

index < par3EntityPlayer.inventory.getSizeInventory() && (itemstack != null ? itemstack.getItem() == RangerMain.crystal_orb : 35);

 

I'm not 100% sure why either...

 

Posted

Whoops its meant to be: :D

index < par3EntityPlayer.inventory.getSizeInventory() && (itemstack != null ? itemstack.getItem() == RangerMain.crystal_orb : false);

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Thanks again, that seemed to fix all of the errors... But one.

 

After I fixed the code so it would stop "yelling" at me, it was complaining that the local variable itemstack might not have been initialized. I'm assuming putting "new ItemStack(mainmod.myitem)" or even "null" as Eclipse suggessts would break it.

 

Once again thank you for your assistance!

 

EDIT: "ItemStack itemstack = null;" didnt break it. I put a print line on the damage of the item, and it goes up each time i use it (yay!). The only obstacle to pass is displaying the damage on the hot-bar, similar to a pickaxe or bow. You mentioned something earlier about returning it to inventory?

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.

Announcements



×
×
  • Create New...

Important Information

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