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/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2021-06-12 00:37:16 +02:00
|
|
|
index b82dd96147224057ea0e0dc92506b27ffbc9f034..568ce924efcad6ab6b986f1a450eb56c80e89b02 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2021-06-12 00:37:16 +02:00
|
|
|
@@ -1498,6 +1498,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
2021-06-11 14:02:28 +02:00
|
|
|
return Mth.sqrt(f * f + f1 * f1 + f2 * f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public double getDistanceSquared(double x, double y, double z) { return distanceToSqr(x, y, z); } // Paper - OBFHELPER
|
|
|
|
public double distanceToSqr(double x, double y, double z) {
|
|
|
|
double d3 = this.getX() - x;
|
|
|
|
double d4 = this.getY() - y;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntitySelector.java b/src/main/java/net/minecraft/world/entity/EntitySelector.java
|
2021-06-12 00:37:16 +02:00
|
|
|
index 195989667c7d844399a72787819f62a3fd0d9c78..d17b75ad13bbc8a38cdc2f2d77ee5d88438cec31 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-06-12 00:37:16 +02:00
|
|
|
@@ -28,6 +28,11 @@ public final class EntitySelector {
|
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> affectsSpawning = (entity) -> {
|
2021-06-12 00:37:16 +02:00
|
|
|
+ return !entity.isSpectator() && entity.isAlive() && (entity instanceof net.minecraft.server.level.ServerPlayer) && ((net.minecraft.server.level.ServerPlayer) entity).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
|
2021-06-12 00:37:16 +02:00
|
|
|
index 697f73cabfe89e716c9fceeb8362237d27ca3d02..b13774873f795b149c15fddb8053d9419f1841ca 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
|
2021-06-12 00:37:16 +02:00
|
|
|
@@ -766,7 +766,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.affectsSpawning); // Paper
|
|
|
|
|
|
|
|
if (entityhuman != null) {
|
|
|
|
double d0 = entityhuman.distanceToSqr((Entity) this); // CraftBukkit - decompile error
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java
|
2021-06-12 00:37:16 +02:00
|
|
|
index 7d741c2aebbc1c6cf1ff59cca6480325db6ca29c..2459ae800a5f6b234a4f4bb1cd3738e4e9cac67d 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
|
2021-06-12 00:37:16 +02:00
|
|
|
@@ -123,7 +123,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/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
2021-06-12 00:37:16 +02:00
|
|
|
index 24530af0382be01e26516d8fa29f61c912ebb9aa..a76f1cab566a3c8c8d1b0204b5c2c8492312c9f0 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
|
2021-06-12 00:37:16 +02:00
|
|
|
@@ -176,6 +176,9 @@ public abstract class Player extends LivingEntity {
|
2021-06-11 14:02:28 +02:00
|
|
|
private final ItemCooldowns cooldowns;
|
|
|
|
@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
|
2021-06-12 00:37:16 +02:00
|
|
|
index 03bdbb832ff6a86f2dac9c008de45f3bb53aa688..a003e1c0d99a4d4c88269ea5bad250ba73bbc9c9 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-06-12 00:37:16 +02:00
|
|
|
@@ -77,7 +77,7 @@ public abstract class BaseSpawner {
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-12 00:37:16 +02:00
|
|
|
private 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.isAffectsSpawningPlayerNearby((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper
|
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
|
2021-06-12 00:37:16 +02:00
|
|
|
index 389985e022b82c675fb21f363422471bd15b84b0..0b6e5ee9872a73823219bff7f642375fdc4ec243 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
|
2021-06-12 00:37:16 +02:00
|
|
|
@@ -71,8 +71,9 @@ public interface EntityGetter {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- @Nullable
|
|
|
|
- default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) {
|
|
|
|
+ default Player findNearbyPlayer(Entity entity, double d0, @Nullable Predicate<Entity> predicate) { return this.findNearbyPlayer(entity.getX(), entity.getY(), entity.getZ(), d0, predicate); } // Paper
|
|
|
|
+ @Nullable default Player findNearbyPlayer(double d0, double d1, double d2, double d3, @Nullable Predicate<Entity> predicate) { return getNearestPlayer(d0, d1, d2, d3, predicate); } // Paper - OBFHELPER
|
|
|
|
+ @Nullable default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) { // Paper
|
2021-06-12 00:37:16 +02:00
|
|
|
double d = -1.0D;
|
|
|
|
Player player = null;
|
|
|
|
|
|
|
|
@@ -100,6 +101,27 @@ public interface EntityGetter {
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.getNearestPlayer(x, y, z, maxDistance, predicate);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper end
|
|
|
|
+ default boolean isAffectsSpawningPlayerNearby(double d0, double d1, double d2, double d3) {
|
2021-06-12 00:37:16 +02:00
|
|
|
+ java.util.Iterator iterator = this.players().iterator();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ double d4;
|
|
|
|
+ do {
|
|
|
|
+ Player entityhuman;
|
|
|
|
+ do {
|
|
|
|
+ if (!iterator.hasNext()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ entityhuman = (Player) iterator.next();
|
|
|
|
+ } while (!EntitySelector.affectsSpawning.test(entityhuman));
|
|
|
|
+
|
|
|
|
+ d4 = entityhuman.getDistanceSquared(d0, d1, d2);
|
|
|
|
+ } while (d3 >= 0.0D && d4 >= d3 * d3);
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // 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
|
2021-06-12 00:37:16 +02:00
|
|
|
index f4dff38b0f9e33be3495433559935765f77d662e..531ebabd1682539c453825111ba46a9a07f9dc8f 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
|
2021-06-12 00:37:16 +02:00
|
|
|
@@ -1769,8 +1769,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;
|