2013-04-20 19:25:59 +00:00
|
|
|
From b59089bc2de520bc295712f1320a568dfb218bdd Mon Sep 17 00:00:00 2001
|
2013-04-20 08:50:09 +00:00
|
|
|
From: Ammar Askar <ammar@ammaraskar.com>
|
|
|
|
Date: Sat, 20 Apr 2013 12:26:20 +0500
|
|
|
|
Subject: [PATCH] Save entity counts for randomly spawned creatures to avoid
|
2013-04-20 19:25:59 +00:00
|
|
|
repeatedly traversing over the entity slices and chunks
|
2013-04-20 08:50:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2013-04-20 19:25:59 +00:00
|
|
|
index 7f1c155..7dd931c 100644
|
2013-04-20 08:50:09 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2013-04-20 19:25:59 +00:00
|
|
|
@@ -560,6 +560,13 @@ public class Chunk {
|
2013-04-20 08:50:09 +00:00
|
|
|
entity.ak = k;
|
|
|
|
entity.al = this.z;
|
|
|
|
this.entitySlices[k].add(entity);
|
|
|
|
+ // Spigot start - increment creature type count
|
|
|
|
+ for (EnumCreatureType creatureType : EnumCreatureType.values()) {
|
|
|
|
+ if (creatureType.a().isAssignableFrom(entity.getClass())) {
|
2013-04-20 19:25:59 +00:00
|
|
|
+ world.entityCount.adjustOrPutValue(creatureType.a(), 1, 1);
|
2013-04-20 08:50:09 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(Entity entity) {
|
2013-04-20 19:25:59 +00:00
|
|
|
@@ -576,6 +583,13 @@ public class Chunk {
|
2013-04-20 08:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.entitySlices[i].remove(entity);
|
|
|
|
+ // Spigot start - decrement creature type count
|
|
|
|
+ for (EnumCreatureType creatureType : EnumCreatureType.values()) {
|
|
|
|
+ if (creatureType.a().isAssignableFrom(entity.getClass())) {
|
2013-04-20 19:25:59 +00:00
|
|
|
+ world.entityCount.adjustValue(creatureType.a(), -1);
|
2013-04-20 08:50:09 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean d(int i, int j, int k) {
|
2013-04-20 19:25:59 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
|
|
index 7e10318..3b23a58 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
|
|
@@ -76,6 +76,7 @@ public abstract class World implements IBlockAccess {
|
|
|
|
int[] H;
|
|
|
|
public boolean isStatic;
|
|
|
|
// Spigot start
|
|
|
|
+ protected gnu.trove.map.hash.TObjectIntHashMap<Class> entityCount = new gnu.trove.map.hash.TObjectIntHashMap<Class>();
|
|
|
|
|
|
|
|
public static long chunkToKey(int x, int z) {
|
|
|
|
long k = ((((long)x) & 0xFFFF0000L) << 16) | ((((long)x) & 0x0000FFFFL) << 0);
|
|
|
|
@@ -2456,6 +2457,9 @@ public abstract class World implements IBlockAccess {
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a(Class oclass) {
|
|
|
|
+ // Spigot start - commented out inefficient chunk traversing in favour of keeping entity counts in a map
|
|
|
|
+ return this.entityCount.get(oclass);
|
|
|
|
+ /*
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < this.entityList.size(); ++j) {
|
|
|
|
@@ -2467,6 +2471,8 @@ public abstract class World implements IBlockAccess {
|
2013-04-20 08:50:09 +00:00
|
|
|
}
|
2013-04-20 19:25:59 +00:00
|
|
|
|
2013-04-20 08:50:09 +00:00
|
|
|
return i;
|
2013-04-20 19:25:59 +00:00
|
|
|
+ */
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(List list) {
|
2013-04-20 08:50:09 +00:00
|
|
|
--
|
|
|
|
1.7.11.msysgit.0
|
|
|
|
|