mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 00:47:38 +01:00
015e038b89
Tick a hopper only if certain conditions have changed i.e. inventory changes, redstone updates, etc.
149 lines
6.5 KiB
Diff
149 lines
6.5 KiB
Diff
From 23f036658cfea94cb5d68f4522617d3a77dcd2be 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/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java
|
|
index de38e80..1f7dd1a 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityTracker.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityTracker.java
|
|
@@ -95,6 +95,7 @@ public class EntityTracker {
|
|
|
|
public void addEntity(Entity entity, int i, final int j, boolean flag) {
|
|
org.spigotmc.AsyncCatcher.catchOp( "entity track"); // Spigot
|
|
+ i = org.spigotmc.TrackingRange.getEntityTrackingRange(entity, i); // Spigot
|
|
if (i > this.e) {
|
|
i = this.e;
|
|
}
|
|
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
|
|
index d3f4af1..0143623 100644
|
|
--- a/src/main/java/org/spigotmc/ActivationRange.java
|
|
+++ b/src/main/java/org/spigotmc/ActivationRange.java
|
|
@@ -106,7 +106,7 @@ public class ActivationRange
|
|
maxRange = Math.max( maxRange, miscActivationRange );
|
|
maxRange = Math.min( ( world.spigotConfig.viewDistance << 4 ) - 8, maxRange );
|
|
|
|
- for ( Entity player : (List<Entity>) world.players )
|
|
+ for ( Entity player : (List<Entity>) (List) world.players )
|
|
{
|
|
|
|
player.activatedTick = MinecraftServer.currentTick;
|
|
@@ -188,7 +188,7 @@ public class ActivationRange
|
|
public static boolean checkEntityImmunities(Entity entity)
|
|
{
|
|
// quick checks.
|
|
- if ( entity.inWater /* isInWater */ || entity.fireTicks > 0 )
|
|
+ if ( entity.inWater || entity.fireTicks > 0 )
|
|
{
|
|
return true;
|
|
}
|
|
@@ -215,14 +215,14 @@ public class ActivationRange
|
|
{
|
|
return true;
|
|
}
|
|
- if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).ck() /* Getter for first boolean */ )
|
|
+ if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).cm() /* Getter for first boolean */ )
|
|
{
|
|
return true;
|
|
}
|
|
if ( entity instanceof EntityAnimal )
|
|
{
|
|
EntityAnimal animal = (EntityAnimal) entity;
|
|
- if ( animal.isBaby() || animal.cp() /*love*/ )
|
|
+ if ( animal.isBaby() || animal.isInLove() )
|
|
{
|
|
return true;
|
|
}
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
index da8563b..3d4896b 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
@@ -151,4 +151,19 @@ public class SpigotWorldConfig
|
|
miscActivationRange = getInt( "entity-activation-range.misc", miscActivationRange );
|
|
log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Mi " + miscActivationRange );
|
|
}
|
|
+
|
|
+ public int playerTrackingRange = 48;
|
|
+ public int animalTrackingRange = 48;
|
|
+ public int monsterTrackingRange = 48;
|
|
+ public int miscTrackingRange = 32;
|
|
+ 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 );
|
|
+ otherTrackingRange = getInt( "entity-tracking-range.other", otherTrackingRange );
|
|
+ log( "Entity Tracking Range: Pl " + playerTrackingRange + " / An " + animalTrackingRange + " / Mo " + monsterTrackingRange + " / Mi " + miscTrackingRange + " / 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 0000000..4bf4d2a
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/spigotmc/TrackingRange.java
|
|
@@ -0,0 +1,51 @@
|
|
+package org.spigotmc;
|
|
+
|
|
+import net.minecraft.server.Entity;
|
|
+import net.minecraft.server.EntityExperienceOrb;
|
|
+import net.minecraft.server.EntityGhast;
|
|
+import net.minecraft.server.EntityItem;
|
|
+import net.minecraft.server.EntityItemFrame;
|
|
+import net.minecraft.server.EntityPainting;
|
|
+import net.minecraft.server.EntityPlayer;
|
|
+
|
|
+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)
|
|
+ {
|
|
+ SpigotWorldConfig config = entity.world.spigotConfig;
|
|
+ if ( entity instanceof EntityPlayer )
|
|
+ {
|
|
+ return config.playerTrackingRange;
|
|
+ } else if ( entity.activationType == 1 )
|
|
+ {
|
|
+ return config.monsterTrackingRange;
|
|
+ } else if ( entity instanceof EntityGhast )
|
|
+ {
|
|
+ if ( config.monsterTrackingRange > config.monsterActivationRange )
|
|
+ {
|
|
+ return config.monsterTrackingRange;
|
|
+ } else
|
|
+ {
|
|
+ return config.monsterActivationRange;
|
|
+ }
|
|
+ } else if ( entity.activationType == 2 )
|
|
+ {
|
|
+ return config.animalTrackingRange;
|
|
+ } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityExperienceOrb )
|
|
+ {
|
|
+ return config.miscTrackingRange;
|
|
+ } else
|
|
+ {
|
|
+ return config.otherTrackingRange;
|
|
+ }
|
|
+ }
|
|
+}
|
|
--
|
|
2.1.4
|
|
|