mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Move potion effect tick into its own method
This commit is contained in:
parent
ef58d770b4
commit
8acb2e292c
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user