mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
6fda3fd0ed
This makes it so entities that are passengers of other entities no longer count in the parents timings, as well as tracks them as a separate timers per their tick status. This lets you see how much time is spent in activated entities vs inactive (as inactive still has to do work) Passengers is also tracked separately so you can identify "Villagers in Minecarts" vs roaming villagers, as the lack of ability to move can impact their performance characteristics. This will likely break any plugin that was naughty and directly messed with our internal timings as this moves the timings to the EntityTypes object, speeding up creation of Entities to no longer store a timing handler object per entity. This will also change the output of the entities in timings to use internal ID's instead of class names. If a plugin is broken by this, shame them for doing bad things. Paper will not fix it, they will have to fix it.
156 lines
8 KiB
Diff
156 lines
8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jedediah Smith <jedediah@silencegreys.com>
|
|
Date: Tue, 1 Mar 2016 14:47:52 -0600
|
|
Subject: [PATCH] Player affects spawning API
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index f76476fba765c04a19931a36d88d9cebcba93334..9bfbbacdf19801aee1f1e566006059181401f676 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -1268,6 +1268,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
return MathHelper.c(f * f + f1 * f1 + f2 * f2);
|
|
}
|
|
|
|
+ public double getDistanceSquared(double x, double y, double z) { return h(x, y, z); } // Paper - OBFHELPER
|
|
public double h(double d0, double d1, double d2) {
|
|
double d3 = this.locX() - d0;
|
|
double d4 = this.locY() - d1;
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
index e16be546b22c09e1c6ed50c453e1f2c711832a81..683d98dea1b46931478ac7b55e49bc9d92d36f77 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
@@ -70,6 +70,9 @@ public abstract class EntityHuman extends EntityLiving {
|
|
private final ItemCooldown bM;
|
|
@Nullable
|
|
public EntityFishingHook hookedFish;
|
|
+ // Paper start
|
|
+ public boolean affectsSpawning = true;
|
|
+ // Paper end
|
|
|
|
// 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 30530057e2e25288abfdb138be4abe242d418612..ce6a6f91b27111535029c86ec1280d458427ea66 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
|
|
@@ -691,7 +691,7 @@ public abstract class EntityInsentient extends EntityLiving {
|
|
if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL && this.L()) {
|
|
this.die();
|
|
} else if (!this.isPersistent() && !this.isSpecialPersistence()) {
|
|
- EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
|
|
+ EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D, IEntitySelector.affectsSpawning); // Paper
|
|
|
|
if (entityhuman != null) {
|
|
double d0 = entityhuman.h((Entity) this); // CraftBukkit - decompile error
|
|
diff --git a/src/main/java/net/minecraft/server/EntitySilverfish.java b/src/main/java/net/minecraft/server/EntitySilverfish.java
|
|
index 17a0ebfcd7eefa63adc581479244231b20150340..35f15c8ddd7c85aeb599bc7921053abe09130e59 100644
|
|
--- a/src/main/java/net/minecraft/server/EntitySilverfish.java
|
|
+++ b/src/main/java/net/minecraft/server/EntitySilverfish.java
|
|
@@ -95,7 +95,7 @@ public class EntitySilverfish extends EntityMonster {
|
|
if (c(entitytypes, generatoraccess, enummobspawn, blockposition, random)) {
|
|
EntityHuman entityhuman = generatoraccess.a((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, 5.0D, true);
|
|
|
|
- return entityhuman == null;
|
|
+ return !(entityhuman != null && !entityhuman.affectsSpawning) && entityhuman == null; // Paper - Affects Spawning API
|
|
} else {
|
|
return false;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/IEntityAccess.java b/src/main/java/net/minecraft/server/IEntityAccess.java
|
|
index 797249069b0b2adf91b4e69497752eed7116f02a..b6cf294e785b36b8bc800f26dbb8cfcb2119eae1 100644
|
|
--- a/src/main/java/net/minecraft/server/IEntityAccess.java
|
|
+++ b/src/main/java/net/minecraft/server/IEntityAccess.java
|
|
@@ -83,8 +83,9 @@ public interface IEntityAccess {
|
|
}
|
|
}
|
|
|
|
- @Nullable
|
|
- default EntityHuman a(double d0, double d1, double d2, double d3, @Nullable Predicate<Entity> predicate) {
|
|
+ default EntityHuman findNearbyPlayer(Entity entity, double d0, @Nullable Predicate<Entity> predicate) { return this.findNearbyPlayer(entity.locX(), entity.locY(), entity.locZ(), d0, predicate); } // Paper
|
|
+ @Nullable default EntityHuman findNearbyPlayer(double d0, double d1, double d2, double d3, @Nullable Predicate<Entity> predicate) { return a(d0, d1, d2, d3, predicate); } // Paper - OBFHELPER
|
|
+ @Nullable default EntityHuman a(double d0, double d1, double d2, double d3, @Nullable Predicate<Entity> predicate) { // Paper
|
|
double d4 = -1.0D;
|
|
EntityHuman entityhuman = null;
|
|
Iterator iterator = this.getPlayers().iterator();
|
|
@@ -117,6 +118,27 @@ public interface IEntityAccess {
|
|
return this.a(d0, d1, d2, d3, predicate);
|
|
}
|
|
|
|
+ // Paper end
|
|
+ default boolean isAffectsSpawningPlayerNearby(double d0, double d1, double d2, double d3) {
|
|
+ Iterator iterator = this.getPlayers().iterator();
|
|
+ double d4;
|
|
+ do {
|
|
+ EntityHuman entityhuman;
|
|
+ do {
|
|
+ if (!iterator.hasNext()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ entityhuman = (EntityHuman) iterator.next();
|
|
+ } while (!IEntitySelector.affectsSpawning.test(entityhuman));
|
|
+
|
|
+ d4 = entityhuman.getDistanceSquared(d0, d1, d2);
|
|
+ } while (d3 >= 0.0D && d4 >= d3 * d3);
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
default boolean isPlayerNearby(double d0, double d1, double d2, double d3) {
|
|
Iterator iterator = this.getPlayers().iterator();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/IEntitySelector.java b/src/main/java/net/minecraft/server/IEntitySelector.java
|
|
index 8061f33c01b9c2382f72d2d1d1fa2fb8a731e3c8..e8e7532493c973ce10d94a41676859674fc4e6f6 100644
|
|
--- a/src/main/java/net/minecraft/server/IEntitySelector.java
|
|
+++ b/src/main/java/net/minecraft/server/IEntitySelector.java
|
|
@@ -24,6 +24,12 @@ public final class IEntitySelector {
|
|
return !entity.isSpectator();
|
|
};
|
|
|
|
+ // Paper start
|
|
+ public static final Predicate<Entity> affectsSpawning = (entity) -> {
|
|
+ return !entity.isSpectator() && entity.isAlive() && (entity instanceof EntityPlayer) && ((EntityPlayer) entity).affectsSpawning;
|
|
+ };
|
|
+ // Paper end
|
|
+
|
|
public static Predicate<Entity> a(double d0, double d1, double d2, double d3) {
|
|
double d4 = d3 * d3;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
|
index 90af43930f9141b0c7f51bb3d887d7b9c4d935eb..1741ec5e241f8ae7a3c30a9021d14cb0224da840 100644
|
|
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
|
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
|
|
@@ -49,7 +49,7 @@ public abstract class MobSpawnerAbstract {
|
|
private boolean h() {
|
|
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().isAffectsSpawningPlayerNearby((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper
|
|
}
|
|
|
|
public void c() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 495470f9c397e80b9e6e8e3c9360b0d659b916ed..11f80c6f58e611f33ad8bbd09aa8bf90c7933426 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1686,7 +1686,19 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
@Override
|
|
public String getLocale() {
|
|
return getHandle().locale;
|
|
+
|
|
+ }
|
|
+
|
|
+ // Paper start
|
|
+ public void setAffectsSpawning(boolean affects) {
|
|
+ this.getHandle().affectsSpawning = affects;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean getAffectsSpawning() {
|
|
+ return this.getHandle().affectsSpawning;
|
|
}
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public void updateCommands() {
|