2013-06-21 09:30:13 +02:00
|
|
|
From 944e72c8c821cfea28fb2d0f49262f209ab99bec Mon Sep 17 00:00:00 2001
|
|
|
|
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-01 23:02:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2013-06-21 09:30:13 +02:00
|
|
|
index 056100f..c17ad8b 100644
|
2013-02-01 23:02:14 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
2013-06-21 09:30:13 +02:00
|
|
|
@@ -26,6 +26,32 @@ public final class SpawnerCreature {
|
2013-04-22 00:47:35 +02:00
|
|
|
return new ChunkPosition(k, i1, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Spigot start - get entity count only from chunks being processed in b
|
2013-06-21 09:30:13 +02:00
|
|
|
+ private static int getEntityCount(WorldServer server, Class oClass)
|
|
|
|
+ {
|
2013-04-22 00:47:35 +02:00
|
|
|
+ int i = 0;
|
2013-06-21 09:30:13 +02:00
|
|
|
+ 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() ) )
|
|
|
|
+ {
|
2013-04-22 00:47:35 +02:00
|
|
|
+ ++i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return i;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+
|
|
|
|
public static final int spawnEntities(WorldServer worldserver, boolean flag, boolean flag1, boolean flag2) {
|
|
|
|
if (!flag && !flag1) {
|
|
|
|
return 0;
|
2013-06-21 09:30:13 +02:00
|
|
|
@@ -41,6 +67,11 @@ public final class SpawnerCreature {
|
2013-02-01 23:02:14 +01:00
|
|
|
|
|
|
|
j = MathHelper.floor(entityhuman.locZ / 16.0D);
|
2013-06-21 09:30:13 +02: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-01 23:02:14 +01:00
|
|
|
|
|
|
|
for (int l = -b0; l <= b0; ++l) {
|
|
|
|
for (int i1 = -b0; i1 <= b0; ++i1) {
|
2013-06-21 09:30:13 +02:00
|
|
|
@@ -88,13 +119,15 @@ public final class SpawnerCreature {
|
2013-02-01 23:02:14 +01:00
|
|
|
if (limit == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
+ int mobcnt = 0;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
- if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && worldserver.a(enumcreaturetype.a()) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
|
2013-06-21 09:30:13 +02:00
|
|
|
+ if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && (mobcnt = getEntityCount(worldserver, enumcreaturetype.a())) <= limit * b.size() / 256) { // Spigot - use per-world limits and use all loaded chunks
|
2013-02-01 23:02:14 +01:00
|
|
|
Iterator iterator = b.keySet().iterator();
|
|
|
|
|
2013-06-21 09:30:13 +02:00
|
|
|
+ int moblimit = (limit * b.size() / 256) - mobcnt + 1; // Spigot - up to 1 more than limit
|
2013-02-01 23:02:14 +01:00
|
|
|
label110:
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
+ while (iterator.hasNext() && (moblimit > 0)) { // Spigot - while more allowed
|
|
|
|
// CraftBukkit start
|
|
|
|
long key = ((Long) iterator.next()).longValue();
|
|
|
|
|
2013-06-21 09:30:13 +02:00
|
|
|
@@ -158,6 +191,13 @@ public final class SpawnerCreature {
|
2013-02-01 23:02:14 +01:00
|
|
|
a(entityliving, worldserver, f, f1, f2);
|
|
|
|
worldserver.addEntity(entityliving, SpawnReason.NATURAL);
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Spigot start
|
2013-06-21 09:30:13 +02:00
|
|
|
+ if ( --moblimit <= 0 )
|
|
|
|
+ {
|
|
|
|
+ // If we're past limit, stop spawn
|
2013-02-01 23:02:14 +01:00
|
|
|
+ continue label110;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
2013-03-15 22:35:56 +01:00
|
|
|
if (j2 >= entityliving.by()) {
|
2013-02-01 23:02:14 +01:00
|
|
|
continue label110;
|
|
|
|
}
|
2013-06-21 09:30:13 +02:00
|
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
index 5e1cfa9..e807ec8 100644
|
|
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
@@ -142,4 +142,11 @@ public class SpigotWorldConfig
|
|
|
|
|
|
|
|
antiXrayInstance = new AntiXray( this );
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public byte mobSpawnRange;
|
|
|
|
+ private void mobSpawnRange()
|
|
|
|
+ {
|
|
|
|
+ mobSpawnRange = getByte( "mob-spawn-range", 4 );
|
|
|
|
+ log( "Mob Spawn Range: " + mobSpawnRange );
|
|
|
|
+ }
|
|
|
|
}
|
2013-02-01 23:02:14 +01:00
|
|
|
--
|
2013-06-02 07:15:15 +02:00
|
|
|
1.8.1.2
|
2013-02-01 23:02:14 +01:00
|
|
|
|