From 0bf41c7610e071565fed7b0691a5a581a315ec93 Mon Sep 17 00:00:00 2001 From: Jedediah Smith 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 2bc2ef6..0199856 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 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 71d4249..438ec3b 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 67273f7..3571ead 100644 --- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java +++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java @@ -52,7 +52,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 186d25d..fa68938 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; @@ -2762,6 +2760,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 c81d5d2..942a6ab 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -1443,6 +1443,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { packet.components = components; getHandle().playerConnection.sendPacket(packet); } + + // 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.5.msysgit.0