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
|
2023-12-05 20:39:26 +01:00
|
|
|
index 3126e8cab3c40e3af47f4c8925e1c6a9523309ba..170fbb1d80947b9b21c2106497baae5c37bcdc0c 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
|
2023-12-05 20:39:26 +01:00
|
|
|
@@ -30,6 +30,11 @@ public final class EntitySelector {
|
2021-11-23 12:27:39 +01:00
|
|
|
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
|
2022-11-15 20:15:01 +01:00
|
|
|
+ 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
|
2023-12-05 20:39:26 +01:00
|
|
|
index 007a5c9a6dc70ca6a215fdeb3fe77f8a8ee46818..3d054cfa5050f4b75eab4a18035655c1bfd9290b 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
|
2023-12-05 20:39:26 +01:00
|
|
|
@@ -849,7 +849,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
|
2023-06-07 20:31:32 +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()) {
|
2023-06-07 20:31:32 +02:00
|
|
|
- Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
|
2023-06-08 00:12:41 +02:00
|
|
|
+ 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);
|
2022-11-15 20:15:01 +01:00
|
|
|
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
|
2023-06-07 20:31:32 +02:00
|
|
|
index c7ab59aa0e2fd0f3e7252647ddb25b82ac604830..8f20239f3ef7ebe41fac8ee6e024c36dafec33c4 100644
|
2022-11-15 20:15:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
|
2022-12-07 19:32:25 +01:00
|
|
|
@@ -25,7 +25,7 @@ public class SkeletonTrapGoal extends Goal {
|
2022-11-15 20:15:01 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canUse() {
|
2023-06-07 20:31:32 +02:00
|
|
|
- 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
|
2022-11-15 20:15:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2023-09-21 21:54:46 +02:00
|
|
|
index 96181e8925aef7f3d0a2010305caf1f6d9bcfcc9..6f452605e9dc9ebd9980eae9fdeea34417a37a88 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
|
2023-09-21 21:54:46 +02: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;
|
|
|
|
}
|
2022-11-15 20:15:01 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
2023-12-06 19:21:23 +01:00
|
|
|
index 38403a5bb8569f105056d61ca444d6b3a19becd2..2aec8e2f45fe6ba56d84e5a51a6e30d36505df42 100644
|
2022-11-15 20:15:01 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
2023-09-21 21:54:46 +02:00
|
|
|
@@ -326,7 +326,7 @@ public class Zombie extends Monster {
|
2022-11-15 20:15:01 +01:00
|
|
|
|
2023-06-07 20:31:32 +02:00
|
|
|
if (NaturalSpawner.isSpawnPositionOk(entitypositiontypes_surface, this.level(), blockposition, entitytypes) && SpawnPlacements.checkSpawnRules(entitytypes, worldserver, MobSpawnType.REINFORCEMENT, blockposition, this.level().random)) {
|
2022-11-15 20:15:01 +01:00
|
|
|
entityzombie.setPos((double) i1, (double) j1, (double) k1);
|
2023-06-07 20:31:32 +02:00
|
|
|
- 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
|
2022-11-15 20:15:01 +01:00
|
|
|
entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit
|
2023-06-07 20:31:32 +02:00
|
|
|
entityzombie.finalizeSpawn(worldserver, this.level().getCurrentDifficultyAt(entityzombie.blockPosition()), MobSpawnType.REINFORCEMENT, (SpawnGroupData) null, (CompoundTag) null);
|
2022-11-15 20:15:01 +01:00
|
|
|
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
|
2023-12-05 20:39:26 +01:00
|
|
|
index eed6481bc88ed15a5e3fe7056b545ab44ed81983..86d187cadb73dbe0757f9417c4549e358ff303ca 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
|
2023-12-05 20:39:26 +01:00
|
|
|
@@ -179,6 +179,9 @@ public abstract class Player extends LivingEntity {
|
2021-06-11 14:02:28 +02:00
|
|
|
@Nullable
|
|
|
|
public FishingHook fishing;
|
2023-03-14 19:05:23 +01:00
|
|
|
protected float hurtDir;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // 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
|
2023-12-05 20:39:26 +01:00
|
|
|
index d156f7e3430685947d2b4c30aa867e8002ca70ad..e888cf862662ae6baa6d0de8188aa74a9c6a8e00 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
|
2023-12-05 20:39:26 +01:00
|
|
|
@@ -56,7 +56,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);
|
2022-11-15 20:15:01 +01:00
|
|
|
+ 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
|
2023-09-22 22:13:57 +02:00
|
|
|
index 2ec2b1d9d987c7f31c685aec3d3c87f42758c94b..36d793b492d9776ee36f8285b5bab09e6463cdce 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
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -82,6 +82,11 @@ public interface EntityGetter {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:15:01 +01: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;
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -111,6 +116,20 @@ public interface EntityGetter {
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.getNearestPlayer(x, y, z, maxDistance, predicate);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:15:01 +01:00
|
|
|
+ // 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
|
|
|
+ }
|
2022-11-15 20:15:01 +01: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
|
2023-12-09 00:13:02 +01:00
|
|
|
index 41a4f6126f24848a26ff0f928a23b5be13783c90..4bdcff78393b618b2201753bbffbd9001d5ad2d1 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
|
2023-12-09 00:13:02 +01:00
|
|
|
@@ -2267,6 +2267,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-09-21 21:54:46 +02:00
|
|
|
return this.getHandle().language;
|
|
|
|
}
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ public void setAffectsSpawning(boolean affects) {
|
|
|
|
+ this.getHandle().affectsSpawning = affects;
|
2023-09-21 21:54:46 +02:00
|
|
|
+ }
|
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @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;
|