Paper/CraftBukkit-Patches/0022-Entity-Tracking-Ranges.patch

110 lines
4.9 KiB
Diff
Raw Normal View History

From 6dffe591a8463b5525a743b97af91e479e4b2e47 Mon Sep 17 00:00:00 2001
2013-03-23 00:12:04 +01:00
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/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java
2013-12-01 04:40:53 +01:00
index 97d0bbb..fc679ae 100644
2013-03-23 00:12:04 +01:00
--- a/src/main/java/net/minecraft/server/EntityTracker.java
+++ b/src/main/java/net/minecraft/server/EntityTracker.java
2013-12-01 04:40:53 +01:00
@@ -92,6 +92,7 @@ public class EntityTracker {
2013-03-23 00:12:04 +01:00
public void addEntity(Entity entity, int i, int j, boolean flag) {
if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous entity track!"); // Spigot
2013-06-20 11:37:15 +02:00
+ i = org.spigotmc.TrackingRange.getEntityTrackingRange(entity, i); // Spigot
2013-12-01 04:40:53 +01:00
if (i > this.e) {
i = this.e;
2013-03-23 00:12:04 +01:00
}
2013-06-20 11:37:15 +02:00
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 1d95207..de221d9 100644
2013-06-20 11:37:15 +02:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -149,4 +149,19 @@ public class SpigotWorldConfig
2013-06-20 11:37:15 +02:00
miscActivationRange = getInt( "entity-activation-range.misc", miscActivationRange );
log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Mi " + miscActivationRange );
}
+
+ public int playerTrackingRange = 48;
2013-03-23 00:12:04 +01:00
+ public int animalTrackingRange = 48;
+ public int monsterTrackingRange = 48;
2013-06-20 11:37:15 +02:00
+ public int miscTrackingRange = 32;
+ public int otherTrackingRange = 64;
2013-06-20 11:37:15 +02:00
+ 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 );
+ otherTrackingRange = getInt( "entity-tracking-range.other", otherTrackingRange );
+ log( "Entity Tracking Range: Pl " + playerTrackingRange + " / An " + animalTrackingRange + " / Mo " + monsterTrackingRange + " / Mi " + miscTrackingRange + " / Other " + otherTrackingRange );
2013-06-20 11:37:15 +02:00
+ }
}
diff --git a/src/main/java/org/spigotmc/TrackingRange.java b/src/main/java/org/spigotmc/TrackingRange.java
new file mode 100644
index 0000000..4bf4d2a
2013-06-20 11:37:15 +02:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/TrackingRange.java
@@ -0,0 +1,51 @@
2013-06-20 11:37:15 +02:00
+package org.spigotmc;
+
+import net.minecraft.server.Entity;
2013-04-25 01:01:05 +02:00
+import net.minecraft.server.EntityExperienceOrb;
+import net.minecraft.server.EntityGhast;
+import net.minecraft.server.EntityItem;
2013-06-08 01:29:32 +02:00
+import net.minecraft.server.EntityItemFrame;
2013-04-25 01:01:05 +02:00
+import net.minecraft.server.EntityPainting;
2013-06-20 11:37:15 +02:00
+import net.minecraft.server.EntityPlayer;
+
+public class TrackingRange
+{
+
2013-03-23 00:12:04 +01:00
+ /**
2013-06-20 11:37:15 +02:00
+ * Gets the range an entity should be 'tracked' by players and visible in
+ * the client.
+ *
2013-03-23 00:12:04 +01:00
+ * @param entity
+ * @param defaultRange Default range defined by Mojang
+ * @return
+ */
2013-06-20 11:37:15 +02:00
+ public static int getEntityTrackingRange(Entity entity, int defaultRange)
+ {
+ SpigotWorldConfig config = entity.world.spigotConfig;
+ if ( entity instanceof EntityPlayer )
+ {
+ return config.playerTrackingRange;
+ } else if ( entity.activationType == 1 )
2013-06-20 11:37:15 +02:00
+ {
+ return config.monsterTrackingRange;
+ } else if ( entity instanceof EntityGhast )
2013-06-20 11:37:15 +02:00
+ {
+ if ( config.monsterTrackingRange > config.monsterActivationRange )
+ {
+ return config.monsterTrackingRange;
+ } else
+ {
+ return config.monsterActivationRange;
+ }
2013-06-20 11:37:15 +02:00
+ } else if ( entity.activationType == 2 )
+ {
+ return config.animalTrackingRange;
2013-06-20 11:37:15 +02:00
+ } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityExperienceOrb )
+ {
+ return config.miscTrackingRange;
+ } else
+ {
+ return config.otherTrackingRange;
2013-03-23 00:12:04 +01:00
+ }
+ }
2013-06-20 11:37:15 +02:00
+}
2013-03-23 00:12:04 +01:00
--
1.8.5.2.msysgit.0
2013-03-23 00:12:04 +01:00