diff --git a/patches/server/Configurable-entity-tracking-range-by-Y-coordinate.patch b/patches/server/Configurable-entity-tracking-range-by-Y-coordinate.patch new file mode 100644 index 0000000000..b855a030a7 --- /dev/null +++ b/patches/server/Configurable-entity-tracking-range-by-Y-coordinate.patch @@ -0,0 +1,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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/level/ChunkMap.java ++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +@@ -0,0 +0,0 @@ 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())) { diff --git a/patches/server/Paper-config-files.patch b/patches/server/Paper-config-files.patch index 5626c41077..94defbff9b 100644 --- a/patches/server/Paper-config-files.patch +++ b/patches/server/Paper-config-files.patch @@ -1520,6 +1520,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +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; @@ -1530,6 +1532,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +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; @@ -1773,6 +1776,42 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + } + } ++ ++ 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;