From f28f21b061f9402b7c766a2bb5f8b4356262ea61 Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Mon, 25 Apr 2022 02:16:01 -0700 Subject: [PATCH] Dont deregister scenes if the player is going to tp back into them --- .../emu/grasscutter/game/GenshinScene.java | 11 +++++++++- src/main/java/emu/grasscutter/game/World.java | 22 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/GenshinScene.java b/src/main/java/emu/grasscutter/game/GenshinScene.java index b738e6d26..60d72c9a7 100644 --- a/src/main/java/emu/grasscutter/game/GenshinScene.java +++ b/src/main/java/emu/grasscutter/game/GenshinScene.java @@ -47,6 +47,7 @@ public class GenshinScene { private final Set spawnedEntities; private final Set deadSpawnedEntities; + private boolean dontDestroyWhenEmpty; private int time; private ClimateType climate; @@ -121,6 +122,14 @@ public class GenshinScene { this.weather = weather; } + public boolean dontDestroyWhenEmpty() { + return dontDestroyWhenEmpty; + } + + public void setDontDestroyWhenEmpty(boolean dontDestroyWhenEmpty) { + this.dontDestroyWhenEmpty = dontDestroyWhenEmpty; + } + public Set getSpawnedEntities() { return spawnedEntities; } @@ -166,7 +175,7 @@ public class GenshinScene { } // Deregister scene if not in use - if (this.getEntities().size() <= 0) { + if (this.getEntities().size() <= 0 && !this.dontDestroyWhenEmpty()) { this.getWorld().deregisterScene(this); } } diff --git a/src/main/java/emu/grasscutter/game/World.java b/src/main/java/emu/grasscutter/game/World.java index ffffb1e53..25cbcd3e5 100644 --- a/src/main/java/emu/grasscutter/game/World.java +++ b/src/main/java/emu/grasscutter/game/World.java @@ -212,19 +212,29 @@ public class World implements Iterable { return false; } - Integer oldSceneId = null; + GenshinScene oldScene = null; if (player.getScene() != null) { - oldSceneId = player.getScene().getId(); - player.getScene().removePlayer(player); + oldScene = player.getScene(); + + // Dont deregister scenes if the player is going to tp back into them + if (oldScene.getId() == sceneId) { + oldScene.setDontDestroyWhenEmpty(true); + } + + oldScene.removePlayer(player); } - GenshinScene scene = this.getSceneById(sceneId); - scene.addPlayer(player); + GenshinScene newScene = this.getSceneById(sceneId); + newScene.addPlayer(player); player.getPos().set(pos); + if (oldScene != null) { + oldScene.setDontDestroyWhenEmpty(false); + } + // Teleport packet - if (oldSceneId.equals(sceneId)) { + if (oldScene == newScene) { player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterGoto, EnterReason.TransPoint, sceneId, pos)); } else { player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterJump, EnterReason.TransPoint, sceneId, pos));