mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Add entity source to PotionAddedEvent (#8147)
This commit is contained in:
1 parent
e9f8acd191
commit
827ca83cfd
3 files changed
+23
-3
No files matched your search
@@ -84,7 +84,7 @@
|
||||
return false;
|
||||
} else {
|
||||
MobEffectInstance mobeffectinstance = this.f_20945_.get(p_147208_.m_19544_());
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.PotionEvent.PotionAddedEvent(this, mobeffectinstance, p_147208_));
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.PotionEvent.PotionAddedEvent(this, mobeffectinstance, p_147208_, p_147209_));
|
||||
if (mobeffectinstance == null) {
|
||||
this.f_20945_.put(p_147208_.m_19544_(), p_147208_);
|
||||
this.m_142540_(p_147208_, p_147209_);
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.event.entity.living;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
@@ -127,11 +128,19 @@ public class PotionEvent extends LivingEvent
|
||||
public static class PotionAddedEvent extends PotionEvent
|
||||
{
|
||||
private final MobEffectInstance oldEffect;
|
||||
|
||||
private final Entity source;
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.17.1")
|
||||
public PotionAddedEvent(LivingEntity living, MobEffectInstance oldEffect, MobEffectInstance newEffect)
|
||||
{
|
||||
this(living, oldEffect, newEffect, null);
|
||||
}
|
||||
|
||||
public PotionAddedEvent(LivingEntity living, MobEffectInstance oldEffect, MobEffectInstance newEffect, Entity source)
|
||||
{
|
||||
super(living, newEffect);
|
||||
this.oldEffect = oldEffect;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,6 +161,17 @@ public class PotionEvent extends LivingEvent
|
||||
{
|
||||
return oldEffect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity source of the effect, or {@code null} if none exists.
|
||||
*
|
||||
* @return the entity source of the effect, or {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getPotionSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PotionEventTest
|
||||
public static void onPotionAdded(PotionEvent.PotionAddedEvent event)
|
||||
{
|
||||
if (!event.getEntity().getCommandSenderWorld().isClientSide)
|
||||
LOGGER.info("{} has a new PotionEffect {}, the old one was {}", event.getEntityLiving(), event.getPotionEffect(), event.getOldPotionEffect());
|
||||
LOGGER.info("{} has a new PotionEffect {} from {}, the old one was {}", event.getEntityLiving(), event.getPotionEffect(), event.getPotionSource(), event.getOldPotionEffect());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
Reference in new issue
Block a user