Skip to content

Commit

Permalink
chore: some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Mar 23, 2024
1 parent 241bbbf commit 3d4466b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private void onPlayerInitialized(PlayerInitializedEvent event) {
list.add("Time: §a" + player.getWorld().getWorldData().getTime());
list.add("World: §a" + player.getWorld().getWorldData().getName());
list.add("DimId: §a" + player.getDimension().getDimensionInfo().dimensionId());
if (!player.isInWorld()) return true;
var loc = player.getLocation();
var chunk = player.getCurrentChunk();
if (chunk == null) return true;
int cx = chunk.getX();
int cz = chunk.getZ();
list.add("Chunk: §a" + cx + ", " + cz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public void setState(ChunkState next) {
} while (!STATE_FIELD.compareAndSet(this, curr, next));
}

private static void checkXYZ(int x, int y, int z) {
private void checkXYZ(int x, int y, int z) {
Preconditions.checkArgument(x >= 0 && x <= 15);
Preconditions.checkArgument(y >= -512 && y <= 511);
Preconditions.checkArgument(y >= dimensionInfo.minHeight() && y <= dimensionInfo.maxHeight());
Preconditions.checkArgument(z >= 0 && z <= 15);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ protected void handleScheduledMoveQueue() {
while (!queue.isEmpty()) {
var scheduledMove = queue.poll();
var entity = scheduledMove.entity;
// The entity may have been removed
if (!entities.containsKey(entity.getRuntimeId())) {
continue;
}
// Calculate delta pos (motion)
var motion = scheduledMove.newLoc.sub(entity.getLocation(), new Vector3f());
entity.setMotion(motion);
Expand Down Expand Up @@ -497,10 +501,13 @@ public boolean containEntity(Entity entity) {
return entities.containsKey(entity.getRuntimeId());
}

/**
* Please note that this method usually been called asynchronously <p/>
* See {@link org.allaymc.server.network.processor.PlayerAuthInputPacketProcessor#handleAsync}
*/
@Override
public void offerScheduledMove(Entity entity, Location3fc newLoc) {
if (!entities.containsKey(entity.getRuntimeId())) {
log.warn("Entity " + entity.getRuntimeId() + " is not registered in physics service");
return;
}
if (entity.getLocation().equals(newLoc)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private void removeEntityImmediately(Entity entity) {
var chunk = (AllayChunk) entity.getCurrentChunk();
if (chunk == null)
throw new IllegalStateException("Trying to despawn an entity from an unload chunk!");
entityPhysicsService.removeEntity(entity);
chunk.removeEntity(entity.getRuntimeId());
entityPhysicsService.removeEntity(entity);
entity.despawnFromAll();
entity.setWillBeDespawnedNextTick(false);
entity.setSpawned(false);
Expand Down

0 comments on commit 3d4466b

Please sign in to comment.