mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-15 00:15:33 +01:00
Call checkSpawns from World instead of from Player
This commit is contained in:
@@ -695,10 +695,6 @@ public class GenshinPlayer {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
//
|
||||
if (this.getScene() != null && this.getSceneLoadState() == SceneLoadState.LOADED) {
|
||||
this.getScene().checkSpawns(this);
|
||||
}
|
||||
// Ping
|
||||
if (this.getWorld() != null) {
|
||||
// RTT notify - very important to send this often
|
||||
|
||||
@@ -315,32 +315,31 @@ public class GenshinScene {
|
||||
target.onDeath(attackerId);
|
||||
}
|
||||
|
||||
// TODO Do not use yet
|
||||
public synchronized void onTick() {
|
||||
for (GenshinPlayer player : this.getPlayers()) {
|
||||
this.checkSpawns(player);
|
||||
}
|
||||
public void onTick() {
|
||||
this.checkSpawns();
|
||||
}
|
||||
|
||||
// TODO - Test
|
||||
public void checkSpawns(GenshinPlayer player) {
|
||||
public void checkSpawns() {
|
||||
SpatialIndex<SpawnGroupEntry> list = GenshinDepot.getSpawnListById(this.getId());
|
||||
Set<SpawnDataEntry> visible = new HashSet<>();
|
||||
|
||||
int RANGE = 100;
|
||||
Collection<SpawnGroupEntry> entries = list.query(
|
||||
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE},
|
||||
new double[] {player.getPos().getX() + RANGE, player.getPos().getZ() + RANGE}
|
||||
);
|
||||
|
||||
for (SpawnGroupEntry entry : entries) {
|
||||
for (SpawnDataEntry spawnData : entry.getSpawns()) {
|
||||
visible.add(spawnData);
|
||||
for (GenshinPlayer player : this.getPlayers()) {
|
||||
int RANGE = 100;
|
||||
Collection<SpawnGroupEntry> entries = list.query(
|
||||
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE},
|
||||
new double[] {player.getPos().getX() + RANGE, player.getPos().getZ() + RANGE}
|
||||
);
|
||||
|
||||
for (SpawnGroupEntry entry : entries) {
|
||||
for (SpawnDataEntry spawnData : entry.getSpawns()) {
|
||||
visible.add(spawnData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// World level
|
||||
WorldLevelData worldLevelData = GenshinData.getWorldLevelDataMap().get(player.getWorldLevel());
|
||||
WorldLevelData worldLevelData = GenshinData.getWorldLevelDataMap().get(getWorld().getWorldLevel());
|
||||
int worldLevelOverride = 0;
|
||||
|
||||
if (worldLevelData != null) {
|
||||
|
||||
@@ -37,6 +37,7 @@ import emu.grasscutter.server.packet.send.PacketWorldPlayerInfoNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class World implements Iterable<GenshinPlayer> {
|
||||
@@ -58,11 +59,13 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
public World(GenshinPlayer player, boolean isMultiplayer) {
|
||||
this.owner = player;
|
||||
this.players = Collections.synchronizedList(new ArrayList<>());
|
||||
this.scenes = new Int2ObjectOpenHashMap<>();
|
||||
this.scenes = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
|
||||
|
||||
this.levelEntityId = getNextEntityId(EntityIdType.MPLEVEL);
|
||||
this.worldLevel = player.getWorldLevel();
|
||||
this.isMultiplayer = isMultiplayer;
|
||||
|
||||
this.owner.getServer().registerWorld(this);
|
||||
}
|
||||
|
||||
public GenshinPlayer getHost() {
|
||||
@@ -273,6 +276,12 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
}
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
for (GenshinScene scene : this.getScenes().values()) {
|
||||
scene.onTick();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user