From f2b3e5546465e00723669af91ec29a2488b7b9a3 Mon Sep 17 00:00:00 2001 From: liach <7806504+liach@users.noreply.github.com> Date: Wed, 31 Mar 2021 04:40:35 +0700 Subject: [PATCH] Clarify server player's watching position (#2199) * Clarify server player's watching position Fixes #2178 Signed-off-by: liach * Update poor names Signed-off-by: liach * Apply suggestions from code review Co-authored-by: YanisBft Co-authored-by: liach Co-authored-by: YanisBft --- .../server/network/ServerPlayerEntity.mapping | 28 +++++++++-- .../server/world/ServerChunkManager.mapping | 7 ++- .../world/ThreadedAnvilChunkStorage.mapping | 50 ++++++++++++++++--- 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/mappings/net/minecraft/server/network/ServerPlayerEntity.mapping b/mappings/net/minecraft/server/network/ServerPlayerEntity.mapping index d8e4e05312..9fb7e61277 100644 --- a/mappings/net/minecraft/server/network/ServerPlayerEntity.mapping +++ b/mappings/net/minecraft/server/network/ServerPlayerEntity.mapping @@ -24,7 +24,13 @@ CLASS net/minecraft/class_3222 net/minecraft/server/network/ServerPlayerEntity FIELD field_13987 networkHandler Lnet/minecraft/class_3244; FIELD field_13988 removedEntities Lit/unimi/dsi/fastutil/ints/IntList; FIELD field_13989 notInAnyWorld Z - FIELD field_13990 cameraPosition Lnet/minecraft/class_4076; + FIELD field_13990 watchedSection Lnet/minecraft/class_4076; + COMMENT A chunk section position indicating where the player's client is currently + COMMENT watching chunks from. Used referentially for the game to update the chunks + COMMENT watched by this player. + COMMENT + COMMENT @see #getWatchedSection() + COMMENT @see #setWatchedSection(ChunkSectionPos) FIELD field_13992 levitationStartPos Lnet/minecraft/class_243; FIELD field_13993 clientChatVisibility Lnet/minecraft/class_1659; FIELD field_13994 enteredNetherPos Lnet/minecraft/class_243; @@ -86,7 +92,15 @@ CLASS net/minecraft/class_3222 net/minecraft/server/network/ServerPlayerEntity METHOD method_14228 setExperiencePoints (I)V METHOD method_14230 isPvpEnabled ()Z METHOD method_14231 onDisconnect ()V - METHOD method_14232 getCameraPosition ()Lnet/minecraft/class_4076; + METHOD method_14232 getWatchedSection ()Lnet/minecraft/class_4076; + COMMENT Returns the chunk section position the player's client is currently watching + COMMENT from. This may differ from the chunk section the player is currently in. + COMMENT + COMMENT

This is only for chunk loading (watching) purpose. This is updated together + COMMENT with entity tracking, but they are separate mechanisms. + COMMENT + COMMENT @see #watchedSection + COMMENT @see #setWatchedSection(ChunkSectionPos) METHOD method_14234 updateLastActionTime ()V METHOD method_14235 onSpawn (Lnet/minecraft/class_1703;)V METHOD method_14236 getAdvancementTracker ()Lnet/minecraft/class_2985; @@ -125,8 +139,14 @@ CLASS net/minecraft/class_3222 net/minecraft/server/network/ServerPlayerEntity ARG 1 url ARG 2 hash ARG 3 required - METHOD method_17668 setCameraPosition (Lnet/minecraft/class_4076;)V - ARG 1 cameraPosition + METHOD method_17668 setWatchedSection (Lnet/minecraft/class_4076;)V + COMMENT Sets the chunk section position the player's client is currently watching + COMMENT from. This is usually called when the player moves to a new chunk section. + COMMENT + COMMENT @see #watchedSection + COMMENT @see #getWatchedSection() + ARG 1 section + COMMENT the updated section position METHOD method_18783 worldChanged (Lnet/minecraft/class_3218;)V ARG 1 origin METHOD method_26280 getSpawnPointPosition ()Lnet/minecraft/class_2338; diff --git a/mappings/net/minecraft/server/world/ServerChunkManager.mapping b/mappings/net/minecraft/server/world/ServerChunkManager.mapping index 5ec23b6077..1192c2a1a1 100644 --- a/mappings/net/minecraft/server/world/ServerChunkManager.mapping +++ b/mappings/net/minecraft/server/world/ServerChunkManager.mapping @@ -27,7 +27,12 @@ CLASS net/minecraft/class_3215 net/minecraft/server/world/ServerChunkManager METHOD method_12127 tick (Ljava/util/function/BooleanSupplier;)V ARG 1 shouldKeepTicking METHOD method_12129 getChunkGenerator ()Lnet/minecraft/class_2794; - METHOD method_14096 updateCameraPosition (Lnet/minecraft/class_3222;)V + METHOD method_14096 updatePosition (Lnet/minecraft/class_3222;)V + COMMENT Updates the chunk section position of the {@code player}. This can either be a + COMMENT result of the player's movement or its camera entity's movement. + COMMENT + COMMENT

This updates the section position player's client is currently watching and + COMMENT the player's position in its entity tracker. ARG 1 player METHOD method_14128 markForUpdate (Lnet/minecraft/class_2338;)V ARG 1 pos diff --git a/mappings/net/minecraft/server/world/ThreadedAnvilChunkStorage.mapping b/mappings/net/minecraft/server/world/ThreadedAnvilChunkStorage.mapping index 50a285e539..96744568ab 100644 --- a/mappings/net/minecraft/server/world/ThreadedAnvilChunkStorage.mapping +++ b/mappings/net/minecraft/server/world/ThreadedAnvilChunkStorage.mapping @@ -91,7 +91,11 @@ CLASS net/minecraft/class_3898 net/minecraft/server/world/ThreadedAnvilChunkStor METHOD method_18704 getSquaredDistance (Lnet/minecraft/class_1923;Lnet/minecraft/class_1297;)D ARG 0 pos ARG 1 entity - METHOD method_18713 updateCameraPosition (Lnet/minecraft/class_3222;)V + METHOD method_18713 updatePosition (Lnet/minecraft/class_3222;)V + COMMENT Updates the chunk section position of the {@code player}. This updates the player + COMMENT position for both entity tracking and chunk loading (watching) logic. + COMMENT + COMMENT @see ServerChunkManager#updatePosition(ServerPlayerEntity) ARG 1 player METHOD method_18714 handlePlayerAddedOrRemoved (Lnet/minecraft/class_3222;Z)V ARG 1 player @@ -107,11 +111,17 @@ CLASS net/minecraft/class_3898 net/minecraft/server/world/ThreadedAnvilChunkStor METHOD method_18719 getChebyshevDistance (Lnet/minecraft/class_1923;Lnet/minecraft/class_3222;Z)I ARG 0 pos ARG 1 player - ARG 2 useCameraPosition + ARG 2 useWatchedPosition METHOD method_18722 doesNotGenerateChunks (Lnet/minecraft/class_3222;)Z ARG 1 player METHOD method_18724 isTooFarFromPlayersToSpawnMobs (Lnet/minecraft/class_1923;)Z - METHOD method_18727 tickPlayerMovement ()V + METHOD method_18727 tickEntityMovement ()V + COMMENT Ticks and updates the tracked status of each tracker. + COMMENT + COMMENT

This first checks if entities have changed chunk sections, and updates + COMMENT tracking status of those entities to all players. It then checks if any player + COMMENT has changed chunk sections, and updates all entities tracking status to those + COMMENT players. This ensures all possible updates are accounted for. METHOD method_19488 getPointOfInterestStorage ()Lnet/minecraft/class_4153; METHOD method_20441 releaseLightTicket (Lnet/minecraft/class_1923;)V ARG 1 pos @@ -125,22 +135,40 @@ CLASS net/minecraft/class_3898 net/minecraft/server/world/ThreadedAnvilChunkStor ARG 2 requiredStatus METHOD method_20619 loadChunk (Lnet/minecraft/class_1923;)Ljava/util/concurrent/CompletableFuture; ARG 1 pos + METHOD method_20726 updateWatchedSection (Lnet/minecraft/class_3222;)Lnet/minecraft/class_4076; + COMMENT Updates the watched chunk section position for the {@code player}, and sends a + COMMENT render distance update packet to the client. + ARG 1 player METHOD method_21619 dump (Ljava/io/Writer;)V METHOD method_21676 getFutureStatus (Ljava/util/concurrent/CompletableFuture;)Ljava/lang/String; METHOD method_23272 getChunkLoadingDebugInfo (Lnet/minecraft/class_1923;)Ljava/lang/String; CLASS class_3208 EntityTracker + COMMENT An entity tracker governs which players' clients can see an entity. Each + COMMENT tracker corresponds to one entity in a server world and is mapped from the + COMMENT entity's network ID. + COMMENT + COMMENT @see ThreadedAnvilChunkStorage#entityTrackers FIELD field_18246 entry Lnet/minecraft/class_3231; FIELD field_18247 entity Lnet/minecraft/class_1297; FIELD field_18248 maxDistance I - FIELD field_18249 lastCameraPosition Lnet/minecraft/class_4076; + FIELD field_18249 trackedSection Lnet/minecraft/class_4076; + COMMENT The chunk section position of the tracked entity, may be outdated as an entity + COMMENT ticks. This is used by {@link ThreadedAnvilChunkStorage#tickEntityMovement() + COMMENT tickEntityMovement()} to bypass unnecessary status updates before calling + COMMENT {@link #updateTrackedStatus(ServerPlayerEntity) updateTrackedStatus()}. FIELD field_18250 listeners Ljava/util/Set; METHOD (Lnet/minecraft/class_3898;Lnet/minecraft/class_1297;IIZ)V - ARG 2 maxDistance - ARG 3 tickInterval + ARG 2 entity + ARG 3 maxDistance + ARG 4 tickInterval + ARG 5 alwaysUpdateVelocity METHOD equals (Ljava/lang/Object;)Z ARG 1 o METHOD method_18728 stopTracking ()V - METHOD method_18729 updateCameraPosition (Ljava/util/List;)V + METHOD method_18729 updateTrackedStatus (Ljava/util/List;)V + COMMENT Updates the tracked status of this tracker's entity for the given players. + COMMENT + COMMENT @see updateTrackedStatus(ServerPlayerEntity) ARG 1 players METHOD method_18730 sendToOtherNearbyPlayers (Lnet/minecraft/class_2596;)V ARG 1 packet @@ -148,7 +176,13 @@ CLASS net/minecraft/class_3898 net/minecraft/server/world/ThreadedAnvilChunkStor ARG 1 player METHOD method_18734 sendToNearbyPlayers (Lnet/minecraft/class_2596;)V ARG 1 packet - METHOD method_18736 updateCameraPosition (Lnet/minecraft/class_3222;)V + METHOD method_18736 updateTrackedStatus (Lnet/minecraft/class_3222;)V + COMMENT Updates the tracked status of this tracker's entity for the {@code player}. + COMMENT + COMMENT

If this tracker should be listened by the player, the player's tracking + COMMENT listener is added if it is not in the listeners; if this tracker should not be + COMMENT listened by the player, the player's tracking listener is removed if it is in + COMMENT the listeners. ARG 1 player METHOD method_22844 getMaxTrackDistance ()I METHOD method_27906 adjustTrackingDistance (I)I