mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 06:24:06 +01:00
112 lines
6.6 KiB
Diff
112 lines
6.6 KiB
Diff
--- a/net/minecraft/server/SpawnerCreature.java
|
|
+++ b/net/minecraft/server/SpawnerCreature.java
|
|
@@ -9,11 +9,17 @@
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.craftbukkit.util.LongHash;
|
|
+import org.bukkit.craftbukkit.util.LongHashSet;
|
|
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
|
+// CraftBukkit end
|
|
+
|
|
public final class SpawnerCreature {
|
|
|
|
private static final Logger a = LogManager.getLogger();
|
|
private static final int b = (int) Math.pow(17.0D, 2.0D);
|
|
- private final Set<ChunkCoordIntPair> c = Sets.newHashSet();
|
|
+ private final LongHashSet c = new LongHashSet(); // CraftBukkit
|
|
|
|
public SpawnerCreature() {}
|
|
|
|
@@ -42,13 +48,16 @@
|
|
boolean flag4 = i1 == -8 || i1 == 8 || k == -8 || k == 8;
|
|
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i1 + l, k + j);
|
|
|
|
- if (!this.c.contains(chunkcoordintpair)) {
|
|
+ // CraftBukkit start - use LongHash and LongHashSet
|
|
+ long chunkCoords = LongHash.toLong(chunkcoordintpair.x, chunkcoordintpair.z);
|
|
+ if (!this.c.contains(chunkCoords)) {
|
|
++i;
|
|
if (!flag4 && worldserver.getWorldBorder().isInBounds(chunkcoordintpair)) {
|
|
PlayerChunk playerchunk = worldserver.getPlayerChunkMap().getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
|
|
|
|
if (playerchunk != null && playerchunk.e()) {
|
|
- this.c.add(chunkcoordintpair);
|
|
+ this.c.add(chunkCoords);
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
}
|
|
@@ -66,9 +75,31 @@
|
|
for (int k1 = 0; k1 < j; ++k1) {
|
|
EnumCreatureType enumcreaturetype = aenumcreaturetype[k1];
|
|
|
|
+ // 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
|
|
+
|
|
if ((!enumcreaturetype.c() || flag1) && (enumcreaturetype.c() || flag) && (!enumcreaturetype.d() || flag2)) {
|
|
k = worldserver.a(enumcreaturetype.a());
|
|
- int l1 = enumcreaturetype.b() * i / SpawnerCreature.b;
|
|
+ int l1 = limit * i / b; // CraftBukkit - use per-world limits
|
|
|
|
if (k <= l1) {
|
|
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
|
|
@@ -76,8 +107,10 @@
|
|
|
|
label128:
|
|
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));
|
|
+ // CraftBukkit
|
|
int i2 = blockposition1.getX();
|
|
int j2 = blockposition1.getY();
|
|
int k2 = blockposition1.getZ();
|
|
@@ -136,9 +169,12 @@
|
|
if (entityinsentient.M() && entityinsentient.a((IWorldReader) worldserver)) {
|
|
groupdataentity = entityinsentient.prepare(worldserver.getDamageScaler(new BlockPosition(entityinsentient)), groupdataentity, (NBTTagCompound) null);
|
|
if (entityinsentient.a((IWorldReader) worldserver)) {
|
|
- ++l2;
|
|
- ++j4;
|
|
- worldserver.addEntity(entityinsentient);
|
|
+ // CraftBukkit start
|
|
+ if (worldserver.addEntity(entityinsentient, SpawnReason.NATURAL)) {
|
|
+ ++l2;
|
|
+ ++j4;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
} else {
|
|
entityinsentient.die();
|
|
}
|
|
@@ -255,7 +291,7 @@
|
|
entityinsentient.setPositionRotation((double) f, (double) blockposition.getY(), (double) f1, random.nextFloat() * 360.0F, 0.0F);
|
|
if (entityinsentient.a(generatoraccess) && entityinsentient.a((IWorldReader) generatoraccess)) {
|
|
groupdataentity = entityinsentient.prepare(generatoraccess.getDamageScaler(new BlockPosition(entityinsentient)), groupdataentity, (NBTTagCompound) null);
|
|
- generatoraccess.addEntity(entityinsentient);
|
|
+ generatoraccess.addEntity(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
|
|
flag = true;
|
|
}
|
|
}
|