2013-08-04 06:51:09 +08:00
|
|
|
From 774f4afb154aafc002d1bd87843b2cafafeea32f Mon Sep 17 00:00:00 2001
|
2013-06-21 15:30:13 +08:00
|
|
|
From: md_5 <md_5@live.com.au>
|
|
|
|
Date: Fri, 21 Jun 2013 17:29:54 +1000
|
|
|
|
Subject: [PATCH] Fix Mob Spawning Relative to View Distance
|
2013-02-02 06:02:14 +08:00
|
|
|
|
|
|
|
|
2013-06-21 15:35:08 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2013-08-03 23:24:33 +08:00
|
|
|
index 5b13dea..c353b29 100644
|
2013-06-21 15:35:08 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
@@ -33,6 +33,7 @@ public class Chunk {
|
|
|
|
public int p;
|
2013-07-02 11:03:56 +08:00
|
|
|
public long q;
|
2013-06-21 15:35:08 +08:00
|
|
|
private int u;
|
|
|
|
+ protected gnu.trove.map.hash.TObjectIntHashMap<Class> entityCount = new gnu.trove.map.hash.TObjectIntHashMap<Class>(); // Spigot
|
|
|
|
|
|
|
|
public Chunk(World world, int i, int j) {
|
|
|
|
this.sections = new ChunkSection[16];
|
2013-08-03 23:24:33 +08:00
|
|
|
@@ -552,6 +553,22 @@ public class Chunk {
|
2013-06-21 15:35:08 +08:00
|
|
|
entity.ak = k;
|
|
|
|
entity.al = this.z;
|
|
|
|
this.entitySlices[k].add(entity);
|
|
|
|
+ // Spigot start - increment creature type count
|
2013-08-03 23:24:33 +08:00
|
|
|
+ // Keep this synced up with World.a(Class)
|
|
|
|
+ if (entity instanceof EntityInsentient) {
|
|
|
|
+ EntityInsentient entityinsentient = (EntityInsentient) entity;
|
|
|
|
+ if (entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
2013-06-21 15:35:08 +08:00
|
|
|
+ for ( EnumCreatureType creatureType : EnumCreatureType.values() )
|
|
|
|
+ {
|
|
|
|
+ if ( creatureType.a().isAssignableFrom( entity.getClass() ) )
|
|
|
|
+ {
|
|
|
|
+ this.entityCount.adjustOrPutValue( creatureType.a(), 1, 1 );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(Entity entity) {
|
2013-08-03 23:24:33 +08:00
|
|
|
@@ -568,6 +585,22 @@ public class Chunk {
|
2013-06-21 15:35:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.entitySlices[i].remove(entity);
|
|
|
|
+ // Spigot start - decrement creature type count
|
2013-08-03 23:24:33 +08:00
|
|
|
+ // Keep this synced up with World.a(Class)
|
|
|
|
+ if (entity instanceof EntityInsentient) {
|
|
|
|
+ EntityInsentient entityinsentient = (EntityInsentient) entity;
|
|
|
|
+ if (entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
2013-06-21 15:35:08 +08:00
|
|
|
+ for ( EnumCreatureType creatureType : EnumCreatureType.values() )
|
|
|
|
+ {
|
|
|
|
+ if ( creatureType.a().isAssignableFrom( entity.getClass() ) )
|
|
|
|
+ {
|
|
|
|
+ this.entityCount.adjustValue( creatureType.a(), -1 );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean d(int i, int j, int k) {
|
2013-02-02 06:02:14 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2013-07-09 08:31:10 +08:00
|
|
|
index 9812538..ecf13aa 100644
|
2013-02-02 06:02:14 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2013-07-02 11:03:56 +08:00
|
|
|
@@ -27,6 +27,23 @@ public final class SpawnerCreature {
|
2013-04-22 06:47:35 +08:00
|
|
|
return new ChunkPosition(k, i1, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Spigot start - get entity count only from chunks being processed in b
|
2013-07-02 11:24:59 +08:00
|
|
|
+ private int getEntityCount(WorldServer server, Class oClass)
|
2013-06-21 15:30:13 +08:00
|
|
|
+ {
|
2013-04-22 06:47:35 +08:00
|
|
|
+ int i = 0;
|
2013-07-02 11:24:59 +08:00
|
|
|
+ for ( Long coord : this.a.keySet() )
|
2013-06-21 15:30:13 +08:00
|
|
|
+ {
|
|
|
|
+ int x = LongHash.msw( coord );
|
|
|
|
+ int z = LongHash.lsw( coord );
|
2013-06-21 15:35:08 +08:00
|
|
|
+ if ( !server.chunkProviderServer.unloadQueue.contains( coord ) && server.isChunkLoaded( x, z ) )
|
2013-06-21 15:30:13 +08:00
|
|
|
+ {
|
2013-06-21 15:35:08 +08:00
|
|
|
+ i += server.getChunkAt( x, z ).entityCount.get( oClass );
|
2013-04-22 06:47:35 +08:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return i;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+
|
2013-07-02 11:03:56 +08:00
|
|
|
public int spawnEntities(WorldServer worldserver, boolean flag, boolean flag1, boolean flag2) {
|
2013-04-22 06:47:35 +08:00
|
|
|
if (!flag && !flag1) {
|
|
|
|
return 0;
|
2013-07-02 11:03:56 +08:00
|
|
|
@@ -42,6 +59,11 @@ public final class SpawnerCreature {
|
2013-02-02 06:02:14 +08:00
|
|
|
|
|
|
|
j = MathHelper.floor(entityhuman.locZ / 16.0D);
|
2013-06-21 15:30:13 +08:00
|
|
|
byte b0 = 8;
|
|
|
|
+ // Spigot Start
|
|
|
|
+ b0 = worldserver.spigotConfig.mobSpawnRange;
|
|
|
|
+ b0 = ( b0 > worldserver.spigotConfig.viewDistance ) ? (byte) worldserver.spigotConfig.viewDistance : b0;
|
|
|
|
+ b0 = ( b0 > 8 ) ? 8 : b0;
|
|
|
|
+ // Spigot End
|
2013-02-02 06:02:14 +08:00
|
|
|
|
|
|
|
for (int l = -b0; l <= b0; ++l) {
|
|
|
|
for (int i1 = -b0; i1 <= b0; ++i1) {
|
2013-07-02 11:03:56 +08:00
|
|
|
@@ -89,13 +111,15 @@ public final class SpawnerCreature {
|
2013-02-02 06:02:14 +08:00
|
|
|
if (limit == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
+ int mobcnt = 0;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-07-02 11:03:56 +08:00
|
|
|
- if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && worldserver.a(enumcreaturetype.a()) <= limit * this.a.size() / 256) { // CraftBukkit - use per-world limits
|
|
|
|
+ if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && (mobcnt = getEntityCount(worldserver, enumcreaturetype.a())) <= limit * this.a.size() / 256) { // Spigot - use per-world limits and use all loaded chunks
|
|
|
|
Iterator iterator = this.a.keySet().iterator();
|
2013-02-02 06:02:14 +08:00
|
|
|
|
2013-07-02 11:24:59 +08:00
|
|
|
+ int moblimit = (limit * this.a.size() / 256) - mobcnt + 1; // Spigot - up to 1 more than limit
|
2013-02-02 06:02:14 +08:00
|
|
|
label110:
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
+ while (iterator.hasNext() && (moblimit > 0)) { // Spigot - while more allowed
|
|
|
|
// CraftBukkit start
|
|
|
|
long key = ((Long) iterator.next()).longValue();
|
|
|
|
|
2013-07-02 11:03:56 +08:00
|
|
|
@@ -160,6 +184,13 @@ public final class SpawnerCreature {
|
|
|
|
groupdataentity = entityinsentient.a(groupdataentity);
|
|
|
|
worldserver.addEntity(entityinsentient, SpawnReason.NATURAL);
|
2013-02-02 06:02:14 +08:00
|
|
|
// CraftBukkit end
|
|
|
|
+ // Spigot start
|
2013-06-21 15:30:13 +08:00
|
|
|
+ if ( --moblimit <= 0 )
|
|
|
|
+ {
|
|
|
|
+ // If we're past limit, stop spawn
|
2013-02-02 06:02:14 +08:00
|
|
|
+ continue label110;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
2013-07-09 08:31:10 +08:00
|
|
|
if (j2 >= entityinsentient.bv()) {
|
2013-02-02 06:02:14 +08:00
|
|
|
continue label110;
|
|
|
|
}
|
2013-06-21 15:30:13 +08:00
|
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
2013-08-04 06:51:09 +08:00
|
|
|
index bab9d8f..9f95452 100644
|
2013-06-21 15:30:13 +08:00
|
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
2013-07-28 19:47:45 +08:00
|
|
|
@@ -154,4 +154,11 @@ public class SpigotWorldConfig
|
2013-07-13 09:37:21 +08:00
|
|
|
|
2013-06-21 15:30:13 +08:00
|
|
|
antiXrayInstance = new AntiXray( this );
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public byte mobSpawnRange;
|
|
|
|
+ private void mobSpawnRange()
|
|
|
|
+ {
|
2013-06-21 15:41:26 +08:00
|
|
|
+ mobSpawnRange = (byte) getInt( "mob-spawn-range", 4 );
|
2013-06-21 15:30:13 +08:00
|
|
|
+ log( "Mob Spawn Range: " + mobSpawnRange );
|
|
|
|
+ }
|
|
|
|
}
|
2013-02-02 06:02:14 +08:00
|
|
|
--
|
2013-08-04 06:51:09 +08:00
|
|
|
1.8.1.2
|
|
|
|
|