mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 04:55:47 +01:00
b68b282439
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Warning: this commit contains more mapping changes from upstream, As always, ensure that you have working backups and test this build before deployment; Developers working on paper will, yet again, need to delete their work/Minecraft/1.13.2 folder Bukkit Changes: 7fca5fd4 SPIGOT-4558: Preserve user order in the face of copied defaults in configurations 15c9b1eb Ignore spurious slot IDs sent by client, e.g. in enchanting tables 5d2a10c5 SPIGOT-3747: Add API for force loaded chunks d6dd2bb3 SPIGOT-3538: Add getHitBlockFace for ProjectileHitEvent 771db4aa SPIGOT-794: Call EntityPlaceEvent for Minecart placement 55462509 Add InventoryView#getSlotType 2f3ce5b6 Remove EntityTransformEvent and CustomItemTagContainer from draft API f04ad7b6 Make ProjectileLaunchEvent extend EntitySpawnEvent ccb85808 Define EntitySpawnEvent b8cc3ebe Add PlayerItemDamageEvent 184a495d Ease ClassLoader Deadlocks Where Possible 11ac4728 Expand Boolean Prompt Values in Conversation API aae62d51 Added getAllSessionData() to the Conversation API. 9290ff91 Add InventoryView#getInventory API 995e530f Add API to get / set base arrow damage CraftBukkit Changes:c4a67eed
SPIGOT-4556: Fix plugins closing inventory during drop events5be2ddcb
Replace version constants with methods to prevent compiler inlininga5b9c7b3
Use API method to create offset command completions2bc7d1df
SPIGOT-3747: Add API for force loaded chunksa408f375
SPIGOT-3538: Add getHitBlockFace for ProjectileHitEventb54b9409
SPIGOT-2864: Make Arrow / Item setTicksLived behave like FallingBlock79ded7a8
SPIGOT-1811: Death message not shown on respawn screenb4a4f15d
SPIGOT-943: InventoryCloseEvent called on death regardless of open inventory0afed592
SPIGOT-794: Call EntityPlaceEvent for Minecart placement2b2d084a
Add InventoryView#getSlotType01a9959a
Do not use deprecated ItemSpawnEvent constructor9642498d
SPIGOT-4547: Call EntitySpawnEvent as general spawn fallback event963f4a5f
Add PlayerItemDamageEvent63db0445
Add API to get / set base arrow damage531c25d7
Add CraftMagicNumbers.MAPPINGS_VERSION for use by NMS pluginsd05c8b14
Mappings Updatebd36e200
SPIGOT-4551: Ignore invalid attribute modifier slots Spigot Changes: 518206a1 Remove redundant trove depend 1959ad21 MC-11211,SPIGOT-4552: Fix placing double slabs at y = 255 29ab5e43 SPIGOT-3661: Allow arguments in restart-script 7cc46316 SPIGOT-852: Growth modifiers for beetroots, potatoes, carrots 82e117e1 Squelch "fatal: Resolve operation not in progress" message 0a1a68e7 Mappings Update & Patch Rebuild
215 lines
8.2 KiB
Diff
215 lines
8.2 KiB
Diff
From f3535616c140d470acb08dfa6671ea715300c8f8 Mon Sep 17 00:00:00 2001
|
|
From: Colin Godsey <crgodsey@gmail.com>
|
|
Date: Wed, 8 Aug 2018 10:10:06 -0600
|
|
Subject: [PATCH] Cache World Entity Type counts
|
|
|
|
Optimizes mob spawning by keeping a count of entities by type
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldEntityList.java b/src/main/java/com/destroystokyo/paper/PaperWorldEntityList.java
|
|
new file mode 100644
|
|
index 000000000..a10a5bc13
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldEntityList.java
|
|
@@ -0,0 +1,121 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+import net.minecraft.server.Entity;
|
|
+import net.minecraft.server.EntityInsentient;
|
|
+import net.minecraft.server.EnumCreatureType;
|
|
+import net.minecraft.server.IAnimal;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.World;
|
|
+import net.minecraft.server.WorldServer;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.Collection;
|
|
+
|
|
+public class PaperWorldEntityList extends ArrayList<Entity> {
|
|
+
|
|
+ private final WorldServer world;
|
|
+ private final int[] entityCounts = new int[EnumCreatureType.values().length];
|
|
+
|
|
+
|
|
+ public PaperWorldEntityList(World world) {
|
|
+ this.world = (WorldServer) world;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean addAll(Collection<? extends Entity> c) {
|
|
+ for (Entity e : c) {
|
|
+ updateEntityCount(e, 1);
|
|
+ }
|
|
+
|
|
+ return super.addAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean removeAll(Collection<?> c) {
|
|
+ for (Object e : c) {
|
|
+ if (e instanceof Entity && ((Entity) e).getWorld() == world) {
|
|
+ updateEntityCount((Entity) e, -1);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return super.removeAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean add(Entity e) {
|
|
+ updateEntityCount(e, 1);
|
|
+
|
|
+ return super.add(e);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Entity remove(int index) {
|
|
+ guard();
|
|
+ Entity entity = super.remove(index);
|
|
+ if (entity != null) updateEntityCount(entity, -1);
|
|
+ return entity;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean remove(Object o) {
|
|
+ guard();
|
|
+ if (super.remove(o)) {
|
|
+ updateEntityCount((Entity) o, -1);
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ private void guard() {
|
|
+ if (world.guardEntityList) {
|
|
+ throw new java.util.ConcurrentModificationException();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public int getCreatureCount(EnumCreatureType type) {
|
|
+ return entityCounts[type.ordinal()];
|
|
+ }
|
|
+
|
|
+ private void updateEntityCount(EnumCreatureType type, int amt) {
|
|
+ int count = entityCounts[type.ordinal()];
|
|
+
|
|
+ count += amt;
|
|
+
|
|
+ if (count < 0) {
|
|
+ MinecraftServer.LOGGER.error("Paper - Entity count cache has gone negative");
|
|
+ count = 0;
|
|
+ }
|
|
+
|
|
+ entityCounts[type.ordinal()] = count;
|
|
+ }
|
|
+
|
|
+ public void updateEntityCount(Entity entity, int amt) {
|
|
+ if (!(entity instanceof IAnimal)) return;
|
|
+
|
|
+ if (entity instanceof EntityInsentient) {
|
|
+ EntityInsentient entityinsentient = (EntityInsentient) entity;
|
|
+ if (amt > 0 && entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent()) {
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ if (amt < 0) {
|
|
+ if (!entity.hasBeenCounted) {
|
|
+ return;
|
|
+ }
|
|
+ // Only remove once, we remove from if the entity list is guarded, but may be called later
|
|
+ entity.hasBeenCounted = false;
|
|
+ } else {
|
|
+ if (entity.hasBeenCounted) {
|
|
+ return;
|
|
+ }
|
|
+ entity.hasBeenCounted = true;
|
|
+ }
|
|
+
|
|
+ for (EnumCreatureType type : EnumCreatureType.values()) {
|
|
+ if (type.matches(entity)) {
|
|
+ updateEntityCount(type, amt);
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index a9b0f8497..3311e2b24 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -122,6 +122,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
private boolean az;
|
|
public boolean dead;
|
|
public boolean shouldBeRemoved; // Paper
|
|
+ public boolean hasBeenCounted = false; // Paper
|
|
public float width;
|
|
public float length;
|
|
public float J;
|
|
diff --git a/src/main/java/net/minecraft/server/EnumCreatureType.java b/src/main/java/net/minecraft/server/EnumCreatureType.java
|
|
index 79e52f7ba..42f6a6a93 100644
|
|
--- a/src/main/java/net/minecraft/server/EnumCreatureType.java
|
|
+++ b/src/main/java/net/minecraft/server/EnumCreatureType.java
|
|
@@ -16,6 +16,8 @@ public enum EnumCreatureType {
|
|
this.h = flag1;
|
|
}
|
|
|
|
+ public boolean matches(Entity entity) { return innerClass().isAssignableFrom(entity.getClass()); } // Paper
|
|
+ public Class<? extends IAnimal> innerClass() { return this.a(); } // Paper - OBFHELPER
|
|
public Class<? extends IAnimal> a() {
|
|
return this.e;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
index e62616552..bfbe4d3e3 100644
|
|
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
@@ -114,7 +114,7 @@ public final class SpawnerCreature {
|
|
|
|
if ((!enumcreaturetype.c() || flag1) && (enumcreaturetype.c() || flag) && (!enumcreaturetype.d() || flag2)) {
|
|
k = limit * i / SpawnerCreature.b; // CraftBukkit - use per-world limits
|
|
- int l1 = worldserver.a(enumcreaturetype.a(), k);
|
|
+ int l1 = worldserver.entityList.getCreatureCount(enumcreaturetype); // Paper - entity count cache
|
|
|
|
if (l1 <= k) {
|
|
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index 187506b57..823c3900b 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -45,7 +45,8 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
private static final EnumDirection[] a = EnumDirection.values();
|
|
private int b = 63;
|
|
// Spigot start - guard entity list from removals
|
|
- public final List<Entity> entityList = new java.util.ArrayList<Entity>()
|
|
+ public final com.destroystokyo.paper.PaperWorldEntityList entityList = new com.destroystokyo.paper.PaperWorldEntityList(this);
|
|
+ /* // Paper start
|
|
{
|
|
@Override
|
|
public Entity remove(int index)
|
|
@@ -69,6 +70,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
}
|
|
}
|
|
};
|
|
+ */ // Paper end
|
|
// Spigot end
|
|
protected final Set<Entity> g = com.google.common.collect.Sets.newHashSet(); public Set<Entity> getEntityUnloadQueue() { return g; };// Paper - OBFHELPER
|
|
//public final List<TileEntity> tileEntityList = Lists.newArrayList(); // Paper - remove unused list
|
|
@@ -139,7 +141,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
public final com.destroystokyo.paper.PaperWorldConfig paperConfig; // Paper
|
|
|
|
public final co.aikar.timings.WorldTimingsHandler timings; // Paper
|
|
- private boolean guardEntityList; // Spigot
|
|
+ public boolean guardEntityList; // Spigot // Paper - public
|
|
public static boolean haveWeSilencedAPhysicsCrash;
|
|
public static String blockLocation;
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
@@ -1117,6 +1119,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
this.getChunkAt(i, j).b(entity);
|
|
}
|
|
entity.shouldBeRemoved = true; // Paper
|
|
+ entityList.updateEntityCount(entity, -1); // Paper
|
|
|
|
if (!guardEntityList) { // Spigot - It will get removed after the tick if we are ticking // Paper - always remove from current chunk above
|
|
// CraftBukkit start - Decrement loop variable field if we've already ticked this entity
|
|
--
|
|
2.20.1
|
|
|