mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
Fix potion remove event not always firing, add expiry event
This commit is contained in:
1 parent
914fe91db5
commit
65cfef1b2e
3 files changed
+91
-34
No files matched your search
@@ -62,10 +62,16 @@ public class PotionEvent extends LivingEvent
|
||||
|
||||
public PotionRemoveEvent(EntityLivingBase living, Potion potion)
|
||||
{
|
||||
super(living, living.getActivePotionMap().get(potion));
|
||||
super(living, living.getActivePotionEffect(potion));
|
||||
this.potion = potion;
|
||||
}
|
||||
|
||||
public PotionRemoveEvent(EntityLivingBase living, PotionEffect effect)
|
||||
{
|
||||
super(living, effect);
|
||||
this.potion = effect.getPotion();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Potion which is tried to remove from the Entity.
|
||||
*/
|
||||
@@ -147,4 +153,16 @@ public class PotionEvent extends LivingEvent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This Event is fired when a Potion effect expires on an Entity.
|
||||
* This Event is not {@link Cancelable}
|
||||
* This Event does not have a Result.
|
||||
*/
|
||||
public static class PotionExpiryEvent extends PotionEvent
|
||||
{
|
||||
public PotionExpiryEvent(EntityLivingBase living, PotionEffect effect)
|
||||
{
|
||||
super(living, effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,19 +52,37 @@ public class PotionEventTest
|
||||
@SubscribeEvent
|
||||
public void onPotionAdded(PotionEvent.PotionAddedEvent event)
|
||||
{
|
||||
log.info("{} has a new PotionEffect {}, the old one was {}", event.getEntityLiving(), event.getPotionEffect(), event.getOldPotionEffect());
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
log.info("{} has a new PotionEffect {}, the old one was {}", event.getEntityLiving(), event.getPotionEffect(), event.getOldPotionEffect());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void isPotionApplicable(PotionEvent.PotionApplicableEvent event)
|
||||
{
|
||||
event.setResult(Result.ALLOW);
|
||||
log.info("Allowed Potion {} for Entity {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
event.setResult(Result.ALLOW);
|
||||
log.info("Allowed Potion {} for Entity {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPotionRemove(PotionEvent.PotionRemoveEvent event)
|
||||
{
|
||||
log.info("Effect {} got Removed from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
log.info("Effect {} got Removed from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPotionExpiry(PotionEvent.PotionExpiryEvent event)
|
||||
{
|
||||
if (!event.getEntity().getEntityWorld().isRemote)
|
||||
{
|
||||
log.info("Effect {} expired from {}", event.getPotionEffect(), event.getEntityLiving());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user