2013-05-14 02:08:11 +00:00
|
|
|
From b5e5145a64d772c22a4b0967dfdd31bec35e3f95 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-21 22:47:35 +00:00
|
|
|
repeatedly traversing over the entity slices
|
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-05-03 23:24:15 +00:00
|
|
|
index 7416edc..958b5af 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-21 22:47:35 +00:00
|
|
|
@@ -9,6 +9,7 @@ import java.util.Map;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit; // CraftBukkit
|
|
|
|
+import gnu.trove.map.hash.TObjectIntHashMap; // Spigot
|
|
|
|
|
|
|
|
public class Chunk {
|
|
|
|
|
|
|
|
@@ -33,6 +34,7 @@ public class Chunk {
|
|
|
|
public int p;
|
|
|
|
private int u;
|
|
|
|
boolean q;
|
|
|
|
+ protected TObjectIntHashMap<Class> entityCount = new TObjectIntHashMap<Class>(); // Spigot
|
|
|
|
|
|
|
|
public Chunk(World world, int i, int j) {
|
|
|
|
this.sections = new ChunkSection[16];
|
|
|
|
@@ -560,6 +562,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-21 22:47:35 +00:00
|
|
|
+ this.entityCount.adjustOrPutValue(creatureType.a(), 1, 1);
|
2013-04-20 08:50:09 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(Entity entity) {
|
2013-04-21 22:47:35 +00:00
|
|
|
@@ -576,6 +585,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-21 22:47:35 +00:00
|
|
|
+ this.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-21 22:47:35 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2013-05-03 23:24:15 +00:00
|
|
|
index 3529074..25b83f7 100644
|
2013-04-21 22:47:35 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
|
|
@@ -33,14 +33,8 @@ public final class SpawnerCreature {
|
|
|
|
for (Long coord : b.keySet()) {
|
|
|
|
int x = LongHash.msw(coord);
|
|
|
|
int z = LongHash.lsw(coord);
|
|
|
|
- if (!server.chunkProviderServer.unloadQueue.contains(x,z) && server.isChunkLoaded(x, z)) {
|
|
|
|
- for (List<Entity> entitySlice : server.getChunkAt(x, z).entitySlices) {
|
|
|
|
- for (Entity entity : entitySlice) {
|
|
|
|
- if (oClass.isAssignableFrom(entity.getClass())) {
|
|
|
|
- ++i;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
+ if (!server.chunkProviderServer.unloadQueue.contains(coord) && server.isChunkLoaded(x, z)) {
|
|
|
|
+ i += server.getChunkAt(x, z).entityCount.get(oClass);
|
|
|
|
}
|
2013-04-20 08:50:09 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
--
|
2013-04-23 01:27:55 +00:00
|
|
|
1.8.2.1
|
2013-04-20 08:50:09 +00:00
|
|
|
|