The Meaning of Life, the Universe, and Everything.
Join Date:
10/14/2012
Posts:
192
Location:
On Earth
Minecraft:
Nathmon565
Member Details
This is more of a multi question. I have been trying all day, and have researched for quite a while on how to do this. I want an item (rag) to be deleted on rightclick (stack size of 1). The other item would be damaged (bandage) by 1 every time it is used. The result of right clicking would apply a potion effect and remove a different potion effect. So far, I haven't even gotten the right click event to work... It seems to be a silent error, eclipse says nothing is wrong with the code. And yes I have setMaxDamage(3); and maxStackSize=1;
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
itemstack.damageItem(1, entityplayer);
return itemstack;
}
That's the code that doesn't even activate... Otherwise the name of the effect I want to remove is bleedingeffect, and I want to apply instant_health. Considering how I can't even get an item to damage or delete itself, I have no clue where to go from here. I have reached a dead end and can't find any tutorials that are recent and actually work when I try to apply them. Any help is greatly appreciated!
Rollback Post to RevisionRollBack
"But even the word 'hopeless' has 'hope' in it! And if you rearrange the letters, it spells 'peeslosh'!" - BattleBlock Theater
That's the wrong signature for Item#onItemRightClick, so your method doesn't override the super method and it's never called from anywhere. Always annotate override methods with @Override so you get a compilation error when they don't actually override a super method.
I suggest using your IDE to auto-generate override methods with the correct signature and annotation. You should be able to start typing a method name in the main body of your class and your IDE will bring up a list of matching methods you can override. Selecting one will generate the override method.
ItemStack#damageItem is the correct method to damage the item. Use ItemStack#shrink to reduce the stack size by the specified amount. An ItemStack with stack size 0 becomes empty, effectively deleting it from the slot.
Use EntityLivingBase#addPotionEffect to add a PotionEffect and EntityLivingBase#removePotionEffect to remove one.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
The Meaning of Life, the Universe, and Everything.
Join Date:
10/14/2012
Posts:
192
Location:
On Earth
Minecraft:
Nathmon565
Member Details
Alright. So I got a proper @Override now that I researched it and used IDEs... It now removes the custom potion effect "bleedingeffect" (ashen.bleedingeffect) with no problems, however trying to add a potion causes an error. I'm not sure if the names for potions is different than what I am putting, but it reports "instant_health cannot be resolved or is not a field".
After that,
ItemStack.damageItem(1, playerIn);
gives the error across the whole thing of "Cannot make a static reference to the non-static method damageItem(int, EntityLivingBase) from the type ItemStack"... If I remove those two errors (the whole lines) it will work, no problems at all.
Regarding
ItemStack.shrink(1);
for the single use item, it provides the error of "Cannot make a static reference to the non-static method shrink(int) from the type ItemStack".
p.s. this is actually a huge step forward, thanks so much!
Rollback Post to RevisionRollBack
"But even the word 'hopeless' has 'hope' in it! And if you rearrange the letters, it spells 'peeslosh'!" - BattleBlock Theater
You really need to spend some time learning the basics of Java before making a mod.
I use Class#member to refer to non-static fields/methods and Class.member to refer to static fields/methods.
ItemStack#damageItem and ItemStack#shrink are non-static methods, so they need to be called on an instance of ItemStack.
You can't just type a name like instant_health and expect Java to know what you mean, you need to reference an actual field. The Instant Health Potion object is stored in the MobEffects.INSTANT_HEALTH field.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
The Meaning of Life, the Universe, and Everything.
Join Date:
10/14/2012
Posts:
192
Location:
On Earth
Minecraft:
Nathmon565
Member Details
Alright, thanks for your help! I got it to work after I did some research on how to use those tags. Yeah, I'm going to go learn Java before I continue (it's only going to get more complicated from here). Thank you for your help!
Rollback Post to RevisionRollBack
"But even the word 'hopeless' has 'hope' in it! And if you rearrange the letters, it spells 'peeslosh'!" - BattleBlock Theater
This is more of a multi question. I have been trying all day, and have researched for quite a while on how to do this. I want an item (rag) to be deleted on rightclick (stack size of 1). The other item would be damaged (bandage) by 1 every time it is used. The result of right clicking would apply a potion effect and remove a different potion effect. So far, I haven't even gotten the right click event to work... It seems to be a silent error, eclipse says nothing is wrong with the code. And yes I have setMaxDamage(3); and maxStackSize=1;
That's the code that doesn't even activate... Otherwise the name of the effect I want to remove is bleedingeffect, and I want to apply instant_health. Considering how I can't even get an item to damage or delete itself, I have no clue where to go from here. I have reached a dead end and can't find any tutorials that are recent and actually work when I try to apply them. Any help is greatly appreciated!
"But even the word 'hopeless' has 'hope' in it! And if you rearrange the letters, it spells 'peeslosh'!" - BattleBlock Theater
That's the wrong signature for Item#onItemRightClick, so your method doesn't override the super method and it's never called from anywhere. Always annotate override methods with @Override so you get a compilation error when they don't actually override a super method.
I suggest using your IDE to auto-generate override methods with the correct signature and annotation. You should be able to start typing a method name in the main body of your class and your IDE will bring up a list of matching methods you can override. Selecting one will generate the override method.
ItemStack#damageItem is the correct method to damage the item. Use ItemStack#shrink to reduce the stack size by the specified amount. An ItemStack with stack size 0 becomes empty, effectively deleting it from the slot.
Use EntityLivingBase#addPotionEffect to add a PotionEffect and EntityLivingBase#removePotionEffect to remove one.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Alright. So I got a proper @Override now that I researched it and used IDEs... It now removes the custom potion effect "bleedingeffect" (ashen.bleedingeffect) with no problems, however trying to add a potion causes an error. I'm not sure if the names for potions is different than what I am putting, but it reports "instant_health cannot be resolved or is not a field".
After that,
gives the error across the whole thing of "Cannot make a static reference to the non-static method damageItem(int, EntityLivingBase) from the type ItemStack"... If I remove those two errors (the whole lines) it will work, no problems at all.
Regarding
for the single use item, it provides the error of "Cannot make a static reference to the non-static method shrink(int) from the type ItemStack".
p.s. this is actually a huge step forward, thanks so much!
"But even the word 'hopeless' has 'hope' in it! And if you rearrange the letters, it spells 'peeslosh'!" - BattleBlock Theater
You really need to spend some time learning the basics of Java before making a mod.
I use Class#member to refer to non-static fields/methods and Class.member to refer to static fields/methods.
ItemStack#damageItem and ItemStack#shrink are non-static methods, so they need to be called on an instance of ItemStack.
You can't just type a name like instant_health and expect Java to know what you mean, you need to reference an actual field. The Instant Health Potion object is stored in the MobEffects.INSTANT_HEALTH field.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Alright, thanks for your help! I got it to work after I did some research on how to use those tags. Yeah, I'm going to go learn Java before I continue (it's only going to get more complicated from here). Thank you for your help!
"But even the word 'hopeless' has 'hope' in it! And if you rearrange the letters, it spells 'peeslosh'!" - BattleBlock Theater