But how's the getItem().toString() composed? I mean, if i have an output item called "hydrogen" from the mod "testmod", what do i have to write in case 1? I've tried with "testmod:hydrogen", "HYDROGEN", "testmod.Hydrogen" but it doesn't work...
Sorry if my English in snot that good, but I'm italian..
You could add a System.out.println() call to see exactly what toString() is returning (ideally, your method should only be called when a specific action is performed, else you may end up with a huge amount of console spam); I can't say for newer versions but the code below is what the ItemStack class in 1.6.4 does (the Item class itself does not have a toString() method so it would just return the class name and location of the object in memory, which will vary); if 1.18 still does something similar I can see why it wouldn't work by calling toString() on the ItemStack itself or on ItemStack.getItem(), but you could parse the output from ItemStack so only the unlocalized name is used (this is the "default" name used by language translations):
public String toString()
return this.stackSize + "x" + this.getItem().getUnlocalizedName() + "@" + this.itemDamage;
That said, this is not the proper way to check for items; if they are from your own mod or vanilla you should be able to directly reference them (if item instances are still static you can just do "getItem() == Item.whatever", or the equivalent for your mod's item references; this will not work with switch but for only 2-3 cases I'd use if-else instead).