Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0019-Player-affects-spawning-API.patch

210 Zeilen
11 KiB
Diff

2016-05-12 04:07:46 +02:00
From ec731f31e18887483d230fc0ae9143b6e152860c Mon Sep 17 00:00:00 2001
2015-05-19 02:22:48 +02:00
From: Jedediah Smith <jedediah@silencegreys.com>
2016-03-01 00:09:49 +01:00
Date: Tue, 1 Mar 2016 14:47:52 -0600
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
2016-05-12 04:07:46 +02:00
index 3e1a84e..0f73fcf 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
@@ -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;
2016-05-12 04:07:46 +02:00
@@ -66,6 +67,19 @@ public abstract class EntityHuman extends EntityLiving {
private final ItemCooldown bV = this.l();
2014-11-28 02:17:45 +01:00
public EntityFishingHook hookedFish;
2015-03-08 02:16:09 +01:00
+ // 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
+
2014-11-28 02:17:45 +01:00
// CraftBukkit start
public boolean fauxSleeping;
public String spawnWorld = "";
2014-11-28 02:17:45 +01:00
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
2016-05-12 04:07:46 +02:00
index ff3443a..da102e3 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
2016-05-12 04:07:46 +02:00
@@ -602,7 +602,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.findNearbyPlayer(this, -1.0D, EntityHuman.affectsSpawningFilter()); // Paper - affectsSpawning filter
2014-11-28 02:17:45 +01:00
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
2016-05-12 04:07:46 +02:00
index b5fce84..ed8a425 100644
--- a/src/main/java/net/minecraft/server/EntitySilverfish.java
+++ b/src/main/java/net/minecraft/server/EntitySilverfish.java
2016-05-12 04:07:46 +02:00
@@ -88,7 +88,7 @@ public class EntitySilverfish extends EntityMonster {
2016-05-12 04:07:46 +02:00
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
2016-05-12 04:07:46 +02:00
index 9f81142..774d773 100644
--- a/src/main/java/net/minecraft/server/EntityZombie.java
+++ b/src/main/java/net/minecraft/server/EntityZombie.java
2016-05-12 04:07:46 +02:00
@@ -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);
2014-11-28 02:17:45 +01:00
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
2016-05-12 04:07:46 +02:00
index df35d71..6c3e365 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
2016-03-01 00:09:49 +01:00
@@ -32,7 +32,7 @@ public abstract class MobSpawnerAbstract {
private boolean h() {
2014-11-28 02:17:45 +01:00
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
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
2016-05-12 04:07:46 +02:00
index 4eedd41..852bdf8 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
@@ -50,6 +50,8 @@ public final class SpawnerCreature {
2014-11-28 02:17:45 +01:00
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
+ if (!entityhuman.affectsSpawning) continue; // Paper - affectsSpawning check
+
if (!entityhuman.isSpectator()) {
2014-11-28 02:17:45 +01:00
int l = MathHelper.floor(entityhuman.locX / 16.0D);
@@ -160,7 +162,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;
2016-03-01 00:09:49 +01:00
- 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
2015-03-08 02:16:09 +01:00
if (biomebase_biomemeta == null) {
2016-03-01 00:09:49 +01:00
biomebase_biomemeta = worldserver.a(enumcreaturetype, (BlockPosition) blockposition_mutableblockposition);
2015-03-08 02:16:09 +01:00
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
2016-05-12 04:07:46 +02:00
index 9599849..81f4a42 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
@@ -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;
2016-05-12 04:07:46 +02:00
@@ -2701,16 +2702,31 @@ public abstract class World implements IBlockAccess {
2015-05-19 01:41:57 +02:00
2016-05-12 04:07:46 +02:00
@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());
2015-03-08 02:16:09 +01:00
+ }
+
+ public EntityHuman findNearbyPlayer(Entity entity, double d0, Predicate<EntityHuman> filter) {
+ return this.findNearbyPlayer(entity.locX, entity.locY, entity.locZ, d0, false, filter);
}
2016-05-12 04:07:46 +02:00
@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());
2014-11-28 02:17:45 +01:00
+ }
+
+ public EntityHuman findNearbyPlayerNotInCreativeMode(Entity entity, double d0, Predicate<EntityHuman> filter) {
+ return this.findNearbyPlayer(entity.locX, entity.locY, entity.locZ, d0, true, filter);
}
2016-05-12 04:07:46 +02:00
@Nullable
public EntityHuman a(double d0, double d1, double d2, double d3, boolean flag) {
+ return findNearbyPlayer(d0, d1, d2, d3, flag, Predicates.<EntityHuman>alwaysTrue());
+ }
2014-11-28 02:17:45 +01:00
+
+ 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;
2016-05-12 04:07:46 +02:00
@@ -2722,6 +2738,8 @@ public abstract class World implements IBlockAccess {
}
// CraftBukkit end
+ if (!filter.apply(entityhuman1)) continue; // Paper - check filter
2014-11-28 02:17:45 +01:00
+
if ((IEntitySelector.d.apply(entityhuman1) || !flag) && (IEntitySelector.e.apply(entityhuman1) || flag)) {
double d5 = entityhuman1.e(d0, d1, d2);
2016-05-12 04:07:46 +02:00
@@ -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());
2014-11-28 02:17:45 +01:00
+ }
2015-05-19 01:41:57 +02:00
+
+ 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);
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
2016-05-12 04:07:46 +02:00
index 35f6c27..b7ff27c 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
2016-05-12 04:07:46 +02:00
@@ -1408,6 +1408,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2016-03-01 00:09:49 +01:00
}
2015-05-19 01:41:57 +02:00
2016-03-01 00:09:49 +01:00
+ @Override
+ public void setAffectsSpawning(boolean affects) {
+ this.getHandle().affectsSpawning = affects;
2016-03-01 00:09:49 +01:00
+ }
2014-11-28 02:17:45 +01:00
+
2016-03-01 00:09:49 +01:00
+ @Override
+ public boolean getAffectsSpawning() {
+ return this.getHandle().affectsSpawning;
2016-03-01 00:09:49 +01:00
+ }
2015-03-08 02:16:09 +01:00
+
2016-03-01 00:09:49 +01:00
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{
2014-11-28 02:17:45 +01:00
--
2016-05-12 04:07:46 +02:00
2.8.2
2014-11-28 02:17:45 +01:00