Skip to content

Commit

Permalink
feat: effect time updating
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jun 28, 2024
1 parent af00123 commit 291844d
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,23 @@ private void updateHitBoxAndCollisionBoxMetadata() {
@Override
public void tick() {
checkDead();
updateEffect();
}

protected void updateEffect() {
if (effects.isEmpty()) return;
for (var effect : effects.values().toArray(EffectInstance[]::new)) {
effect.setDuration(effect.getDuration() - 1);
if (effect.getDuration() <= 0) {
removeEffect(effect.getType());
}
}
}

protected void checkDead() {
if (attributeComponent == null) return;
if (attributeComponent.getHealth() == 0 && !dead) {
var event = new EntityDieEvent(thisEntity);
getWorld().getEventBus().callEvent(event);
manager.callEvent(new org.allaymc.api.entity.component.event.EntityDieEvent());
dead = true;
deadTimer = DEFAULT_DEAD_TIMER;
applyEntityEvent(EntityEventType.DEATH, 0);
onDie();
}
if (dead) {
if (deadTimer > 0) deadTimer--;
Expand All @@ -202,6 +208,16 @@ protected void checkDead() {
}
}

protected void onDie() {
var event = new EntityDieEvent(thisEntity);
getWorld().getEventBus().callEvent(event);
manager.callEvent(new org.allaymc.api.entity.component.event.EntityDieEvent());
dead = true;
deadTimer = DEFAULT_DEAD_TIMER;
applyEntityEvent(EntityEventType.DEATH, 0);
removeAllEffects();
}

protected void spawnDeadParticle() {
var offsetAABB = getOffsetAABB();
for (float x = offsetAABB.minX(); x <= offsetAABB.maxX(); x += 0.5f) {
Expand Down

0 comments on commit 291844d

Please sign in to comment.