Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
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
Posted

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

 

Posted (edited)

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

 

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

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

Posted (edited)
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
Posted

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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