Enchantment Damage to Entity Tag

Started by RamenNoods on

Topic category: Help with modding (Java Edition)

Last seen on 02:42, 3. May 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Enchantment Damage to Entity Tag

I am trying to make an enchantment that deals more damage to fire/ender mobs called Moisture.
I copied another script exactly(replacing enchantment and tag of course), but it still does not deal extra damage. Tried several other scripts to no avail.

(I swear if it's some stupid mistake :/ ...)
 

Script here:

package net.mcreator.persona.procedures;

/* imports omitted */

@Mod.EventBusSubscriber
public class MoistureDamageProcedure {
	@SubscribeEvent
	public static void onEntityAttacked(LivingHurtEvent event) {
		if (event != null && event.getEntity() != null) {
			execute(event, event.getSource(), event.getEntity(), event.getSource().getEntity());
		}
	}

	public static void execute(DamageSource damagesource, Entity entity, Entity sourceentity) {
		execute(null, damagesource, entity, sourceentity);
	}

	private static void execute(@Nullable Event event, DamageSource damagesource, Entity entity, Entity sourceentity) {
		if (damagesource == null || entity == null || sourceentity == null)
			return;
		if (EnchantmentHelper.getItemEnchantmentLevel(PersonaModEnchantments.MOISTURE.get(), (sourceentity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY)) != 0
				&& entity.getType().is(TagKey.create(Registries.ENTITY_TYPE, new ResourceLocation("persona:firemobs")))) {
			entity.hurt(damagesource, (sourceentity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getEnchantmentLevel(PersonaModEnchantments.MOISTURE.get()));
		}
	}
}