testserver/Spigot-Server-Patches/0021-Player-affects-spawnin...

148 lines
7.1 KiB
Diff

From 531e69345a9a1546a0a517891ba5cf0df3ecd9c5 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Sat, 7 Mar 2015 22:52:21 -0600
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
index e7fd331..4aa8096 100644
--- 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 {
private final GameProfile bH;
private boolean bI = false;
public EntityFishingHook hookedFish;
+ public boolean affectsSpawning = true; // PaperSpigot
// 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
index 4f49ed0..c0d1c13 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -424,7 +424,7 @@ public abstract class EntityInsentient extends EntityLiving {
if (this.persistent) {
this.ticksFarFromPlayer = 0;
} 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
index df71db5..00754cd 100644
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
@@ -52,7 +52,7 @@ public abstract class MobSpawnerAbstract {
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);
+ 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
}
public void c() {
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
index aeb0a44..7df5b84 100644
--- 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);
@@ -156,7 +156,7 @@ public final class SpawnerCreature {
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) {
+ 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) {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 3523abf..d8464b2 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -3119,4 +3119,50 @@ public abstract class World implements IBlockAccess {
return k >= -short0 && k <= short0 && l >= -short0 && l <= short0 && this.keepSpawnInMemory; // CraftBukkit - Added 'this.keepSpawnInMemory'
}
+
+ // 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;
+
+ for (int i = 0; i < this.players.size(); ++i) {
+ EntityHuman entityhuman1 = (EntityHuman) this.players.get(i);
+ // CraftBukkit start - Fixed an NPE
+ if (entityhuman1 == null || entityhuman1.dead || !entityhuman1.affectsSpawning) {
+ continue;
+ }
+ // CraftBukkit end
+
+ if (IEntitySelector.d.apply(entityhuman1)) {
+ double d5 = entityhuman1.e(d0, d1, d2);
+
+ if ((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1.0D || d5 < d4)) {
+ d4 = d5;
+ entityhuman = entityhuman1;
+ }
+ }
+ }
+
+ return entityhuman;
+ }
+
+ public boolean isPlayerNearbyWhoAffectsSpawning(double d0, double d1, double d2, double d3) {
+ for (int i = 0; i < this.players.size(); ++i) {
+ EntityHuman entityhuman = (EntityHuman) this.players.get(i);
+
+ if (IEntitySelector.d.apply(entityhuman)) {
+ double d4 = entityhuman.e(d0, d1, d2);
+
+ if (d3 < 0.0D || d4 < d3 * d3 && entityhuman.affectsSpawning) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 8091b4e..571e066 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1443,6 +1443,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
packet.components = components;
getHandle().playerConnection.sendPacket(packet);
}
+
+ // PaperSpigot start - Implement affects spawning API
+ @Override
+ public boolean getAffectsSpawning() {
+ return getHandle().affectsSpawning;
+ }
+
+ @Override
+ public void setAffectsSpawning(boolean affects) {
+ getHandle().affectsSpawning = affects;
+ }
+ // PaperSpigot end
};
public Player.Spigot spigot()
--
1.9.1