Jump to content

[1.7.10] Comparing ItemStacks and Items


DaComputerNerd

Recommended Posts

I am having a hard time with comparing these two objects.

What I am trying to do is verify if the Item (from GameRegistry.findItem(modid, name)) matches the ItemStack (from the player's inventory)

 

I am certain that none of the objects used are null, and yet I have had no luck getting it to return true when it does match. I have checked that all of the parameters are correct, and have tried several different condtions, such as these 3:

ItemStack.areItemStacksEqual(new ItemStack(item, stack.stackSize), stack)

item.getClass().isInstance(stack.getItem())

stack.getItem().getClass().isInstance(item)

However, all 3 give the same result of always returning false

•Fact: Updating a mod to a new version of minecraft takes time. Especially if the original mod was never open source.

•Fact: The more users pester people who make mods to update their mods to a new version of minecraft, the less likely it is that it will be quickly updated.

•Fact: The more you comment about it, the more likely you are to be ignored.

•Fact: The more recent the last post about updating a mod is, the more annoying yours will be.

•Fact: Using all caps does not reverse any of the above effects

Link to comment
Share on other sites

stack.getItem() == item

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.

Link to comment
Share on other sites

Sorry, wifi issues made it post twice without actually loading at all on my end.

•Fact: Updating a mod to a new version of minecraft takes time. Especially if the original mod was never open source.

•Fact: The more users pester people who make mods to update their mods to a new version of minecraft, the less likely it is that it will be quickly updated.

•Fact: The more you comment about it, the more likely you are to be ignored.

•Fact: The more recent the last post about updating a mod is, the more annoying yours will be.

•Fact: Using all caps does not reverse any of the above effects

Link to comment
Share on other sites

It may also be that it is not causing the command to count successes properly. How does one make a command fail or succeed? Thinking about it, this is an alternate possibility. I should log the output of this method.

Edited by DaComputerNerd
properly causing it to properly

•Fact: Updating a mod to a new version of minecraft takes time. Especially if the original mod was never open source.

•Fact: The more users pester people who make mods to update their mods to a new version of minecraft, the less likely it is that it will be quickly updated.

•Fact: The more you comment about it, the more likely you are to be ignored.

•Fact: The more recent the last post about updating a mod is, the more annoying yours will be.

•Fact: Using all caps does not reverse any of the above effects

Link to comment
Share on other sites

Also,  1.7.10 is no longer supported here. 

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.

Link to comment
Share on other sites

OK big facepalm, I forgot two very important lines for after the loop through the player's inventory...

if(count == 0)
            return false;

•Fact: Updating a mod to a new version of minecraft takes time. Especially if the original mod was never open source.

•Fact: The more users pester people who make mods to update their mods to a new version of minecraft, the less likely it is that it will be quickly updated.

•Fact: The more you comment about it, the more likely you are to be ignored.

•Fact: The more recent the last post about updating a mod is, the more annoying yours will be.

•Fact: Using all caps does not reverse any of the above effects

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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