spigot/CraftBukkit-Patches/0013-Entity-Activation-Range.patch

586 lines
24 KiB
Diff
Raw Normal View History

2019-10-18 20:03:04 +11:00
From 8108d1a322a2cf6460819d824a9aa11365ecc11e Mon Sep 17 00:00:00 2001
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
2019-07-20 09:00:00 +10:00
index ad25d45ea..c5ab2943d 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2019-04-27 10:30:04 +10:00
@@ -162,6 +162,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
2017-11-07 17:30:57 +11:00
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
public boolean forceExplosionKnockback; // SPIGOT-949
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
2016-03-01 08:33:06 +11:00
+ // Spigot start
+ public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
+ public final boolean defaultActivationState;
2014-12-21 09:01:55 +11:00
+ public long activatedTick = Integer.MIN_VALUE;
2013-06-08 09:27:14 +10:00
+ public void inactiveTick() { }
+ // Spigot end
2013-12-01 14:40:53 +11:00
2017-11-07 17:30:57 +11:00
public float getBukkitYaw() {
return this.yaw;
2019-05-28 06:30:00 +10:00
@@ -193,7 +199,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
this.setPosition(0.0D, 0.0D, 0.0D);
if (world != null) {
2018-08-26 12:00:00 +10:00
this.dimension = world.worldProvider.getDimensionManager();
+ // Spigot start
2013-06-20 19:00:26 +10:00
+ this.defaultActivationState = org.spigotmc.ActivationRange.initializeEntityActivationState(this, world.spigotConfig);
+ } else {
+ this.defaultActivationState = false;
}
+ // Spigot end
2013-12-01 14:40:53 +11:00
this.datawatcher = new DataWatcher(this);
2019-04-23 12:00:00 +10:00
this.datawatcher.register(Entity.W, (byte) 0);
2013-06-08 09:27:14 +10:00
diff --git a/src/main/java/net/minecraft/server/EntityAgeable.java b/src/main/java/net/minecraft/server/EntityAgeable.java
index dfd1a7da4..da9740a99 100644
2013-06-08 09:27:14 +10:00
--- a/src/main/java/net/minecraft/server/EntityAgeable.java
+++ b/src/main/java/net/minecraft/server/EntityAgeable.java
2019-04-23 12:00:00 +10:00
@@ -14,6 +14,31 @@ public abstract class EntityAgeable extends EntityCreature {
2018-07-15 10:00:00 +10:00
super(entitytypes, world);
}
2013-06-08 09:27:14 +10:00
+ // Spigot start
+ @Override
+ public void inactiveTick()
+ {
+ super.inactiveTick();
2015-02-28 11:36:22 +00:00
+ if ( this.world.isClientSide || this.ageLocked )
2013-06-08 09:27:14 +10:00
+ { // CraftBukkit
2019-04-23 12:00:00 +10:00
+ this.updateSize();
2013-06-08 09:27:14 +10:00
+ } else
+ {
+ int i = this.getAge();
+
+ if ( i < 0 )
+ {
+ ++i;
2014-12-01 20:42:58 +00:00
+ this.setAgeRaw( i );
2013-06-08 09:27:14 +10:00
+ } else if ( i > 0 )
+ {
+ --i;
2014-12-01 20:42:58 +00:00
+ this.setAgeRaw( i );
2013-06-08 09:27:14 +10:00
+ }
+ }
+ }
+ // Spigot end
+
2018-07-15 10:00:00 +10:00
@Nullable
public abstract EntityAgeable createChild(EntityAgeable entityageable);
diff --git a/src/main/java/net/minecraft/server/EntityAreaEffectCloud.java b/src/main/java/net/minecraft/server/EntityAreaEffectCloud.java
index 91b434aff..3a8e10533 100644
--- a/src/main/java/net/minecraft/server/EntityAreaEffectCloud.java
+++ b/src/main/java/net/minecraft/server/EntityAreaEffectCloud.java
@@ -158,6 +158,18 @@ public class EntityAreaEffectCloud extends Entity {
this.at = i;
}
+ // Spigot start - copied from below
+ @Override
+ public void inactiveTick() {
+ super.inactiveTick();
+
+ if (this.ticksLived >= this.waitTime + this.at) {
+ this.die();
+ return;
+ }
+ }
+ // Spigot end
+
@Override
public void tick() {
super.tick();
diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java
2019-07-20 09:00:00 +10:00
index 4ef5c40c7..14ca024e2 100644
--- a/src/main/java/net/minecraft/server/EntityArrow.java
+++ b/src/main/java/net/minecraft/server/EntityArrow.java
2019-04-23 12:00:00 +10:00
@@ -35,6 +35,18 @@ public abstract class EntityArrow extends Entity implements IProjectile {
private IntOpenHashSet az;
private List<Entity> aA;
+ // Spigot Start
+ @Override
+ public void inactiveTick()
+ {
+ if ( this.inGround )
+ {
2018-07-15 10:00:00 +10:00
+ this.despawnCounter += 1;
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
2019-04-23 12:00:00 +10:00
protected EntityArrow(EntityTypes<? extends EntityArrow> entitytypes, World world) {
2018-07-15 10:00:00 +10:00
super(entitytypes, world);
2019-04-23 12:00:00 +10:00
this.fromPlayer = EntityArrow.PickupStatus.DISALLOWED;
diff --git a/src/main/java/net/minecraft/server/EntityFireworks.java b/src/main/java/net/minecraft/server/EntityFireworks.java
2019-10-18 20:03:04 +11:00
index a7e239a22..8f4116cde 100644
--- a/src/main/java/net/minecraft/server/EntityFireworks.java
+++ b/src/main/java/net/minecraft/server/EntityFireworks.java
@@ -18,6 +18,22 @@ public class EntityFireworks extends Entity implements IProjectile {
2019-04-23 12:00:00 +10:00
super(entitytypes, world);
2016-03-01 08:33:06 +11:00
}
+ // Spigot Start - copied from tick
+ @Override
2016-03-01 08:33:06 +11:00
+ public void inactiveTick() {
+ this.ticksFlown += 1;
+
+ if (!this.world.isClientSide && this.ticksFlown > this.expectedLifespan) {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) {
+ this.explode();
+ }
+ // CraftBukkit end
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
2019-04-23 12:00:00 +10:00
@Override
protected void initDatawatcher() {
2016-11-17 12:41:12 +11:00
this.datawatcher.register(EntityFireworks.FIREWORK_ITEM, ItemStack.a);
diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
2019-10-18 20:03:04 +11:00
index ccbb81bdb..87158dc85 100644
--- a/src/main/java/net/minecraft/server/EntityItem.java
+++ b/src/main/java/net/minecraft/server/EntityItem.java
2019-05-14 10:00:00 +10:00
@@ -137,6 +137,28 @@ public class EntityItem extends Entity {
}
}
+ // Spigot start - copied from above
+ @Override
+ public void inactiveTick() {
+ // CraftBukkit start - Use wall time for pickup and despawn timers
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+ if (this.pickupDelay != 32767) this.pickupDelay -= elapsedTicks;
+ if (this.age != -32768) this.age += elapsedTicks;
+ this.lastTick = MinecraftServer.currentTick;
+ // CraftBukkit end
+
2015-02-28 11:36:22 +00:00
+ if (!this.world.isClientSide && this.age >= world.spigotConfig.itemDespawnRate) { // Spigot
+ // CraftBukkit start - fire ItemDespawnEvent
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
+ this.die();
+ }
+ }
+ // Spigot end
+
2019-04-23 12:00:00 +10:00
private void v() {
Vec3D vec3d = this.getMot();
2013-06-08 09:27:14 +10:00
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 1a3e6b2fa..bd8480ae3 100644
2013-06-08 09:27:14 +10:00
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2019-04-23 12:00:00 +10:00
@@ -132,6 +132,13 @@ public abstract class EntityLiving extends Entity {
2017-11-07 17:30:57 +11:00
return getHeadRotation();
}
2013-06-08 09:27:14 +10:00
// CraftBukkit end
+ // Spigot start
+ public void inactiveTick()
+ {
+ super.inactiveTick();
2015-02-28 11:36:22 +00:00
+ ++this.ticksFarFromPlayer; // Above all the floats
2013-06-08 09:27:14 +10:00
+ }
+ // Spigot end
2019-04-23 12:00:00 +10:00
protected EntityLiving(EntityTypes<? extends EntityLiving> entitytypes, World world) {
2018-07-15 10:00:00 +10:00
super(entitytypes, world);
diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
index dca1bf090..89065deb4 100644
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
2019-07-20 09:00:00 +10:00
@@ -131,6 +131,17 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2019-04-23 12:00:00 +10:00
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(48.0D);
}
+ // Spigot Start
+ @Override
+ public void inactiveTick() {
+ // SPIGOT-3874, SPIGOT-3894, SPIGOT-3846, SPIGOT-5286 :(
+ if (world.spigotConfig.tickInactiveVillagers && this.df()) {
2019-04-23 12:00:00 +10:00
+ this.mobTick();
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
2019-04-23 12:00:00 +10:00
@Override
2018-07-15 10:00:00 +10:00
protected void mobTick() {
2019-04-23 12:00:00 +10:00
this.world.getMethodProfiler().enter("brain");
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-10-18 20:03:04 +11:00
index 070a5be16..85efa839c 100644
2019-04-23 12:00:00 +10:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-10-18 20:03:04 +11:00
@@ -346,6 +346,7 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
this.tickingEntities = true;
ObjectIterator objectiterator = this.entitiesById.int2ObjectEntrySet().iterator();
2019-04-23 12:00:00 +10:00
+ org.spigotmc.ActivationRange.activateEntities(this); // Spigot
timings.entityTick.startTiming(); // Spigot
while (objectiterator.hasNext()) {
Entry<Entity> entry = (Entry) objectiterator.next();
2019-10-18 20:03:04 +11:00
@@ -577,6 +578,14 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
public void entityJoinedWorld(Entity entity) {
if (entity instanceof EntityHuman || this.getChunkProvider().a(entity)) {
+ // Spigot start
+ if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
+ entity.ticksLived++;
+ entity.inactiveTick();
+ return;
+ }
+ // Spigot end
+
entity.tickTimer.startTiming(); // Spigot
2019-04-23 12:00:00 +10:00
entity.H = entity.locX;
entity.I = entity.locY;
2013-06-20 19:00:26 +10:00
diff --git a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
2019-07-20 09:00:00 +10:00
index 86f2d6b5c..b98a7b56a 100644
2013-06-20 19:00:26 +10:00
--- a/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
+++ b/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java
2019-04-23 15:12:43 +10:00
@@ -38,6 +38,9 @@ public class SpigotTimings {
2013-06-20 19:00:26 +10:00
public static final CustomTimingsHandler playerCommandTimer = new CustomTimingsHandler("** playerCommand");
2013-06-20 19:00:26 +10: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/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2019-10-18 20:03:04 +11:00
index 747994464..9d85fafbf 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2019-04-28 11:41:06 +10:00
@@ -473,6 +473,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
2016-11-24 09:47:25 +11:00
// SPIGOT-619: Force sync head rotation also
entity.setHeadRotation(location.getYaw());
2019-04-23 15:12:43 +10:00
+ ((net.minecraft.server.WorldServer) entity.world).chunkCheck(entity); // Spigot - register to new chunk
2016-11-24 09:47:25 +11:00
return true;
}
2013-06-20 19:00:26 +10:00
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
new file mode 100644
index 000000000..5f31b1a8f
2013-06-20 19:00:26 +10:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -0,0 +1,277 @@
2013-06-20 19:00:26 +10:00
+package org.spigotmc;
+
2019-04-23 12:00:00 +10:00
+import java.util.Collection;
+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.EntityCreeper;
+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;
2019-04-23 12:00:00 +10:00
+import net.minecraft.server.EntityLightning;
+import net.minecraft.server.EntityLiving;
+import net.minecraft.server.EntityMonster;
+import net.minecraft.server.EntityProjectile;
+import net.minecraft.server.EntityRaider;
+import net.minecraft.server.EntitySheep;
+import net.minecraft.server.EntitySlice;
+import net.minecraft.server.EntitySlime;
+import net.minecraft.server.EntityTNTPrimed;
2018-07-15 10:00:00 +10:00
+import net.minecraft.server.EntityThrownTrident;
2013-06-08 09:27:14 +10:00
+import net.minecraft.server.EntityVillager;
+import net.minecraft.server.EntityWither;
+import net.minecraft.server.MathHelper;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.World;
2013-06-20 19:00:26 +10:00
+import org.bukkit.craftbukkit.SpigotTimings;
+
2013-06-20 19:00:26 +10:00
+public class ActivationRange
+{
+
+ public enum ActivationType
+ {
+ MONSTER,
+ ANIMAL,
+ RAIDER,
+ MISC;
+
+ AxisAlignedBB boundingBox = new AxisAlignedBB( 0, 0, 0, 0, 0, 0 );
+ }
+
2016-03-01 08:33:06 +11:00
+ static AxisAlignedBB maxBB = new AxisAlignedBB( 0, 0, 0, 0, 0, 0 );
+
+ /**
+ * Initializes an entities type on construction to specify what group this
+ * entity is in for activation ranges.
+ *
+ * @param entity
+ * @return group id
+ */
+ public static ActivationType initializeEntityActivationType(Entity entity)
2013-06-20 19:00:26 +10:00
+ {
+ if ( entity instanceof EntityRaider )
+ {
+ return ActivationType.RAIDER;
+ } else if ( entity instanceof EntityMonster || entity instanceof EntitySlime )
2013-06-20 19:00:26 +10:00
+ {
+ return ActivationType.MONSTER;
2013-06-20 19:00:26 +10:00
+ } else if ( entity instanceof EntityCreature || entity instanceof EntityAmbient )
+ {
+ return ActivationType.ANIMAL;
2013-06-20 19:00:26 +10:00
+ } else
+ {
+ return ActivationType.MISC;
+ }
+ }
+
+ /**
+ * These entities are excluded from Activation range checks.
+ *
+ * @param entity
+ * @param config
+ * @return boolean If it should always tick.
+ */
2013-06-20 19:00:26 +10:00
+ public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config)
+ {
+ if ( ( entity.activationType == ActivationType.MISC && config.miscActivationRange == 0 )
+ || ( entity.activationType == ActivationType.RAIDER && config.raiderActivationRange == 0 )
+ || ( entity.activationType == ActivationType.ANIMAL && config.animalActivationRange == 0 )
+ || ( entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0 )
+ || entity instanceof EntityHuman
+ || entity instanceof EntityProjectile
+ || entity instanceof EntityEnderDragon
+ || entity instanceof EntityComplexPart
+ || entity instanceof EntityWither
+ || entity instanceof EntityFireball
2019-04-23 12:00:00 +10:00
+ || entity instanceof EntityLightning
+ || entity instanceof EntityTNTPrimed
+ || entity instanceof EntityEnderCrystal
2018-07-15 10:00:00 +10:00
+ || entity instanceof EntityFireworks
+ || entity instanceof EntityThrownTrident )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Find what entities are in range of the players in the world and set
+ * active if in range.
+ *
+ * @param world
+ */
2013-06-20 19:00:26 +10:00
+ public static void activateEntities(World world)
+ {
+ SpigotTimings.entityActivationCheckTimer.startTiming();
2013-06-20 19:00:26 +10:00
+ final int miscActivationRange = world.spigotConfig.miscActivationRange;
+ final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
2013-06-20 19:00:26 +10:00
+ final int animalActivationRange = world.spigotConfig.animalActivationRange;
+ final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
+
2013-06-20 19:00:26 +10:00
+ int maxRange = Math.max( monsterActivationRange, animalActivationRange );
+ maxRange = Math.max( maxRange, raiderActivationRange );
2013-06-20 19:00:26 +10:00
+ maxRange = Math.max( maxRange, miscActivationRange );
+ maxRange = Math.min( ( world.spigotConfig.viewDistance << 4 ) - 8, maxRange );
+
2019-04-23 12:00:00 +10:00
+ for ( EntityHuman player : world.getPlayers() )
2013-06-20 19:00:26 +10:00
+ {
+
+ player.activatedTick = MinecraftServer.currentTick;
+ maxBB = player.getBoundingBox().grow( maxRange, 256, maxRange );
+ ActivationType.MISC.boundingBox = player.getBoundingBox().grow( miscActivationRange, 256, miscActivationRange );
+ ActivationType.RAIDER.boundingBox = player.getBoundingBox().grow( raiderActivationRange, 256, raiderActivationRange );
+ ActivationType.ANIMAL.boundingBox = player.getBoundingBox().grow( animalActivationRange, 256, animalActivationRange );
+ ActivationType.MONSTER.boundingBox = player.getBoundingBox().grow( monsterActivationRange, 256, monsterActivationRange );
+
2018-10-23 06:00:00 +11:00
+ int i = MathHelper.floor( maxBB.minX / 16.0D );
+ int j = MathHelper.floor( maxBB.maxX / 16.0D );
+ int k = MathHelper.floor( maxBB.minZ / 16.0D );
+ int l = MathHelper.floor( maxBB.maxZ / 16.0D );
+
2013-06-20 19:00:26 +10: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 ) );
+ }
+ }
+ }
+ }
+ SpigotTimings.entityActivationCheckTimer.stopTiming();
+ }
+
+ /**
+ * Checks for the activation state of all entities in this chunk.
+ *
+ * @param chunk
+ */
2013-06-20 19:00:26 +10:00
+ private static void activateChunkEntities(Chunk chunk)
+ {
+ for ( EntitySlice slice : chunk.entitySlices )
2013-06-20 19:00:26 +10:00
+ {
2019-04-23 12:00:00 +10:00
+ for ( Entity entity : (Collection<Entity>) slice )
2013-06-20 19:00:26 +10:00
+ {
+ if ( MinecraftServer.currentTick > entity.activatedTick )
+ {
+ if ( entity.defaultActivationState )
+ {
+ entity.activatedTick = MinecraftServer.currentTick;
+ continue;
+ }
+ if ( entity.activationType.boundingBox.c( entity.getBoundingBox() ) )
2013-06-20 19:00:26 +10: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.
+ *
+ * @param entity
+ * @return
+ */
2013-06-20 19:00:26 +10:00
+ public static boolean checkEntityImmunities(Entity entity)
+ {
+ // quick checks.
2016-03-01 08:33:06 +11:00
+ if ( entity.inWater || entity.fireTicks > 0 )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
2013-06-20 19:00:26 +10:00
+ if ( !( entity instanceof EntityArrow ) )
+ {
+ if ( !entity.onGround || !entity.passengers.isEmpty() || entity.isPassenger() )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
2013-06-20 19:00:26 +10:00
+ } else if ( !( (EntityArrow) entity ).inGround )
+ {
+ return true;
+ }
+ // special cases.
2013-06-20 19:00:26 +10:00
+ if ( entity instanceof EntityLiving )
+ {
+ EntityLiving living = (EntityLiving) entity;
+ if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTicks > 0 || living.effects.size() > 0 )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
+ if ( entity instanceof EntityCreature && ( (EntityCreature) entity ).getGoalTarget() != null )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
2019-04-23 12:00:00 +10:00
+ if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).canBreed() )
2013-06-20 19:00:26 +10:00
+ {
2013-06-08 09:27:14 +10:00
+ return true;
+ }
2013-06-20 19:00:26 +10:00
+ if ( entity instanceof EntityAnimal )
+ {
+ EntityAnimal animal = (EntityAnimal) entity;
2016-03-01 08:33:06 +11:00
+ if ( animal.isBaby() || animal.isInLove() )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
2013-06-20 19:00:26 +10:00
+ if ( entity instanceof EntitySheep && ( (EntitySheep) entity ).isSheared() )
+ {
+ return true;
+ }
+ }
2016-03-01 08:33:06 +11:00
+ if (entity instanceof EntityCreeper && ((EntityCreeper) entity).isIgnited()) { // isExplosive
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the entity is active for this tick.
+ *
+ * @param entity
+ * @return
+ */
+ public static boolean checkIfActive(Entity entity)
2013-06-20 19:00:26 +10:00
+ {
+ SpigotTimings.checkIfActiveTimer.startTiming();
+ // Never safe to skip fireworks or entities not yet added to chunk
2018-07-15 10:00:00 +10:00
+ if ( !entity.inChunk || entity instanceof EntityFireworks ) {
+ SpigotTimings.checkIfActiveTimer.stopTiming();
+ return true;
+ }
+
+ boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
+
+ // Should this entity tick?
2013-06-20 19:00:26 +10:00
+ if ( !isActive )
+ {
+ if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
+ {
+ // Check immunities every 20 ticks.
2013-06-20 19:00:26 +10:00
+ if ( checkEntityImmunities( entity ) )
+ {
+ // 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 19:00:26 +10:00
+ } else if ( !entity.defaultActivationState && entity.ticksLived % 4 == 0 && !checkEntityImmunities( entity ) )
+ {
+ isActive = false;
+ }
+ SpigotTimings.checkIfActiveTimer.stopTiming();
+ return isActive;
2013-06-20 19:00:26 +10:00
+ }
+}
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 7dd66b48e..d873b32b9 100644
2013-06-20 19:00:26 +10:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -175,4 +175,19 @@ public class SpigotWorldConfig
2016-03-01 08:33:06 +11:00
itemDespawnRate = getInt( "item-despawn-rate", 6000 );
log( "Item Despawn Rate: " + itemDespawnRate );
}
+
2013-06-20 19:00:26 +10:00
+ public int animalActivationRange = 32;
+ public int monsterActivationRange = 32;
+ public int raiderActivationRange = 48;
2013-06-20 19:00:26 +10:00
+ public int miscActivationRange = 16;
+ public boolean tickInactiveVillagers = true;
2013-06-20 19:00:26 +10:00
+ private void activationRange()
+ {
+ animalActivationRange = getInt( "entity-activation-range.animals", animalActivationRange );
+ monsterActivationRange = getInt( "entity-activation-range.monsters", monsterActivationRange );
+ raiderActivationRange = getInt( "entity-activation-range.raiders", raiderActivationRange );
2013-06-20 19:00:26 +10:00
+ miscActivationRange = getInt( "entity-activation-range.misc", miscActivationRange );
+ tickInactiveVillagers = getBoolean( "entity-activation-range.tick-inactive-villagers", tickInactiveVillagers );
+ log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Ra " + raiderActivationRange + " / Mi " + miscActivationRange + " / Tiv " + tickInactiveVillagers );
2013-06-20 19:00:26 +10:00
+ }
}
--
2019-04-23 09:33:25 +10:00
2.20.1