Paper/nms-patches/SpawnerCreature.patch

111 Zeilen
6.6 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/SpawnerCreature.java
+++ b/net/minecraft/server/SpawnerCreature.java
2018-07-15 02:00:00 +02:00
@@ -9,11 +9,17 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-07-15 12:08:04 +02: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 12:08:04 +02:00
+
public final class SpawnerCreature {
2018-07-15 02:00:00 +02:00
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() {}
2018-07-15 02:00:00 +02:00
@@ -42,13 +48,16 @@
2016-06-09 03:43:49 +02:00
boolean flag4 = i1 == -8 || i1 == 8 || k == -8 || k == 8;
2016-12-19 13:05:39 +01:00
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i1 + l, k + j);
2018-07-15 02:00:00 +02:00
- if (!this.c.contains(chunkcoordintpair)) {
2016-12-19 13:05:39 +01:00
+ // CraftBukkit start - use LongHash and LongHashSet
+ long chunkCoords = LongHash.toLong(chunkcoordintpair.x, chunkcoordintpair.z);
2018-07-15 02:00:00 +02:00
+ if (!this.c.contains(chunkCoords)) {
++i;
2016-12-19 13:05:39 +01:00
if (!flag4 && worldserver.getWorldBorder().isInBounds(chunkcoordintpair)) {
PlayerChunk playerchunk = worldserver.getPlayerChunkMap().getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
2016-02-29 22:32:46 +01:00
if (playerchunk != null && playerchunk.e()) {
2018-07-15 02:00:00 +02:00
- this.c.add(chunkcoordintpair);
+ this.c.add(chunkCoords);
2016-06-09 03:43:49 +02:00
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
}
}
}
2018-08-26 04:00:00 +02:00
@@ -66,8 +75,30 @@
for (int k1 = 0; k1 < j; ++k1) {
EnumCreatureType enumcreaturetype = aenumcreaturetype[k1];
2015-02-26 23:41:06 +01: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-26 23:41:06 +01:00
+
2018-07-15 02:00:00 +02:00
if ((!enumcreaturetype.c() || flag1) && (enumcreaturetype.c() || flag) && (!enumcreaturetype.d() || flag2)) {
2018-08-26 04:00:00 +02:00
- k = enumcreaturetype.b() * i / SpawnerCreature.b;
+ k = limit * i / SpawnerCreature.b; // CraftBukkit - use per-world limits
int l1 = worldserver.a(enumcreaturetype.a(), k);
2018-08-26 04:00:00 +02:00
if (l1 <= k) {
2018-07-15 02:00:00 +02:00
@@ -76,8 +107,10 @@
2018-10-22 21:00:00 +02:00
label137:
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-26 23:41:06 +01:00
+ // CraftBukkit
int i2 = blockposition1.getX();
int j2 = blockposition1.getY();
int k2 = blockposition1.getZ();
2018-10-22 21:00:00 +02:00
@@ -140,9 +173,12 @@
if ((d0 <= 16384.0D || !entityinsentient.isTypeNotPersistent()) && entityinsentient.a((GeneratorAccess) worldserver, false) && 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();
}
2018-12-06 00:00:00 +01:00
@@ -259,7 +295,7 @@
2018-08-26 04:00:00 +02:00
entityinsentient.setPositionRotation(d0, (double) blockposition.getY(), d1, random.nextFloat() * 360.0F, 0.0F);
if (entityinsentient.a(generatoraccess, false) && entityinsentient.a((IWorldReader) generatoraccess)) {
2018-07-15 02:00:00 +02:00
groupdataentity = entityinsentient.prepare(generatoraccess.getDamageScaler(new BlockPosition(entityinsentient)), groupdataentity, (NBTTagCompound) null);
- generatoraccess.addEntity(entityinsentient);
+ generatoraccess.addEntity(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit
flag = true;
}
}