Paper/patches/unapplied/server/0028-Player-affects-spawnin...

164 lines
9.9 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Tue, 1 Mar 2016 14:47:52 -0600
Subject: [PATCH] Player affects spawning API
diff --git a/src/main/java/net/minecraft/world/entity/EntitySelector.java b/src/main/java/net/minecraft/world/entity/EntitySelector.java
index 5c3b11f738c1ea19981cc878aa6c2323497391a0..6fd874a83a248e6a7d427d18d11fc608544662c5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/EntitySelector.java
+++ b/src/main/java/net/minecraft/world/entity/EntitySelector.java
2021-11-23 12:27:39 +01:00
@@ -29,6 +29,11 @@ public final class EntitySelector {
public static final Predicate<Entity> CAN_BE_COLLIDED_WITH = EntitySelector.NO_SPECTATORS.and(Entity::canBeCollidedWith);
2021-06-11 14:02:28 +02:00
2021-06-12 00:37:16 +02:00
private EntitySelector() {}
2021-06-11 14:02:28 +02:00
+ // Paper start
+ public static final Predicate<Entity> PLAYER_AFFECTS_SPAWNING = (entity) -> {
+ return !entity.isSpectator() && entity.isAlive() && entity instanceof Player player && player.affectsSpawning;
2021-06-11 14:02:28 +02:00
+ };
+ // Paper end
2021-06-12 00:37:16 +02:00
public static Predicate<Entity> withinDistance(double x, double y, double z, double max) {
double d4 = max * max;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
2022-12-07 17:46:46 +01:00
index a27082368913e5c6dc926bd197f3b135a633f30d..d315d9e0e6724e210924ec5814545e8c52ba2d8b 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
@@ -790,7 +790,7 @@ public abstract class Mob extends LivingEntity {
2021-06-11 14:02:28 +02:00
if (this.level.getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
2021-06-12 00:37:16 +02:00
this.discard();
2021-06-11 14:02:28 +02:00
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
- Player entityhuman = this.level.getNearestPlayer(this, -1.0D);
+ Player entityhuman = this.level.findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper
2021-06-11 14:02:28 +02:00
if (entityhuman != null) {
2021-11-23 12:27:39 +01:00
double d0 = entityhuman.distanceToSqr((Entity) this);
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
index 114352b9e8aeea7c728b6b58047e38e2530401a9..43e481377ba1596e740eacefd21d9664b7807883 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
@@ -24,7 +24,7 @@ public class SkeletonTrapGoal extends Goal {
@Override
public boolean canUse() {
- return this.horse.level.hasNearbyAlivePlayer(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D);
+ return this.horse.level.hasNearbyAlivePlayerThatAffectsSpawning(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D); // Paper - Affects Spawning API
}
@Override
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
2022-06-07 21:15:06 +02:00
index 87f66fd33e404367d924137b2d8aac3b06937f43..2dcda3b03796655da443e1b3dd68c6f6bca20d21 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
2022-03-01 06:43:03 +01:00
@@ -127,7 +127,7 @@ public class Silverfish extends Monster {
2021-06-11 14:02:28 +02:00
if (checkAnyLightMonsterSpawnRules(type, world, spawnReason, pos, random)) {
Player entityhuman = world.getNearestPlayer((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, 5.0D, true);
- return entityhuman == null;
+ return !(entityhuman != null && !entityhuman.affectsSpawning) && entityhuman == null; // Paper - Affects Spawning API
} else {
return false;
}
diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
index 1b48576beca178af14bfab297bd427b5f5bdaf42..d3ca0706e8dc3160d2100d23788dd3d501b29215 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
@@ -324,7 +324,7 @@ public class Zombie extends Monster {
if (NaturalSpawner.isSpawnPositionOk(entitypositiontypes_surface, this.level, blockposition, entitytypes) && SpawnPlacements.checkSpawnRules(entitytypes, worldserver, MobSpawnType.REINFORCEMENT, blockposition, this.level.random)) {
entityzombie.setPos((double) i1, (double) j1, (double) k1);
- if (!this.level.hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && this.level.isUnobstructed(entityzombie) && this.level.noCollision((Entity) entityzombie) && !this.level.containsAnyLiquid(entityzombie.getBoundingBox())) {
+ if (!this.level.hasNearbyAlivePlayerThatAffectsSpawning((double) i1, (double) j1, (double) k1, 7.0D) && this.level.isUnobstructed(entityzombie) && this.level.noCollision((Entity) entityzombie) && !this.level.containsAnyLiquid(entityzombie.getBoundingBox())) { // Paper - Affects Spawning API
entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit
entityzombie.finalizeSpawn(worldserver, this.level.getCurrentDifficultyAt(entityzombie.blockPosition()), MobSpawnType.REINFORCEMENT, (SpawnGroupData) null, (CompoundTag) null);
worldserver.addFreshEntityWithPassengers(entityzombie, CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2022-12-07 17:46:46 +01:00
index 1883c6a4a6a58b25913eaed40786ea67785bad37..4751fea5e7319600422c4fb3e40026a36db85a6a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2022-07-27 21:18:51 +02:00
@@ -184,6 +184,9 @@ public abstract class Player extends LivingEntity {
2022-06-07 21:15:06 +02:00
private Optional<GlobalPos> lastDeathLocation;
2021-06-11 14:02:28 +02:00
@Nullable
public FishingHook fishing;
+ // Paper start
+ public boolean affectsSpawning = true;
+ // Paper end
// CraftBukkit start
public boolean fauxSleeping;
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
index ab22310d5ab4ad7014b88080cbd44a2881002b55..b0ac72a69e13f2376aa4c66d9a1f5a01b480785c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
2021-11-23 12:27:39 +01:00
@@ -51,7 +51,7 @@ public abstract class BaseSpawner {
2021-06-12 00:37:16 +02:00
}
2021-06-11 14:02:28 +02:00
2021-11-24 04:42:31 +01:00
public boolean isNearPlayer(Level world, BlockPos pos) {
2021-06-12 00:37:16 +02:00
- return world.hasNearbyAlivePlayer((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange);
+ return world.hasNearbyAlivePlayerThatAffectsSpawning((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper - Affects Spawning API
2021-06-11 14:02:28 +02:00
}
2021-06-12 00:37:16 +02:00
public void clientTick(Level world, BlockPos pos) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java
index f62e4e36dd26bde067e4787fd0da1440b15a57fa..abd74c6502e07857e0f64c5f99534b68975acd69 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/EntityGetter.java
+++ b/src/main/java/net/minecraft/world/level/EntityGetter.java
@@ -82,6 +82,11 @@ public interface EntityGetter {
2021-06-11 14:02:28 +02:00
}
}
+ // Paper start
+ default @Nullable Player findNearbyPlayer(Entity entity, double maxDistance, @Nullable Predicate<Entity> predicate) {
+ return this.getNearestPlayer(entity.getX(), entity.getY(), entity.getZ(), maxDistance, predicate);
+ }
+ // Paper end
@Nullable
default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) {
2021-06-12 00:37:16 +02:00
double d = -1.0D;
@@ -111,6 +116,20 @@ public interface EntityGetter {
2021-06-11 14:02:28 +02:00
return this.getNearestPlayer(x, y, z, maxDistance, predicate);
}
+ // Paper start
+ default boolean hasNearbyAlivePlayerThatAffectsSpawning(double x, double y, double z, double range) {
+ for (Player player : this.players()) {
+ if (EntitySelector.PLAYER_AFFECTS_SPAWNING.test(player)) { // combines NO_SPECTATORS and LIVING_ENTITY_STILL_ALIVE with an "affects spawning" check
+ double distanceSqr = player.distanceToSqr(x, y, z);
+ if (range < 0.0D || distanceSqr < range * range) {
+ return true;
2021-06-11 14:02:28 +02:00
+ }
+ }
+ }
+ return false;
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
default boolean hasNearbyAlivePlayer(double x, double y, double z, double range) {
2021-06-12 00:37:16 +02:00
for(Player player : this.players()) {
if (EntitySelector.NO_SPECTATORS.test(player) && EntitySelector.LIVING_ENTITY_STILL_ALIVE.test(player)) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
index 6708c2c88251f4e5f623cd785c14b2d3ed2d3de0..182881c867e68e59e89f56f8dc66001b0d2b3add 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
@@ -2084,8 +2084,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
@Override
public String getLocale() {
2021-06-12 00:37:16 +02:00
return this.getHandle().locale;
2021-06-11 14:02:28 +02:00
+
+ }
+
+ // Paper start
+ public void setAffectsSpawning(boolean affects) {
+ this.getHandle().affectsSpawning = affects;
}
+ @Override
+ public boolean getAffectsSpawning() {
+ return this.getHandle().affectsSpawning;
+ }
+ // Paper end
+
@Override
public void updateCommands() {
2021-06-12 00:37:16 +02:00
if (this.getHandle().connection == null) return;