13
0
geforkt von Mirrors/Paper
Paper/CraftBukkit-Patches/0033-Entity-Tracking-Ranges.patch

154 Zeilen
8.8 KiB
Diff

2013-06-11 06:06:05 +02:00
From 7a9eac68de775fb0a6335ab48aa250a50b455776 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
index d7efe3e..f6f1ab0 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
@@ -90,6 +90,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-03-23 00:12:04 +01:00
+ i = org.bukkit.craftbukkit.Spigot.getEntityTrackingRange(entity, i); // Spigot
if (i > this.d) {
i = this.d;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 2f9d859..6218f16 100644
2013-03-23 00:12:04 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -89,6 +89,12 @@ public class CraftWorld implements World {
2013-03-23 00:12:04 +01:00
public int miscEntityActivationRange = 16;
public int animalEntityActivationRange = 32;
public int monsterEntityActivationRange = 32;
+ // Tracking Ranges:
2013-03-23 00:12:04 +01:00
+ public int playerTrackingRange = 64;
+ public int miscTrackingRange = 32;
+ public int animalTrackingRange = 48;
+ public int monsterTrackingRange = 48;
+ public int maxTrackingRange = 64;
// Spigot end
public CraftWorld(WorldServer world, ChunkGenerator gen, Environment env) {
@@ -129,6 +135,11 @@ public class CraftWorld implements World {
miscEntityActivationRange = configuration.getInt( "world-settings.default.entity-activation-range-misc" );
animalEntityActivationRange = configuration.getInt( "world-settings.default.entity-activation-range-animals" );
monsterEntityActivationRange = configuration.getInt( "world-settings.default.entity-activation-range-monsters" );
+ playerTrackingRange = configuration.getInt( "world-settings.default.entity-tracking-range-players" );
+ miscTrackingRange = configuration.getInt( "world-settings.default.entity-tracking-range-misc" );
+ animalTrackingRange = configuration.getInt( "world-settings.default.entity-tracking-range-animals" );
+ monsterTrackingRange = configuration.getInt( "world-settings.default.entity-tracking-range-monsters" );
+ maxTrackingRange = configuration.getInt( "world-settings.default.entity-tracking-range-max" );
// Override defaults with world specific, if they exist
info = configuration.getBoolean( "world-settings." + name + ".info", info );
@@ -148,10 +159,19 @@ public class CraftWorld implements World {
miscEntityActivationRange = configuration.getInt( "world-settings." + name + ".entity-activation-range-misc", miscEntityActivationRange );
animalEntityActivationRange = configuration.getInt( "world-settings." + name + ".entity-activation-range-animals", animalEntityActivationRange );
monsterEntityActivationRange = configuration.getInt( "world-settings." + name + ".entity-activation-range-monsters", monsterEntityActivationRange );
+ maxTrackingRange = configuration.getInt( "world-settings." + name + ".entity-tracking-range-max", maxTrackingRange );
+ playerTrackingRange = Math.min( maxTrackingRange, configuration.getInt( "world-settings." + name + ".entity-tracking-range-players", playerTrackingRange ) );
+ miscTrackingRange = Math.min( maxTrackingRange, configuration.getInt( "world-settings." + name + ".entity-tracking-range-misc", miscTrackingRange ) );
+ animalTrackingRange = Math.min( maxTrackingRange, configuration.getInt( "world-settings." + name + ".entity-tracking-range-animals", animalTrackingRange ) );
+ monsterTrackingRange = Math.min( maxTrackingRange, configuration.getInt( "world-settings." + name + ".entity-tracking-range-monsters", monsterTrackingRange ) );
viewDistance = Bukkit.getServer().getViewDistance();
viewDistance = configuration.getInt( "world-settings." + name + ".view-distance", viewDistance );
obfuscated = world.getServer().orebfuscatorEnabled && !world.getServer().orebfuscatorDisabledWorlds.contains( name );
+ if ( maxTrackingRange == 0 )
+ {
+ System.err.println( "Error! Should not have 0 maxRange" );
+ }
if ( info )
{
@@ -173,6 +193,7 @@ public class CraftWorld implements World {
server.getLogger().info( "View distance: " + viewDistance );
server.getLogger().info( "Orebfuscator: " + obfuscated );
server.getLogger().info( "Entity Activation Range: An " + animalEntityActivationRange + " / Mo " + monsterEntityActivationRange + " / Mi " + miscEntityActivationRange );
+ server.getLogger().info( "Entity Tracking Range: Pl " + playerTrackingRange + " / An " + animalTrackingRange + " / Mo " + monsterTrackingRange + " / Mi " + miscTrackingRange + " / Max " + maxTrackingRange );
server.getLogger().info( "-------------------------------------------------" );
}
// Spigot end
2013-03-23 00:12:04 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/Spigot.java b/src/main/java/org/bukkit/craftbukkit/Spigot.java
2013-06-08 01:29:32 +02:00
index 6a164ca..c434f14 100644
2013-03-23 00:12:04 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/Spigot.java
+++ b/src/main/java/org/bukkit/craftbukkit/Spigot.java
2013-06-08 01:29:32 +02:00
@@ -16,11 +16,16 @@ import net.minecraft.server.EntityComplexPart;
2013-04-25 01:01:05 +02:00
import net.minecraft.server.EntityCreature;
import net.minecraft.server.EntityEnderCrystal;
import net.minecraft.server.EntityEnderDragon;
+import net.minecraft.server.EntityExperienceOrb;
import net.minecraft.server.EntityFireball;
import net.minecraft.server.EntityFireworks;
+import net.minecraft.server.EntityGhast;
import net.minecraft.server.EntityHuman;
+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.EntityLiving;
import net.minecraft.server.EntityMonster;
+import net.minecraft.server.EntityPainting;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityProjectile;
import net.minecraft.server.EntitySheep;
2013-06-08 01:29:32 +02:00
@@ -374,6 +379,30 @@ public class Spigot {
2013-03-23 00:12:04 +01:00
}
}
2013-03-23 00:12:04 +01:00
+ /**
+ * 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) {
+ CraftWorld world = entity.world.getWorld();
+ int range = defaultRange;
+ if (entity instanceof EntityPlayer) {
+ range = world.playerTrackingRange;
+ } else if (entity.defaultActivationState || entity instanceof EntityGhast) {
+ range = defaultRange;
+ } else if (entity.activationType == 1) {
+ range = world.monsterTrackingRange;
2013-03-23 00:12:04 +01:00
+ } else if (entity.activationType == 2) {
+ range = world.animalTrackingRange;
+ } else if (entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityExperienceOrb) {
+ range = world.miscTrackingRange;
+ }
+
2013-03-23 00:12:04 +01:00
+ return Math.min(world.maxTrackingRange, range);
+ }
+
2013-04-25 01:58:55 +02:00
public static boolean filterIp(PendingConnection con) {
if (filterIps) {
try {
2013-03-23 00:12:04 +01:00
diff --git a/src/main/resources/configurations/bukkit.yml b/src/main/resources/configurations/bukkit.yml
2013-06-11 04:10:31 +02:00
index 53db120..28d13fb 100644
2013-03-23 00:12:04 +01:00
--- a/src/main/resources/configurations/bukkit.yml
+++ b/src/main/resources/configurations/bukkit.yml
2013-04-23 03:50:42 +02:00
@@ -55,6 +55,11 @@ world-settings:
2013-03-23 00:12:04 +01:00
entity-activation-range-animals: 32
entity-activation-range-monsters: 32
entity-activation-range-misc: 16
+ entity-tracking-range-players: 48
+ entity-tracking-range-animals: 48
+ entity-tracking-range-monsters: 48
+ entity-tracking-range-misc: 32
+ entity-tracking-range-max: 64
info: true
2013-03-23 00:12:04 +01:00
world:
growth-chunks-per-tick: 1000
--
1.8.1.2
2013-03-23 00:12:04 +01:00