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
|
2024-10-22 20:04:31 +02:00
|
|
|
index 048c8af16fad8708a486bb29304db22e2fb1ecb3..a617ea34cfc28cefd68dd14ffbb334b87f98f65c 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
|
2024-10-22 20:04:31 +02:00
|
|
|
@@ -29,6 +29,11 @@ public final class EntitySelector {
|
|
|
|
public static final Predicate<Entity> CAN_BE_PICKED = EntitySelector.NO_SPECTATORS.and(Entity::isPickable);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-12 00:37:16 +02:00
|
|
|
private EntitySelector() {}
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start - Affects Spawning API
|
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
|
|
|
+ };
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper end - Affects Spawning API
|
2021-06-11 14:02:28 +02:00
|
|
|
|
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
|
2024-12-03 18:27:11 +01:00
|
|
|
index 137e645950eab0fc083ef3ff0fc65ee702dc2ea7..0562039114a90ddb64547eb8396920813d54f46b 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-22 20:04:31 +02:00
|
|
|
@@ -858,7 +858,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
2023-06-07 20:31:32 +02:00
|
|
|
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
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);
|
2024-01-24 11:45:17 +01:00
|
|
|
+ Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
if (entityhuman != null) {
|
2024-08-17 21:13:10 +02:00
|
|
|
// Paper start - Configurable despawn distances
|
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
|
2024-10-22 20:04:31 +02:00
|
|
|
index c86e2d75ac627e9c92a6e006cb4c06ec6a2cb91e..521b09ac14372f524b06ffdce57932d0a590700b 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
|
2024-04-23 23:31:37 +02:00
|
|
|
@@ -27,7 +27,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
|
2024-10-22 20:04:31 +02:00
|
|
|
index 0594b6adcb849bba2c810de245a3bdaeeca0be60..52d8ea3e40cdb01eab428f5d3d945c0c9f6088ce 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
|
2024-10-22 20:04:31 +02:00
|
|
|
@@ -123,7 +123,7 @@ public class Silverfish extends Monster {
|
|
|
|
} else {
|
2021-06-11 14:02:28 +02:00
|
|
|
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
|
|
|
|
}
|
2024-10-22 20:04:31 +02:00
|
|
|
}
|
|
|
|
|
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
|
2024-10-25 13:34:01 +02:00
|
|
|
index 3836d9255ac326a7220e1decd2e9d98be7884c17..73c4585870b7af409f84474f126a58497ed0495f 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
|
2024-10-22 20:04:31 +02:00
|
|
|
@@ -349,7 +349,7 @@ public class Zombie extends Monster {
|
2022-11-15 20:15:01 +01:00
|
|
|
|
2024-10-22 20:04:31 +02:00
|
|
|
if (SpawnPlacements.isSpawnPositionOk(entitytypes, world, blockposition) && SpawnPlacements.checkSpawnRules(entitytypes, world, EntitySpawnReason.REINFORCEMENT, blockposition, world.random)) {
|
2022-11-15 20:15:01 +01:00
|
|
|
entityzombie.setPos((double) i1, (double) j1, (double) k1);
|
2024-10-22 20:04:31 +02:00
|
|
|
- if (!world.hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && world.isUnobstructed(entityzombie) && world.noCollision((Entity) entityzombie) && (entityzombie.canSpawnInLiquids() || !world.containsAnyLiquid(entityzombie.getBoundingBox()))) {
|
2024-10-25 13:34:01 +02:00
|
|
|
+ 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
|
2022-11-15 20:15:01 +01:00
|
|
|
entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit
|
2024-10-22 20:04:31 +02:00
|
|
|
entityzombie.finalizeSpawn(world, world.getCurrentDifficultyAt(entityzombie.blockPosition()), EntitySpawnReason.REINFORCEMENT, (SpawnGroupData) null);
|
|
|
|
world.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
|
2024-12-03 18:27:11 +01:00
|
|
|
index f917b43240b2fa4207b276ac850832fd1618302a..09a7c6171e50b6cf08cf7096b6005d3f9d8d2de7 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
|
2024-12-03 18:27:11 +01:00
|
|
|
@@ -198,6 +198,7 @@ public abstract class Player extends LivingEntity {
|
2024-04-23 23:31:37 +02:00
|
|
|
public Entity currentExplosionCause;
|
2024-06-13 19:12:48 +02:00
|
|
|
private boolean ignoreFallDamageFromCurrentImpulse;
|
|
|
|
private int currentImpulseContextResetGraceTime;
|
2024-01-24 11:45:17 +01:00
|
|
|
+ public boolean affectsSpawning = true; // Paper - Affects Spawning API
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
// 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
|
2024-10-22 20:04:31 +02:00
|
|
|
index b2bed46f809abee056aa99f39f26f8c0fbf0036c..366661561544f8e99f238583259991e9fcbab8af 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
|
2024-04-23 23:31:37 +02:00
|
|
|
@@ -58,7 +58,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
|
2024-10-22 20:04:31 +02:00
|
|
|
index f689b2ca0ebc15c099f36ebfd14e455bda540296..fb043d67eaa6336fc0b5d62774b8f1107f9dfa1e 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
|
2024-10-22 20:04:31 +02:00
|
|
|
@@ -71,6 +71,11 @@ public interface EntityGetter {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start - Affects Spawning API
|
2022-11-15 20:15:01 +01:00
|
|
|
+ default @Nullable Player findNearbyPlayer(Entity entity, double maxDistance, @Nullable Predicate<Entity> predicate) {
|
|
|
|
+ return this.getNearestPlayer(entity.getX(), entity.getY(), entity.getZ(), maxDistance, predicate);
|
|
|
|
+ }
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper end - Affects Spawning API
|
2022-11-15 20:15:01 +01:00
|
|
|
@Nullable
|
|
|
|
default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) {
|
2024-04-12 21:14:06 +02:00
|
|
|
double d = -1.0;
|
2024-10-22 20:04:31 +02:00
|
|
|
@@ -100,6 +105,20 @@ public interface EntityGetter {
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.getNearestPlayer(x, y, z, maxDistance, predicate);
|
|
|
|
}
|
|
|
|
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start - Affects Spawning API
|
2022-11-15 20:15:01 +01:00
|
|
|
+ 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
|
|
|
+ }
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper end - Affects Spawning API
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
default boolean hasNearbyAlivePlayer(double x, double y, double z, double range) {
|
2024-04-12 21:14:06 +02:00
|
|
|
for (Player player : this.players()) {
|
2021-06-12 00:37:16 +02:00
|
|
|
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
|
2024-12-03 18:27:11 +01:00
|
|
|
index a37e5d822e93b3a4b1c0becf22290017c4709b94..90428fbc332fb8b621725ade8eb010d5edec1286 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
|
2024-12-03 18:27:11 +01:00
|
|
|
@@ -2437,6 +2437,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;
|