aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0867-Configurable-entity-tracking-range-by-Y-coordinate.patch
blob: 294fe6ef9ee78e65e769fc445d5e52cd3965a215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ruViolence <78062896+ruViolence@users.noreply.github.com>
Date: Tue, 27 Jun 2023 15:38:18 +0800
Subject: [PATCH] Configurable entity tracking range by Y coordinate

Options to configure entity tracking by Y coordinate, also for each entity category.

diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index ca98b4c405afc2d86085759ba50d02eba75784a7..51c6f20a7402ff3809c8b7690fa4651eee0304cd 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1526,6 +1526,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
                 double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z;
                 double d2 = d0 * d0;
                 boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(player) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z);
+                // Paper start - Configurable entity tracking range by Y
+                if (flag && level.paperConfig().entities.trackingRangeY.enabled) {
+                    double rangeY = level.paperConfig().entities.trackingRangeY.get(this.entity, -1);
+                    if (rangeY != -1) {
+                        double vec3d_dy = player.getY() - this.entity.getY();
+                        flag = vec3d_dy * vec3d_dy <= rangeY * rangeY;
+                    }
+                }
+                // Paper end - Configurable entity tracking range by Y
 
                 // CraftBukkit start - respect vanish API
                 if (!player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) {