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

172 lines
7.8 KiB
Diff

From 325cee0020dfc470cae368187992852c4face538 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Fri, 28 Nov 2014 03:31: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 5d03955..847b507 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -59,6 +59,7 @@ public abstract class EntityHuman extends EntityLiving {
private final GameProfile bF;
private boolean bG = 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 91c6b71..40abc51 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.aO = 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 4ff4ece..ecd518b 100644
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
@@ -47,7 +47,8 @@ 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);
+ // PaperSpigot - Affects Spawning API
+ return this.a().isPlayerNearbyWhoAffectsSpawning((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, (double) this.requiredPlayerRange);
}
public void c() {
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
index 43954b3..932a572 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,8 @@ 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) {
+ // PaperSpigot - Affects Spawning API
+ if (!worldserver.isPlayerNearbyWhoAffectsSpawning((double) f, (double) k3, (double) f1, 24.0D) && blockposition.c((double) f, (double) k3, (double) f1) >= 576.0D) {
if (biomemeta == null) {
biomemeta = worldserver.a(enumcreaturetype, blockposition2);
if (biomemeta == null) {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index bf697c2..91c0a2f 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -2,14 +2,13 @@ package net.minecraft.server;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
+
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
@@ -17,7 +16,6 @@ import java.util.concurrent.Callable;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
-import org.bukkit.craftbukkit.util.LongHashSet;
import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.craftbukkit.CraftServer;
@@ -2754,6 +2752,50 @@ public abstract class World implements IBlockAccess {
return false;
}
+ // PaperSpigot start - Affects spawning API
+ 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;
+ }
+
+ public EntityHuman findNearbyPlayerWhoAffectsSpawning(Entity entity, double radius) {
+ return this.findNearbyPlayerWhoAffectsSpawning(entity.locX, entity.locY, entity.locZ, radius);
+ }
+
+ public EntityHuman findNearbyPlayerWhoAffectsSpawning(double x, double y, double z, double radius) {
+ double nearestRadius = - 1.0D;
+ EntityHuman entityHuman = null;
+
+ for (int i = 0; i < this.players.size(); ++i) {
+ EntityHuman nearestPlayer = (EntityHuman) this.players.get(i);
+
+ if (nearestPlayer == null || nearestPlayer.dead || !nearestPlayer.affectsSpawning) {
+ continue;
+ }
+
+ double distance = nearestPlayer.e(x, y, z);
+
+ if ((radius < 0.0D || distance < radius * radius) && (nearestRadius == -1.0D || distance < nearestRadius)) {
+ nearestRadius = distance;
+ entityHuman = nearestPlayer;
+ }
+ }
+
+ return entityHuman;
+ }
+ // PaperSpigot end
+
public EntityHuman a(String s) {
for (int i = 0; i < this.players.size(); ++i) {
EntityHuman entityhuman = (EntityHuman) this.players.get(i);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 2d4398e..914187d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1457,6 +1457,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return java.util.Collections.unmodifiableSet( ret );
}
+
+ // PaperSpigot start - Add affects spawning API
+ public void setAffectsSpawning(boolean affects) {
+ getHandle().affectsSpawning = affects;
+ }
+
+ public boolean getAffectsSpawning() {
+ return getHandle().affectsSpawning;
+ }
+ // PaperSpigot end
};
public Player.Spigot spigot()
--
1.9.1