2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 13 May 2016 01:38:06 -0400
Subject: [PATCH] Entity Activation Range 2.0
Optimizes performance of Activation Range
Adds many new configurations and a new wake up inactive system
Fixes and adds new Immunities to improve gameplay behavior
Adds water Mobs to activation range config and nerfs fish
Adds flying monsters to control ghast and phantoms
Adds villagers as separate config
2024-11-09 21:44:55 +01:00
Feature patch
2022-11-20 00:53:20 +01:00
== AT ==
public net.minecraft.world.entity.Entity isInsidePortal
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
index be35f9ab6d8877aad755a6ac0344a901b61a49de..5b1ba650973a603ecb77324eb18dda4647e0340b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
@@ -967,11 +967,11 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
2024-10-27 18:11:15 +01:00
public void tickNonPassenger(Entity entity) {
2021-06-13 21:29:58 +02:00
// Spigot start
- if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
2024-10-27 18:11:15 +01:00
+ /*if (!org.spigotmc.ActivationRange.checkIfActive(entity)) { // Paper - comment out EAR 2
2021-06-13 21:29:58 +02:00
entity.tickCount++;
entity.inactiveTick();
return;
- }
+ }*/ // Paper - comment out EAR 2
// Spigot end
2021-06-17 14:50:16 +02:00
entity.setOldPosAndRot();
2024-10-27 18:11:15 +01:00
ProfilerFiller gameprofilerfiller = Profiler.get();
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
@@ -981,20 +981,23 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
2022-12-07 20:22:28 +01:00
return BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).toString();
2021-06-13 21:29:58 +02:00
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
2024-10-30 14:06:43 +01:00
+ final boolean isActive = org.spigotmc.ActivationRange.checkIfActive(entity); // Paper - EAR 2
2021-06-13 21:29:58 +02:00
+ if (isActive) { // Paper - EAR 2
entity.tick();
entity.postTick(); // CraftBukkit
+ } else { entity.inactiveTick(); } // Paper - EAR 2
2024-10-24 20:40:24 +02:00
gameprofilerfiller.pop();
2021-06-13 21:29:58 +02:00
Iterator iterator = entity.getPassengers().iterator();
while (iterator.hasNext()) {
2024-10-24 20:40:24 +02:00
Entity entity1 = (Entity) iterator.next();
2021-08-30 09:02:24 +02:00
2024-10-24 20:40:24 +02:00
- this.tickPassenger(entity, entity1);
+ this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
2021-06-13 21:29:58 +02:00
}
2021-06-11 14:02:28 +02:00
}
2021-06-13 21:29:58 +02:00
2024-10-24 20:40:24 +02:00
- private void tickPassenger(Entity vehicle, Entity passenger) {
+ private void tickPassenger(Entity vehicle, Entity passenger, boolean isActive) { // Paper - EAR 2
2021-06-13 21:29:58 +02:00
if (!passenger.isRemoved() && passenger.getVehicle() == vehicle) {
if (passenger instanceof Player || this.entityTickList.contains(passenger)) {
passenger.setOldPosAndRot();
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
@@ -1005,15 +1008,24 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
2022-12-07 20:22:28 +01:00
return BuiltInRegistries.ENTITY_TYPE.getKey(passenger.getType()).toString();
2021-06-13 21:29:58 +02:00
});
gameprofilerfiller.incrementCounter("tickPassenger");
+ // Paper start - EAR 2
+ if (isActive) {
passenger.rideTick();
passenger.postTick(); // CraftBukkit
+ } else {
2024-10-24 20:40:24 +02:00
+ passenger.setDeltaMovement(Vec3.ZERO);
+ passenger.inactiveTick();
+ // copied from inside of if (isPassenger()) of passengerTick, but that ifPassenger is unnecessary
+ vehicle.positionRider(passenger);
2021-06-13 21:29:58 +02:00
+ }
+ // Paper end - EAR 2
gameprofilerfiller.pop();
Iterator iterator = passenger.getPassengers().iterator();
2021-06-11 14:02:28 +02:00
2024-10-24 20:40:24 +02:00
while (iterator.hasNext()) {
Entity entity2 = (Entity) iterator.next();
- this.tickPassenger(passenger, entity2);
+ this.tickPassenger(passenger, entity2, isActive); // Paper - EAR 2
2021-06-13 21:29:58 +02:00
}
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2024-11-09 21:44:55 +01:00
index ef764777c3054522aa875026addd3d1e7cc3d2ec..c2b98da88e30b7d84a4b51c48e12fd16c1d52c35 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2024-11-04 18:42:38 +01:00
@@ -421,6 +421,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2024-01-24 11:45:17 +01:00
// Spigot end
2024-01-22 19:01:10 +01:00
protected int numCollisions = 0; // Paper - Cap entity collisions
2024-01-23 15:43:48 +01:00
public boolean fromNetherPortal; // Paper - Add option to nerf pigmen from nether portals
+ public long activatedImmunityTick = Integer.MIN_VALUE; // Paper - EAR
+ public boolean isTemporarilyActive; // Paper - EAR
2021-12-03 22:28:15 +01:00
public boolean spawnedViaMobSpawner; // Paper - Yes this name is similar to above, upstream took the better one
2024-01-24 11:45:17 +01:00
// Paper start - Entity origin API
2021-12-03 22:28:15 +01:00
@javax.annotation.Nullable
2024-11-04 18:42:38 +01:00
@@ -993,6 +995,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2021-06-11 14:02:28 +02:00
} else {
2021-06-13 21:29:58 +02:00
this.wasOnFire = this.isOnFire();
2024-10-24 20:40:24 +02:00
if (type == MoverType.PISTON) {
+ this.activatedTick = Math.max(this.activatedTick, MinecraftServer.currentTick + 20); // Paper - EAR 2
+ this.activatedImmunityTick = Math.max(this.activatedImmunityTick, MinecraftServer.currentTick + 20); // Paper - EAR 2
2021-06-11 14:02:28 +02:00
movement = this.limitPistonMovement(movement);
if (movement.equals(Vec3.ZERO)) {
return;
2024-11-04 18:42:38 +01:00
@@ -1007,6 +1011,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2021-06-11 14:02:28 +02:00
this.stuckSpeedMultiplier = Vec3.ZERO;
this.setDeltaMovement(Vec3.ZERO);
}
+ // Paper start - ignore movement changes while inactive.
2024-10-24 20:40:24 +02:00
+ if (isTemporarilyActive && !(this instanceof ItemEntity) && movement == getDeltaMovement() && type == MoverType.SELF) {
2021-06-11 14:02:28 +02:00
+ setDeltaMovement(Vec3.ZERO);
2024-10-24 20:40:24 +02:00
+ gameprofilerfiller.pop();
2021-06-11 14:02:28 +02:00
+ return;
+ }
+ // Paper end
2024-10-24 20:40:24 +02:00
movement = this.maybeBackOffFromEdge(movement, type);
2021-06-11 14:02:28 +02:00
Vec3 vec3d1 = this.collide(movement);
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
2024-10-24 20:40:24 +02:00
index aad63549d7c4f501b683b8dead4938eac27895eb..dbd321f3dc3cc80737830db63aed47a6935e8e89 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
2024-10-24 20:40:24 +02:00
@@ -235,6 +235,19 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
2021-06-11 14:02:28 +02:00
return this.lookControl;
}
+ // Paper start
+ @Override
+ public void inactiveTick() {
+ super.inactiveTick();
+ if (this.goalSelector.inactiveTick()) {
+ this.goalSelector.tick();
+ }
+ if (this.targetSelector.inactiveTick()) {
+ this.targetSelector.tick();
+ }
+ }
+ // Paper end
+
public MoveControl getMoveControl() {
2023-03-14 20:54:57 +01:00
Entity entity = this.getControlledVehicle();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/PathfinderMob.java b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
2024-10-24 20:40:24 +02:00
index 7c69c9145eff938ce4615e3058d3d12edfc8bdd2..da1be210a41c3a2fbfa132326a623f1e748f8b77 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/PathfinderMob.java
+++ b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
2024-07-18 16:50:16 +02:00
@@ -22,6 +22,8 @@ public abstract class PathfinderMob extends Mob {
super(type, world);
2021-11-24 08:37:09 +01:00
}
2021-06-11 14:02:28 +02:00
2024-07-18 16:50:16 +02:00
+ public BlockPos movingTarget; public BlockPos getMovingTarget() { return movingTarget; } // Paper
+
2021-11-24 08:37:09 +01:00
public float getWalkTargetValue(BlockPos pos) {
2023-06-07 23:14:56 +02:00
return this.getWalkTargetValue(pos, this.level());
2024-07-18 16:50:16 +02:00
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
2024-10-24 20:40:24 +02:00
index 8775ce55654e4b99e287acd4a113cd72b9df4ff6..d871975f943a04b49644dc6eb18314d65a7836dc 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
2024-10-24 20:40:24 +02:00
@@ -25,6 +25,7 @@ public class GoalSelector {
private final Map<Goal.Flag, WrappedGoal> lockedFlags = new EnumMap<>(Goal.Flag.class);
2024-04-25 11:42:10 +02:00
private final Set<WrappedGoal> availableGoals = new ObjectLinkedOpenHashSet<>();
2021-06-11 14:02:28 +02:00
private final EnumSet<Goal.Flag> disabledFlags = EnumSet.noneOf(Goal.Flag.class);
2024-10-24 20:40:24 +02:00
+ private int curRate; // Paper - EAR 2
2021-06-11 14:02:28 +02:00
2024-10-24 20:40:24 +02:00
public void addGoal(int priority, Goal goal) {
this.availableGoals.add(new WrappedGoal(priority, goal));
@@ -35,6 +36,20 @@ public class GoalSelector {
2024-04-12 21:14:06 +02:00
this.availableGoals.removeIf(goal -> predicate.test(goal.getGoal()));
2021-06-11 14:02:28 +02:00
}
2024-10-24 20:40:24 +02:00
+ // Paper start - EAR 2
2021-06-11 14:02:28 +02:00
+ public boolean inactiveTick() {
2021-06-13 21:29:58 +02:00
+ this.curRate++;
2024-04-25 11:42:10 +02:00
+ return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct
2021-06-11 14:02:28 +02:00
+ }
+ public boolean hasTasks() {
2021-06-13 21:29:58 +02:00
+ for (WrappedGoal task : this.availableGoals) {
2021-06-11 14:02:28 +02:00
+ if (task.isRunning()) {
+ return true;
+ }
+ }
+ return false;
+ }
2024-10-24 20:40:24 +02:00
+ // Paper end - EAR 2
2021-06-11 14:02:28 +02:00
public void removeGoal(Goal goal) {
2024-04-25 11:42:10 +02:00
for (WrappedGoal wrappedGoal : this.availableGoals) {
if (wrappedGoal.getGoal() == goal && wrappedGoal.isRunning()) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
2024-04-16 21:44:59 +02:00
index 6d8ea05e5e86e9f6359b560043bb55a10784e952..aee0147649d458b87d92496eda0c1723ebe570d2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
2024-01-21 13:56:22 +01:00
@@ -23,6 +23,14 @@ public abstract class MoveToBlockGoal extends Goal {
2021-06-11 14:02:28 +02:00
public MoveToBlockGoal(PathfinderMob mob, double speed, int range) {
this(mob, speed, range, 1);
}
+ // Paper start - activation range improvements
+ @Override
2021-06-13 21:29:58 +02:00
+ public void stop() {
+ super.stop();
2024-01-21 13:56:22 +01:00
+ this.blockPos = BlockPos.ZERO;
+ this.mob.movingTarget = null;
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
public MoveToBlockGoal(PathfinderMob mob, double speed, int range, int maxYDifference) {
2021-06-13 21:29:58 +02:00
this.mob = mob;
2024-04-16 21:44:59 +02:00
@@ -115,6 +123,7 @@ public abstract class MoveToBlockGoal extends Goal {
2021-06-13 21:29:58 +02:00
mutableBlockPos.setWithOffset(blockPos, m, k - 1, n);
2023-06-07 23:14:56 +02:00
if (this.mob.isWithinRestriction(mutableBlockPos) && this.isValidTarget(this.mob.level(), mutableBlockPos)) {
2021-06-13 21:29:58 +02:00
this.blockPos = mutableBlockPos;
2024-01-21 13:56:22 +01:00
+ this.mob.movingTarget = mutableBlockPos == BlockPos.ZERO ? null : mutableBlockPos.immutable(); // Paper
2021-06-11 14:02:28 +02:00
return true;
}
}
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
2024-10-24 20:40:24 +02:00
index a573aa4d387ad3a4e1017890f2b50b83a3c27ff4..b7a34f1c4d7b5ef3f7a843d152e33c839dcdedd5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
2024-10-24 20:40:24 +02:00
@@ -228,19 +228,34 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
@Override
public void inactiveTick() {
// SPIGOT-3874, SPIGOT-3894, SPIGOT-3846, SPIGOT-5286 :(
2023-06-07 23:14:56 +02:00
- if (this.level().spigotConfig.tickInactiveVillagers && this.isEffectiveAi()) {
2024-10-24 20:40:24 +02:00
- this.customServerAiStep((ServerLevel) this.level());
2021-06-11 14:02:28 +02:00
+ // Paper start
2021-06-13 21:29:58 +02:00
+ if (this.getUnhappyCounter() > 0) {
+ this.setUnhappyCounter(this.getUnhappyCounter() - 1);
2024-10-24 20:40:24 +02:00
+ }
2021-06-11 14:02:28 +02:00
+ if (this.isEffectiveAi()) {
2023-06-07 23:35:19 +02:00
+ if (this.level().spigotConfig.tickInactiveVillagers) {
2024-10-24 20:40:24 +02:00
+ this.customServerAiStep(this.level().getMinecraftWorld());
2021-06-11 14:02:28 +02:00
+ } else {
2024-10-24 20:40:24 +02:00
+ this.customServerAiStep(this.level().getMinecraftWorld(), true);
2021-06-11 14:02:28 +02:00
+ }
2024-10-24 20:40:24 +02:00
}
2021-06-13 21:29:58 +02:00
+ maybeDecayGossip();
2021-06-11 14:02:28 +02:00
+ // Paper end
super.inactiveTick();
}
// Spigot End
@Override
2024-10-24 20:40:24 +02:00
protected void customServerAiStep(ServerLevel world) {
+ // Paper start - EAR 2
+ this.customServerAiStep(world, false);
2023-06-07 23:14:56 +02:00
+ }
2024-10-24 20:40:24 +02:00
+ protected void customServerAiStep(ServerLevel world, final boolean inactive) {
+ // Paper end - EAR 2
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("villagerBrain");
- this.getBrain().tick(world, this);
+ if (!inactive) this.getBrain().tick(world, this);
gameprofilerfiller.pop();
2021-06-11 14:02:28 +02:00
if (this.assignProfessionWhenSpawned) {
this.assignProfessionWhenSpawned = false;
2024-10-24 20:40:24 +02:00
@@ -264,7 +279,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
this.lastTradedPlayer = null;
}
- if (!this.isNoAi() && this.random.nextInt(100) == 0) {
2024-10-24 20:40:24 +02:00
+ if (!inactive && !this.isNoAi() && this.random.nextInt(100) == 0) { // Paper - EAR 2
Raid raid = world.getRaidAt(this.blockPosition());
2021-06-11 14:02:28 +02:00
if (raid != null && raid.isActive() && !raid.isOver()) {
2024-10-24 20:40:24 +02:00
@@ -275,6 +290,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
if (this.getVillagerData().getProfession() == VillagerProfession.NONE && this.isTrading()) {
this.stopTrading();
}
2024-10-24 20:40:24 +02:00
+ if (inactive) return; // Paper - EAR 2
2021-06-11 14:02:28 +02:00
2024-10-24 20:40:24 +02:00
super.customServerAiStep(world);
2021-06-11 14:02:28 +02:00
}
2022-08-14 19:41:15 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java b/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java
2024-10-24 20:40:24 +02:00
index f0a005724ab64a3b0cbc44d8f430716f7958461c..d81a6874e8b25f098df619f84c359e146c7f64de 100644
2022-08-14 19:41:15 +02:00
--- a/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java
2024-10-24 20:40:24 +02:00
@@ -47,6 +47,7 @@ public class MinecartHopper extends AbstractMinecartContainer implements Hopper
2022-08-14 19:41:15 +02:00
if (bl != this.isEnabled()) {
this.setEnabled(bl);
}
+ this.immunize(); // Paper
}
2024-04-12 21:14:06 +02:00
public boolean isEnabled() {
2024-10-24 20:40:24 +02:00
@@ -100,11 +101,13 @@ public class MinecartHopper extends AbstractMinecartContainer implements Hopper
2022-08-14 19:41:15 +02:00
public boolean suckInItems() {
2023-06-07 23:14:56 +02:00
if (HopperBlockEntity.suckInItems(this.level(), this)) {
2022-08-14 19:41:15 +02:00
+ this.immunize(); // Paper
return true;
} else {
2024-04-12 21:14:06 +02:00
for (ItemEntity itemEntity : this.level()
.getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.25, 0.0, 0.25), EntitySelector.ENTITY_STILL_ALIVE)) {
2023-03-14 20:54:57 +01:00
if (HopperBlockEntity.addItem(this, itemEntity)) {
+ this.immunize(); // Paper
return true;
}
2022-08-14 19:41:15 +02:00
}
2024-10-24 20:40:24 +02:00
@@ -139,4 +142,11 @@ public class MinecartHopper extends AbstractMinecartContainer implements Hopper
2022-08-14 19:41:15 +02:00
public AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
return new HopperMenu(syncId, playerInventory, this);
}
+
+ // Paper start
+ public void immunize() {
+ this.activatedImmunityTick = Math.max(this.activatedImmunityTick, net.minecraft.server.MinecraftServer.currentTick + 20);
+ }
+ // Paper end
+
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2024-10-27 18:11:15 +01:00
index a124a360f45cd71810b8253ce266d52145b6f83b..128bda0d2a690a69b41325a1bb9a2b924cc883cc 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2024-10-24 20:40:24 +02:00
@@ -157,6 +157,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2024-01-23 15:43:48 +01:00
public Map<BlockPos, BlockEntity> capturedTileEntities = new java.util.LinkedHashMap<>(); // Paper - Retain block place order when capturing blockstates
2022-02-12 14:20:33 +01:00
public List<ItemEntity> captureDrops;
public final it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<SpawnCategory> ticksPerSpawnCategory = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
2021-06-11 14:02:28 +02:00
+ // Paper start
+ public int wakeupInactiveRemainingAnimals;
+ public int wakeupInactiveRemainingFlying;
+ public int wakeupInactiveRemainingMonsters;
+ public int wakeupInactiveRemainingVillagers;
+ // Paper end
public boolean populating;
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
2024-01-13 21:31:02 +01:00
// Paper start - add paper world config
2021-08-21 16:15:29 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
2024-10-24 20:40:24 +02:00
index 46afba838cf12eeb1bbccaa260131a76f090364b..e1c9a961064887070b29207efd7af47884f8dc29 100644
2021-08-21 16:15:29 +02:00
--- a/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/piston/PistonMovingBlockEntity.java
2024-10-24 20:40:24 +02:00
@@ -149,6 +149,10 @@ public class PistonMovingBlockEntity extends BlockEntity {
2021-08-21 16:15:29 +02:00
}
entity.setDeltaMovement(e, g, h);
+ // Paper - EAR items stuck in in slime pushed by a piston
2021-08-25 09:59:26 +02:00
+ entity.activatedTick = Math.max(entity.activatedTick, net.minecraft.server.MinecraftServer.currentTick + 10);
+ entity.activatedImmunityTick = Math.max(entity.activatedImmunityTick, net.minecraft.server.MinecraftServer.currentTick + 10);
2021-08-21 16:15:29 +02:00
+ // Paper end
break;
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
2024-11-05 10:52:18 +01:00
index 84ff1210e944ea9d1ec88874d218458773e341c9..bd7c37123c70d2afdef252f39548725d4ef318ed 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
2024-11-04 18:42:38 +01:00
@@ -1,14 +1,22 @@
2021-06-11 14:02:28 +02:00
package org.spigotmc;
+import net.minecraft.core.BlockPos;
import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.entity.Entity;
2022-01-01 04:05:42 +01:00
import net.minecraft.world.entity.ExperienceOrb;
2021-06-11 14:02:28 +02:00
+import net.minecraft.world.entity.FlyingMob;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.LivingEntity;
+import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.PathfinderMob;
+import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ambient.AmbientCreature;
import net.minecraft.world.entity.animal.Animal;
+import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.entity.animal.Sheep;
+import net.minecraft.world.entity.animal.WaterAnimal;
+import net.minecraft.world.entity.animal.horse.Llama;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
2024-11-04 18:42:38 +01:00
@@ -16,12 +24,13 @@ import net.minecraft.world.entity.boss.wither.WitherBoss;
import net.minecraft.world.entity.item.ItemEntity;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.entity.monster.Creeper;
-import net.minecraft.world.entity.monster.Monster;
-import net.minecraft.world.entity.monster.Slime;
+import net.minecraft.world.entity.monster.Enemy;
+import net.minecraft.world.entity.monster.Pillager;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
+import net.minecraft.world.entity.projectile.EyeOfEnder;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.entity.projectile.ThrowableProjectile;
import net.minecraft.world.entity.projectile.ThrownTrident;
2024-11-04 18:42:38 +01:00
@@ -44,6 +53,43 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
AABB boundingBox = new AABB( 0, 0, 0, 0, 0, 0 );
}
+ // Paper start
+
2024-10-27 18:11:15 +01:00
+ static net.minecraft.world.entity.schedule.Activity[] VILLAGER_PANIC_IMMUNITIES = {
+ net.minecraft.world.entity.schedule.Activity.HIDE,
+ net.minecraft.world.entity.schedule.Activity.PRE_RAID,
+ net.minecraft.world.entity.schedule.Activity.RAID,
+ net.minecraft.world.entity.schedule.Activity.PANIC
2021-06-11 14:02:28 +02:00
+ };
+
+ private static int checkInactiveWakeup(Entity entity) {
2023-06-07 23:35:19 +02:00
+ Level world = entity.level();
2021-06-11 14:02:28 +02:00
+ SpigotWorldConfig config = world.spigotConfig;
+ long inactiveFor = MinecraftServer.currentTick - entity.activatedTick;
+ if (entity.activationType == ActivationType.VILLAGER) {
+ if (inactiveFor > config.wakeUpInactiveVillagersEvery && world.wakeupInactiveRemainingVillagers > 0) {
+ world.wakeupInactiveRemainingVillagers--;
+ return config.wakeUpInactiveVillagersFor;
+ }
+ } else if (entity.activationType == ActivationType.ANIMAL) {
+ if (inactiveFor > config.wakeUpInactiveAnimalsEvery && world.wakeupInactiveRemainingAnimals > 0) {
+ world.wakeupInactiveRemainingAnimals--;
+ return config.wakeUpInactiveAnimalsFor;
+ }
+ } else if (entity.activationType == ActivationType.FLYING_MONSTER) {
+ if (inactiveFor > config.wakeUpInactiveFlyingEvery && world.wakeupInactiveRemainingFlying > 0) {
+ world.wakeupInactiveRemainingFlying--;
+ return config.wakeUpInactiveFlyingFor;
+ }
+ } else if (entity.activationType == ActivationType.MONSTER || entity.activationType == ActivationType.RAIDER) {
+ if (inactiveFor > config.wakeUpInactiveMonstersEvery && world.wakeupInactiveRemainingMonsters > 0) {
+ world.wakeupInactiveRemainingMonsters--;
+ return config.wakeUpInactiveMonstersFor;
+ }
+ }
+ return -1;
+ }
+ // Paper end
static AABB maxBB = new AABB( 0, 0, 0, 0, 0, 0 );
2024-11-04 18:42:38 +01:00
@@ -56,10 +102,13 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
*/
public static ActivationType initializeEntityActivationType(Entity entity)
{
+ if (entity instanceof WaterAnimal) { return ActivationType.WATER; } // Paper
+ else if (entity instanceof Villager) { return ActivationType.VILLAGER; } // Paper
+ else if (entity instanceof FlyingMob && entity instanceof Enemy) { return ActivationType.FLYING_MONSTER; } // Paper - doing & Monster incase Flying no longer includes monster in future
if ( entity instanceof Raider )
{
return ActivationType.RAIDER;
- } else if ( entity instanceof Monster || entity instanceof Slime )
+ } else if ( entity instanceof Enemy ) // Paper - correct monster check
{
return ActivationType.MONSTER;
} else if ( entity instanceof PathfinderMob || entity instanceof AmbientCreature )
2024-11-04 18:42:38 +01:00
@@ -80,10 +129,14 @@ public class ActivationRange
2021-06-11 14:02:28 +02: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 )
+ 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.activationType == ActivationType.VILLAGER && config.villagerActivationRange <= 0 ) // Paper
+ || ( entity.activationType == ActivationType.WATER && config.waterActivationRange <= 0 ) // Paper
+ || ( entity.activationType == ActivationType.FLYING_MONSTER && config.flyingMonsterActivationRange <= 0 ) // Paper
+ || entity instanceof EyeOfEnder // Paper
|| entity instanceof Player
|| entity instanceof ThrowableProjectile
|| entity instanceof EnderDragon
2024-11-04 18:42:38 +01:00
@@ -117,10 +170,25 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
final int animalActivationRange = world.spigotConfig.animalActivationRange;
final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
+ // Paper start
+ final int waterActivationRange = world.spigotConfig.waterActivationRange;
+ final int flyingActivationRange = world.spigotConfig.flyingMonsterActivationRange;
+ final int villagerActivationRange = world.spigotConfig.villagerActivationRange;
+ world.wakeupInactiveRemainingAnimals = Math.min(world.wakeupInactiveRemainingAnimals + 1, world.spigotConfig.wakeUpInactiveAnimals);
+ world.wakeupInactiveRemainingVillagers = Math.min(world.wakeupInactiveRemainingVillagers + 1, world.spigotConfig.wakeUpInactiveVillagers);
+ world.wakeupInactiveRemainingMonsters = Math.min(world.wakeupInactiveRemainingMonsters + 1, world.spigotConfig.wakeUpInactiveMonsters);
+ world.wakeupInactiveRemainingFlying = Math.min(world.wakeupInactiveRemainingFlying + 1, world.spigotConfig.wakeUpInactiveFlying);
+ final ServerChunkCache chunkProvider = (ServerChunkCache) world.getChunkSource();
+ // Paper end
int maxRange = Math.max( monsterActivationRange, animalActivationRange );
maxRange = Math.max( maxRange, raiderActivationRange );
maxRange = Math.max( maxRange, miscActivationRange );
+ // Paper start
+ maxRange = Math.max( maxRange, flyingActivationRange );
+ maxRange = Math.max( maxRange, waterActivationRange );
+ maxRange = Math.max( maxRange, villagerActivationRange );
+ // Paper end
2021-12-03 22:28:15 +01:00
maxRange = Math.min( ( world.spigotConfig.simulationDistance << 4 ) - 8, maxRange );
2021-06-11 14:02:28 +02:00
for ( Player player : world.players() )
2024-11-04 18:42:38 +01:00
@@ -131,13 +199,30 @@ public class ActivationRange
2022-07-30 18:47:35 +02:00
continue;
}
- ActivationRange.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-06-11 14:02:28 +02:00
+ // Paper start
2022-07-30 18:47:35 +02:00
+ int worldHeight = world.getHeight();
+ ActivationRange.maxBB = player.getBoundingBox().inflate( maxRange, worldHeight, maxRange );
+ ActivationType.MISC.boundingBox = player.getBoundingBox().inflate( miscActivationRange, worldHeight, miscActivationRange );
+ ActivationType.RAIDER.boundingBox = player.getBoundingBox().inflate( raiderActivationRange, worldHeight, raiderActivationRange );
+ ActivationType.ANIMAL.boundingBox = player.getBoundingBox().inflate( animalActivationRange, worldHeight, animalActivationRange );
+ ActivationType.MONSTER.boundingBox = player.getBoundingBox().inflate( monsterActivationRange, worldHeight, monsterActivationRange );
+ ActivationType.WATER.boundingBox = player.getBoundingBox().inflate( waterActivationRange, worldHeight, waterActivationRange );
+ ActivationType.FLYING_MONSTER.boundingBox = player.getBoundingBox().inflate( flyingActivationRange, worldHeight, flyingActivationRange );
+ ActivationType.VILLAGER.boundingBox = player.getBoundingBox().inflate( villagerActivationRange, worldHeight, villagerActivationRange );
2021-06-11 14:02:28 +02:00
+ // Paper end
2024-01-24 15:57:53 +01:00
- world.getEntities().get(ActivationRange.maxBB, ActivationRange::activateEntity);
+ // Paper start
+ java.util.List<Entity> entities = world.getEntities((Entity)null, ActivationRange.maxBB, null);
+ boolean tickMarkers = world.paperConfig().entities.markers.tick; // Paper - Configurable marker ticking
+ for (Entity entity : entities) {
+ // Paper start - Configurable marker ticking
+ if (!tickMarkers && entity instanceof net.minecraft.world.entity.Marker) {
+ continue;
+ }
+ // Paper end - Configurable marker ticking
+ ActivationRange.activateEntity(entity);
+ }
+ // Paper end
}
}
2024-10-27 18:11:15 +01:00
2024-11-04 18:42:38 +01:00
@@ -169,60 +254,118 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
* @param entity
* @return
*/
- public static boolean checkEntityImmunities(Entity entity)
+ public static int checkEntityImmunities(Entity entity) // Paper - return # of ticks to get immunity
{
+ // Paper start
2023-06-07 23:35:19 +02:00
+ SpigotWorldConfig config = entity.level().spigotConfig;
2021-06-11 14:02:28 +02:00
+ int inactiveWakeUpImmunity = checkInactiveWakeup(entity);
+ if (inactiveWakeUpImmunity > -1) {
+ return inactiveWakeUpImmunity;
2023-03-23 22:57:03 +01:00
+ }
2023-06-13 01:51:45 +02:00
+ if (entity.getRemainingFireTicks() > 0) {
2021-06-11 14:02:28 +02:00
+ return 2;
+ }
2021-08-21 16:15:29 +02:00
+ if (entity.activatedImmunityTick >= MinecraftServer.currentTick) {
+ return 1;
+ }
2021-06-11 14:02:28 +02:00
+ long inactiveFor = MinecraftServer.currentTick - entity.activatedTick;
+ // Paper end
2023-03-23 22:57:03 +01:00
// quick checks.
2023-06-13 01:51:45 +02:00
- if ( entity.wasTouchingWater || entity.getRemainingFireTicks() > 0 )
2021-06-13 21:29:58 +02:00
+ if ( (entity.activationType != ActivationType.WATER && entity.wasTouchingWater && entity.isPushedByFluid()) ) // Paper
2023-03-23 22:57:03 +01:00
{
- return true;
2021-06-11 14:02:28 +02:00
+ return 100; // Paper
2022-04-20 11:34:00 +02:00
+ }
+ // Paper start
2023-06-07 23:35:19 +02:00
+ if ( !entity.onGround() || entity.getDeltaMovement().horizontalDistanceSqr() > 9.999999747378752E-6D )
2022-04-20 11:34:00 +02:00
+ {
+ return 100;
2023-03-23 22:57:03 +01:00
}
2022-04-20 11:34:00 +02:00
+ // Paper end
2021-06-11 14:02:28 +02:00
if ( !( entity instanceof AbstractArrow ) )
{
2023-06-07 23:14:56 +02:00
- if ( !entity.onGround() || !entity.passengers.isEmpty() || entity.isPassenger() )
+ if ( (!entity.onGround() && !(entity instanceof FlyingMob)) ) // Paper - remove passengers logic
2021-06-11 14:02:28 +02:00
{
- return true;
+ return 10; // Paper
}
2024-10-24 20:40:24 +02:00
} else if ( !( (AbstractArrow) entity ).isInGround() )
2021-06-11 14:02:28 +02:00
{
- return true;
+ return 1; // Paper
}
// special cases.
if ( entity instanceof LivingEntity )
{
LivingEntity living = (LivingEntity) entity;
- if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTime > 0 || living.activeEffects.size() > 0 )
2024-01-02 20:08:34 +01:00
+ if ( living.onClimbable() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing()) // Paper
2021-06-11 14:02:28 +02:00
{
- return true;
+ return 1; // Paper
}
- if ( entity instanceof PathfinderMob && ( (PathfinderMob) entity ).getTarget() != null )
+ if ( entity instanceof Mob && ((Mob) entity ).getTarget() != null) // Paper
{
- return true;
+ return 20; // Paper
2024-10-27 18:11:15 +01:00
}
- if ( entity instanceof Villager && ( (Villager) entity ).canBreed() )
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (entity instanceof Bee) {
+ Bee bee = (Bee)entity;
+ BlockPos movingTarget = bee.getMovingTarget();
+ if (bee.isAngry() ||
+ (bee.getHivePos() != null && bee.getHivePos().equals(movingTarget)) ||
+ (bee.getSavedFlowerPos() != null && bee.getSavedFlowerPos().equals(movingTarget))
+ ) {
+ return 20;
+ }
2024-10-27 18:11:15 +01:00
+ }
2021-06-11 14:02:28 +02:00
+ if ( entity instanceof Villager ) {
+ Brain<Villager> behaviorController = ((Villager) entity).getBrain();
+
+ if (config.villagersActiveForPanic) {
2024-10-27 18:11:15 +01:00
+ for (net.minecraft.world.entity.schedule.Activity activity : VILLAGER_PANIC_IMMUNITIES) {
2021-06-11 14:02:28 +02:00
+ if (behaviorController.isActive(activity)) {
+ return 20*5;
+ }
+ }
+ }
+
+ if (config.villagersWorkImmunityAfter > 0 && inactiveFor >= config.villagersWorkImmunityAfter) {
2024-10-27 18:11:15 +01:00
+ if (behaviorController.isActive(net.minecraft.world.entity.schedule.Activity.WORK)) {
2021-06-11 14:02:28 +02:00
+ return config.villagersWorkImmunityFor;
+ }
+ }
2024-01-24 15:57:53 +01:00
+ }
2021-06-11 14:02:28 +02:00
+ if ( entity instanceof Llama && ( (Llama) entity ).inCaravan() )
{
- return true;
+ return 1;
}
+ // Paper end
if ( entity instanceof Animal )
{
Animal animal = (Animal) entity;
if ( animal.isBaby() || animal.isInLove() )
{
- return true;
+ return 5; // Paper
}
if ( entity instanceof Sheep && ( (Sheep) entity ).isSheared() )
{
- return true;
+ return 1; // Paper
}
}
if (entity instanceof Creeper && ((Creeper) entity).isIgnited()) { // isExplosive
- return true;
+ return 20; // Paper
2023-03-23 22:57:03 +01:00
+ }
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (entity instanceof Mob && ((Mob) entity).targetSelector.hasTasks() ) {
+ return 0;
2024-10-30 14:06:43 +01:00
}
2021-06-11 14:02:28 +02:00
+ if (entity instanceof Pillager) {
+ Pillager pillager = (Pillager) entity;
+ // TODO:?
2024-10-30 14:06:43 +01:00
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
}
2022-01-01 04:05:42 +01:00
// SPIGOT-6644: Otherwise the target refresh tick will be missed
if (entity instanceof ExperienceOrb) {
- return true;
+ return 20; // Paper
}
2021-06-11 14:02:28 +02:00
- return false;
+ return -1; // Paper
}
/**
2024-11-04 18:42:38 +01:00
@@ -237,8 +380,19 @@ public class ActivationRange
2024-11-05 10:52:18 +01:00
if (entity instanceof FireworkRocketEntity || (entity instanceof ItemEntity && (entity.tickCount + entity.getId()) % 4 == 0)) { // Paper - Needed for item gravity, see ItemEntity tick
2021-06-11 14:02:28 +02:00
return true;
}
+ // Paper start - special case always immunities
+ // immunize brand new entities, dead entities, and portal scenarios
2024-06-15 14:12:22 +02:00
+ if (entity.defaultActivationState || entity.tickCount < 20*10 || !entity.isAlive() || (entity.portalProcess != null && !entity.portalProcess.hasExpired()) || entity.portalCooldown > 0) {
2021-06-11 14:02:28 +02:00
+ return true;
+ }
+ // immunize leashed entities
2022-11-20 00:53:20 +01:00
+ if (entity instanceof Mob && ((Mob)entity).getLeashHolder() instanceof Player) {
2021-06-11 14:02:28 +02:00
+ return true;
+ }
+ // Paper end
- boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
+ boolean isActive = entity.activatedTick >= MinecraftServer.currentTick;
+ entity.isTemporarilyActive = false; // Paper
// Should this entity tick?
if ( !isActive )
2024-11-04 18:42:38 +01:00
@@ -246,11 +400,14 @@ public class ActivationRange
2021-06-11 14:02:28 +02:00
if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
{
// Check immunities every 20 ticks.
2021-06-13 21:29:58 +02:00
- if ( ActivationRange.checkEntityImmunities( entity ) )
2021-06-11 14:02:28 +02:00
- {
- // 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;
2024-11-04 18:42:38 +01:00
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2024-06-27 22:08:34 +02:00
index 2b263246135c85aa225120519e9702a628773935..2c408fa4abcbe1171c58aee8799c8cf7867d0f0a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2024-01-23 15:43:48 +01:00
@@ -211,14 +211,60 @@ public class SpigotWorldConfig
2021-06-11 14:02:28 +02:00
public int monsterActivationRange = 32;
2024-06-27 22:08:34 +02:00
public int raiderActivationRange = 64;
2021-06-11 14:02:28 +02:00
public int miscActivationRange = 16;
+ // Paper start
+ public int flyingMonsterActivationRange = 32;
+ public int waterActivationRange = 16;
+ public int villagerActivationRange = 32;
+ public int wakeUpInactiveAnimals = 4;
+ public int wakeUpInactiveAnimalsEvery = 60*20;
+ public int wakeUpInactiveAnimalsFor = 5*20;
+ public int wakeUpInactiveMonsters = 8;
+ public int wakeUpInactiveMonstersEvery = 20*20;
+ public int wakeUpInactiveMonstersFor = 5*20;
+ public int wakeUpInactiveVillagers = 4;
+ public int wakeUpInactiveVillagersEvery = 30*20;
+ public int wakeUpInactiveVillagersFor = 5*20;
+ public int wakeUpInactiveFlying = 8;
+ public int wakeUpInactiveFlyingEvery = 10*20;
+ public int wakeUpInactiveFlyingFor = 5*20;
+ public int villagersWorkImmunityAfter = 5*20;
+ public int villagersWorkImmunityFor = 20;
+ public boolean villagersActiveForPanic = true;
+ // Paper end
public boolean tickInactiveVillagers = true;
2022-01-09 06:12:05 +01:00
public boolean ignoreSpectatorActivation = false;
2021-06-11 14:02:28 +02:00
private void activationRange()
{
2021-06-13 21:29:58 +02:00
+ boolean hasAnimalsConfig = config.getInt("entity-activation-range.animals", this.animalActivationRange) != this.animalActivationRange; // Paper
this.animalActivationRange = this.getInt( "entity-activation-range.animals", this.animalActivationRange );
this.monsterActivationRange = this.getInt( "entity-activation-range.monsters", this.monsterActivationRange );
this.raiderActivationRange = this.getInt( "entity-activation-range.raiders", this.raiderActivationRange );
this.miscActivationRange = this.getInt( "entity-activation-range.misc", this.miscActivationRange );
2021-06-11 14:02:28 +02:00
+ // Paper start
2021-06-13 21:29:58 +02:00
+ this.waterActivationRange = this.getInt( "entity-activation-range.water", this.waterActivationRange );
+ this.villagerActivationRange = this.getInt( "entity-activation-range.villagers", hasAnimalsConfig ? this.animalActivationRange : this.villagerActivationRange );
+ this.flyingMonsterActivationRange = this.getInt( "entity-activation-range.flying-monsters", this.flyingMonsterActivationRange );
2021-06-11 14:02:28 +02:00
+
2021-06-13 21:29:58 +02:00
+ this.wakeUpInactiveAnimals = this.getInt("entity-activation-range.wake-up-inactive.animals-max-per-tick", this.wakeUpInactiveAnimals);
+ this.wakeUpInactiveAnimalsEvery = this.getInt("entity-activation-range.wake-up-inactive.animals-every", this.wakeUpInactiveAnimalsEvery);
+ this.wakeUpInactiveAnimalsFor = this.getInt("entity-activation-range.wake-up-inactive.animals-for", this.wakeUpInactiveAnimalsFor);
2021-06-11 14:02:28 +02:00
+
2021-06-13 21:29:58 +02:00
+ this.wakeUpInactiveMonsters = this.getInt("entity-activation-range.wake-up-inactive.monsters-max-per-tick", this.wakeUpInactiveMonsters);
+ this.wakeUpInactiveMonstersEvery = this.getInt("entity-activation-range.wake-up-inactive.monsters-every", this.wakeUpInactiveMonstersEvery);
+ this.wakeUpInactiveMonstersFor = this.getInt("entity-activation-range.wake-up-inactive.monsters-for", this.wakeUpInactiveMonstersFor);
2021-06-11 14:02:28 +02:00
+
2021-06-13 21:29:58 +02:00
+ this.wakeUpInactiveVillagers = this.getInt("entity-activation-range.wake-up-inactive.villagers-max-per-tick", this.wakeUpInactiveVillagers);
+ this.wakeUpInactiveVillagersEvery = this.getInt("entity-activation-range.wake-up-inactive.villagers-every", this.wakeUpInactiveVillagersEvery);
+ this.wakeUpInactiveVillagersFor = this.getInt("entity-activation-range.wake-up-inactive.villagers-for", this.wakeUpInactiveVillagersFor);
2021-06-11 14:02:28 +02:00
+
2021-06-13 21:29:58 +02:00
+ this.wakeUpInactiveFlying = this.getInt("entity-activation-range.wake-up-inactive.flying-monsters-max-per-tick", this.wakeUpInactiveFlying);
+ this.wakeUpInactiveFlyingEvery = this.getInt("entity-activation-range.wake-up-inactive.flying-monsters-every", this.wakeUpInactiveFlyingEvery);
+ this.wakeUpInactiveFlyingFor = this.getInt("entity-activation-range.wake-up-inactive.flying-monsters-for", this.wakeUpInactiveFlyingFor);
2021-06-11 14:02:28 +02:00
+
2021-06-13 21:29:58 +02:00
+ this.villagersWorkImmunityAfter = this.getInt( "entity-activation-range.villagers-work-immunity-after", this.villagersWorkImmunityAfter );
+ this.villagersWorkImmunityFor = this.getInt( "entity-activation-range.villagers-work-immunity-for", this.villagersWorkImmunityFor );
+ this.villagersActiveForPanic = this.getBoolean( "entity-activation-range.villagers-active-for-panic", this.villagersActiveForPanic );
2021-06-11 14:02:28 +02:00
+ // Paper end
2021-06-13 21:29:58 +02:00
this.tickInactiveVillagers = this.getBoolean( "entity-activation-range.tick-inactive-villagers", this.tickInactiveVillagers );
2022-01-09 06:12:05 +01:00
this.ignoreSpectatorActivation = this.getBoolean( "entity-activation-range.ignore-spectators", this.ignoreSpectatorActivation );
this.log( "Entity Activation Range: An " + this.animalActivationRange + " / Mo " + this.monsterActivationRange + " / Ra " + this.raiderActivationRange + " / Mi " + this.miscActivationRange + " / Tiv " + this.tickInactiveVillagers + " / Isa " + this.ignoreSpectatorActivation );