diff --git a/paper-server/patches/sources/net/minecraft/world/entity/EntitySelector.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/EntitySelector.java.patch index bef21e6fcd..96427356c0 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/EntitySelector.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/EntitySelector.java.patch @@ -1,6 +1,18 @@ --- a/net/minecraft/world/entity/EntitySelector.java +++ b/net/minecraft/world/entity/EntitySelector.java -@@ -43,7 +43,7 @@ +@@ -29,6 +29,11 @@ + public static final Predicate CAN_BE_PICKED = EntitySelector.NO_SPECTATORS.and(Entity::isPickable); + + private EntitySelector() {} ++ // Paper start - Affects Spawning API ++ public static final Predicate PLAYER_AFFECTS_SPAWNING = (entity) -> { ++ return !entity.isSpectator() && entity.isAlive() && entity instanceof Player player && player.affectsSpawning; ++ }; ++ // Paper end - Affects Spawning API + + public static Predicate withinDistance(double x, double y, double z, double max) { + double d4 = max * max; +@@ -43,7 +48,7 @@ Team.CollisionRule scoreboardteambase_enumteampush = scoreboardteam == null ? Team.CollisionRule.ALWAYS : scoreboardteam.getCollisionRule(); return (Predicate) (scoreboardteambase_enumteampush == Team.CollisionRule.NEVER ? Predicates.alwaysFalse() : EntitySelector.NO_SPECTATORS.and((entity1) -> { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch index 6ee0b1ce0f..43fb144bfd 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch @@ -213,7 +213,8 @@ - this.discard(); + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) { - Player entityhuman = this.level().getNearestPlayer(this, -1.0D); +- Player entityhuman = this.level().getNearestPlayer(this, -1.0D); ++ Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API if (entityhuman != null) { - double d0 = entityhuman.distanceToSqr((Entity) this); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java.patch index 25fb150bd1..24ffd615a5 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java +++ b/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java +@@ -27,7 +27,7 @@ + + @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 @@ -43,12 +43,12 @@ if (entitylightning != null) { entitylightning.moveTo(this.horse.getX(), this.horse.getY(), this.horse.getZ()); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/monster/Silverfish.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/monster/Silverfish.java.patch index 949f780c92..799778d522 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/monster/Silverfish.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/monster/Silverfish.java.patch @@ -11,6 +11,15 @@ public class Silverfish extends Monster { +@@ -119,7 +123,7 @@ + } else { + 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 + } + } + @@ -160,6 +164,11 @@ Block block = iblockdata.getBlock(); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/monster/Zombie.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/monster/Zombie.java.patch index 509753551b..acc19eefa4 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/monster/Zombie.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/monster/Zombie.java.patch @@ -163,11 +163,13 @@ } public boolean isSunSensitive() { -@@ -324,9 +350,9 @@ +@@ -323,10 +349,10 @@ + if (SpawnPlacements.isSpawnPositionOk(entitytypes, world, blockposition) && SpawnPlacements.checkSpawnRules(entitytypes, world, EntitySpawnReason.REINFORCEMENT, blockposition, world.random)) { entityzombie.setPos((double) i1, (double) j1, (double) k1); - if (!world.hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && world.isUnobstructed(entityzombie) && world.noCollision((Entity) entityzombie) && (entityzombie.canSpawnInLiquids() || !world.containsAnyLiquid(entityzombie.getBoundingBox()))) { +- if (!world.hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && world.isUnobstructed(entityzombie) && world.noCollision((Entity) entityzombie) && (entityzombie.canSpawnInLiquids() || !world.containsAnyLiquid(entityzombie.getBoundingBox()))) { - entityzombie.setTarget(entityliving); ++ if (!world.hasNearbyAlivePlayerThatAffectsSpawning((double) i1, (double) j1, (double) k1, 7.0D) && world.isUnobstructed(entityzombie) && world.noCollision((Entity) entityzombie) && (entityzombie.canSpawnInLiquids() || !world.containsAnyLiquid(entityzombie.getBoundingBox()))) { // Paper - affects spawning api + entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit entityzombie.finalizeSpawn(world, world.getCurrentDifficultyAt(entityzombie.blockPosition()), EntitySpawnReason.REINFORCEMENT, (SpawnGroupData) null); - world.addFreshEntityWithPassengers(entityzombie); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch index 3c2362c4f5..6f40f981cd 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch @@ -35,10 +35,11 @@ public final InventoryMenu inventoryMenu; public AbstractContainerMenu containerMenu; protected FoodData foodData = new FoodData(); -@@ -188,7 +198,17 @@ +@@ -188,7 +198,18 @@ public Entity currentExplosionCause; private boolean ignoreFallDamageFromCurrentImpulse; private int currentImpulseContextResetGraceTime; ++ public boolean affectsSpawning = true; // Paper - Affects Spawning API + + // CraftBukkit start + public boolean fauxSleeping; @@ -53,7 +54,7 @@ public Player(Level world, BlockPos pos, float yaw, GameProfile gameProfile) { super(EntityType.PLAYER, world); this.lastItemInMainHand = ItemStack.EMPTY; -@@ -353,7 +373,7 @@ +@@ -353,7 +374,7 @@ } private void turtleHelmetTick() { @@ -62,7 +63,7 @@ } private boolean isEquipped(Item item) { -@@ -523,8 +543,14 @@ +@@ -523,8 +544,14 @@ public void rideTick() { if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) { this.stopRiding(); @@ -79,7 +80,7 @@ super.rideTick(); this.oBob = this.bob; this.bob = 0.0F; -@@ -719,7 +745,14 @@ +@@ -719,7 +746,14 @@ @Nullable public ItemEntity drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership) { @@ -95,7 +96,7 @@ this.swing(InteractionHand.MAIN_HAND); } -@@ -809,7 +842,7 @@ +@@ -809,7 +843,7 @@ } if (nbt.contains("LastDeathLocation", 10)) { @@ -104,7 +105,7 @@ Logger logger = Player.LOGGER; Objects.requireNonNull(logger); -@@ -817,7 +850,7 @@ +@@ -817,7 +851,7 @@ } if (nbt.contains("current_explosion_impact_pos", 9)) { @@ -113,7 +114,7 @@ Logger logger1 = Player.LOGGER; Objects.requireNonNull(logger1); -@@ -854,7 +887,7 @@ +@@ -854,7 +888,7 @@ } this.getLastDeathLocation().flatMap((globalpos) -> { @@ -122,7 +123,7 @@ Logger logger = Player.LOGGER; Objects.requireNonNull(logger); -@@ -886,10 +919,10 @@ +@@ -886,10 +920,10 @@ if (this.isDeadOrDying()) { return false; } else { @@ -135,7 +136,7 @@ } if (world.getDifficulty() == Difficulty.EASY) { -@@ -901,7 +934,13 @@ +@@ -901,7 +935,13 @@ } } @@ -150,7 +151,7 @@ } } } -@@ -923,10 +962,29 @@ +@@ -923,10 +963,29 @@ } public boolean canHarmPlayer(Player player) { @@ -183,7 +184,7 @@ } @Override -@@ -966,32 +1024,38 @@ +@@ -966,32 +1025,38 @@ } } @@ -236,7 +237,7 @@ } public boolean isTextFilteringEnabled() { -@@ -1144,10 +1208,15 @@ +@@ -1144,10 +1209,15 @@ f *= 0.2F + f2 * f2 * 0.8F; f1 *= f2; @@ -253,7 +254,7 @@ if (iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) { this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource()); return; -@@ -1223,8 +1292,13 @@ +@@ -1223,8 +1293,13 @@ if (entityliving2 != this && entityliving2 != target && !this.isAlliedTo((Entity) entityliving2) && (!(entityliving2 instanceof ArmorStand) || !((ArmorStand) entityliving2).isMarker()) && this.distanceToSqr((Entity) entityliving2) < 9.0D) { float f7 = this.getEnchantedDamage(entityliving2, f6, damagesource) * f2; @@ -268,7 +269,7 @@ Level world = this.level(); if (world instanceof ServerLevel) { -@@ -1240,9 +1314,26 @@ +@@ -1240,9 +1315,26 @@ } if (target instanceof ServerPlayer && target.hurtMarked) { @@ -295,7 +296,7 @@ } if (flag2) { -@@ -1308,9 +1399,14 @@ +@@ -1308,9 +1400,14 @@ } } @@ -311,7 +312,7 @@ } } -@@ -1351,7 +1447,14 @@ +@@ -1351,7 +1448,14 @@ @Override public void remove(Entity.RemovalReason reason) { @@ -327,7 +328,7 @@ this.inventoryMenu.removed(this); if (this.containerMenu != null && this.hasContainerOpen()) { this.doCloseContainer(); -@@ -1391,7 +1494,13 @@ +@@ -1391,7 +1495,13 @@ } public Either startSleepInBed(BlockPos pos) { @@ -342,7 +343,7 @@ this.sleepCounter = 0; return Either.right(Unit.INSTANCE); } -@@ -1545,12 +1654,24 @@ +@@ -1545,12 +1655,24 @@ } public void startFallFlying() { @@ -368,7 +369,7 @@ } @Override -@@ -1665,10 +1786,21 @@ +@@ -1665,10 +1787,21 @@ return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2); } @@ -391,7 +392,7 @@ } } -@@ -1748,13 +1880,20 @@ +@@ -1748,13 +1881,20 @@ @Override public void setItemSlot(EquipmentSlot slot, ItemStack stack) { @@ -419,7 +420,7 @@ } } -@@ -1798,26 +1937,31 @@ +@@ -1798,26 +1938,31 @@ public void removeEntitiesOnShoulder() { if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { diff --git a/paper-server/patches/sources/net/minecraft/world/level/BaseSpawner.java.patch b/paper-server/patches/sources/net/minecraft/world/level/BaseSpawner.java.patch index 26c161d3e4..cfb9a18f60 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/BaseSpawner.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/BaseSpawner.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/BaseSpawner.java +++ b/net/minecraft/world/level/BaseSpawner.java -@@ -54,6 +54,7 @@ +@@ -54,10 +54,11 @@ public void setEntityId(EntityType type, @Nullable Level world, RandomSource random, BlockPos pos) { this.getOrCreateNextSpawnData(world, random, pos).getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(type).toString()); @@ -8,6 +8,11 @@ } public boolean isNearPlayer(Level world, BlockPos pos) { +- 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 + } + + public void clientTick(Level world, BlockPos pos) { @@ -157,13 +158,24 @@ ((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.SPAWNER, (SpawnGroupData) null); } diff --git a/paper-server/patches/sources/net/minecraft/world/level/EntityGetter.java.patch b/paper-server/patches/sources/net/minecraft/world/level/EntityGetter.java.patch new file mode 100644 index 0000000000..d2f4c56f21 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/EntityGetter.java.patch @@ -0,0 +1,35 @@ +--- a/net/minecraft/world/level/EntityGetter.java ++++ b/net/minecraft/world/level/EntityGetter.java +@@ -71,6 +71,11 @@ + } + } + ++ // Paper start - Affects Spawning API ++ default @Nullable Player findNearbyPlayer(Entity entity, double maxDistance, @Nullable Predicate predicate) { ++ return this.getNearestPlayer(entity.getX(), entity.getY(), entity.getZ(), maxDistance, predicate); ++ } ++ // Paper end - Affects Spawning API + @Nullable + default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate targetPredicate) { + double d = -1.0; +@@ -100,6 +105,20 @@ + return this.getNearestPlayer(x, y, z, maxDistance, predicate); + } + ++ // Paper start - Affects Spawning API ++ 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; ++ } ++ } ++ } ++ return false; ++ } ++ // Paper end - Affects Spawning API ++ + default boolean hasNearbyAlivePlayer(double x, double y, double z, double range) { + for (Player player : this.players()) { + if (EntitySelector.NO_SPECTATORS.test(player) && EntitySelector.LIVING_ENTITY_STILL_ALIVE.test(player)) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index a37e5d822e..90428fbc33 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2437,6 +2437,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return this.getHandle().language; } + // 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() { if (this.getHandle().connection == null) return;