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

151 lines
7 KiB
Diff
Raw Normal View History

From eb8ba651ad60e2edc9ef0d68d7204434351acc9b Mon Sep 17 00:00:00 2001
2015-05-19 02:22:48 +02:00
From: Jedediah Smith <jedediah@silencegreys.com>
2016-03-01 00:09:49 +01:00
Date: Tue, 1 Mar 2016 14:47:52 -0600
2014-11-28 02:17:45 +01: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
2016-03-29 02:26:11 +02:00
index 8e143f7..b6aa51e 100644
2014-11-28 02:17:45 +01:00
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
2016-03-12 21:23:17 +01:00
@@ -64,6 +64,7 @@ public abstract class EntityHuman extends EntityLiving {
2016-03-01 00:09:49 +01:00
private ItemStack bT = null;
private final ItemCooldown bU = this.l();
2014-11-28 02:17:45 +01:00
public EntityFishingHook hookedFish;
2016-03-01 00:09:49 +01:00
+ public boolean affectsSpawning = true; // Paper
2015-03-08 02:16:09 +01:00
2014-11-28 02:17:45 +01: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
2016-03-12 21:23:17 +01:00
index fdda1ae..6ad5279 100644
2014-11-28 02:17:45 +01:00
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
2016-03-07 22:54:14 +01:00
@@ -593,7 +593,7 @@ public abstract class EntityInsentient extends EntityLiving {
2014-11-28 02:17:45 +01:00
if (this.persistent) {
2015-03-08 02:16:09 +01:00
this.ticksFarFromPlayer = 0;
2014-11-28 02:17:45 +01:00
} else {
- EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
2016-03-01 00:09:49 +01:00
+ EntityHuman entityhuman = this.world.findNearbyPlayerWhoAffectsSpawning(this, -1.0D); // Paper - Affects Spawning API
2014-11-28 02:17:45 +01:00
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
2016-03-03 10:46:26 +01:00
index a7903a2..2eee845 100644
2014-11-28 02:17:45 +01:00
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
2016-03-01 00:09:49 +01:00
@@ -32,7 +32,7 @@ public abstract class MobSpawnerAbstract {
private boolean h() {
2014-11-28 02:17:45 +01:00
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);
2016-03-01 00:09:49 +01:00
+ return this.a().isPlayerNearbyWhoAffectsSpawning((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper - Affects spawning API
2014-11-28 02:17:45 +01:00
}
public void c() {
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
2016-03-01 00:09:49 +01:00
index 9e19dfd..b724586 100644
2014-11-28 02:17:45 +01:00
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
2016-03-01 00:09:49 +01:00
@@ -50,7 +50,7 @@ public final class SpawnerCreature {
2014-11-28 02:17:45 +01:00
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
2015-05-19 01:41:57 +02:00
- if (!entityhuman.isSpectator()) {
2016-03-01 00:09:49 +01:00
+ if (!entityhuman.isSpectator() || !entityhuman.affectsSpawning) {
2014-11-28 02:17:45 +01:00
int l = MathHelper.floor(entityhuman.locX / 16.0D);
j = MathHelper.floor(entityhuman.locZ / 16.0D);
2016-03-01 00:09:49 +01:00
@@ -160,7 +160,7 @@ public final class SpawnerCreature {
2014-11-28 02:17:45 +01:00
float f = (float) j3 + 0.5F;
float f1 = (float) l3 + 0.5F;
2016-03-01 00:09:49 +01:00
- if (!worldserver.isPlayerNearby((double) f, (double) k3, (double) f1, 24.0D) && blockposition.distanceSquared((double) f, (double) k3, (double) f1) >= 576.0D) {
+ if (!worldserver.isPlayerNearbyWhoAffectsSpawning((double) f, (double) k3, (double) f1, 24.0D) && blockposition.distanceSquared((double) f, (double) k3, (double) f1) >= 576.0D) {
2015-03-08 02:16:09 +01:00
if (biomebase_biomemeta == null) {
2016-03-01 00:09:49 +01:00
biomebase_biomemeta = worldserver.a(enumcreaturetype, (BlockPosition) blockposition_mutableblockposition);
2015-03-08 02:16:09 +01:00
if (biomebase_biomemeta == null) {
2014-11-28 02:17:45 +01:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2016-03-29 02:26:11 +02:00
index 5524e43..0460dc5 100644
2014-11-28 02:17:45 +01:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2016-03-29 02:26:11 +02:00
@@ -2689,6 +2689,53 @@ public abstract class World implements IBlockAccess {
2016-03-01 00:09:49 +01:00
return i;
2015-05-19 01:41:57 +02:00
}
2016-03-01 00:09:49 +01:00
+ // Paper start - Modified methods for affects spawning
2015-03-08 02:16:09 +01:00
+ 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 02:17:45 +01:00
+ for (int i = 0; i < this.players.size(); ++i) {
2015-03-08 02:16:09 +01: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 02:17:45 +01:00
+
2015-03-08 02:16:09 +01:00
+ if (IEntitySelector.d.apply(entityhuman1)) {
+ double d5 = entityhuman1.e(d0, d1, d2);
2014-11-28 02:17:45 +01:00
+
2015-03-08 02:16:09 +01:00
+ if ((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1.0D || d5 < d4)) {
+ d4 = d5;
+ entityhuman = entityhuman1;
2014-11-28 02:17:45 +01:00
+ }
+ }
+ }
+
2015-03-08 02:16:09 +01:00
+ return entityhuman;
2014-11-28 02:17:45 +01:00
+ }
+
2015-03-08 02:16:09 +01:00
+ public boolean isPlayerNearbyWhoAffectsSpawning(double d0, double d1, double d2, double d3) {
2014-11-28 02:17:45 +01:00
+ for (int i = 0; i < this.players.size(); ++i) {
2015-03-08 02:16:09 +01:00
+ EntityHuman entityhuman = (EntityHuman) this.players.get(i);
2014-11-28 02:17:45 +01:00
+
2015-03-08 02:16:09 +01:00
+ if (IEntitySelector.d.apply(entityhuman)) {
+ double d4 = entityhuman.e(d0, d1, d2);
2014-11-28 02:17:45 +01:00
+
2015-03-08 02:16:09 +01:00
+ if (d3 < 0.0D || d4 < d3 * d3 && entityhuman.affectsSpawning) {
+ return true;
+ }
2014-11-28 02:17:45 +01:00
+ }
+ }
+
2015-03-08 02:16:09 +01:00
+ return false;
2014-11-28 02:17:45 +01:00
+ }
2016-03-01 00:09:49 +01:00
+ // Paper end
2015-05-19 01:41:57 +02:00
+
2016-03-01 00:09:49 +01:00
public EntityHuman findNearbyPlayer(Entity entity, double d0) {
return this.a(entity.locX, entity.locY, entity.locZ, d0, false);
}
2014-11-28 02:17:45 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2016-03-29 02:26:11 +02:00
index dfa5962..3203458 100644
2014-11-28 02:17:45 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1405,6 +1405,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2016-03-01 00:09:49 +01:00
}
2015-05-19 01:41:57 +02:00
2016-03-01 00:09:49 +01:00
+ // Paper start
+ @Override
+ public boolean getAffectsSpawning() {
+ return getHandle().affectsSpawning;
+ }
2014-11-28 02:17:45 +01:00
+
2016-03-01 00:09:49 +01:00
+ @Override
+ public void setAffectsSpawning(boolean affects) {
+ getHandle().affectsSpawning = affects;
+ }
+ // Paper end
2015-03-08 02:16:09 +01:00
+
2016-03-01 00:09:49 +01:00
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{
2014-11-28 02:17:45 +01:00
--
2016-03-25 08:30:39 +01:00
2.7.4
2014-11-28 02:17:45 +01:00