Posted October 25, 20186 yr Hello, So I am creating an item that will burn the player if they aren't immune to fire and don't have fire protection armor, However the event doesn't appear to be getting called... Can someone explain what I did wrong? public class SolstoneRockItem extends ItemBlockBase{ public SolstoneRockItem() { super(ModBlocks.SOLSTONE_ROCK, "solstone_rock", "SolstoneRock"); } @Override public void onUpdate(ItemStack s, World w, Entity e, int l, boolean h) { for(ItemStack armor : e.getArmorInventoryList()) { NBTTagList enchList = armor.getEnchantmentTagList(); for(int i = 0; i < enchList.tagCount(); i++) { if(enchList.getCompoundTagAt(i).getInteger("id") == Enchantment.getEnchantmentID(Enchantments.FIRE_PROTECTION))return; } } e.attackEntityFrom(DamageSource.ON_FIRE, 1.0f); } } Thank you!EDIT: It appears that onUpdate isn't being called period. I will try a different approach. Edited October 25, 20186 yr by WolfHybrid23
October 25, 20186 yr Author 4 minutes ago, diesieben07 said: Don't do this. How did you come to this conclusion? onUpdate works fine. I just tried onUpdate without any return statements and my code didn't execute, also the reason I used an ItemBlockBase was so I could override onUpdate in the first place. And because the Item I wanted to update was an ItemBlock. Edited October 25, 20186 yr by WolfHybrid23
October 25, 20186 yr Author How do I override it then? I'm new to forge development sorry. I mainly use C++ and GML... Edited October 25, 20186 yr by WolfHybrid23
October 25, 20186 yr Author Could you give me an example? Here is the code for ItemBlockBase: public class ItemBlockBase extends ItemBlock{ public ItemBlockBase(Block b, String name, String unlocalName) { super(b); this.setRegistryName(name); this.setUnlocalizedName(unlocalName); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); ModItems.ITEMS.add(this); } }
October 25, 20186 yr Author It's still not damaging me. @diesieben07 public class SolstoneRockItem extends ItemBlock{ public SolstoneRockItem() { super(ModBlocks.SOLSTONE_ROCK); this.setRegistryName("solstone_rock"); this.setUnlocalizedName("SolstoneRock"); ModItems.ITEMS.add(this); } @Override public void onUpdate(ItemStack s, World w, Entity e, int l, boolean h) { if(e.isImmuneToFire() || e.getIsInvulnerable())return; for(ItemStack armor : e.getArmorInventoryList()) { for(int k = 0; k < armor.getEnchantmentTagList().tagCount(); k++) { if(armor.getEnchantmentTagList().getCompoundTagAt(k).getString("id") == "fire_protection")return; } } e.attackEntityFrom(DamageSource.ON_FIRE,1.0f); } } Edited October 25, 20186 yr by WolfHybrid23
October 25, 20186 yr Author 1 minute ago, diesieben07 said: Ah, so you finally answered my question from above: In the future: Use the debugger to figure out what is happening. Your code to check for Enchantments is broken (you cannot compare Strings with ==). To check for enchantments on a specific ItemStack use EnchantmentHelper.getEnchantmentLevel. To check for enchantments on a complete entity (probably what you want) use EnchantmentHelper.getMaxEnchantmentLevel. Like this? if(EnchantmentHelper.getEnchantmentLevel(Enchantments.FIRE_PROTECTION, armor) > 0)return;
October 25, 20186 yr Author Just now, diesieben07 said: That would check for one piece, yes. However you should not exclusively just check the armor pieces. Use the method that checks the whole entity for you. Okay, Thank you so very much for your help. And thanks for being patent with me too!
October 25, 20186 yr Author 2 minutes ago, diesieben07 said: That would check for one piece, yes. However you should not exclusively just check the armor pieces. Use the method that checks the whole entity for you. It seems it's still not damaging me. I am at a loss.
October 25, 20186 yr Author 2 minutes ago, diesieben07 said: Post updated code. Oh My Gosh... I am perhaps the biggest idiot to ever mod minecraft. I didn't update my ModItems class to use the SolstoneRock class instead of the ModBlockBase class... Yep it works now... Edited October 25, 20186 yr by WolfHybrid23
October 26, 20186 yr You should delete any “base” classes About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
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.