Fixes some possible NPEs in PotionEventHandler (#1668)

* Fixes some possible NPEs in PotionEventHandler

* Added Brackets for clarification

* Update PotionEventHandlers.java
This commit is contained in:
Tobias 2019-11-05 03:21:29 +01:00 committed by Nick Ignoffo
parent 5f31f8c69a
commit 268469f078

View file

@ -93,6 +93,7 @@ public class PotionEventHandlers {
// } // }
// } // }
List<EntityLivingBase> noGravityList = noGravityListMap.getOrDefault(event.getEntityLiving().getEntityWorld(), Lists.newArrayList()); List<EntityLivingBase> noGravityList = noGravityListMap.getOrDefault(event.getEntityLiving().getEntityWorld(), Lists.newArrayList());
if (noGravityList != null) {
if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.SUSPENDED) && !eventEntityLiving.hasNoGravity()) { if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.SUSPENDED) && !eventEntityLiving.hasNoGravity()) {
eventEntityLiving.setNoGravity(true); eventEntityLiving.setNoGravity(true);
noGravityList.add(eventEntityLiving); noGravityList.add(eventEntityLiving);
@ -100,12 +101,17 @@ public class PotionEventHandlers {
eventEntityLiving.setNoGravity(false); eventEntityLiving.setNoGravity(false);
noGravityList.remove(eventEntityLiving); noGravityList.remove(eventEntityLiving);
} }
}
if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.GROUNDED)) if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.GROUNDED)) {
PotionEffect activeEffect = eventEntityLiving.getActivePotionEffect(RegistrarBloodMagic.GROUNDED);
if (activeEffect != null) {
if (eventEntityLiving instanceof EntityPlayer && ((EntityPlayer) eventEntityLiving).capabilities.isFlying) if (eventEntityLiving instanceof EntityPlayer && ((EntityPlayer) eventEntityLiving).capabilities.isFlying)
eventEntityLiving.motionY -= (0.05D * (double) (eventEntityLiving.getActivePotionEffect(RegistrarBloodMagic.GROUNDED).getAmplifier() + 1) - eventEntityLiving.motionY) * 0.2D; eventEntityLiving.motionY -= (0.05D * (double) activeEffect.getAmplifier() + 1 - eventEntityLiving.motionY) * 0.2D;
else else
eventEntityLiving.motionY -= (0.1D * (double) (eventEntityLiving.getActivePotionEffect(RegistrarBloodMagic.GROUNDED).getAmplifier() + 1) - eventEntityLiving.motionY) * 0.2D; eventEntityLiving.motionY -= (0.1D * (double) activeEffect.getAmplifier() + 1 - eventEntityLiving.motionY) * 0.2D;
}
}
if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.WHIRLWIND)) { if (eventEntityLiving.isPotionActive(RegistrarBloodMagic.WHIRLWIND)) {
int d0 = 3; int d0 = 3;