2014-04-24 06:27:12 +00:00
From 7ee37a400f775d11d94b1382912ea39316871ff5 Mon Sep 17 00:00:00 2001
2013-02-26 17:21:40 +00:00
From: Aikar <aikar@aikar.co>
Date: Sun, 3 Feb 2013 05:10:21 -0500
Subject: [PATCH] Entity Activation Range
This feature gives 3 new configurable ranges that if an entity of the matching type is outside of this radius of any player, will tick at 5% of its normal rate.
This will drastically cut down on tick timings for entities that are not in range of a user to actually be "used".
This change can have dramatic impact on gameplay if configured too low. Balance according to your servers desired gameplay.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2014-04-18 17:08:19 +00:00
index d817369..0b6e9cf 100644
2013-02-26 17:21:40 +00:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2014-04-18 17:08:19 +00:00
@@ -91,7 +91,7 @@ public abstract class Entity {
2013-02-26 17:21:40 +00:00
public int ticksLived;
public int maxFireTicks;
public int fireTicks; // CraftBukkit - private -> public
2013-03-20 21:54:12 +00:00
- protected boolean inWater;
+ public boolean inWater; // Spigot - protected -> public
2013-02-26 17:21:40 +00:00
public int noDamageTicks;
private boolean justCreated;
protected boolean fireProof;
2014-04-18 17:08:19 +00:00
@@ -115,7 +115,13 @@ public abstract class Entity {
2013-07-02 03:03:56 +00:00
public boolean valid; // CraftBukkit
2014-01-31 20:42:29 +00:00
public org.bukkit.projectiles.ProjectileSource projectileSource; // CraftBukkit - For projectiles only
2013-02-26 17:21:40 +00:00
+ // Spigot start
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
2013-06-20 09:00:26 +00:00
+ public final byte activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
2013-02-26 17:21:40 +00:00
+ public final boolean defaultActivationState;
+ public long activatedTick = 0;
2013-06-07 23:27:14 +00:00
+ public void inactiveTick() { }
2013-02-26 17:21:40 +00:00
+ // Spigot end
2013-12-01 03:40:53 +00:00
public int getId() {
return this.id;
2014-04-18 17:08:19 +00:00
@@ -142,7 +148,12 @@ public abstract class Entity {
2013-02-26 17:21:40 +00:00
this.setPosition(0.0D, 0.0D, 0.0D);
if (world != null) {
this.dimension = world.worldProvider.dimension;
2013-02-27 15:10:07 +00:00
+ // Spigot start
2013-06-20 09:00:26 +00:00
+ this.defaultActivationState = org.spigotmc.ActivationRange.initializeEntityActivationState(this, world.spigotConfig);
2013-02-27 15:10:07 +00:00
+ } else {
+ this.defaultActivationState = false;
}
+ // Spigot end
2013-12-01 03:40:53 +00:00
this.datawatcher = new DataWatcher(this);
2013-02-27 15:10:07 +00:00
this.datawatcher.a(0, Byte.valueOf((byte) 0));
2013-06-07 23:27:14 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityAgeable.java b/src/main/java/net/minecraft/server/EntityAgeable.java
2013-12-01 03:40:53 +00:00
index 36ed831..7ddca48 100644
2013-06-07 23:27:14 +00:00
--- a/src/main/java/net/minecraft/server/EntityAgeable.java
+++ b/src/main/java/net/minecraft/server/EntityAgeable.java
@@ -6,6 +6,31 @@ public abstract class EntityAgeable extends EntityCreature {
2013-07-02 03:03:56 +00:00
private float bq;
2013-06-07 23:27:14 +00:00
public boolean ageLocked = false; // CraftBukkit
+ // Spigot start
+ @Override
+ public void inactiveTick()
+ {
+ super.inactiveTick();
+ if ( this.world.isStatic || this.ageLocked )
+ { // CraftBukkit
+ this.a( this.isBaby() );
+ } else
+ {
+ int i = this.getAge();
+
+ if ( i < 0 )
+ {
+ ++i;
+ this.setAge( i );
+ } else if ( i > 0 )
+ {
+ --i;
+ this.setAge( i );
+ }
+ }
+ }
+ // Spigot end
+
public EntityAgeable(World world) {
super(world);
}
2013-02-26 17:21:40 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java
2014-04-14 16:22:45 +00:00
index 3628774..3137bcf 100644
2013-02-26 17:21:40 +00:00
--- a/src/main/java/net/minecraft/server/EntityArrow.java
+++ b/src/main/java/net/minecraft/server/EntityArrow.java
2014-01-31 20:42:29 +00:00
@@ -15,7 +15,7 @@ public class EntityArrow extends Entity implements IProjectile {
2013-02-26 17:21:40 +00:00
private int f = -1;
2013-12-01 03:40:53 +00:00
private Block g;
2013-07-02 03:03:56 +00:00
private int h;
- private boolean inGround;
2013-02-26 17:21:40 +00:00
+ public boolean inGround = false; // Spigot - private -> public
2013-07-02 03:03:56 +00:00
public int fromPlayer;
public int shake;
2013-02-26 17:21:40 +00:00
public Entity shooter;
2014-04-14 16:22:45 +00:00
@@ -24,6 +24,18 @@ public class EntityArrow extends Entity implements IProjectile {
private double damage = 2.0D;
public int knockbackStrength; // CraftBukkit - private -> public
+ // Spigot Start
+ @Override
+ public void inactiveTick()
+ {
+ if ( this.inGround )
+ {
+ this.at += 19; // Despawn counter. First int after shooter
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
public EntityArrow(World world) {
super(world);
this.j = 10.0D;
diff --git a/src/main/java/net/minecraft/server/EntityFireworks.java b/src/main/java/net/minecraft/server/EntityFireworks.java
index a228a2c..0a81006 100644
--- a/src/main/java/net/minecraft/server/EntityFireworks.java
+++ b/src/main/java/net/minecraft/server/EntityFireworks.java
@@ -5,6 +5,15 @@ public class EntityFireworks extends Entity {
private int ticksFlown;
public int expectedLifespan; // CraftBukkit - private -> public
+ // Spigot Start
+ @Override
+ public void inactiveTick()
+ {
+ this.ticksFlown += 19;
+ super.inactiveTick();
+ }
+ // Spigot End
+
public EntityFireworks(World world) {
super(world);
this.a(0.25F, 0.25F);
2013-06-07 23:27:14 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2014-04-12 09:01:59 +00:00
index f90e2a3..6c77253 100644
2013-06-07 23:27:14 +00:00
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2013-07-09 00:31:10 +00:00
@@ -78,6 +78,13 @@ public abstract class EntityLiving extends Entity {
2013-07-02 22:27:18 +00:00
public int expToDrop;
2013-06-07 23:27:14 +00:00
public int maxAirTicks = 300;
// CraftBukkit end
+ // Spigot start
+ public void inactiveTick()
+ {
+ super.inactiveTick();
2014-04-12 09:01:59 +00:00
+ ++this.aU; // Above all the floats
2013-06-07 23:27:14 +00:00
+ }
+ // Spigot end
public EntityLiving(World world) {
super(world);
2013-02-26 17:21:40 +00:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2014-04-24 06:27:12 +00:00
index e0daffb..1a2a640 100644
2013-02-26 17:21:40 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2014-04-24 06:27:12 +00:00
@@ -1318,6 +1318,7 @@ public abstract class World implements IBlockAccess {
2013-02-26 17:21:40 +00:00
this.f.clear();
this.methodProfiler.c("regular");
2013-06-20 09:00:26 +00:00
+ org.spigotmc.ActivationRange.activateEntities(this); // Spigot
2013-02-26 17:21:40 +00:00
timings.entityTick.startTiming(); // Spigot
2014-02-12 13:48:26 +00:00
// CraftBukkit start - Use field for loop variable
for (this.tickPosition = 0; this.tickPosition < this.entityList.size(); ++this.tickPosition) {
2014-04-24 06:27:12 +00:00
@@ -1479,7 +1480,11 @@ public abstract class World implements IBlockAccess {
2013-03-15 21:35:56 +00:00
int j = MathHelper.floor(entity.locZ);
byte b0 = 32;
2013-02-26 17:21:40 +00:00
2013-12-01 03:40:53 +00:00
- if (!flag || this.b(i - b0, 0, j - b0, i + b0, 0, j + b0)) {
2013-02-26 17:21:40 +00:00
+ // Spigot start
2013-06-20 09:00:26 +00:00
+ if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
2013-02-26 17:21:40 +00:00
+ entity.ticksLived++;
2013-06-07 23:27:14 +00:00
+ entity.inactiveTick();
2013-02-26 17:21:40 +00:00
+ } else {
2013-12-01 03:40:53 +00:00
entity.tickTimer.startTiming(); // Spigot
2014-03-23 00:06:43 +00:00
entity.S = entity.locX;
entity.T = entity.locY;
2013-06-20 09:00:26 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
2013-08-03 09:54:36 +00:00
index 8340c13..541dfe4 100644
2013-06-20 09:00:26 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
+++ b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
2013-08-03 09:54:36 +00:00
@@ -30,6 +30,9 @@ public class SpigotTimings {
2013-06-11 03:14:01 +00:00
2013-06-20 09:00:26 +00:00
public static final CustomTimingsHandler playerCommandTimer = new CustomTimingsHandler("** playerCommand");
2013-02-26 17:21:40 +00:00
2013-06-20 09:00:26 +00:00
+ public static final CustomTimingsHandler entityActivationCheckTimer = new CustomTimingsHandler("entityActivationCheck");
+ public static final CustomTimingsHandler checkIfActiveTimer = new CustomTimingsHandler("** checkIfActive");
+
public static final HashMap<String, CustomTimingsHandler> entityTypeTimingMap = new HashMap<String, CustomTimingsHandler>();
public static final HashMap<String, CustomTimingsHandler> tileEntityTypeTimingMap = new HashMap<String, CustomTimingsHandler>();
public static final HashMap<String, CustomTimingsHandler> pluginTaskTimingMap = new HashMap<String, CustomTimingsHandler>();
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
new file mode 100644
2014-03-23 00:06:43 +00:00
index 0000000..06284ad
2013-06-20 09:00:26 +00:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -0,0 +1,296 @@
+package org.spigotmc;
+
2013-03-01 22:09:10 +00:00
+import java.util.ArrayList;
2013-04-23 01:27:55 +00:00
+import java.util.List;
+import net.minecraft.server.AxisAlignedBB;
+import net.minecraft.server.Chunk;
+import net.minecraft.server.Entity;
+import net.minecraft.server.EntityAmbient;
+import net.minecraft.server.EntityAnimal;
+import net.minecraft.server.EntityArrow;
+import net.minecraft.server.EntityComplexPart;
+import net.minecraft.server.EntityCreature;
+import net.minecraft.server.EntityEnderCrystal;
+import net.minecraft.server.EntityEnderDragon;
+import net.minecraft.server.EntityFireball;
+import net.minecraft.server.EntityFireworks;
+import net.minecraft.server.EntityHuman;
+import net.minecraft.server.EntityLiving;
+import net.minecraft.server.EntityMonster;
+import net.minecraft.server.EntityProjectile;
+import net.minecraft.server.EntitySheep;
+import net.minecraft.server.EntitySlime;
+import net.minecraft.server.EntityTNTPrimed;
2013-06-07 23:27:14 +00:00
+import net.minecraft.server.EntityVillager;
2013-04-23 01:27:55 +00:00
+import net.minecraft.server.EntityWeather;
+import net.minecraft.server.EntityWither;
+import net.minecraft.server.MathHelper;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.World;
2013-06-20 09:00:26 +00:00
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.SpigotTimings;
2013-02-26 17:21:40 +00:00
+
2013-06-20 09:00:26 +00:00
+public class ActivationRange
+{
+
+ static AxisAlignedBB maxBB = AxisAlignedBB.a( 0, 0, 0, 0, 0, 0 );
+ static AxisAlignedBB miscBB = AxisAlignedBB.a( 0, 0, 0, 0, 0, 0 );
+ static AxisAlignedBB animalBB = AxisAlignedBB.a( 0, 0, 0, 0, 0, 0 );
+ static AxisAlignedBB monsterBB = AxisAlignedBB.a( 0, 0, 0, 0, 0, 0 );
2013-02-26 17:21:40 +00:00
+
+ /**
+ * Initializes an entities type on construction to specify what group this
+ * entity is in for activation ranges.
2013-04-23 01:27:55 +00:00
+ *
2013-02-26 17:21:40 +00:00
+ * @param entity
+ * @return group id
+ */
2013-06-20 09:00:26 +00:00
+ public static byte initializeEntityActivationType(Entity entity)
+ {
+ if ( entity instanceof EntityMonster || entity instanceof EntitySlime )
+ {
2013-02-26 17:21:40 +00:00
+ return 1; // Monster
2013-06-20 09:00:26 +00:00
+ } else if ( entity instanceof EntityCreature || entity instanceof EntityAmbient )
+ {
2013-02-26 17:21:40 +00:00
+ return 2; // Animal
2013-06-20 09:00:26 +00:00
+ } else
+ {
2013-02-26 17:21:40 +00:00
+ return 3; // Misc
+ }
+ }
+
+ /**
+ * These entities are excluded from Activation range checks.
+ *
+ * @param entity
+ * @param world
+ * @return boolean If it should always tick.
+ */
2013-06-20 09:00:26 +00:00
+ public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config)
+ {
+ if ( ( entity.activationType == 3 && config.miscActivationRange == 0 )
+ || ( entity.activationType == 2 && config.animalActivationRange == 0 )
+ || ( entity.activationType == 1 && config.monsterActivationRange == 0 )
2013-04-23 01:27:55 +00:00
+ || entity instanceof EntityHuman
+ || entity instanceof EntityProjectile
+ || entity instanceof EntityEnderDragon
+ || entity instanceof EntityComplexPart
+ || entity instanceof EntityWither
+ || entity instanceof EntityFireball
+ || entity instanceof EntityWeather
+ || entity instanceof EntityTNTPrimed
+ || entity instanceof EntityEnderCrystal
2013-06-20 09:00:26 +00:00
+ || entity instanceof EntityFireworks )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Utility method to grow an AABB without creating a new AABB or touching
+ * the pool, so we can re-use ones we have.
2013-04-23 01:27:55 +00:00
+ *
2013-02-26 17:21:40 +00:00
+ * @param target
+ * @param source
+ * @param x
+ * @param y
+ * @param z
+ */
2013-06-20 09:00:26 +00:00
+ public static void growBB(AxisAlignedBB target, AxisAlignedBB source, int x, int y, int z)
+ {
2013-02-26 17:21:40 +00:00
+ target.a = source.a - x;
+ target.b = source.b - y;
+ target.c = source.c - z;
+ target.d = source.d + x;
+ target.e = source.e + y;
+ target.f = source.f + z;
+ }
+
+ /**
+ * Find what entities are in range of the players in the world and set
+ * active if in range.
2013-04-23 01:27:55 +00:00
+ *
2013-02-26 17:21:40 +00:00
+ * @param world
+ */
2013-06-20 09:00:26 +00:00
+ public static void activateEntities(World world)
+ {
2013-02-26 17:21:40 +00:00
+ SpigotTimings.entityActivationCheckTimer.startTiming();
2013-06-20 09:00:26 +00:00
+ final int miscActivationRange = world.spigotConfig.miscActivationRange;
+ final int animalActivationRange = world.spigotConfig.animalActivationRange;
+ final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
2013-02-26 17:21:40 +00:00
+
2013-06-20 09:00:26 +00:00
+ int maxRange = Math.max( monsterActivationRange, animalActivationRange );
+ maxRange = Math.max( maxRange, miscActivationRange );
+ maxRange = Math.min( ( world.spigotConfig.viewDistance << 4 ) - 8, maxRange );
2013-02-26 17:21:40 +00:00
+
2013-06-20 09:00:26 +00:00
+ for ( Entity player : new ArrayList<Entity>( world.players ) )
+ {
2013-02-26 17:21:40 +00:00
+
+ player.activatedTick = MinecraftServer.currentTick;
2013-06-20 09:00:26 +00:00
+ growBB( maxBB, player.boundingBox, maxRange, 256, maxRange );
+ growBB( miscBB, player.boundingBox, miscActivationRange, 256, miscActivationRange );
+ growBB( animalBB, player.boundingBox, animalActivationRange, 256, animalActivationRange );
+ growBB( monsterBB, player.boundingBox, monsterActivationRange, 256, monsterActivationRange );
2013-02-26 17:21:40 +00:00
+
2013-06-20 09:00:26 +00:00
+ int i = MathHelper.floor( maxBB.a / 16.0D );
+ int j = MathHelper.floor( maxBB.d / 16.0D );
+ int k = MathHelper.floor( maxBB.c / 16.0D );
+ int l = MathHelper.floor( maxBB.f / 16.0D );
2013-02-26 17:21:40 +00:00
+
2013-06-20 09:00:26 +00:00
+ for ( int i1 = i; i1 <= j; ++i1 )
+ {
+ for ( int j1 = k; j1 <= l; ++j1 )
+ {
+ if ( world.getWorld().isChunkLoaded( i1, j1 ) )
+ {
+ activateChunkEntities( world.getChunkAt( i1, j1 ) );
2013-02-26 17:21:40 +00:00
+ }
+ }
+ }
+ }
+ SpigotTimings.entityActivationCheckTimer.stopTiming();
+ }
+
+ /**
+ * Checks for the activation state of all entities in this chunk.
2013-04-23 01:27:55 +00:00
+ *
2013-02-26 17:21:40 +00:00
+ * @param chunk
+ */
2013-06-20 09:00:26 +00:00
+ private static void activateChunkEntities(Chunk chunk)
+ {
+ for ( List<Entity> slice : chunk.entitySlices )
+ {
+ for ( Entity entity : slice )
+ {
+ if ( MinecraftServer.currentTick > entity.activatedTick )
+ {
+ if ( entity.defaultActivationState )
+ {
2013-02-26 17:21:40 +00:00
+ entity.activatedTick = MinecraftServer.currentTick;
+ continue;
+ }
2013-06-20 09:00:26 +00:00
+ switch ( entity.activationType )
+ {
2013-02-26 17:21:40 +00:00
+ case 1:
2013-07-02 03:32:34 +00:00
+ if ( monsterBB.b( entity.boundingBox ) )
2013-06-20 09:00:26 +00:00
+ {
2013-02-26 17:21:40 +00:00
+ entity.activatedTick = MinecraftServer.currentTick;
+ }
+ break;
+ case 2:
2013-07-02 03:32:34 +00:00
+ if ( animalBB.b( entity.boundingBox ) )
2013-06-20 09:00:26 +00:00
+ {
2013-02-26 17:21:40 +00:00
+ entity.activatedTick = MinecraftServer.currentTick;
+ }
+ break;
+ case 3:
+ default:
2013-07-02 03:32:34 +00:00
+ if ( miscBB.b( entity.boundingBox ) )
2013-06-20 09:00:26 +00:00
+ {
2013-02-26 17:21:40 +00:00
+ entity.activatedTick = MinecraftServer.currentTick;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * If an entity is not in range, do some more checks to see if we should
+ * give it a shot.
2013-04-23 01:27:55 +00:00
+ *
2013-02-26 17:21:40 +00:00
+ * @param entity
+ * @return
+ */
2013-06-20 09:00:26 +00:00
+ public static boolean checkEntityImmunities(Entity entity)
+ {
2013-02-26 17:21:40 +00:00
+ // quick checks.
2013-06-20 09:00:26 +00:00
+ if ( entity.inWater /* isInWater */ || entity.fireTicks > 0 )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
2013-06-20 09:00:26 +00:00
+ if ( !( entity instanceof EntityArrow ) )
+ {
+ if ( !entity.onGround || entity.passenger != null
+ || entity.vehicle != null )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
2013-06-20 09:00:26 +00:00
+ } else if ( !( (EntityArrow) entity ).inGround )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
+ // special cases.
2013-06-20 09:00:26 +00:00
+ if ( entity instanceof EntityLiving )
+ {
2013-02-26 17:21:40 +00:00
+ EntityLiving living = (EntityLiving) entity;
2013-06-20 09:00:26 +00:00
+ if ( living.attackTicks > 0 || living.hurtTicks > 0 || living.effects.size() > 0 )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
2013-06-20 09:00:26 +00:00
+ if ( entity instanceof EntityCreature && ( (EntityCreature) entity ).target != null )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
2013-12-01 05:00:50 +00:00
+ if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).bY() /* Getter for first boolean */ )
2013-06-20 09:00:26 +00:00
+ {
2013-06-07 23:27:14 +00:00
+ return true;
+ }
2013-06-20 09:00:26 +00:00
+ if ( entity instanceof EntityAnimal )
+ {
2013-02-26 17:21:40 +00:00
+ EntityAnimal animal = (EntityAnimal) entity;
2014-03-23 00:06:43 +00:00
+ if ( animal.isBaby() || animal.ce() /*love*/ )
2013-06-20 09:00:26 +00:00
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
2013-06-20 09:00:26 +00:00
+ if ( entity instanceof EntitySheep && ( (EntitySheep) entity ).isSheared() )
+ {
2013-02-26 17:21:40 +00:00
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the entity is active for this tick.
2013-04-23 01:27:55 +00:00
+ *
2013-02-26 17:21:40 +00:00
+ * @param entity
+ * @return
+ */
2013-06-20 09:00:26 +00:00
+ public static boolean checkIfActive(Entity entity)
+ {
2013-02-26 17:21:40 +00:00
+ SpigotTimings.checkIfActiveTimer.startTiming();
+ boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
+
+ // Should this entity tick?
2013-06-20 09:00:26 +00:00
+ if ( !isActive )
+ {
+ if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
+ {
2013-02-26 17:21:40 +00:00
+ // Check immunities every 20 ticks.
2013-06-20 09:00:26 +00:00
+ if ( checkEntityImmunities( entity ) )
+ {
2013-02-26 17:21:40 +00:00
+ // Triggered some sort of immunity, give 20 full ticks before we check again.
+ entity.activatedTick = MinecraftServer.currentTick + 20;
+ }
+ isActive = true;
+ }
+ // Add a little performance juice to active entities. Skip 1/4 if not immune.
2013-06-20 09:00:26 +00:00
+ } else if ( !entity.defaultActivationState && entity.ticksLived % 4 == 0 && !checkEntityImmunities( entity ) )
+ {
2013-02-26 17:21:40 +00:00
+ isActive = false;
+ }
2013-06-20 09:00:26 +00:00
+ int x = MathHelper.floor( entity.locX );
+ int z = MathHelper.floor( entity.locZ );
2013-02-27 07:27:14 +00:00
+ // Make sure not on edge of unloaded chunk
2013-06-20 09:00:26 +00:00
+ if ( isActive && !entity.world.areChunksLoaded( x, 0, z, 16 ) )
+ {
2013-02-27 07:27:14 +00:00
+ isActive = false;
+ }
2013-02-26 17:21:40 +00:00
+ SpigotTimings.checkIfActiveTimer.stopTiming();
+ return isActive;
2013-06-20 09:00:26 +00:00
+ }
+}
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2014-03-09 22:14:45 +00:00
index 46249d7..ed2836a 100644
2013-06-20 09:00:26 +00:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2014-01-14 08:16:43 +00:00
@@ -138,4 +138,15 @@ public class SpigotWorldConfig
2013-06-21 07:41:26 +00:00
mobSpawnRange = (byte) getInt( "mob-spawn-range", 4 );
2013-06-21 07:35:08 +00:00
log( "Mob Spawn Range: " + mobSpawnRange );
2013-02-26 17:21:40 +00:00
}
+
2013-06-20 09:00:26 +00:00
+ public int animalActivationRange = 32;
+ public int monsterActivationRange = 32;
+ public int miscActivationRange = 16;
+ private void activationRange()
+ {
+ animalActivationRange = getInt( "entity-activation-range.animals", animalActivationRange );
+ monsterActivationRange = getInt( "entity-activation-range.monsters", monsterActivationRange );
+ miscActivationRange = getInt( "entity-activation-range.misc", miscActivationRange );
+ log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Mi " + miscActivationRange );
+ }
}
2013-02-26 17:21:40 +00:00
--
2014-04-18 17:08:19 +00:00
1.9.1
2013-02-26 17:21:40 +00:00