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 2420200c9b
commit 67832e641f
3 changed files with 159 additions and 30 deletions

View file

@ -10,9 +10,17 @@ 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
@@ -0,0 +0,0 @@ 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() { }
@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
this.recalcPosition();
} else {
@ -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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ import net.minecraft.server.MathHelper;
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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;
@ -237,44 +283,127 @@ index 92601c581..6e165a164 100644
int i = MathHelper.floor( maxBB.minX / 16.0D );
int j = MathHelper.floor( maxBB.maxX / 16.0D );
@@ -0,0 +0,0 @@ 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 )
@@ -0,0 +0,0 @@ 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
}
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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
}
/**
@@ -0,0 +0,0 @@ public class ActivationRange
}
boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
+ entity.isTemporarilyActive = false; // Paper
// Should this entity tick?
if ( !isActive )
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ public class SpigotWorldConfig

View file

@ -5,7 +5,7 @@ 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
@@ -0,0 +0,0 @@ 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
@@ -0,0 +0,0 @@ public class BlockPortal extends Block {
@ -32,12 +32,12 @@ 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
@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
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
+ public boolean fromNetherPortal; // Paper
protected int numCollisions = 0; // Paper

View file

@ -13,7 +13,7 @@ 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
@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke