Move potion effect tick into its own method

This commit is contained in:
TheMode 2021-08-22 07:34:11 +02:00
parent ef58d770b4
commit 8acb2e292c

View File

@ -448,19 +448,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
EventDispatcher.call(new EntityTickEvent(this));
// remove expired effects
if (!effects.isEmpty()) {
this.effects.removeIf(timedPotion -> {
final long potionTime = (long) timedPotion.getPotion().getDuration() * MinecraftServer.TICK_MS;
// Remove if the potion should be expired
if (time >= timedPotion.getStartingTime() + potionTime) {
// Send the packet that the potion should no longer be applied
timedPotion.getPotion().sendRemovePacket(this);
EventDispatcher.call(new EntityPotionRemoveEvent(this, timedPotion.getPotion()));
return true;
}
return false;
});
}
effectTick(time);
}
// Scheduled synchronization
if (!Cooldown.hasCooldown(time, lastAbsoluteSynchronizationTime, getSynchronizationCooldown())) {
@ -581,6 +569,22 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
}
}
private void effectTick(long time) {
final List<TimedPotion> effects = this.effects;
if (effects.isEmpty()) return;
effects.removeIf(timedPotion -> {
final long potionTime = (long) timedPotion.getPotion().getDuration() * MinecraftServer.TICK_MS;
// Remove if the potion should be expired
if (time >= timedPotion.getStartingTime() + potionTime) {
// Send the packet that the potion should no longer be applied
timedPotion.getPotion().sendRemovePacket(this);
EventDispatcher.call(new EntityPotionRemoveEvent(this, timedPotion.getPotion()));
return true;
}
return false;
});
}
/**
* Gets the number of ticks this entity has been active for.
*