Create 0050-EMC-EAR-improvements.patch

This commit is contained in:
tr7zw 2020-03-30 01:53:21 +02:00
parent 9f93a8da37
commit 4958e9327f

View File

@ -0,0 +1,181 @@
From 502fb2bcff02682fffc83a505a9c6b49c6cae03a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 28 Mar 2020 18:18:03 -0400
Subject: [PATCH] EMC EAR improvements
---
.../java/net/minecraft/server/Entity.java | 1 +
.../net/minecraft/server/EntityLiving.java | 2 +-
.../java/org/spigotmc/ActivationRange.java | 45 +++++++++++--------
.../java/org/spigotmc/SpigotWorldConfig.java | 2 +
4 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 837044d96..cee9fb29c 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 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
public boolean fromNetherPortal; // Paper
protected int numCollisions = 0; // Paper
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index dd92758a6..fe9d90ce5 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2400,7 +2400,7 @@ public abstract class EntityLiving extends Entity {
}
}
- this.movementTick();
+ if (!this.isTemporarilyActive || this.world.spigotConfig.moveInactiveEntities) 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/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index e160f03c1..381317f16 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -200,22 +200,22 @@ public class ActivationRange
* @param entity
* @return
*/
- public static boolean checkEntityImmunities(Entity entity)
+ public static int checkEntityImmunities(Entity entity)
{
// quick checks.
if ( entity.inWater || entity.fireTicks > 0 )
{
- return true;
+ return 1;
}
if ( !( entity instanceof EntityArrow ) )
{
if ( !entity.onGround || !entity.passengers.isEmpty() || entity.isPassenger() )
{
- return true;
+ return 10;
}
} else if ( !( (EntityArrow) entity ).inGround )
{
- return true;
+ return 1;
}
// special cases.
if ( entity instanceof EntityLiving )
@@ -223,20 +223,20 @@ 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;
}
if ( entity instanceof EntityCreature && (( (EntityCreature) entity ).getGoalTarget() != null || ( (EntityCreature) entity ).getMovingTarget() != null)) // Paper
{
- return true;
+ return 20;
}
if ( entity instanceof EntityVillager && ( (EntityVillager) entity ).canBreed() )
{
- return true;
+ return 1;
}
// Paper start
if ( entity instanceof EntityLlama && ( (EntityLlama ) entity ).inCaravan() )
{
- return true;
+ return 0;
}
// Paper end
if ( entity instanceof EntityAnimal )
@@ -244,18 +244,23 @@ public class ActivationRange
EntityAnimal animal = (EntityAnimal) entity;
if ( animal.isBaby() || animal.isInLove() )
{
- return true;
+ return 1; // Paper
}
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
+ if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks() ) {
+ return 0;
}
+ // Paper end
}
- return false;
+ return -1; // Paper
}
/**
@@ -272,6 +277,7 @@ public class ActivationRange
}
boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
+ entity.isTemporarilyActive = !isActive; // Paper
// Should this entity tick?
if ( !isActive )
@@ -279,11 +285,14 @@ 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;
// Paper start
} else if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks()) {
@@ -291,7 +300,7 @@ public class ActivationRange
}
// Paper end
// Add a little performance juice to active entities. Skip 1/4 if not immune.
- } 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 3ceeed3f9..1540afd80 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -181,6 +181,7 @@ public class SpigotWorldConfig
public int raiderActivationRange = 48;
public int miscActivationRange = 16;
public int waterActivationRange = 16; // Paper
+ public boolean moveInactiveEntities = false; // Paper
public boolean tickInactiveVillagers = true;
private void activationRange()
{
@@ -189,6 +190,7 @@ public class SpigotWorldConfig
raiderActivationRange = getInt( "entity-activation-range.raiders", raiderActivationRange );
miscActivationRange = getInt( "entity-activation-range.misc", miscActivationRange );
waterActivationRange = getInt( "entity-activation-range.water", waterActivationRange ); // Paper
+ moveInactiveEntities = getBoolean( "entity-activation-range.move-inactive-entities", moveInactiveEntities ); // Paper
tickInactiveVillagers = getBoolean( "entity-activation-range.tick-inactive-villagers", tickInactiveVillagers );
log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Ra " + raiderActivationRange + " / Mi " + miscActivationRange + " / Tiv " + tickInactiveVillagers );
}
--
2.25.1.windows.1