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

203 lines
8.9 KiB
Diff
Raw Normal View History

From afaf20bf4d69579819800ee7daa8c9a677ebe318 Mon Sep 17 00:00:00 2001
2015-05-19 02:22:48 +02:00
From: Jedediah Smith <jedediah@silencegreys.com>
2015-05-19 01:41:57 +02:00
Date: Mon, 18 May 2015 17:52:45 -0500
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
index ae2c44e..b901c69 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
2015-06-06 19:15:22 +02:00
@@ -60,6 +60,7 @@ public abstract class EntityHuman extends EntityLiving {
2015-03-08 02:16:09 +01:00
private final GameProfile bH;
private boolean bI = false;
2014-11-28 02:17:45 +01:00
public EntityFishingHook hookedFish;
+ public boolean affectsSpawning = true; // PaperSpigot
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
index 2d4d34c..b82b984 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
@@ -431,7 +431,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);
+ 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
2015-06-06 19:15:22 +02:00
index 6004e23..ebd1e36 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
2015-03-08 02:16:09 +01:00
@@ -52,7 +52,7 @@ public abstract class MobSpawnerAbstract {
2014-11-28 02:17:45 +01:00
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);
2015-03-08 02:16:09 +01:00
+ 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
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
2015-06-05 14:45:30 +02:00
index 3964e3f..611b8fd 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
@@ -52,7 +52,7 @@ public final class SpawnerCreature {
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
2015-05-19 01:41:57 +02:00
- if (!entityhuman.isSpectator()) {
2015-05-19 02:22:48 +02:00
+ if (!entityhuman.isSpectator() || !entityhuman.affectsSpawning) { // PaperSpigot
2014-11-28 02:17:45 +01:00
int l = MathHelper.floor(entityhuman.locX / 16.0D);
j = MathHelper.floor(entityhuman.locZ / 16.0D);
2015-03-08 02:16:09 +01:00
@@ -156,7 +156,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;
- if (!worldserver.isPlayerNearby((double) f, (double) k3, (double) f1, 24.0D) && blockposition.c((double) f, (double) k3, (double) f1) >= 576.0D) {
2015-03-08 02:16:09 +01:00
+ 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) {
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
2015-07-14 17:59:57 +02:00
index 03eb5f2..641db2a 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
2015-05-19 01:41:57 +02:00
@@ -2,35 +2,23 @@ package net.minecraft.server;
2014-11-28 02:17:45 +01:00
2015-05-19 01:41:57 +02:00
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;
-
-// CraftBukkit start
import com.google.common.collect.Maps;
-import java.util.Map;
-
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;
import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.SpigotTimings;
import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
-import org.bukkit.event.weather.WeatherChangeEvent;
-import org.bukkit.event.weather.ThunderChangeEvent;
+import org.bukkit.generator.ChunkGenerator;
+
+import java.util.*;
+import java.util.concurrent.Callable;
2015-03-08 02:16:09 +01:00
+
2015-05-19 01:41:57 +02:00
+// CraftBukkit start
// CraftBukkit end
public abstract class World implements IBlockAccess {
2015-07-14 17:59:57 +02:00
@@ -2807,6 +2795,53 @@ public abstract class World implements IBlockAccess {
2015-05-19 01:41:57 +02:00
return false;
}
2015-03-08 02:16:09 +01:00
+ // 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;
+
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
+ }
2015-05-19 01:41:57 +02:00
+ // PaperSpigot end
+
public EntityHuman a(String s) {
for (int i = 0; i < this.players.size(); ++i) {
EntityHuman entityhuman = (EntityHuman) this.players.get(i);
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
2015-07-14 17:59:57 +02:00
index 35608b7..a9b4160 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
@@ -7,6 +7,7 @@ import io.netty.buffer.Unpooled;
2015-05-19 01:41:57 +02:00
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.lang.Override;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
2015-07-14 17:59:57 +02:00
@@ -1470,6 +1471,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
packet.components = components;
getHandle().playerConnection.sendPacket(packet);
2014-11-28 02:17:45 +01:00
}
+
2015-03-08 02:16:09 +01:00
+ // PaperSpigot start - Implement affects spawning API
+ @Override
2014-11-28 02:17:45 +01:00
+ public boolean getAffectsSpawning() {
+ return getHandle().affectsSpawning;
+ }
2015-03-08 02:16:09 +01:00
+
+ @Override
+ public void setAffectsSpawning(boolean affects) {
+ getHandle().affectsSpawning = affects;
+ }
2014-11-28 02:17:45 +01:00
+ // PaperSpigot end
};
public Player.Spigot spigot()
--
2.5.1
2014-11-28 02:17:45 +01:00