3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 15:20:11 +01:00
Paper/nms-patches/SpawnerCreature.patch

120 Zeilen
6.5 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/SpawnerCreature.java
+++ b/net/minecraft/server/SpawnerCreature.java
2016-02-29 22:32:46 +01:00
@@ -1,15 +1,19 @@
package net.minecraft.server;
2016-02-29 22:32:46 +01:00
-import com.google.common.collect.Sets;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
-import java.util.Set;
+
+// CraftBukkit start
+import org.bukkit.craftbukkit.util.LongHash;
+import org.bukkit.craftbukkit.util.LongHashSet;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
2016-02-29 22:32:46 +01:00
public final class SpawnerCreature {
private static final int a = (int) Math.pow(17.0D, 2.0D);
2015-02-26 23:41:06 +01:00
- private final Set<ChunkCoordIntPair> b = Sets.newHashSet();
+ private final LongHashSet b = new LongHashSet(); // CraftBukkit
public SpawnerCreature() {}
2016-02-29 22:32:46 +01:00
@@ -36,18 +40,21 @@
for (int i1 = -b0; i1 <= b0; ++i1) {
for (k = -b0; k <= b0; ++k) {
boolean flag3 = i1 == -b0 || i1 == b0 || k == -b0 || k == b0;
- ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i1 + l, k + j);
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - use LongHash and LongHashSet
+ // ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i1 + l, k + j);
- if (!this.b.contains(chunkcoordintpair)) {
+ long chunkCoords = LongHash.toLong(i1 + l, k + j);
+ if (!this.b.contains(chunkCoords)) {
++i;
2015-02-26 23:41:06 +01:00
- if (!flag3 && worldserver.getWorldBorder().isInBounds(chunkcoordintpair)) {
2016-02-29 22:32:46 +01:00
- PlayerChunk playerchunk = worldserver.getPlayerChunkMap().b(chunkcoordintpair.x, chunkcoordintpair.z);
+ if (!flag3 && worldserver.getWorldBorder().isInBounds(i1 + l, k + j)) { // CraftBukkit
+ PlayerChunk playerchunk = worldserver.getPlayerChunkMap().b(i1 + l, k + j); // CraftBukkit
if (playerchunk != null && playerchunk.e()) {
- this.b.add(chunkcoordintpair);
+ this.b.add(chunkCoords);
}
}
}
+ // CraftBukkit end
}
}
}
2016-02-29 22:32:46 +01:00
@@ -62,9 +69,31 @@
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
+
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-02-29 22:32:46 +01:00
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
@@ -72,8 +101,10 @@
2016-02-29 22:32:46 +01:00
label120:
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();
2016-02-29 22:32:46 +01:00
@@ -126,7 +157,7 @@
groupdataentity = entityinsentient.prepare(worldserver.D(new BlockPosition(entityinsentient)), groupdataentity);
if (entityinsentient.canSpawn()) {
++l2;
- worldserver.addEntity(entityinsentient);
+ worldserver.addEntity(entityinsentient, SpawnReason.NATURAL); // CraftBukkit - Added a reason for spawning this creature
2016-02-29 22:32:46 +01:00
} else {
entityinsentient.die();
}
2016-02-29 22:32:46 +01:00
@@ -226,8 +257,10 @@
}
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-02-29 22:32:46 +01:00
groupdataentity = entityinsentient.prepare(world.D(new BlockPosition(entityinsentient)), groupdataentity);
+ world.addEntity(entityinsentient, SpawnReason.CHUNK_GEN);
+ // CraftBukkit end
flag = true;
}