performance: Many Entity Activation Range Improvements

1) Immunity no longer gives 20 tick immunity, each immunity check can
give its own tick value on how long it lasts, drastically cutting down on most to 0-1 ticks.

2) Fixed Villager Immunity to use proper 1.15 check for Breeding.

3) Fixed Water Mobs being 100% immune due to the inWater check...

4) Fixed flying mobs being 100% immune due to the !onGround check...

5) Made Insentient mobs only check for the hasTasks during immunity check window, not every single tick. this made them way more active than desired
  - this puts behavior closer to inline with my original behavior in Spigot, but still does some checks to allow them temporary immunity, just not as much as before.

6) Inactive Entities would "inch" while trying to move, effectively getting nowhere. Now while an entity is inactive, it just won't even try to move.
  - this saves us from the expensiveness of Entity movement 1 out of 20 ticks. Now they will only move while either active or triggered a true immunity.
This commit is contained in:
Aikar 2020-03-29 22:26:44 -04:00
parent 269394fe15
commit bacbd8805f
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
3 changed files with 172 additions and 43 deletions

View file

@ -1,4 +1,4 @@
From d50043feff731801bb51d0f14b5fe3654c2c9c63 Mon Sep 17 00:00:00 2001
From 2e1b3ceece0448dcb8edbe4d2bbd1a30fea0828c Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 13 May 2016 01:38:06 -0400
Subject: [PATCH] Activation Range Improvements
@ -10,10 +10,18 @@ Fixes and adds new Immunities to improve gameplay behavior
Adds water Mobs to activation range config and nerfs fish
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 2c8603e2f..659591e02 100644
index 2c8603e2fc..e10740a65c 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -553,6 +553,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@@ -192,6 +192,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
public final boolean defaultActivationState;
public long activatedTick = Integer.MIN_VALUE;
+ public boolean isTemporarilyActive = false; // Paper
public boolean spawnedViaMobSpawner; // Paper - Yes this name is similar to above, upstream took the better one
protected int numCollisions = 0; // Paper
public void inactiveTick() { }
@@ -553,6 +554,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
this.recalcPosition();
} else {
if (enummovetype == EnumMoveType.PISTON) {
@ -22,7 +30,7 @@ index 2c8603e2f..659591e02 100644
if (vec3d.equals(Vec3D.a)) {
return;
diff --git a/src/main/java/net/minecraft/server/EntityCreature.java b/src/main/java/net/minecraft/server/EntityCreature.java
index b40c8d2f8..4eda13075 100644
index b40c8d2f83..4eda130750 100644
--- a/src/main/java/net/minecraft/server/EntityCreature.java
+++ b/src/main/java/net/minecraft/server/EntityCreature.java
@@ -7,6 +7,7 @@ import org.bukkit.event.entity.EntityUnleashEvent;
@ -34,7 +42,7 @@ index b40c8d2f8..4eda13075 100644
protected EntityCreature(EntityTypes<? extends EntityCreature> entitytypes, World world) {
super(entitytypes, world);
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
index 6d53254f8..1991cee43 100644
index 6d53254f83..1991cee43d 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -114,6 +114,17 @@ public abstract class EntityInsentient extends EntityLiving {
@ -55,8 +63,21 @@ index 6d53254f8..1991cee43 100644
public ControllerMove getControllerMove() {
if (this.isPassenger() && this.getVehicle() instanceof EntityInsentient) {
EntityInsentient entityinsentient = (EntityInsentient) this.getVehicle();
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 1b9551ae09..d0dc1c127d 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2380,7 +2380,7 @@ public abstract class EntityLiving extends Entity {
}
}
- this.movementTick();
+ if (!this.isTemporarilyActive) this.movementTick(); // Paper - don't move if only temporarily active
double d0 = this.locX() - this.lastX;
double d1 = this.locZ() - this.lastZ;
float f = (float) (d0 * d0 + d1 * d1);
diff --git a/src/main/java/net/minecraft/server/EntityLlama.java b/src/main/java/net/minecraft/server/EntityLlama.java
index 6d4d41c88..193dbfc5f 100644
index 6d4d41c88c..193dbfc5f6 100644
--- a/src/main/java/net/minecraft/server/EntityLlama.java
+++ b/src/main/java/net/minecraft/server/EntityLlama.java
@@ -382,6 +382,7 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn
@ -68,7 +89,7 @@ index 6d4d41c88..193dbfc5f 100644
return this.bJ != null;
}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoal.java b/src/main/java/net/minecraft/server/PathfinderGoal.java
index f22f12eeb..bdb90a346 100644
index f22f12eeb0..bdb90a3466 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoal.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoal.java
@@ -20,7 +20,10 @@ public abstract class PathfinderGoal {
@ -84,7 +105,7 @@ index f22f12eeb..bdb90a346 100644
public void e() {}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalGotoTarget.java b/src/main/java/net/minecraft/server/PathfinderGoalGotoTarget.java
index 41fb166ce..e93129f0b 100644
index 41fb166ce0..e93129f0b2 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalGotoTarget.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalGotoTarget.java
@@ -4,12 +4,12 @@ import java.util.EnumSet;
@ -125,7 +146,7 @@ index 41fb166ce..e93129f0b 100644
}
}
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
index 44bb18c59..935136771 100644
index 44bb18c594..935136771e 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
@@ -24,10 +24,11 @@ public class PathfinderGoalSelector {
@ -169,7 +190,7 @@ index 44bb18c59..935136771 100644
this.d.stream().filter((pathfindergoalwrapped) -> {
return pathfindergoalwrapped.j() == pathfindergoal;
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java b/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java
index 5a8c60ad9..29657fed7 100644
index 5a8c60ad90..29657fed75 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalWrapped.java
@@ -64,6 +64,7 @@ public class PathfinderGoalWrapped extends PathfinderGoal {
@ -181,10 +202,35 @@ index 5a8c60ad9..29657fed7 100644
return this.c;
}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 92601c581..6e165a164 100644
index 92601c581c..b1cd59b047 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -33,12 +33,18 @@ import net.minecraft.server.MathHelper;
@@ -3,6 +3,7 @@ package org.spigotmc;
import java.util.Collection;
import java.util.List;
import net.minecraft.server.AxisAlignedBB;
+import net.minecraft.server.BehaviorController;
import net.minecraft.server.Chunk;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityAmbient;
@@ -16,10 +17,12 @@ import net.minecraft.server.EntityEnderDragon;
import net.minecraft.server.EntityFallingBlock; // Paper
import net.minecraft.server.EntityFireball;
import net.minecraft.server.EntityFireworks;
+import net.minecraft.server.EntityFlying;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityLightning;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityMonster;
+import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityProjectile;
import net.minecraft.server.EntityRaider;
import net.minecraft.server.EntitySheep;
@@ -30,15 +33,22 @@ import net.minecraft.server.EntityThrownTrident;
import net.minecraft.server.EntityVillager;
import net.minecraft.server.EntityWither;
import net.minecraft.server.MathHelper;
+import net.minecraft.server.MemoryModuleType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.World;
import co.aikar.timings.MinecraftTimings;
@ -203,7 +249,7 @@ index 92601c581..6e165a164 100644
MONSTER,
ANIMAL,
RAIDER,
@@ -58,6 +64,7 @@ public class ActivationRange
@@ -58,6 +68,7 @@ public class ActivationRange
*/
public static ActivationType initializeEntityActivationType(Entity entity)
{
@ -211,7 +257,7 @@ index 92601c581..6e165a164 100644
if ( entity instanceof EntityRaider )
{
return ActivationType.RAIDER;
@@ -86,6 +93,7 @@ public class ActivationRange
@@ -86,6 +97,7 @@ public class ActivationRange
|| ( entity.activationType == ActivationType.RAIDER && config.raiderActivationRange == 0 )
|| ( entity.activationType == ActivationType.ANIMAL && config.animalActivationRange == 0 )
|| ( entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0 )
@ -219,7 +265,7 @@ index 92601c581..6e165a164 100644
|| entity instanceof EntityHuman
|| entity instanceof EntityProjectile
|| entity instanceof EntityEnderDragon
@@ -118,6 +126,7 @@ public class ActivationRange
@@ -118,6 +130,7 @@ public class ActivationRange
final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
final int animalActivationRange = world.spigotConfig.animalActivationRange;
final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
@ -227,7 +273,7 @@ index 92601c581..6e165a164 100644
int maxRange = Math.max( monsterActivationRange, animalActivationRange );
maxRange = Math.max( maxRange, raiderActivationRange );
@@ -133,6 +142,8 @@ public class ActivationRange
@@ -133,6 +146,8 @@ public class ActivationRange
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 );
@ -236,45 +282,128 @@ index 92601c581..6e165a164 100644
int i = MathHelper.floor( maxBB.minX / 16.0D );
int j = MathHelper.floor( maxBB.maxX / 16.0D );
@@ -213,7 +224,7 @@ public class ActivationRange
@@ -188,22 +203,22 @@ public class ActivationRange
* @param entity
* @return
*/
- public static boolean checkEntityImmunities(Entity entity)
+ public static int checkEntityImmunities(Entity entity) // Paper - return # of ticks to get immunity
{
// quick checks.
- if ( entity.inWater || entity.fireTicks > 0 )
+ if ( (entity.activationType != ActivationType.WATER && entity.inWater) || entity.fireTicks > 0 ) // Paper
{
- return true;
+ return 1; // Paper
}
if ( !( entity instanceof EntityArrow ) )
{
- if ( !entity.onGround || !entity.passengers.isEmpty() || entity.isPassenger() )
+ if ( (!entity.onGround && !(entity instanceof EntityFlying)) || !entity.passengers.isEmpty() || entity.isPassenger() ) // Paper
{
return true;
- return true;
+ return 10; // Paper
}
} else if ( !( (EntityArrow) entity ).inGround )
{
- return true;
+ return 1; // Paper
}
// special cases.
if ( entity instanceof EntityLiving )
@@ -211,33 +226,49 @@ public class ActivationRange
EntityLiving living = (EntityLiving) entity;
if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTicks > 0 || living.effects.size() > 0 )
{
- return true;
+ return 1; // Paper
}
- if ( entity instanceof EntityCreature && ( (EntityCreature) entity ).getGoalTarget() != null )
+ if ( entity instanceof EntityCreature && (( (EntityCreature) entity ).getGoalTarget() != null || ( (EntityCreature) entity ).getMovingTarget() != null)) // Paper
+ if ( entity instanceof EntityCreature && ( (EntityCreature) entity ).getGoalTarget() instanceof EntityPlayer) // Paper
{
return true;
- return true;
+ return 20; // Paper
}
@@ -221,6 +232,12 @@ public class ActivationRange
+ // Paper start
if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).canBreed() )
{
return true;
}
- return true;
+ BehaviorController<EntityVillager> behaviorController = ((EntityVillager) entity).getBehaviorController();
+ if (behaviorController.hasMemory(MemoryModuleType.BREED_TARGET)) {
+ return 1;
+ }
+ // Paper end
+ }
+ // Paper start
+ if ( entity instanceof EntityLlama && ( (EntityLlama ) entity ).inCaravan() )
+ {
+ return true;
+ }
+ return 0;
}
+ // Paper end
if ( entity instanceof EntityAnimal )
{
EntityAnimal animal = (EntityAnimal) entity;
@@ -267,9 +284,13 @@ public class ActivationRange
entity.activatedTick = MinecraftServer.currentTick + 20;
if ( animal.isBaby() || animal.isInLove() )
{
- return true;
+ return 1; // Paper
}
isActive = true;
if ( entity instanceof EntitySheep && ( (EntitySheep) entity ).isSheared() )
{
- return true;
+ return 1; // Paper
}
}
if (entity instanceof EntityCreeper && ((EntityCreeper) entity).isIgnited()) { // isExplosive
- return true;
+ return 20; // Paper
+ }
+ // Paper start
+ } else if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks()) {
+ isActive = true;
+ if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks() ) {
+ return 0;
}
+ // Paper end
}
- return false;
+ return -1; // Paper
}
/**
@@ -254,6 +285,7 @@ public class ActivationRange
}
boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
+ entity.isTemporarilyActive = false; // Paper
// Should this entity tick?
if ( !isActive )
@@ -261,15 +293,19 @@ public class ActivationRange
if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
{
// Check immunities every 20 ticks.
- if ( checkEntityImmunities( entity ) )
- {
- // Triggered some sort of immunity, give 20 full ticks before we check again.
- entity.activatedTick = MinecraftServer.currentTick + 20;
+ // Paper start
+ int immunity = checkEntityImmunities(entity);
+ if (immunity >= 0) {
+ entity.activatedTick = MinecraftServer.currentTick + immunity;
+ } else {
+ entity.isTemporarilyActive = true;
}
+ // Paper end
isActive = true;
+
}
// Add a little performance juice to active entities. Skip 1/4 if not immune.
- } else if ( !entity.defaultActivationState && entity.ticksLived % 4 == 0 && !checkEntityImmunities( entity ) )
+ } else if ( !entity.defaultActivationState && entity.ticksLived % 4 == 0 && !(entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks()) && !checkEntityImmunities( entity ) ) // Paper - add targetSelector.hasTasks
+ } else if ( !entity.defaultActivationState && entity.ticksLived % 4 == 0 && checkEntityImmunities( entity) < 0 ) // Paper
{
isActive = false;
}
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 58767972a..3ceeed3f9 100644
index 58767972a3..3ceeed3f99 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -180,6 +180,7 @@ public class SpigotWorldConfig

View file

@ -1,4 +1,4 @@
From 2c49f9e2d16a6ba0c20a99acf259cb84e575d607 Mon Sep 17 00:00:00 2001
From 1a7d91f6e4660e9769d17df8db4da4c6652318e0 Mon Sep 17 00:00:00 2001
From: AJMFactsheets <AJMFactsheets@gmail.com>
Date: Wed, 22 Jan 2020 19:52:28 -0600
Subject: [PATCH] Fix items vanishing through end portal
@ -13,10 +13,10 @@ Quickly loading the exact world spawn chunk before searching the
heightmap resolves the issue without having to load all spawn chunks.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 659591e02..6e41a5506 100644
index e10740a65c..c4e85b86d9 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2599,6 +2599,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@@ -2600,6 +2600,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
if (blockposition == null) { // CraftBukkit
if (dimensionmanager1.getType() == DimensionManager.THE_END && dimensionmanager == DimensionManager.OVERWORLD) { // CraftBukkit

View file

@ -1,11 +1,11 @@
From 4ad34092852803562a53371352be2ac229171f87 Mon Sep 17 00:00:00 2001
From 28f89fcd4d3948ad6742e760827edc40c254d23f Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Fri, 7 Feb 2020 14:36:56 -0600
Subject: [PATCH] Add option to nerf pigmen from nether portals
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index bce502181..7d408542e 100644
index bce502181f..7d408542e7 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -653,4 +653,9 @@ public class PaperWorldConfig {
@ -19,7 +19,7 @@ index bce502181..7d408542e 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/BlockPortal.java b/src/main/java/net/minecraft/server/BlockPortal.java
index 2dc3ab4cf..09c7c1318 100644
index 2dc3ab4cfa..09c7c13183 100644
--- a/src/main/java/net/minecraft/server/BlockPortal.java
+++ b/src/main/java/net/minecraft/server/BlockPortal.java
@@ -45,6 +45,8 @@ public class BlockPortal extends Block {
@ -32,18 +32,18 @@ index 2dc3ab4cf..09c7c1318 100644
}
}
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 6e41a5506..8974c16bf 100644
index c4e85b86d9..8da54c68cc 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -193,6 +193,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
public final boolean defaultActivationState;
@@ -194,6 +194,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
public long activatedTick = Integer.MIN_VALUE;
public boolean isTemporarilyActive = false; // Paper
public boolean spawnedViaMobSpawner; // Paper - Yes this name is similar to above, upstream took the better one
+ public boolean fromNetherPortal; // Paper
protected int numCollisions = 0; // Paper
public void inactiveTick() { }
// Spigot end
@@ -1637,6 +1638,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@@ -1638,6 +1639,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
if (spawnedViaMobSpawner) {
nbttagcompound.setBoolean("Paper.FromMobSpawner", true);
}
@ -53,7 +53,7 @@ index 6e41a5506..8974c16bf 100644
// Paper end
return nbttagcompound;
} catch (Throwable throwable) {
@@ -1759,6 +1763,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@@ -1760,6 +1764,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
spawnedViaMobSpawner = nbttagcompound.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status