3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00
Paper/Spigot-Server-Patches/0024-Player-affects-spawning-API.patch

172 Zeilen
7.8 KiB
Diff

From f5c3a5a5da3f65c4ce49e99c9d595075a09041e6 Mon Sep 17 00:00:00 2001
2014-11-28 02:17:45 +01:00
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 2bc2ef6..0199856 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
@@ -61,6 +61,7 @@ public abstract class EntityHuman extends EntityLiving {
2014-11-28 02:17:45 +01:00
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 da3f249..cc4d38c 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
@@ -52,7 +52,8 @@ 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);
+ // 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 3cc9c2e..031a906 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
@@ -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;
@@ -2775,6 +2773,50 @@ public abstract class World implements IBlockAccess {
2014-11-28 02:17:45 +01:00
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 04a2622..fca7893 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
@@ -1476,6 +1476,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
packet.components = components;
getHandle().playerConnection.sendPacket(packet);
2014-11-28 02:17:45 +01:00
}
+
+ // 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