Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED]Switching effect food
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
NeoSup2130

[SOLVED]Switching effect food

By NeoSup2130, November 28, 2014 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

NeoSup2130    1

NeoSup2130

NeoSup2130    1

  • Stone Miner
  • NeoSup2130
  • Forge Modder
  • 1
  • 79 posts
Posted November 28, 2014

I'm having trouble with this code:

 

protected void onFoodEaten(ItemStack item, World world, EntityPlayer player) {

 

player.addPotionEffect(new PotionEffect(Potion.heal.id, 1, 0));

{

if (item == MainClass.CorruptedBlood)

 

player.addPotionEffect(new PotionEffect(Potion.poison.id, 1, 0));

}

}

What I'm trying to code is, when you drink 'CorruptedBlood' you get poison instead of healing

The problem starts with this line : if (item == MainClass.CorruptedBlood) When i hover over the problem it says : Incompatible operand types ItemStack and item

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6667

diesieben07

diesieben07    6667

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6667
  • 45570 posts
Posted November 28, 2014

You cannot compare ItemStacks and Items. Basic java.

You don't need to check those though, the method will only be called for your Item anyways.

  • Quote

Share this post


Link to post
Share on other sites

NeoSup2130    1

NeoSup2130

NeoSup2130    1

  • Stone Miner
  • NeoSup2130
  • Forge Modder
  • 1
  • 79 posts
Posted November 28, 2014

Sorry this may sound stupid but, i don't get what you mean. When i remove item == it still doesn't fix it. The class is used by multiple foods and i want that 'Corruptedblood' has a different effect in the class than healing the player. And i don't want to make a second class just for one food.

  • Quote

Share this post


Link to post
Share on other sites

NeoSup2130    1

NeoSup2130

NeoSup2130    1

  • Stone Miner
  • NeoSup2130
  • Forge Modder
  • 1
  • 79 posts
Posted November 28, 2014

My code: https://github.com/NeoSup2130/Neo/blob/master/BottleOfBloodClass

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6667

diesieben07

diesieben07    6667

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6667
  • 45570 posts
Posted November 28, 2014

Check

this == <someItem>

.

What I meant was that you cannot check if an ItemStack is equal to an Item, because it never is. Same as an Apple is never a Banana.

  • Quote

Share this post


Link to post
Share on other sites

NeoSup2130    1

NeoSup2130

NeoSup2130    1

  • Stone Miner
  • NeoSup2130
  • Forge Modder
  • 1
  • 79 posts
Posted November 28, 2014

Thanks for helping but, i still don't get it. I'm just gonna make a second class that will be easier.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6667

diesieben07

diesieben07    6667

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6667
  • 45570 posts
Posted November 28, 2014

...

  • Quote

Share this post


Link to post
Share on other sites

daafganggdg    3

daafganggdg

daafganggdg    3

  • Creeper Killer
  • daafganggdg
  • Members
  • 3
  • 141 posts
Posted November 29, 2014

Thanks for helping but, i still don't get it. I'm just gonna make a second class that will be easier.

Alright look, its like saying "2" == 2, for our human eye its 2 and 2 and thats ofc the same but for a computer its a string and an integer and you can never ever compare these types like that.

Same as an itemStack is not an item.

you can use item.getItem tho..

Then you have the item of the itemStack and you can compare it with a item

  • Quote

Share this post


Link to post
Share on other sites

larsgerrits    510

larsgerrits

larsgerrits    510

  • Reality Controller
  • larsgerrits
  • Members
  • 510
  • 3455 posts
Posted November 29, 2014

...

Then you have the item of the itemStack and you can compare it with a item

You don't need to check those though, the method will only be called for your Item anyways.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      1.89 crash forge

      By diesieben07 · Posted 13 minutes ago

      1.8.9 is no longer supported on this forum due to it's age. Update to a modern version of Minecraft to receive support.
    • Pixelboss4d
      1.89 crash forge

      By Pixelboss4d · Posted 23 minutes ago

      1.89  
    • Pixelboss4d
      1.89 crash forge

      By Pixelboss4d · Posted 29 minutes ago

      when i start forge it was crashed 
    • jgfarrell
      I'm having trouble with Java on !MAC!

      By jgfarrell · Posted 1 hour ago

      Sorry Junior.   I thought I was going to be a hero!   Good luck.
    • diesieben07
      [1.14.4] [Solved] Trouble With Packets

      By diesieben07 · Posted 1 hour ago

      If you do this, then there is no point having the capability. Just store it in the stack's NBT tag directly at that point...
  • Topics

    • Pixelboss4d
      2
      1.89 crash forge

      By Pixelboss4d
      Started 29 minutes ago

    • Junior240
      4
      I'm having trouble with Java on !MAC!

      By Junior240
      Started November 9

    • Cerandior
      10
      [1.14.4] [Solved] Trouble With Packets

      By Cerandior
      Started Yesterday at 03:20 PM

    • plugsmustard
      18
      on/off button for custom furnace

      By plugsmustard
      Started Yesterday at 03:11 PM

    • AkosM
      3
      Increase target's damage via usable item

      By AkosM
      Started 18 hours ago

  • Who's Online (See full list)

    • Tzatane76
    • Draco18s
    • bokunleo
    • Pixelboss4d
    • diesieben07
    • flame_antoine
    • Choco
    • mr.denqu
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED]Switching effect food
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community