mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2024-11-21 20:56:14 +00:00
120 lines
5.7 KiB
Diff
120 lines
5.7 KiB
Diff
From 421bb2bea6b5a322bbfcba077f825247743f13ac Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 20 Feb 2013 11:58:47 -0500
|
|
Subject: [PATCH] Entity Tracking Ranges
|
|
|
|
This will let you configure how far to track entities in range from players, so that the entity does not render on the client if out of this range.
|
|
This has multiple benefits:
|
|
|
|
1) Less bandwidth. Not sending update packets for entities that are not even close to a player, or even close enough to clearly see.
|
|
2) Less lag by maps in item frames - Default range is 160 blocks... Many players can track that item frame and cause lag and not even see it.
|
|
3) Less lag in general - Less work for the server to do
|
|
4) Less client lag - Not trying to render distant item frames and paintings and entities will reduce entity count on the client, which is major for shop/town worlds which may use tons of item frames.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
index 54dcf22e5a..ba35aafbf9 100644
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
@@ -1270,6 +1270,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
|
|
if (!(entity instanceof EntityComplexPart)) {
|
|
EntityTypes<?> entitytypes = entity.getType();
|
|
int i = entitytypes.clientTrackingRange() * 16;
|
|
+ i = org.spigotmc.TrackingRange.getEntityTrackingRange(entity, i); // Spigot
|
|
|
|
if (i != 0) {
|
|
int j = entitytypes.updateInterval();
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
index 936279b5fb..ab984b2109 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
@@ -211,4 +211,21 @@ public class SpigotWorldConfig
|
|
ignoreSpectatorActivation = getBoolean( "entity-activation-range.ignore-spectators", ignoreSpectatorActivation );
|
|
log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Ra " + raiderActivationRange + " / Mi " + miscActivationRange + " / Tiv " + tickInactiveVillagers + " / Isa " + ignoreSpectatorActivation );
|
|
}
|
|
+
|
|
+ public int playerTrackingRange = 48;
|
|
+ public int animalTrackingRange = 48;
|
|
+ public int monsterTrackingRange = 48;
|
|
+ public int miscTrackingRange = 32;
|
|
+ public int displayTrackingRange = 128;
|
|
+ public int otherTrackingRange = 64;
|
|
+ private void trackingRange()
|
|
+ {
|
|
+ playerTrackingRange = getInt( "entity-tracking-range.players", playerTrackingRange );
|
|
+ animalTrackingRange = getInt( "entity-tracking-range.animals", animalTrackingRange );
|
|
+ monsterTrackingRange = getInt( "entity-tracking-range.monsters", monsterTrackingRange );
|
|
+ miscTrackingRange = getInt( "entity-tracking-range.misc", miscTrackingRange );
|
|
+ displayTrackingRange = getInt( "entity-tracking-range.display", displayTrackingRange );
|
|
+ otherTrackingRange = getInt( "entity-tracking-range.other", otherTrackingRange );
|
|
+ log( "Entity Tracking Range: Pl " + playerTrackingRange + " / An " + animalTrackingRange + " / Mo " + monsterTrackingRange + " / Mi " + miscTrackingRange + " / Di " + displayTrackingRange + " / Other " + otherTrackingRange );
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/org/spigotmc/TrackingRange.java b/src/main/java/org/spigotmc/TrackingRange.java
|
|
new file mode 100644
|
|
index 0000000000..7121ffcd8b
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/spigotmc/TrackingRange.java
|
|
@@ -0,0 +1,59 @@
|
|
+package org.spigotmc;
|
|
+
|
|
+import net.minecraft.server.level.EntityPlayer;
|
|
+import net.minecraft.world.entity.Display;
|
|
+import net.minecraft.world.entity.Entity;
|
|
+import net.minecraft.world.entity.EntityExperienceOrb;
|
|
+import net.minecraft.world.entity.decoration.EntityItemFrame;
|
|
+import net.minecraft.world.entity.decoration.EntityPainting;
|
|
+import net.minecraft.world.entity.item.EntityItem;
|
|
+import net.minecraft.world.entity.monster.EntityGhast;
|
|
+
|
|
+public class TrackingRange
|
|
+{
|
|
+
|
|
+ /**
|
|
+ * Gets the range an entity should be 'tracked' by players and visible in
|
|
+ * the client.
|
|
+ *
|
|
+ * @param entity
|
|
+ * @param defaultRange Default range defined by Mojang
|
|
+ * @return
|
|
+ */
|
|
+ public static int getEntityTrackingRange(Entity entity, int defaultRange)
|
|
+ {
|
|
+ if ( defaultRange == 0 )
|
|
+ {
|
|
+ return defaultRange;
|
|
+ }
|
|
+ SpigotWorldConfig config = entity.level().spigotConfig;
|
|
+ if ( entity instanceof EntityPlayer )
|
|
+ {
|
|
+ return config.playerTrackingRange;
|
|
+ } else if ( entity.activationType == ActivationRange.ActivationType.MONSTER || entity.activationType == ActivationRange.ActivationType.RAIDER )
|
|
+ {
|
|
+ return config.monsterTrackingRange;
|
|
+ } else if ( entity instanceof EntityGhast )
|
|
+ {
|
|
+ if ( config.monsterTrackingRange > config.monsterActivationRange )
|
|
+ {
|
|
+ return config.monsterTrackingRange;
|
|
+ } else
|
|
+ {
|
|
+ return config.monsterActivationRange;
|
|
+ }
|
|
+ } else if ( entity.activationType == ActivationRange.ActivationType.ANIMAL )
|
|
+ {
|
|
+ return config.animalTrackingRange;
|
|
+ } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityExperienceOrb )
|
|
+ {
|
|
+ return config.miscTrackingRange;
|
|
+ } else if ( entity instanceof Display )
|
|
+ {
|
|
+ return config.displayTrackingRange;
|
|
+ } else
|
|
+ {
|
|
+ return config.otherTrackingRange;
|
|
+ }
|
|
+ }
|
|
+}
|
|
--
|
|
2.47.0
|
|
|