aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0019-Player-affects-spawning-API.patch
blob: 7a5c7be910a8a70e68d148e6182110e4a5dd1e90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
From ec731f31e18887483d230fc0ae9143b6e152860c 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/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 3e1a84e..0f73fcf 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -1,6 +1,7 @@
 package net.minecraft.server;
 
 import com.google.common.base.Charsets;
+import com.google.common.base.Predicate; // Paper
 import com.google.common.collect.Lists;
 import com.mojang.authlib.GameProfile;
 import java.util.Arrays;
@@ -66,6 +67,19 @@ public abstract class EntityHuman extends EntityLiving {
     private final ItemCooldown bV = this.l();
     public EntityFishingHook hookedFish;
 
+    // Paper start - affectsSpawning API
+    public boolean affectsSpawning = true;
+
+    public static Predicate<EntityHuman> affectsSpawningFilter() {
+        return new Predicate<EntityHuman>() {
+            @Override
+            public boolean apply(EntityHuman entityHuman) {
+                return entityHuman.affectsSpawning;
+            }
+        };
+    }
+    // Paper end
+
     // CraftBukkit start
     public boolean fauxSleeping;
     public String spawnWorld = "";
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
index ff3443a..da102e3 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -602,7 +602,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.findNearbyPlayer(this, -1.0D, EntityHuman.affectsSpawningFilter()); // Paper - affectsSpawning filter
 
             if (entityhuman != null) {
                 double d0 = entityhuman.locX - this.locX;
diff --git a/src/main/java/net/minecraft/server/EntitySilverfish.java b/src/main/java/net/minecraft/server/EntitySilverfish.java
index b5fce84..ed8a425 100644
--- a/src/main/java/net/minecraft/server/EntitySilverfish.java
+++ b/src/main/java/net/minecraft/server/EntitySilverfish.java
@@ -88,7 +88,7 @@ public class EntitySilverfish extends EntityMonster {
 
     public boolean cG() {
         if (super.cG()) {
-            EntityHuman entityhuman = this.world.b(this, 5.0D);
+            EntityHuman entityhuman = this.world.findNearbyPlayerNotInCreativeMode(this, 5.0D, EntityHuman.affectsSpawningFilter()); // Paper - affectsSpawning filter
 
             return entityhuman == null;
         } else {
diff --git a/src/main/java/net/minecraft/server/EntityZombie.java b/src/main/java/net/minecraft/server/EntityZombie.java
index 9f81142..774d773 100644
--- a/src/main/java/net/minecraft/server/EntityZombie.java
+++ b/src/main/java/net/minecraft/server/EntityZombie.java
@@ -197,7 +197,7 @@ public class EntityZombie extends EntityMonster {
 
                     if (this.world.getType(new BlockPosition(i1, j1 - 1, k1)).q() && this.world.getLightLevel(new BlockPosition(i1, j1, k1)) < 10) {
                         entityzombie.setPosition((double) i1, (double) j1, (double) k1);
-                        if (!this.world.isPlayerNearby((double) i1, (double) j1, (double) k1, 7.0D) && this.world.a(entityzombie.getBoundingBox(), (Entity) entityzombie) && this.world.getCubes(entityzombie, entityzombie.getBoundingBox()).isEmpty() && !this.world.containsLiquid(entityzombie.getBoundingBox())) {
+                        if (!this.world.isPlayerNearby((double) i1, (double) j1, (double) k1, 7.0D, EntityHuman.affectsSpawningFilter()) && this.world.a(entityzombie.getBoundingBox(), (Entity) entityzombie) && this.world.getCubes(entityzombie, entityzombie.getBoundingBox()).isEmpty() && !this.world.containsLiquid(entityzombie.getBoundingBox())) { // Paper - affectsSpawning filter
                             this.world.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit
                             entityzombie.setGoalTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true);
                             entityzombie.prepare(this.world.D(new BlockPosition(entityzombie)), (GroupDataEntity) null);
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
index df35d71..6c3e365 100644
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
@@ -32,7 +32,7 @@ public abstract class MobSpawnerAbstract {
     private boolean h() {
         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().isPlayerNearby((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, (double) this.requiredPlayerRange, EntityHuman.affectsSpawningFilter()); // Paper - affectsSpawning filter
     }
 
     public void c() {
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
index 4eedd41..852bdf8 100644
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
@@ -50,6 +50,8 @@ public final class SpawnerCreature {
             while (iterator.hasNext()) {
                 EntityHuman entityhuman = (EntityHuman) iterator.next();
 
+                if (!entityhuman.affectsSpawning) continue; // Paper - affectsSpawning check
+
                 if (!entityhuman.isSpectator()) {
                     int l = MathHelper.floor(entityhuman.locX / 16.0D);
 
@@ -160,7 +162,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.distanceSquared((double) f, (double) k3, (double) f1) >= 576.0D) {
+                                                if (!worldserver.isPlayerNearby((double) f, (double) k3, (double) f1, 24.0D, EntityHuman.affectsSpawningFilter()) && blockposition.distanceSquared((double) f, (double) k3, (double) f1) >= 576.0D) { // Paper - affectsSpawning filter
                                                     if (biomebase_biomemeta == null) {
                                                         biomebase_biomemeta = worldserver.a(enumcreaturetype, (BlockPosition) blockposition_mutableblockposition);
                                                         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 9599849..81f4a42 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -3,6 +3,7 @@
 import com.google.common.base.Function;
 import com.google.common.base.Objects;
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates; // Paper
 import com.google.common.collect.Lists;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -2701,16 +2702,31 @@ public abstract class World implements IBlockAccess {
 
     @Nullable
     public EntityHuman findNearbyPlayer(Entity entity, double d0) {
-        return this.a(entity.locX, entity.locY, entity.locZ, d0, false);
+        // Paper start - Add filter parameter
+        return findNearbyPlayer(entity, d0, Predicates.<EntityHuman>alwaysTrue());
+    }
+
+    public EntityHuman findNearbyPlayer(Entity entity, double d0, Predicate<EntityHuman> filter) {
+        return this.findNearbyPlayer(entity.locX, entity.locY, entity.locZ, d0, false, filter);
     }
 
     @Nullable
     public EntityHuman b(Entity entity, double d0) {
-        return this.a(entity.locX, entity.locY, entity.locZ, d0, true);
+        return this.findNearbyPlayerNotInCreativeMode(entity, d0, Predicates.<EntityHuman>alwaysTrue());
+    }
+
+    public EntityHuman findNearbyPlayerNotInCreativeMode(Entity entity, double d0, Predicate<EntityHuman> filter) {
+        return this.findNearbyPlayer(entity.locX, entity.locY, entity.locZ, d0, true, filter);
     }
 
     @Nullable
     public EntityHuman a(double d0, double d1, double d2, double d3, boolean flag) {
+        return findNearbyPlayer(d0, d1, d2, d3, flag, Predicates.<EntityHuman>alwaysTrue());
+    }
+
+    public EntityHuman findNearbyPlayer(double d0, double d1, double d2, double d3, boolean flag, Predicate<EntityHuman> filter) {
+        // FYI the flag means "exclude creative mode players"
+        // Paper end
         double d4 = -1.0D;
         EntityHuman entityhuman = null;
 
@@ -2722,6 +2738,8 @@ public abstract class World implements IBlockAccess {
             }
             // CraftBukkit end
 
+            if (!filter.apply(entityhuman1)) continue; // Paper - check filter
+
             if ((IEntitySelector.d.apply(entityhuman1) || !flag) && (IEntitySelector.e.apply(entityhuman1) || flag)) {
                 double d5 = entityhuman1.e(d0, d1, d2);
 
@@ -2736,9 +2754,17 @@ public abstract class World implements IBlockAccess {
     }
 
     public boolean isPlayerNearby(double d0, double d1, double d2, double d3) {
+        // Paper start - add filter parameter
+        return isPlayerNearby(d0, d1, d2, d3, Predicates.<EntityHuman>alwaysTrue());
+    }
+
+    public boolean isPlayerNearby(double d0, double d1, double d2, double d3, Predicate<EntityHuman> filter) {
+        // Paper end
         for (int i = 0; i < this.players.size(); ++i) {
             EntityHuman entityhuman = (EntityHuman) this.players.get(i);
 
+            if (!filter.apply(entityhuman)) continue; // Paper - check filter
+
             if (IEntitySelector.e.apply(entityhuman)) {
                 double d4 = entityhuman.e(d0, d1, d2);
 
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 35f6c27..b7ff27c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1408,6 +1408,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
 
     }
 
+    @Override
+    public void setAffectsSpawning(boolean affects) {
+        this.getHandle().affectsSpawning = affects;
+    }
+
+    @Override
+    public boolean getAffectsSpawning() {
+        return this.getHandle().affectsSpawning;
+    }
+
     // Spigot start
     private final Player.Spigot spigot = new Player.Spigot()
     {
-- 
2.8.2