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

561 lines
24 KiB
Diff
Raw Normal View History

2023-09-22 02:40:00 +10:00
From 7f0c9aa5dbdf1b8ed270358c205933a48d2581e1 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.
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
2023-09-22 02:40:00 +10:00
index 74782ff5af..0d815a7b0c 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
2023-09-22 02:40:00 +10:00
@@ -410,6 +410,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
2021-11-22 09:00:00 +11:00
gameprofilerfiller.pop();
2021-06-11 15:00:00 +10:00
}
2021-03-16 09:00:00 +11:00
+ org.spigotmc.ActivationRange.activateEntities(this); // Spigot
timings.entityTick.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
this.entityTickList.forEach((entity) -> {
2021-06-11 15:00:00 +10:00
if (!entity.isRemoved()) {
2023-09-22 02:40:00 +10:00
@@ -843,6 +844,13 @@ public class WorldServer extends World implements GeneratorAccessSeed {
2021-06-11 15:00:00 +10:00
}
2021-11-22 09:00:00 +11:00
public void tickNonPassenger(Entity entity) {
2021-06-11 15:00:00 +10:00
+ // Spigot start
+ if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
+ entity.tickCount++;
+ entity.inactiveTick();
+ return;
+ }
+ // Spigot end
entity.tickTimer.startTiming(); // Spigot
2021-11-22 09:00:00 +11:00
entity.setOldPosAndRot();
GameProfilerFiller gameprofilerfiller = this.getProfiler();
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2023-09-22 02:40:00 +10:00
index b7a91c91f8..c824c7cf58 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2023-06-08 01:30:00 +10:00
@@ -310,6 +310,12 @@ public abstract class Entity implements INamableTileEntity, EntityAccess, IComma
2020-09-19 17:51:05 +10:00
public boolean persistentInvisibility = false;
2021-12-04 08:08:31 +11:00
public BlockPosition lastLavaContact;
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() {
2021-06-11 15:00:00 +10:00
return this.yRot;
2023-06-08 01:30:00 +10:00
@@ -347,6 +353,13 @@ public abstract class Entity implements INamableTileEntity, EntityAccess, IComma
2022-06-08 02:00:00 +10:00
this.position = Vec3D.ZERO;
2021-06-11 15:00:00 +10:00
this.blockPosition = BlockPosition.ZERO;
2021-11-22 09:00:00 +11:00
this.chunkPosition = ChunkCoordIntPair.ZERO;
2020-06-25 10:00:00 +10:00
+ // Spigot start
+ if (world != null) {
2013-06-20 19:00:26 +10:00
+ this.defaultActivationState = org.spigotmc.ActivationRange.initializeEntityActivationState(this, world.spigotConfig);
+ } else {
+ this.defaultActivationState = false;
2020-06-25 10:00:00 +10:00
+ }
+ // Spigot end
2021-06-11 15:00:00 +10:00
this.entityData = new DataWatcher(this);
2021-11-22 09:00:00 +11:00
this.entityData.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0);
this.entityData.define(Entity.DATA_AIR_SUPPLY_ID, this.getMaxAirSupply());
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityAgeable.java b/src/main/java/net/minecraft/world/entity/EntityAgeable.java
2023-09-22 02:40:00 +10:00
index bd2e7ba4eb..a64ea7677b 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/EntityAgeable.java
+++ b/src/main/java/net/minecraft/world/entity/EntityAgeable.java
2023-03-15 03:30:00 +11:00
@@ -26,6 +26,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();
2023-06-08 01:30:00 +10:00
+ if ( this.level().isClientSide || this.ageLocked )
2013-06-08 09:27:14 +10:00
+ { // CraftBukkit
2021-11-22 09:00:00 +11:00
+ this.refreshDimensions();
2013-06-08 09:27:14 +10:00
+ } else
+ {
+ int i = this.getAge();
+
+ if ( i < 0 )
+ {
+ ++i;
2021-11-22 09:00:00 +11:00
+ this.setAge( i );
2013-06-08 09:27:14 +10:00
+ } else if ( i > 0 )
+ {
+ --i;
2021-11-22 09:00:00 +11:00
+ this.setAge( i );
2013-06-08 09:27:14 +10:00
+ }
+ }
+ }
+ // Spigot end
+
2019-12-11 09:00:00 +11:00
@Override
2021-11-22 09:00:00 +11:00
public GroupDataEntity finalizeSpawn(WorldAccess worldaccess, DifficultyDamageScaler difficultydamagescaler, EnumMobSpawn enummobspawn, @Nullable GroupDataEntity groupdataentity, @Nullable NBTTagCompound nbttagcompound) {
2019-12-11 09:00:00 +11:00
if (groupdataentity == null) {
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityAreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/EntityAreaEffectCloud.java
2023-09-22 02:40:00 +10:00
index 3d67ac66f6..c27be344f7 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/EntityAreaEffectCloud.java
+++ b/src/main/java/net/minecraft/world/entity/EntityAreaEffectCloud.java
2023-09-22 02:40:00 +10:00
@@ -169,6 +169,18 @@ public class EntityAreaEffectCloud extends Entity implements TraceableEntity {
2019-12-11 09:00:00 +11:00
this.duration = i;
}
+ // Spigot start - copied from below
+ @Override
+ public void inactiveTick() {
+ super.inactiveTick();
+
2021-06-11 15:00:00 +10:00
+ if (this.tickCount >= this.waitTime + this.duration) {
2021-11-22 09:00:00 +11:00
+ this.discard();
+ return;
+ }
+ }
+ // Spigot end
+
@Override
public void tick() {
super.tick();
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
2023-09-22 02:40:00 +10:00
index 6242461565..b52ed2f18a 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
2023-06-08 01:30:00 +10:00
@@ -267,6 +267,13 @@ public abstract class EntityLiving extends Entity implements Attackable {
2021-11-22 09:00:00 +11:00
return getYHeadRot();
2021-03-16 09:00:00 +11:00
}
// CraftBukkit end
+ // Spigot start
+ public void inactiveTick()
+ {
+ super.inactiveTick();
2021-06-11 15:00:00 +10:00
+ ++this.noActionTime; // Above all the floats
+ }
2021-03-16 09:00:00 +11:00
+ // Spigot end
2021-03-16 09:00:00 +11:00
protected EntityLiving(EntityTypes<? extends EntityLiving> entitytypes, World world) {
super(entitytypes, world);
diff --git a/src/main/java/net/minecraft/world/entity/item/EntityItem.java b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
2023-09-22 02:40:00 +10:00
index 8e26d92c47..fa2c895d2a 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/item/EntityItem.java
+++ b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
2023-06-24 17:19:51 +10:00
@@ -202,6 +202,28 @@ public class EntityItem extends Entity implements TraceableEntity {
}
}
+ // 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
+
2023-06-08 01:30:00 +10:00
+ if (!this.level().isClientSide && this.age >= this.level().spigotConfig.itemDespawnRate) { // Spigot
+ // CraftBukkit start - fire ItemDespawnEvent
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
+ this.discard();
+ }
+ }
+ // Spigot end
+
2023-06-08 01:30:00 +10:00
@Override
protected BlockPosition getBlockPosBelowThatAffectsMyMovement() {
return this.getOnPos(0.999999F);
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
2023-09-22 02:40:00 +10:00
index ae62c50f1b..68cbd44270 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
2023-09-22 02:40:00 +10:00
@@ -224,6 +224,17 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2021-06-11 15:00:00 +10:00
return this.assignProfessionWhenSpawned;
}
+ // Spigot Start
+ @Override
+ public void inactiveTick() {
+ // SPIGOT-3874, SPIGOT-3894, SPIGOT-3846, SPIGOT-5286 :(
2023-06-08 01:30:00 +10:00
+ if (this.level().spigotConfig.tickInactiveVillagers && this.isEffectiveAi()) {
2021-11-22 09:00:00 +11:00
+ this.customServerAiStep();
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
2019-04-23 12:00:00 +10:00
@Override
2021-11-22 09:00:00 +11:00
protected void customServerAiStep() {
2023-06-08 01:30:00 +10:00
this.level().getProfiler().push("villagerBrain");
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java b/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java
2023-09-22 02:40:00 +10:00
index 8c8663c18e..fc775f5da6 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java
2022-12-08 03:00:00 +11:00
@@ -75,6 +75,18 @@ public abstract class EntityArrow extends IProjectile {
2021-06-11 15:00:00 +10:00
@Nullable
private List<Entity> piercedAndKilledEntities;
2021-03-16 09:00:00 +11:00
+ // Spigot Start
+ @Override
+ public void inactiveTick()
+ {
+ if ( this.inGround )
+ {
2021-06-11 15:00:00 +10:00
+ this.life += 1;
2021-03-16 09:00:00 +11:00
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
protected EntityArrow(EntityTypes<? extends EntityArrow> entitytypes, World world) {
super(entitytypes, world);
2021-06-11 15:00:00 +10:00
this.pickup = EntityArrow.PickupStatus.DISALLOWED;
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityFireworks.java b/src/main/java/net/minecraft/world/entity/projectile/EntityFireworks.java
2023-09-22 02:40:00 +10:00
index 543a3ff083..bed9e8f602 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/projectile/EntityFireworks.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/EntityFireworks.java
2023-03-15 03:30:00 +11:00
@@ -80,6 +80,22 @@ public class EntityFireworks extends IProjectile implements ItemSupplier {
2021-11-22 09:00:00 +11:00
this.setOwner(entity);
2021-03-16 09:00:00 +11:00
}
+ // Spigot Start - copied from tick
+ @Override
+ public void inactiveTick() {
2021-06-11 15:00:00 +10:00
+ this.life += 1;
2021-03-16 09:00:00 +11:00
+
2023-06-08 01:30:00 +10:00
+ if (!this.level().isClientSide && this.life > this.lifetime) {
2021-03-16 09:00:00 +11:00
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) {
+ this.explode();
+ }
2021-03-16 09:00:00 +11:00
+ // CraftBukkit end
+ }
+ super.inactiveTick();
+ }
+ // Spigot End
+
@Override
2021-11-22 09:00:00 +11:00
protected void defineSynchedData() {
this.entityData.define(EntityFireworks.DATA_ID_FIREWORKS_ITEM, ItemStack.EMPTY);
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
2023-09-22 02:40:00 +10:00
index aff7b6b438..d3328a695f 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
2020-06-25 10:00:00 +10:00
@@ -39,6 +39,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/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
new file mode 100644
2023-09-22 02:40:00 +10:00
index 0000000000..c5688dd14f
2013-06-20 19:00:26 +10:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -0,0 +1,262 @@
2013-06-20 19:00:26 +10:00
+package org.spigotmc;
+
+import net.minecraft.server.MinecraftServer;
2021-03-16 09:00:00 +11:00
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityCreature;
+import net.minecraft.world.entity.EntityExperienceOrb;
2021-03-16 09:00:00 +11:00
+import net.minecraft.world.entity.EntityLightning;
+import net.minecraft.world.entity.EntityLiving;
+import net.minecraft.world.entity.ambient.EntityAmbient;
+import net.minecraft.world.entity.animal.EntityAnimal;
+import net.minecraft.world.entity.animal.EntitySheep;
+import net.minecraft.world.entity.boss.EntityComplexPart;
+import net.minecraft.world.entity.boss.enderdragon.EntityEnderCrystal;
+import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
+import net.minecraft.world.entity.boss.wither.EntityWither;
+import net.minecraft.world.entity.item.EntityTNTPrimed;
+import net.minecraft.world.entity.monster.EntityCreeper;
+import net.minecraft.world.entity.monster.EntityMonster;
+import net.minecraft.world.entity.monster.EntitySlime;
+import net.minecraft.world.entity.npc.EntityVillager;
+import net.minecraft.world.entity.player.EntityHuman;
+import net.minecraft.world.entity.projectile.EntityArrow;
+import net.minecraft.world.entity.projectile.EntityFireball;
+import net.minecraft.world.entity.projectile.EntityFireworks;
+import net.minecraft.world.entity.projectile.EntityProjectile;
+import net.minecraft.world.entity.projectile.EntityThrownTrident;
+import net.minecraft.world.entity.raid.EntityRaider;
+import net.minecraft.world.level.World;
+import net.minecraft.world.phys.AxisAlignedBB;
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.simulationDistance << 4 ) - 8, maxRange );
+
2021-11-22 09:00:00 +11:00
+ for ( EntityHuman player : world.players() )
2013-06-20 19:00:26 +10:00
+ {
+ player.activatedTick = MinecraftServer.currentTick;
+ if ( world.spigotConfig.ignoreSpectatorActivation && player.isSpectator() )
+ {
+ continue;
+ }
+
2021-11-22 09:00:00 +11:00
+ maxBB = player.getBoundingBox().inflate( maxRange, 256, maxRange );
+ ActivationType.MISC.boundingBox = player.getBoundingBox().inflate( miscActivationRange, 256, miscActivationRange );
+ ActivationType.RAIDER.boundingBox = player.getBoundingBox().inflate( raiderActivationRange, 256, raiderActivationRange );
+ ActivationType.ANIMAL.boundingBox = player.getBoundingBox().inflate( animalActivationRange, 256, animalActivationRange );
+ ActivationType.MONSTER.boundingBox = player.getBoundingBox().inflate( monsterActivationRange, 256, monsterActivationRange );
+
2021-11-22 09:00:00 +11:00
+ world.getEntities().get(maxBB, ActivationRange::activateEntity);
+ }
+ SpigotTimings.entityActivationCheckTimer.stopTiming();
+ }
+
+ /**
+ * Checks for the activation state of all entities in this chunk.
+ *
+ * @param chunk
+ */
2021-06-11 15:00:00 +10:00
+ private static void activateEntity(Entity entity)
2013-06-20 19:00:26 +10:00
+ {
2021-06-11 15:00:00 +10:00
+ if ( MinecraftServer.currentTick > entity.activatedTick )
2013-06-20 19:00:26 +10:00
+ {
2021-06-11 15:00:00 +10:00
+ if ( entity.defaultActivationState )
2013-06-20 19:00:26 +10:00
+ {
2021-06-11 15:00:00 +10:00
+ entity.activatedTick = MinecraftServer.currentTick;
+ return;
+ }
2021-11-22 09:00:00 +11:00
+ if ( entity.activationType.boundingBox.intersects( entity.getBoundingBox() ) )
2021-06-11 15:00:00 +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.
2023-06-11 17:32:57 +10:00
+ if ( entity.wasTouchingWater || entity.getRemainingFireTicks() > 0 )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
2013-06-20 19:00:26 +10:00
+ if ( !( entity instanceof EntityArrow ) )
+ {
2023-06-08 01:30:00 +10:00
+ 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;
2021-06-11 15:00:00 +10:00
+ if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTime > 0 || living.activeEffects.size() > 0 )
2013-06-20 19:00:26 +10:00
+ {
+ return true;
+ }
2021-11-22 09:00:00 +11:00
+ if ( entity instanceof EntityCreature && ( (EntityCreature) entity ).getTarget() != 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;
+ }
+ }
+ // SPIGOT-6644: Otherwise the target refresh tick will be missed
+ if (entity instanceof EntityExperienceOrb) {
+ 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
2021-06-11 15:00:00 +10:00
+ if ( 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.
2021-06-11 15:00:00 +10:00
+ } else if ( !entity.defaultActivationState && entity.tickCount % 4 == 0 && !checkEntityImmunities( entity ) )
2013-06-20 19:00:26 +10:00
+ {
+ 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
2023-09-22 02:40:00 +10:00
index e3682d28ca..936279b5fb 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
@@ -194,4 +194,21 @@ 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;
+ public boolean ignoreSpectatorActivation = false;
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 );
+ ignoreSpectatorActivation = getBoolean( "entity-activation-range.ignore-spectators", ignoreSpectatorActivation );
+ log( "Entity Activation Range: An " + animalActivationRange + " / Mo " + monsterActivationRange + " / Ra " + raiderActivationRange + " / Mi " + miscActivationRange + " / Tiv " + tickInactiveVillagers + " / Isa " + ignoreSpectatorActivation );
2013-06-20 19:00:26 +10:00
+ }
}
--
2023-09-22 02:40:00 +10:00
2.42.0