Jump to content

Recommended Posts

Posted

I wanted to make one of my custom items cure potion effects upon being eaten. I'm pretty sure I have everything written out correctly but it still doesn't cure the potion effects. Is there another element to this such as an event class?

 

Item:

 

public class Leaf extends Item

{

    public Leaf(int par1)

    {

        super(par1);

        this.setMaxStackSize(1);

        setCreativeTab(TutorialMod.tabRunesMod);

    }

   

    public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

        if (!par3EntityPlayer.capabilities.isCreativeMode)

        {

            --par1ItemStack.stackSize;

        }

 

        if (!par2World.isRemote)

        {

            par3EntityPlayer.curePotionEffects(par1ItemStack);

        }

 

        return par1ItemStack.stackSize <= 0 ? new ItemStack(TutorialMod.ShriveledLeaf) : par1ItemStack;

    }

   

    public int getMaxItemUseDuration(ItemStack par1ItemStack)

    {

        return 32;

    }

 

    /**

    * returns the action that specifies what animation to play when the items is being used

    */

    public EnumAction getItemUseAction(ItemStack par1ItemStack)

    {

        return EnumAction.eat;

    }

 

    /**

    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer

    */

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

        par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));

        return par1ItemStack;

    }

 

    @SideOnly(Side.CLIENT)

public void registerIcons(IconRegister reg) { // Make sure to import IconRegister!

{

this.itemIcon = reg.registerIcon(TutorialMod.modid + ":" + (this.getUnlocalizedName().substring(5)));

}

}

}

 

Posted

That's what I did though. I seem to have all the same code that the milk does, but it still doesn't work. I'm guessing there is some reference to it in another class that allows it to work the way it does.

Posted

In the cure method, it checks the itemstack you pass in with the curing item of each potion effect. In other words, the effects have no clue you want your item to be a cure. Try passing in an itemstack of a bucket of milk instead ;)

 

EDIT:

Or copy the code in the cure method and alter it if you want to target specific effects

Posted

I created my own custom method for this in a new class while extending Potion Effects. I added in my new item but I'm not sure what else to do beyond that? It doesn't work at this point.

 

 

public class CustomPotionEffect extends PotionEffect{

 

private List<ItemStack> curativeItems;

 

 

public CustomPotionEffect(int par1, int par2, int par3, boolean par4) {

super(par1, par2, par3, par4);

this.curativeItems = new ArrayList<ItemStack>();

        this.curativeItems.add(new ItemStack(TutorialMod.Leaf));

}

 

public List<ItemStack> getCurativeItems()

    {

        return this.curativeItems;

    }

 

/***

    * Checks the given ItemStack to see if it is in the list of curative items for the potion effect

    * @param stack The ItemStack being checked against the list of curative items for the potion effect

    * @return true if the given ItemStack is in the list of curative items for the potion effect, false otherwise

    */

    public boolean isCurativeItem(ItemStack stack)

    {

        boolean found = false;

        for (ItemStack curativeItem : this.curativeItems)

        {

            if (curativeItem.isItemEqual(stack))

            {

                found = true;

            }

        }

 

        return found;

    }

   

    /***

    * Sets the array of curative items for the potion effect

    * @param curativeItems The list of ItemStacks being set to the potion effect

    */

    public void setCurativeItems(List<ItemStack> curativeItems)

    {

        this.curativeItems = curativeItems;

    }

   

    /***

    * Adds the given stack to list of curative items for the potion effect

    * @param stack The ItemStack being added to the curative item list

    */

    public void addCurativeItem(ItemStack stack)

    {

        boolean found = false;

        for (ItemStack curativeItem : this.curativeItems)

        {

            if (curativeItem.isItemEqual(stack))

            {

                found = true;

            }

        }

        if (!found)

        {

            this.curativeItems.add(stack);

        }

    }

 

}

 

Posted

You need to add @Override above the method(s) you're trying to use that are inherited by the super class (in this case, Item). Example:

 

@Override
public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer player) {
     if (!player.capabilities.isCreativeMode) {
          --itemstack.stackSize;
     }

     if (!world.isRemote) {
          player.curePotionEffects(itemstack);
     }

     return player.stackSize <= 0 ? new ItemStack(TutorialMod.ShriveledLeaf) : itemstack;
}

 

It seems you don't know a lot about Java or modding in general, since you directly copied the method from the Item class, didn't change anything, and expected it to work.

if (user.hasKnowledgeOfJava) {

    if (user.question.hasCode) {

        return interpetHelpfulResponse(user.getQuestion());

    } else {

        return "Could you post your code please?";

    }

} else {

    return "Learn some freaking Java!";

}

Posted

The @Override annotation doesnt do anything major. It is useful if you update and the names of base methods change because it will be marked with an error, letting you know to change the method name.

Posted

The @Override annotation doesnt do anything major. It is useful if you update and the names of base methods change because it will be marked with an error, letting you know to change the method name.

 

It'll also let you know when the function your trying to use doesn't match the function that exists.

Like I saw one guy do:

 

getIcon (init pass, IconRegister register) { }

 

Because I told him he needed to register, then return, a second icon.

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.

Posted

The @Override annotation doesnt do anything major. It is useful if you update and the names of base methods change because it will be marked with an error, letting you know to change the method name.

 

It'll also let you know when the function your trying to use doesn't match the function that exists.

 

That's what I said.

Posted

Yes, but it doesn't hinge on updating Forge. ;)

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.

Posted

Are you guys really that stupid...

There is literally a function called addCurativeItem

Have you even bothered to try maybe using it..

Like... PotionEffects.slowness.addCurativeItem(new ItemStack(MyShit))

OMFG it works!

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

We're not as smart as you almighty LexManos.

if (user.hasKnowledgeOfJava) {

    if (user.question.hasCode) {

        return interpetHelpfulResponse(user.getQuestion());

    } else {

        return "Could you post your code please?";

    }

} else {

    return "Learn some freaking Java!";

}

Posted

Stupidity and ignorance are two different things. Would the function for adding curative items be used in the main or the new custom class? And from the way you wrote it, it seems as if the curative item would have to be added for each effect, instead of the cure-all for all the effects or am I wrong?

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.