First pass trying to optimise LivingUpdateEvent handlers, see issue #484

This commit is contained in:
Electroblob77
2020-08-03 22:47:08 +01:00
parent 9d8b0b3a90
commit 7401a8e3b4
6 changed files with 17 additions and 16 deletions
@@ -114,7 +114,8 @@ public class PotionContainment extends PotionMagicEffect {
@SubscribeEvent
public static void onLivingUpdateEvent(LivingUpdateEvent event){
if(event.getEntityLiving().getEntityData().hasKey(ENTITY_TAG)
// This is LAST-RESORT CLEANUP. It does NOT need checking every tick! We always check for the actual potion anyway.
if(event.getEntity().ticksExisted % 20 == 0 && event.getEntityLiving().getEntityData().hasKey(ENTITY_TAG)
&& !event.getEntityLiving().isPotionActive(WizardryPotions.containment)){
event.getEntityLiving().getEntityData().removeTag(ENTITY_TAG);
}
@@ -46,9 +46,10 @@ public class PotionDecay extends PotionMagicEffect {
// amplifier of the potion effect, and is too slow for this purpose.
EntityLivingBase target = event.getEntityLiving();
if(!target.world.isRemote && target.isPotionActive(WizardryPotions.decay) && target.onGround
&& target.ticksExisted % Constants.DECAY_SPREAD_INTERVAL == 0){
// Do the timing check first, it'll cut out 95% of calls to all subsequent conditions
if(target.ticksExisted % Constants.DECAY_SPREAD_INTERVAL == 0 && !target.world.isRemote
&& target.isPotionActive(WizardryPotions.decay) && target.onGround){
List<Entity> entities = target.world.getEntitiesWithinAABBExcludingEntity(target,
target.getEntityBoundingBox());