Jump to content

Help applying potion effects to mobs


Dejo26

Recommended Posts

Hello everyone.

First of all I'm junior modder but I have some time programming on Java so everything is ok.

 

Now, here is my question.

How can I apply potion effects to entities(mobs and players)? I'm using 1.12.2

 

I made an enchantment for the sword, and I want to apply slowness to every entity I hit.

I tried a lot of things and I've researched a lot before come here so, here is my "subscribeEvent" method

 

 

@SubscribeEvent
	public static void enchantAttack(LivingAttackEvent event) {
		Object attacker = event.getSource().getTrueSource();		
		
		System.out.println("Hi0");
		if(attacker instanceof EntityLivingBase ) {
			System.out.println("Hi1");
			EntityLivingBase entityAttacker = (EntityLivingBase)attacker; 
			EntityAnimal picha = (EntityAnimal)attacker;
			
			int leve = EnchantmentHelper.getEnchantmentLevel(DAMAGE_HEAL, entityAttacker.getHeldItemMainhand());
			if(leve > 0) {
				System.out.println("hi2");
				
				
				picha.addPotionEffect(Potion.getPotionById(2), 100, 0);
				
			
				
				
			}
		}
		
	}

 

Thanks :c

 

 

 

 

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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