Skip to content

Commit

Permalink
Add entity tracker min Y distance config option (#9406)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruViolence authored Aug 21, 2023
1 parent 1b96c64 commit 7232506
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
43 changes: 41 additions & 2 deletions patches/server/0005-Paper-config-files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,10 @@ index 0000000000000000000000000000000000000000..f0d4ec73bc8872a85e34f5c6b4d342e7
+}
diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..d47c57afafc01e25b965f1844938b2516a7bd031
index 0000000000000000000000000000000000000000..4989f99c0d330da52aeaca5df08edfbd47b5bf3c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -0,0 +1,484 @@
@@ -0,0 +1,523 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.collect.HashBasedTable;
Expand Down Expand Up @@ -1520,6 +1520,8 @@ index 0000000000000000000000000000000000000000..d47c57afafc01e25b965f1844938b251
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.Difficulty;
+import net.minecraft.world.entity.Display;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.MobCategory;
+import net.minecraft.world.entity.monster.Vindicator;
Expand All @@ -1530,6 +1532,7 @@ index 0000000000000000000000000000000000000000..d47c57afafc01e25b965f1844938b251
+import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
+import org.slf4j.Logger;
+import org.spigotmc.SpigotWorldConfig;
+import org.spigotmc.TrackingRange;
+import org.spongepowered.configurate.objectmapping.ConfigSerializable;
+import org.spongepowered.configurate.objectmapping.meta.Required;
+import org.spongepowered.configurate.objectmapping.meta.Setting;
Expand Down Expand Up @@ -1773,6 +1776,42 @@ index 0000000000000000000000000000000000000000..d47c57afafc01e25b965f1844938b251
+ }
+ }
+ }
+
+ public TrackingRangeY trackingRangeY;
+
+ public class TrackingRangeY extends ConfigurationPart {
+ public boolean enabled = false;
+ public IntOr.Default player = IntOr.Default.USE_DEFAULT;
+ public IntOr.Default animal = IntOr.Default.USE_DEFAULT;
+ public IntOr.Default monster = IntOr.Default.USE_DEFAULT;
+ public IntOr.Default misc = IntOr.Default.USE_DEFAULT;
+ public IntOr.Default display = IntOr.Default.USE_DEFAULT;
+ public IntOr.Default other = IntOr.Default.USE_DEFAULT;
+
+ public int get(Entity entity, int def) {
+ if (entity instanceof Display) return display.or(def);
+
+ switch (TrackingRange.getTrackingRangeType(entity)) {
+ case PLAYER -> {
+ return player.or(def);
+ }
+ case ANIMAL -> {
+ return animal.or(def);
+ }
+ case MONSTER -> {
+ return monster.or(def);
+ }
+ case MISC -> {
+ return misc.or(def);
+ }
+ case ENDERDRAGON -> {
+ return -1; // Ender dragon is exempt
+ }
+ }
+
+ return other.or(def);
+ }
+ }
+ }
+
+ public Lootables lootables;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ruViolence <[email protected]>
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 a4bf4ed615653ce30d2416a62e680d74e87b53fa..65d947df910d60f478e7a449eb161e5105e2c0c9 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1554,6 +1554,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
double d1 = vec3d_dx * vec3d_dx + vec3d_dz * vec3d_dz; // Paper
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(player);
+ // Paper start - check 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 - check Y

// CraftBukkit start - respect vanish API
if (!player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) {

0 comments on commit 7232506

Please sign in to comment.