From 8870675dcdeb634060368baac6b0154b005d1bf0 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Fri, 2 Jun 2023 14:31:52 -0400 Subject: [PATCH] Remove dead entities on scene tick --- .../java/emu/grasscutter/game/world/Scene.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index db6d525bf..32252780d 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -22,8 +22,8 @@ import emu.grasscutter.game.props.*; import emu.grasscutter.game.quest.QuestGroupSuite; import emu.grasscutter.game.world.data.TeleportProperties; import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.proto.*; import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult; +import emu.grasscutter.net.proto.*; import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; import emu.grasscutter.scripts.*; import emu.grasscutter.scripts.constants.EventType; @@ -33,11 +33,12 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.objects.KahnsSort; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import lombok.*; + +import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.*; import java.util.stream.Collectors; -import javax.annotation.Nullable; -import lombok.*; public final class Scene { @Getter private final World world; @@ -540,11 +541,18 @@ public final class Scene { } var sceneTime = getSceneTimeSeconds(); - getEntities().forEach((eid, e) -> e.onTick(sceneTime)); + + var entities = Map.copyOf(this.getEntities()); + entities.forEach( + (eid, e) -> { + if (!e.isAlive()) { + this.getEntities().remove(eid); + } else e.onTick(sceneTime); + }); blossomManager.onTick(); - checkNpcGroup(); + this.checkNpcGroup(); this.finishLoading(); this.checkPlayerRespawn();