papermc/Spigot-Server-Patches/0019-Player-affects-spawning-API.patch

148 lines
7.1 KiB
Diff
Raw Normal View History

2015-05-11 00:24:52 +00:00
From 869dbe46052c9b5bc254f32bac1dfd06e5c005bf Mon Sep 17 00:00:00 2001
2014-11-28 01:17:45 +00:00
From: Jedediah Smith <jedediah@silencegreys.com>
2015-03-08 01:16:09 +00:00
Date: Sat, 7 Mar 2015 22:52:21 -0600
2014-11-28 01:17:45 +00:00
Subject: [PATCH] Player affects spawning API
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
2015-03-08 01:16:09 +00:00
index e7fd331..4aa8096 100644
2014-11-28 01:17:45 +00:00
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -61,6 +61,7 @@ public abstract class EntityHuman extends EntityLiving {
2015-03-08 01:16:09 +00:00
private final GameProfile bH;
private boolean bI = false;
2014-11-28 01:17:45 +00:00
public EntityFishingHook hookedFish;
+ public boolean affectsSpawning = true; // PaperSpigot
2015-03-08 01:16:09 +00:00
2014-11-28 01:17:45 +00:00
// CraftBukkit start
public boolean fauxSleeping;
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
2015-04-13 20:48:16 +00:00
index b0cae5b..e4c1cd8 100644
2014-11-28 01:17:45 +00:00
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
2015-04-13 20:48:16 +00:00
@@ -431,7 +431,7 @@ public abstract class EntityInsentient extends EntityLiving {
2014-11-28 01:17:45 +00:00
if (this.persistent) {
2015-03-08 01:16:09 +00:00
this.ticksFarFromPlayer = 0;
2014-11-28 01:17:45 +00:00
} else {
- EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
+ EntityHuman entityhuman = this.world.findNearbyPlayerWhoAffectsSpawning(this, -1.0D); // PaperSpigot - Affects Spawning API
if (entityhuman != null) {
double d0 = entityhuman.locX - this.locX;
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
2015-03-08 01:16:09 +00:00
index df71db5..00754cd 100644
2014-11-28 01:17:45 +00:00
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
2015-03-08 01:16:09 +00:00
@@ -52,7 +52,7 @@ public abstract class MobSpawnerAbstract {
2014-11-28 01:17:45 +00:00
private boolean g() {
BlockPosition blockposition = this.b();
- return this.a().isPlayerNearby((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, (double) this.requiredPlayerRange);
2015-03-08 01:16:09 +00:00
+ return this.a().isPlayerNearbyWhoAffectsSpawning((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, (double) this.requiredPlayerRange); // PaperSpigot - Affects Spawning API
2014-11-28 01:17:45 +00:00
}
public void c() {
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
2015-03-08 01:16:09 +00:00
index aeb0a44..7df5b84 100644
2014-11-28 01:17:45 +00:00
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
@@ -52,7 +52,7 @@ public final class SpawnerCreature {
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
- if (!entityhuman.v()) {
+ if (!entityhuman.v() || !entityhuman.affectsSpawning) { // PaperSpigot
int l = MathHelper.floor(entityhuman.locX / 16.0D);
j = MathHelper.floor(entityhuman.locZ / 16.0D);
2015-03-08 01:16:09 +00:00
@@ -156,7 +156,7 @@ public final class SpawnerCreature {
2014-11-28 01:17:45 +00:00
float f = (float) j3 + 0.5F;
float f1 = (float) l3 + 0.5F;
- if (!worldserver.isPlayerNearby((double) f, (double) k3, (double) f1, 24.0D) && blockposition.c((double) f, (double) k3, (double) f1) >= 576.0D) {
2015-03-08 01:16:09 +00:00
+ if (!worldserver.isPlayerNearbyWhoAffectsSpawning((double) f, (double) k3, (double) f1, 24.0D) && blockposition.c((double) f, (double) k3, (double) f1) >= 576.0D) { // PaperSpigot - Affects Spawning API
if (biomebase_biomemeta == null) {
biomebase_biomemeta = worldserver.a(enumcreaturetype, blockposition2);
if (biomebase_biomemeta == null) {
2014-11-28 01:17:45 +00:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2015-05-11 00:24:52 +00:00
index 05f9351..cf4bf4e 100644
2014-11-28 01:17:45 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2015-05-11 00:24:52 +00:00
@@ -3137,4 +3137,50 @@ public abstract class World implements IBlockAccess {
2014-11-28 01:17:45 +00:00
2015-03-08 01:16:09 +00:00
return k >= -short0 && k <= short0 && l >= -short0 && l <= short0 && this.keepSpawnInMemory; // CraftBukkit - Added 'this.keepSpawnInMemory'
2014-11-28 01:17:45 +00:00
}
2015-03-08 01:16:09 +00:00
+
+ // PaperSpigot start - Modified methods for affects spawning
+ public EntityHuman findNearbyPlayerWhoAffectsSpawning(Entity entity, double d0) {
+ return this.findNearbyPlayerWhoAffectsSpawning(entity.locX, entity.locY, entity.locZ, d0);
+ }
+
+ public EntityHuman findNearbyPlayerWhoAffectsSpawning(double d0, double d1, double d2, double d3) {
+ double d4 = -1.0D;
+ EntityHuman entityhuman = null;
+
2014-11-28 01:17:45 +00:00
+ for (int i = 0; i < this.players.size(); ++i) {
2015-03-08 01:16:09 +00:00
+ EntityHuman entityhuman1 = (EntityHuman) this.players.get(i);
+ // CraftBukkit start - Fixed an NPE
+ if (entityhuman1 == null || entityhuman1.dead || !entityhuman1.affectsSpawning) {
+ continue;
+ }
+ // CraftBukkit end
2014-11-28 01:17:45 +00:00
+
2015-03-08 01:16:09 +00:00
+ if (IEntitySelector.d.apply(entityhuman1)) {
+ double d5 = entityhuman1.e(d0, d1, d2);
2014-11-28 01:17:45 +00:00
+
2015-03-08 01:16:09 +00:00
+ if ((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1.0D || d5 < d4)) {
+ d4 = d5;
+ entityhuman = entityhuman1;
2014-11-28 01:17:45 +00:00
+ }
+ }
+ }
+
2015-03-08 01:16:09 +00:00
+ return entityhuman;
2014-11-28 01:17:45 +00:00
+ }
+
2015-03-08 01:16:09 +00:00
+ public boolean isPlayerNearbyWhoAffectsSpawning(double d0, double d1, double d2, double d3) {
2014-11-28 01:17:45 +00:00
+ for (int i = 0; i < this.players.size(); ++i) {
2015-03-08 01:16:09 +00:00
+ EntityHuman entityhuman = (EntityHuman) this.players.get(i);
2014-11-28 01:17:45 +00:00
+
2015-03-08 01:16:09 +00:00
+ if (IEntitySelector.d.apply(entityhuman)) {
+ double d4 = entityhuman.e(d0, d1, d2);
2014-11-28 01:17:45 +00:00
+
2015-03-08 01:16:09 +00:00
+ if (d3 < 0.0D || d4 < d3 * d3 && entityhuman.affectsSpawning) {
+ return true;
+ }
2014-11-28 01:17:45 +00:00
+ }
+ }
+
2015-03-08 01:16:09 +00:00
+ return false;
2014-11-28 01:17:45 +00:00
+ }
2015-03-08 01:16:09 +00:00
}
2014-11-28 01:17:45 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2015-03-20 00:41:36 +00:00
index 06e014c..5d5f987 100644
2014-11-28 01:17:45 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2015-03-08 01:16:09 +00:00
@@ -1443,6 +1443,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
packet.components = components;
getHandle().playerConnection.sendPacket(packet);
2014-11-28 01:17:45 +00:00
}
+
2015-03-08 01:16:09 +00:00
+ // PaperSpigot start - Implement affects spawning API
+ @Override
2014-11-28 01:17:45 +00:00
+ public boolean getAffectsSpawning() {
+ return getHandle().affectsSpawning;
+ }
2015-03-08 01:16:09 +00:00
+
+ @Override
+ public void setAffectsSpawning(boolean affects) {
+ getHandle().affectsSpawning = affects;
+ }
2014-11-28 01:17:45 +00:00
+ // PaperSpigot end
};
public Player.Spigot spigot()
--
2015-05-11 00:24:52 +00:00
2.4.0.windows.2
2014-11-28 01:17:45 +00:00