2021-06-11 12:02:28 +00: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
|
2021-11-23 11:27:39 +00:00
|
|
|
index 5c3b11f738c1ea19981cc878aa6c2323497391a0..b91a61be7c4829fce0ff8da290eab580e20bb78d 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/EntitySelector.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntitySelector.java
|
2021-11-23 11:27:39 +00: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 12:02:28 +00:00
|
|
|
|
2021-06-11 22:37:16 +00:00
|
|
|
private EntitySelector() {}
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ public static final Predicate<Entity> affectsSpawning = (entity) -> {
|
2021-06-11 22:37:16 +00:00
|
|
|
+ return !entity.isSpectator() && entity.isAlive() && (entity instanceof net.minecraft.server.level.ServerPlayer) && ((net.minecraft.server.level.ServerPlayer) entity).affectsSpawning;
|
2021-06-11 12:02:28 +00:00
|
|
|
+ };
|
|
|
|
+ // Paper end
|
|
|
|
|
2021-06-11 22:37:16 +00:00
|
|
|
public static Predicate<Entity> withinDistance(double x, double y, double z, double max) {
|
|
|
|
double d4 = max * max;
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
2022-09-12 11:31:45 +00:00
|
|
|
index ce04fa5ae8c539fd6f6aa7648a4cdce6b680463e..0b056e65b2efe0f96a6beecfc41709bfa18983ca 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
2022-09-12 11:31:45 +00:00
|
|
|
@@ -790,7 +790,7 @@ public abstract class Mob extends LivingEntity {
|
2021-06-11 12:02:28 +00:00
|
|
|
if (this.level.getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
|
2021-06-11 22:37:16 +00:00
|
|
|
this.discard();
|
2021-06-11 12:02:28 +00:00
|
|
|
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
|
|
|
|
- Player entityhuman = this.level.getNearestPlayer(this, -1.0D);
|
|
|
|
+ Player entityhuman = this.level.findNearbyPlayer(this, -1.0D, EntitySelector.affectsSpawning); // Paper
|
|
|
|
|
|
|
|
if (entityhuman != null) {
|
2021-11-23 11:27:39 +00:00
|
|
|
double d0 = entityhuman.distanceToSqr((Entity) this);
|
2021-06-11 12:02:28 +00: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 19:15:06 +00:00
|
|
|
index 87f66fd33e404367d924137b2d8aac3b06937f43..2dcda3b03796655da443e1b3dd68c6f6bca20d21 100644
|
2021-06-11 12:02:28 +00: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 05:43:03 +00:00
|
|
|
@@ -127,7 +127,7 @@ public class Silverfish extends Monster {
|
2021-06-11 12:02:28 +00: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/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
2022-07-27 19:18:51 +00:00
|
|
|
index 0232baa005e2839317d7ac2d64c88fb93bc29e5e..08b0b7b9146f58c4eb263d5ce1fee1b08d43fafe 100644
|
2021-06-11 12:02:28 +00: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 19:18:51 +00:00
|
|
|
@@ -184,6 +184,9 @@ public abstract class Player extends LivingEntity {
|
2022-06-07 19:15:06 +00:00
|
|
|
private Optional<GlobalPos> lastDeathLocation;
|
2021-06-11 12:02:28 +00: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
|
2022-06-07 19:15:06 +00:00
|
|
|
index ab22310d5ab4ad7014b88080cbd44a2881002b55..c5b9b19763fd944b4f31c6d3c9b71d372f8403cf 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
2021-11-23 11:27:39 +00:00
|
|
|
@@ -51,7 +51,7 @@ public abstract class BaseSpawner {
|
2021-06-11 22:37:16 +00:00
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-11-24 03:42:31 +00:00
|
|
|
public boolean isNearPlayer(Level world, BlockPos pos) {
|
2021-06-11 22:37:16 +00:00
|
|
|
- return world.hasNearbyAlivePlayer((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange);
|
|
|
|
+ return world.isAffectsSpawningPlayerNearby((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 22:37:16 +00:00
|
|
|
public void clientTick(Level world, BlockPos pos) {
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java
|
2022-05-29 19:54:25 +00:00
|
|
|
index 7c5918f84d2b8f9c778258b7e7d745105effb082..cfb286020b8ee87bad7edbda4cd0b999fb607a06 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/EntityGetter.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/EntityGetter.java
|
2022-05-29 19:54:25 +00:00
|
|
|
@@ -70,8 +70,8 @@ public interface EntityGetter {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- @Nullable
|
|
|
|
- default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) {
|
2021-06-17 19:37:37 +00:00
|
|
|
+ default Player findNearbyPlayer(Entity entity, double d0, @Nullable Predicate<Entity> predicate) { return this.getNearestPlayer(entity.getX(), entity.getY(), entity.getZ(), d0, predicate); } // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
+ @Nullable default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) { // Paper
|
2021-06-11 22:37:16 +00:00
|
|
|
double d = -1.0D;
|
|
|
|
Player player = null;
|
|
|
|
|
2022-05-29 19:54:25 +00:00
|
|
|
@@ -99,6 +99,27 @@ public interface EntityGetter {
|
2021-06-11 12:02:28 +00:00
|
|
|
return this.getNearestPlayer(x, y, z, maxDistance, predicate);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper end
|
|
|
|
+ default boolean isAffectsSpawningPlayerNearby(double d0, double d1, double d2, double d3) {
|
2021-06-11 22:37:16 +00:00
|
|
|
+ java.util.Iterator iterator = this.players().iterator();
|
2021-06-11 12:02:28 +00:00
|
|
|
+ double d4;
|
|
|
|
+ do {
|
|
|
|
+ Player entityhuman;
|
|
|
|
+ do {
|
|
|
|
+ if (!iterator.hasNext()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ entityhuman = (Player) iterator.next();
|
|
|
|
+ } while (!EntitySelector.affectsSpawning.test(entityhuman));
|
|
|
|
+
|
2021-06-17 21:39:36 +00:00
|
|
|
+ d4 = entityhuman.distanceToSqr(d0, d1, d2);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ } while (d3 >= 0.0D && d4 >= d3 * d3);
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
default boolean hasNearbyAlivePlayer(double x, double y, double z, double range) {
|
2021-06-11 22:37:16 +00:00
|
|
|
for(Player player : this.players()) {
|
|
|
|
if (EntitySelector.NO_SPECTATORS.test(player) && EntitySelector.LIVING_ENTITY_STILL_ALIVE.test(player)) {
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2022-09-01 16:51:59 +00:00
|
|
|
index a2dd86fde8882c774ad44be3ca66f7c80bb77389..6132d91ba0f1390365f4661bcd7406000fa8a88d 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2022-07-04 14:38:06 +00:00
|
|
|
@@ -1965,8 +1965,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-11 12:02:28 +00:00
|
|
|
@Override
|
|
|
|
public String getLocale() {
|
2021-06-11 22:37:16 +00:00
|
|
|
return this.getHandle().locale;
|
2021-06-11 12:02:28 +00: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-11 22:37:16 +00:00
|
|
|
if (this.getHandle().connection == null) return;
|