Fix potion remove event not always firing, add expiry event
This commit is contained in:
parent
914fe91db5
commit
65cfef1b2e
3 changed files with 91 additions and 34 deletions
|
@ -47,6 +47,15 @@
|
|||
while(i > 0) {
|
||||
int j = EntityXPOrb.func_70527_a(i);
|
||||
i -= j;
|
||||
@@ -534,7 +540,7 @@
|
||||
Potion potion = iterator.next();
|
||||
PotionEffect potioneffect = this.field_70713_bf.get(potion);
|
||||
if (!potioneffect.func_76455_a(this)) {
|
||||
- if (!this.field_70170_p.field_72995_K) {
|
||||
+ if (!this.field_70170_p.field_72995_K && !net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.PotionEvent.PotionExpiryEvent(this, potioneffect))) {
|
||||
iterator.remove();
|
||||
this.func_70688_c(potioneffect);
|
||||
}
|
||||
@@ -584,8 +590,10 @@
|
||||
this.func_82142_c(false);
|
||||
} else {
|
||||
|
@ -60,7 +69,19 @@
|
|||
this.func_82142_c(this.func_70644_a(MobEffects.field_76441_p));
|
||||
}
|
||||
|
||||
@@ -622,6 +630,27 @@
|
||||
@@ -614,7 +622,10 @@
|
||||
|
||||
boolean flag;
|
||||
for(flag = false; iterator.hasNext(); flag = true) {
|
||||
- this.func_70688_c(iterator.next());
|
||||
+ PotionEffect effect = iterator.next();
|
||||
+ if(net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.PotionEvent.PotionRemoveEvent(this, effect))) continue;
|
||||
+
|
||||
+ this.func_70688_c(effect);
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
@@ -622,6 +633,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +96,7 @@
|
|||
+ Iterator<PotionEffect> itr = this.field_70713_bf.values().iterator();
|
||||
+ while (itr.hasNext()) {
|
||||
+ PotionEffect effect = itr.next();
|
||||
+ if (effect.isCurativeItem(curativeItem)) {
|
||||
+ if (effect.isCurativeItem(curativeItem) && !net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.PotionEvent.PotionRemoveEvent(this, effect))) {
|
||||
+ this.func_70688_c(effect);
|
||||
+ itr.remove();
|
||||
+ ret = true;
|
||||
|
@ -88,7 +109,7 @@
|
|||
public Collection<PotionEffect> func_70651_bq() {
|
||||
return this.field_70713_bf.values();
|
||||
}
|
||||
@@ -644,6 +673,7 @@
|
||||
@@ -644,6 +676,7 @@
|
||||
return false;
|
||||
} else {
|
||||
PotionEffect potioneffect = this.field_70713_bf.get(p_195064_1_.func_188419_a());
|
||||
|
@ -96,7 +117,7 @@
|
|||
if (potioneffect == null) {
|
||||
this.field_70713_bf.put(p_195064_1_.func_188419_a(), p_195064_1_);
|
||||
this.func_70670_a(p_195064_1_);
|
||||
@@ -658,6 +688,9 @@
|
||||
@@ -658,6 +691,9 @@
|
||||
}
|
||||
|
||||
public boolean func_70687_e(PotionEffect p_70687_1_) {
|
||||
|
@ -106,7 +127,7 @@
|
|||
if (this.func_70668_bt() == CreatureAttribute.UNDEAD) {
|
||||
Potion potion = p_70687_1_.func_188419_a();
|
||||
if (potion == MobEffects.field_76428_l || potion == MobEffects.field_76436_u) {
|
||||
@@ -678,6 +711,7 @@
|
||||
@@ -678,6 +714,7 @@
|
||||
}
|
||||
|
||||
public boolean func_195063_d(Potion p_195063_1_) {
|
||||
|
@ -114,7 +135,7 @@
|
|||
PotionEffect potioneffect = this.func_184596_c(p_195063_1_);
|
||||
if (potioneffect != null) {
|
||||
this.func_70688_c(potioneffect);
|
||||
@@ -714,6 +748,8 @@
|
||||
@@ -714,6 +751,8 @@
|
||||
}
|
||||
|
||||
public void func_70691_i(float p_70691_1_) {
|
||||
|
@ -123,7 +144,7 @@
|
|||
float f = this.func_110143_aJ();
|
||||
if (f > 0.0F) {
|
||||
this.func_70606_j(f + p_70691_1_);
|
||||
@@ -730,6 +766,7 @@
|
||||
@@ -730,6 +769,7 @@
|
||||
}
|
||||
|
||||
public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_) {
|
||||
|
@ -131,7 +152,7 @@
|
|||
if (this.func_180431_b(p_70097_1_)) {
|
||||
return false;
|
||||
} else if (this.field_70170_p.field_72995_K) {
|
||||
@@ -790,8 +827,8 @@
|
||||
@@ -790,8 +830,8 @@
|
||||
if (entity1 instanceof EntityPlayer) {
|
||||
this.field_70718_bc = 100;
|
||||
this.field_70717_bb = (EntityPlayer)entity1;
|
||||
|
@ -142,7 +163,7 @@
|
|||
if (entitywolf.func_70909_n()) {
|
||||
this.field_70718_bc = 100;
|
||||
this.field_70717_bb = null;
|
||||
@@ -941,11 +978,12 @@
|
||||
@@ -941,11 +981,12 @@
|
||||
}
|
||||
|
||||
public void func_70669_a(ItemStack p_70669_1_) {
|
||||
|
@ -156,7 +177,7 @@
|
|||
if (!this.field_70729_aU) {
|
||||
Entity entity = p_70645_1_.func_76346_g();
|
||||
EntityLivingBase entitylivingbase = this.func_94060_bK();
|
||||
@@ -960,15 +998,16 @@
|
||||
@@ -960,15 +1001,16 @@
|
||||
this.field_70729_aU = true;
|
||||
this.func_110142_aN().func_94549_h();
|
||||
if (!this.field_70170_p.field_72995_K) {
|
||||
|
@ -177,7 +198,7 @@
|
|||
}
|
||||
|
||||
this.field_70170_p.func_72960_a(this, (byte)3);
|
||||
@@ -984,6 +1023,9 @@
|
||||
@@ -984,6 +1026,9 @@
|
||||
}
|
||||
|
||||
public void func_70653_a(Entity p_70653_1_, float p_70653_2_, double p_70653_3_, double p_70653_5_) {
|
||||
|
@ -187,7 +208,7 @@
|
|||
if (!(this.field_70146_Z.nextDouble() < this.func_110148_a(SharedMonsterAttributes.field_111266_c).func_111126_e())) {
|
||||
this.field_70160_al = true;
|
||||
float f = MathHelper.func_76133_a(p_70653_3_ * p_70653_3_ + p_70653_5_ * p_70653_5_);
|
||||
@@ -1028,12 +1070,7 @@
|
||||
@@ -1028,12 +1073,7 @@
|
||||
} else {
|
||||
BlockPos blockpos = new BlockPos(i, j, k);
|
||||
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos);
|
||||
|
@ -201,7 +222,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -1053,6 +1090,9 @@
|
||||
@@ -1053,6 +1093,9 @@
|
||||
}
|
||||
|
||||
public void func_180430_e(float p_180430_1_, float p_180430_2_) {
|
||||
|
@ -211,7 +232,7 @@
|
|||
super.func_180430_e(p_180430_1_, p_180430_2_);
|
||||
PotionEffect potioneffect = this.func_70660_b(MobEffects.field_76430_j);
|
||||
float f = potioneffect == null ? 0.0F : (float)(potioneffect.func_76458_c() + 1);
|
||||
@@ -1065,7 +1105,7 @@
|
||||
@@ -1065,7 +1108,7 @@
|
||||
int l = MathHelper.func_76128_c(this.field_70161_v);
|
||||
IBlockState iblockstate = this.field_70170_p.func_180495_p(new BlockPos(j, k, l));
|
||||
if (!iblockstate.func_196958_f()) {
|
||||
|
@ -220,7 +241,7 @@
|
|||
this.func_184185_a(soundtype.func_185842_g(), soundtype.func_185843_a() * 0.5F, soundtype.func_185847_b() * 0.75F);
|
||||
}
|
||||
}
|
||||
@@ -1134,6 +1174,8 @@
|
||||
@@ -1134,6 +1177,8 @@
|
||||
|
||||
protected void func_70665_d(DamageSource p_70665_1_, float p_70665_2_) {
|
||||
if (!this.func_180431_b(p_70665_1_)) {
|
||||
|
@ -229,7 +250,7 @@
|
|||
p_70665_2_ = this.func_70655_b(p_70665_1_, p_70665_2_);
|
||||
p_70665_2_ = this.func_70672_c(p_70665_1_, p_70665_2_);
|
||||
float f = p_70665_2_;
|
||||
@@ -1144,10 +1186,11 @@
|
||||
@@ -1144,10 +1189,11 @@
|
||||
((EntityPlayerMP)p_70665_1_.func_76346_g()).func_195067_a(StatList.field_212735_F, Math.round(f1 * 10.0F));
|
||||
}
|
||||
|
||||
|
@ -242,7 +263,7 @@
|
|||
this.func_110149_m(this.func_110139_bj() - p_70665_2_);
|
||||
}
|
||||
}
|
||||
@@ -1189,6 +1232,8 @@
|
||||
@@ -1189,6 +1235,8 @@
|
||||
}
|
||||
|
||||
public void func_184609_a(EnumHand p_184609_1_) {
|
||||
|
@ -251,7 +272,7 @@
|
|||
if (!this.field_82175_bq || this.field_110158_av >= this.func_82166_i() / 2 || this.field_110158_av < 0) {
|
||||
this.field_110158_av = -1;
|
||||
this.field_82175_bq = true;
|
||||
@@ -1373,18 +1418,18 @@
|
||||
@@ -1373,18 +1421,18 @@
|
||||
double d12 = d6 + d10;
|
||||
AxisAlignedBB axisalignedbb1 = axisalignedbb.func_72317_d(d9, 0.0D, d10);
|
||||
if (this.field_70170_p.func_195586_b(this, axisalignedbb1)) {
|
||||
|
@ -273,7 +294,7 @@
|
|||
d1 = d11;
|
||||
d13 = this.field_70163_u + 2.0D;
|
||||
d14 = d12;
|
||||
@@ -1439,15 +1484,16 @@
|
||||
@@ -1439,15 +1487,16 @@
|
||||
}
|
||||
|
||||
this.field_70160_al = true;
|
||||
|
@ -292,7 +313,7 @@
|
|||
}
|
||||
|
||||
protected float func_189749_co() {
|
||||
@@ -1518,7 +1564,7 @@
|
||||
@@ -1518,7 +1567,7 @@
|
||||
|
||||
try (BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.func_185345_c(this.field_70165_t, this.func_174813_aQ().field_72338_b - 1.0D, this.field_70161_v)) {
|
||||
if (this.field_70122_E) {
|
||||
|
@ -301,7 +322,7 @@
|
|||
}
|
||||
|
||||
float f8 = 0.16277137F / (f7 * f7 * f7);
|
||||
@@ -1532,7 +1578,7 @@
|
||||
@@ -1532,7 +1581,7 @@
|
||||
this.func_191958_b(p_191986_1_, p_191986_2_, p_191986_3_, f9);
|
||||
f7 = 0.91F;
|
||||
if (this.field_70122_E) {
|
||||
|
@ -310,7 +331,7 @@
|
|||
}
|
||||
|
||||
if (this.func_70617_f_()) {
|
||||
@@ -1663,6 +1709,7 @@
|
||||
@@ -1663,6 +1712,7 @@
|
||||
}
|
||||
|
||||
public void func_70071_h_() {
|
||||
|
@ -318,7 +339,7 @@
|
|||
super.func_70071_h_();
|
||||
this.func_184608_ct();
|
||||
this.func_205014_p();
|
||||
@@ -1694,7 +1741,9 @@
|
||||
@@ -1694,7 +1744,9 @@
|
||||
|
||||
ItemStack itemstack1 = this.func_184582_a(entityequipmentslot);
|
||||
if (!ItemStack.func_77989_b(itemstack1, itemstack)) {
|
||||
|
@ -328,7 +349,7 @@
|
|||
if (!itemstack.func_190926_b()) {
|
||||
this.func_110140_aT().func_111148_a(itemstack.func_111283_C(entityequipmentslot));
|
||||
}
|
||||
@@ -2134,11 +2183,18 @@
|
||||
@@ -2134,11 +2186,18 @@
|
||||
protected void func_184608_ct() {
|
||||
if (this.func_184587_cr()) {
|
||||
if (this.func_184586_b(this.func_184600_cs()) == this.field_184627_bm) {
|
||||
|
@ -348,7 +369,7 @@
|
|||
this.func_71036_o();
|
||||
}
|
||||
} else {
|
||||
@@ -2172,8 +2228,10 @@
|
||||
@@ -2172,8 +2231,10 @@
|
||||
public void func_184598_c(EnumHand p_184598_1_) {
|
||||
ItemStack itemstack = this.func_184586_b(p_184598_1_);
|
||||
if (!itemstack.func_190926_b() && !this.func_184587_cr()) {
|
||||
|
@ -360,7 +381,7 @@
|
|||
if (!this.field_70170_p.field_72995_K) {
|
||||
this.func_204802_c(1, true);
|
||||
this.func_204802_c(2, p_184598_1_ == EnumHand.OFF_HAND);
|
||||
@@ -2229,6 +2287,9 @@
|
||||
@@ -2229,6 +2290,9 @@
|
||||
vec3d1 = vec3d1.func_178789_a(-this.field_70125_A * ((float)Math.PI / 180F));
|
||||
vec3d1 = vec3d1.func_178785_b(-this.field_70177_z * ((float)Math.PI / 180F));
|
||||
vec3d1 = vec3d1.func_72441_c(this.field_70165_t, this.field_70163_u + (double)this.func_70047_e(), this.field_70161_v);
|
||||
|
@ -370,7 +391,7 @@
|
|||
this.field_70170_p.func_195594_a(new ItemParticleData(Particles.field_197591_B, p_195062_1_), vec3d1.field_72450_a, vec3d1.field_72448_b, vec3d1.field_72449_c, vec3d.field_72450_a, vec3d.field_72448_b + 0.05D, vec3d.field_72449_c);
|
||||
}
|
||||
|
||||
@@ -2237,7 +2298,9 @@
|
||||
@@ -2237,7 +2301,9 @@
|
||||
protected void func_71036_o() {
|
||||
if (!this.field_184627_bm.func_190926_b() && this.func_184587_cr()) {
|
||||
this.func_184584_a(this.field_184627_bm, 16);
|
||||
|
@ -381,7 +402,7 @@
|
|||
this.func_184602_cy();
|
||||
}
|
||||
|
||||
@@ -2257,6 +2320,7 @@
|
||||
@@ -2257,6 +2323,7 @@
|
||||
|
||||
public void func_184597_cx() {
|
||||
if (!this.field_184627_bm.func_190926_b()) {
|
||||
|
@ -389,7 +410,7 @@
|
|||
this.field_184627_bm.func_77974_b(this.field_70170_p, this, this.func_184605_cv());
|
||||
}
|
||||
|
||||
@@ -2363,4 +2427,62 @@
|
||||
@@ -2363,4 +2430,62 @@
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void func_191987_a(BlockPos p_191987_1_, boolean p_191987_2_) {
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue