Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by WolfHybrid23

  • 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 by WolfHybrid23

  • Author

How do I override it then?
I'm new to forge development sorry. I mainly use C++ and GML...

Edited by WolfHybrid23

  • 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);
	}
}

 

  • 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 by WolfHybrid23

  • 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;

 

  • 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! :)

  • 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.

  • 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 by WolfHybrid23

You should delete any “base” classes

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.