Paper/patches/server/0021-Player-affects-spawning-API.patch

144 lines
7.3 KiB
Diff
Raw Normal View History

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
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-07-07 08:52:40 +02:00
index f8dcd9cb5e6d223f4f5445a4172cc6c4ea160313..78e2d0165f6f6da4d7d1e1dad76e5edcbe48df9e 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-07-07 08:52:40 +02:00
@@ -767,7 +767,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-07-07 08:52:40 +02:00
index 05c292d08ac98fad408b279d2426ff08472a959c..484b1bf43b897c5ffe47baa340957e3293c7bf92 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-17 23:39:36 +02:00
index 389985e022b82c675fb21f363422471bd15b84b0..849616d9ad140285f7aa4d2ffafd6371f3904bd5 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-17 21:37:37 +02:00
@@ -71,8 +71,8 @@ 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) {
2021-06-17 21:37:37 +02: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 14:02:28 +02:00
+ @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;
2021-06-17 21:37:37 +02:00
@@ -100,6 +100,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));
+
2021-06-17 23:39:36 +02:00
+ d4 = entityhuman.distanceToSqr(d0, d1, d2);
2021-06-11 14:02:28 +02: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-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-07-07 08:52:40 +02:00
index 9c643472f0c271dcd41721cc121f7af161cafd9b..f253483eab0610b9c88174d7ae78b24ef5730242 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 8503c3c9 #621: Add HumanEntity#getItemInUse and Material#getSlipperiness 248deb09 #622: Add methods to check if item is the breed item for an entity 2ce691d8 Clarify Player#breakBlock only works for blocks in the same world 5dcdd48e SPIGOT-6514: Small Dripleaf block data is missing half property cc9610b7 #619: Add Player#breakBlock() 862bc475 Fix bad merge of SPIGOT-6502 fix 989bb0c1 Downgrade SnakeYAML due to issues with comments parsing 1dff62ae Fix inverted visual fire docs CraftBukkit Changes: 40caacc8 SPIGOT-6526: World entities are not populated when plugin onEnable is called c9a92ad0 SPIGOT-6536: Marker position not set on spawn 20d3e57c #855: Add HumanEntity#getItemInUse and Material#getSlipperiness d9c69b44 SPIGOT-6529: Fix BundleMeta#setItems 8bd43be5 SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode 4ece3ff3 #856: Add methods to check if item is the breed item for an entity dd4bec5f Add additional validation to Player#breakBlock bc835ae6 SPIGOT-6532: Fix Entity#setGlowing 384e116e Restore 1.16.5 behaviour of InventoryDragEvent being called even when a single item is 'dragged' to its own slot b42e708c Fix new map colors rendering as transparent cfe7fecf SPIGOT-6524: Inventory desync when InventoryClickEvent is cancelled eeae1b19 SPIGOT-6522: ItemStack on cursor is always AIR 7490724d Fix missing PlayerEditBookEvent 06875f76 SPIGOT-6513: Placing ItemStack in Inventory causes InventoryAction.NOTHING 27835bde SPIGOT-6519: Fix end gateway teleports 4ac634ad SPIGOT-6515: "Un-waterlogging" throws UnsupportedOperationException in some cases da425fa2 SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server 50530da9 SPIGOT-6514: Small Dripleaf block data is missing half property 6fdecf20 #853: Implement Player#breakBlock() 4db9c49f SPIGOT-6510: Bukkit#createMap throws NullPointerException 89e2b127 SPIGOT-6517: Spider jockey crash on dripstone cbf2f678 SPIGOT-6508: Rename conflicted getServer 74575d48 SPIGOT-6506: Fix crash with custom inventories a3df386f Fix NPE with Entity.getNearbyEntities d747f8ed Fix NPE with World.getNearbyEntities 4d2c7800 Fix second usage of worldGenSettings just in case 5182f923 SPIGOT-6504: Fix generating fresh worlds Spigot Changes: 66f9d3c1 Rebuild patches 191e4971 Rebuild patches a09c0bb6 Restore Spigot experience merging
2021-06-13 07:13:07 +02:00
@@ -1778,8 +1778,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;