2015-05-25 18:37:24 +08:00
|
|
|
--- a/net/minecraft/server/SpawnerCreature.java
|
|
|
|
+++ b/net/minecraft/server/SpawnerCreature.java
|
2016-07-15 18:08:04 +08:00
|
|
|
@@ -6,10 +6,16 @@
|
2016-03-01 05:32:46 +08:00
|
|
|
import java.util.Random;
|
2016-07-15 18:08:04 +08:00
|
|
|
import java.util.Set;
|
|
|
|
|
2014-11-26 05:32:16 +08:00
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.craftbukkit.util.LongHash;
|
|
|
|
+import org.bukkit.craftbukkit.util.LongHashSet;
|
|
|
|
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
|
|
|
+// CraftBukkit end
|
2016-07-15 18:08:04 +08:00
|
|
|
+
|
2014-11-26 05:32:16 +08:00
|
|
|
public final class SpawnerCreature {
|
|
|
|
|
|
|
|
private static final int a = (int) Math.pow(17.0D, 2.0D);
|
2015-02-27 06:41:06 +08:00
|
|
|
- private final Set<ChunkCoordIntPair> b = Sets.newHashSet();
|
|
|
|
+ private final LongHashSet b = new LongHashSet(); // CraftBukkit
|
2014-11-26 05:32:16 +08:00
|
|
|
|
|
|
|
public SpawnerCreature() {}
|
|
|
|
|
2016-12-19 20:05:39 +08:00
|
|
|
@@ -38,13 +44,16 @@
|
2016-06-09 09:43:49 +08:00
|
|
|
boolean flag4 = i1 == -8 || i1 == 8 || k == -8 || k == 8;
|
2016-12-19 20:05:39 +08:00
|
|
|
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i1 + l, k + j);
|
2014-11-26 05:32:16 +08:00
|
|
|
|
|
|
|
- if (!this.b.contains(chunkcoordintpair)) {
|
2016-12-19 20:05:39 +08:00
|
|
|
+ // CraftBukkit start - use LongHash and LongHashSet
|
|
|
|
+ long chunkCoords = LongHash.toLong(chunkcoordintpair.x, chunkcoordintpair.z);
|
2014-11-26 05:32:16 +08:00
|
|
|
+ if (!this.b.contains(chunkCoords)) {
|
|
|
|
++i;
|
2016-12-19 20:05:39 +08:00
|
|
|
if (!flag4 && worldserver.getWorldBorder().isInBounds(chunkcoordintpair)) {
|
|
|
|
PlayerChunk playerchunk = worldserver.getPlayerChunkMap().getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
|
2016-03-01 05:32:46 +08:00
|
|
|
|
|
|
|
if (playerchunk != null && playerchunk.e()) {
|
|
|
|
- this.b.add(chunkcoordintpair);
|
|
|
|
+ this.b.add(chunkCoords);
|
2016-06-09 09:43:49 +08:00
|
|
|
+ // CraftBukkit end
|
2016-03-01 05:32:46 +08:00
|
|
|
}
|
2014-11-26 05:32:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-15 18:08:04 +08:00
|
|
|
@@ -62,9 +71,31 @@
|
2014-11-26 05:32:16 +08:00
|
|
|
for (int k1 = 0; k1 < j; ++k1) {
|
|
|
|
EnumCreatureType enumcreaturetype = aenumcreaturetype[k1];
|
2015-02-27 06:41:06 +08:00
|
|
|
|
2014-11-26 05:32:16 +08:00
|
|
|
+ // CraftBukkit start - Use per-world spawn limits
|
|
|
|
+ int limit = enumcreaturetype.b();
|
|
|
|
+ switch (enumcreaturetype) {
|
|
|
|
+ case MONSTER:
|
|
|
|
+ limit = worldserver.getWorld().getMonsterSpawnLimit();
|
|
|
|
+ break;
|
|
|
|
+ case CREATURE:
|
|
|
|
+ limit = worldserver.getWorld().getAnimalSpawnLimit();
|
|
|
|
+ break;
|
|
|
|
+ case WATER_CREATURE:
|
|
|
|
+ limit = worldserver.getWorld().getWaterAnimalSpawnLimit();
|
|
|
|
+ break;
|
|
|
|
+ case AMBIENT:
|
|
|
|
+ limit = worldserver.getWorld().getAmbientSpawnLimit();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (limit == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2015-02-27 06:41:06 +08:00
|
|
|
+
|
2014-11-26 05:32:16 +08:00
|
|
|
if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2)) {
|
|
|
|
k = worldserver.a(enumcreaturetype.a());
|
|
|
|
- int l1 = enumcreaturetype.b() * i / SpawnerCreature.a;
|
|
|
|
+ int l1 = limit * i / a; // CraftBukkit - use per-world limits
|
|
|
|
|
|
|
|
if (k <= l1) {
|
2016-03-01 05:32:46 +08:00
|
|
|
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
|
2016-07-15 18:08:04 +08:00
|
|
|
@@ -72,8 +103,10 @@
|
2014-11-26 05:32:16 +08:00
|
|
|
|
2016-03-01 05:32:46 +08:00
|
|
|
label120:
|
2014-11-26 05:32:16 +08:00
|
|
|
while (iterator1.hasNext()) {
|
|
|
|
- ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair) iterator1.next();
|
|
|
|
- BlockPosition blockposition1 = getRandomPosition(worldserver, chunkcoordintpair1.x, chunkcoordintpair1.z);
|
|
|
|
+ // CraftBukkit start = use LongHash and LongObjectHashMap
|
|
|
|
+ long key = ((Long) iterator1.next()).longValue();
|
|
|
|
+ BlockPosition blockposition1 = getRandomPosition(worldserver, LongHash.msw(key), LongHash.lsw(key));
|
2015-02-27 06:41:06 +08:00
|
|
|
+ // CraftBukkit
|
2014-11-26 05:32:16 +08:00
|
|
|
int i2 = blockposition1.getX();
|
|
|
|
int j2 = blockposition1.getY();
|
|
|
|
int k2 = blockposition1.getZ();
|
2017-04-06 19:31:27 +08:00
|
|
|
@@ -125,8 +158,11 @@
|
|
|
|
if (entityinsentient.cM() && entityinsentient.canSpawn()) {
|
2016-03-01 05:32:46 +08:00
|
|
|
groupdataentity = entityinsentient.prepare(worldserver.D(new BlockPosition(entityinsentient)), groupdataentity);
|
2014-11-26 05:32:16 +08:00
|
|
|
if (entityinsentient.canSpawn()) {
|
2017-04-06 19:31:27 +08:00
|
|
|
- ++l2;
|
2014-11-26 05:32:16 +08:00
|
|
|
- worldserver.addEntity(entityinsentient);
|
2017-04-06 19:31:27 +08:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (worldserver.addEntity(entityinsentient, SpawnReason.NATURAL)) {
|
|
|
|
+ ++l2;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2016-03-01 05:32:46 +08:00
|
|
|
} else {
|
|
|
|
entityinsentient.die();
|
2014-11-26 05:32:16 +08:00
|
|
|
}
|
2017-04-06 19:31:27 +08:00
|
|
|
@@ -226,8 +262,10 @@
|
2014-11-26 05:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
entityinsentient.setPositionRotation((double) ((float) j1 + 0.5F), (double) blockposition.getY(), (double) ((float) k1 + 0.5F), random.nextFloat() * 360.0F, 0.0F);
|
|
|
|
- world.addEntity(entityinsentient);
|
|
|
|
+ // CraftBukkit start - Added a reason for spawning this creature, moved entityinsentient.prepare(groupdataentity) up
|
2016-03-01 05:32:46 +08:00
|
|
|
groupdataentity = entityinsentient.prepare(world.D(new BlockPosition(entityinsentient)), groupdataentity);
|
2014-11-26 05:32:16 +08:00
|
|
|
+ world.addEntity(entityinsentient, SpawnReason.CHUNK_GEN);
|
|
|
|
+ // CraftBukkit end
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
|