Skip to content

Commit 6794db4

Browse files
Make spawning more accurately track vanilla (#12627)
1 parent c68a55c commit 6794db4

File tree

4 files changed

+14
-31
lines changed

4 files changed

+14
-31
lines changed

paper-api/src/main/java/org/bukkit/World.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,11 +2675,14 @@ default <T> void playEffect(@NotNull Location location, @NotNull Effect effect,
26752675

26762676
/**
26772677
* Sets the spawn flags for this.
2678+
* <p>Note that setting {@code false} for either only affects
2679+
* natural spawning. It doesn't affect spawn eggs, summon command, mobs
2680+
* spawned from structure generation, spawners, etc.</p>
26782681
*
26792682
* @param allowMonsters - if true, monsters are allowed to spawn in this
2680-
* world.
2683+
* world via natural spawning mechanisms.
26812684
* @param allowAnimals - if true, animals are allowed to spawn in this
2682-
* world.
2685+
* world via natural spawning mechanisms.
26832686
*/
26842687
public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals);
26852688

paper-server/patches/features/0001-Moonrise-optimisation-patches.patch

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32615,7 +32615,7 @@ index f2aa944dedf917f01d669a703a9b9f4f35af78c2..116efc09663cac3b0f4b8c157e93201e
3261532615
this.chunkType = chunkType;
3261632616
this.heightmapsAfter = heightmapsAfter;
3261732617
diff --git a/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java b/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
32618-
index 2f83f615fb358ef7e6ae915f0bdfbc500407c09a..06e560d9c1deda605e131d0d4da499f90118a3e1 100644
32618+
index 98e85820ac5aad77a003be4b6f7a59346524ae81..d620862e95abf9f098bb53a76825883f2b1f4bbf 100644
3261932619
--- a/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
3262032620
+++ b/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
3262132621
@@ -193,7 +193,7 @@ public class ChunkStatusTasks {
@@ -32627,22 +32627,19 @@ index 2f83f615fb358ef7e6ae915f0bdfbc500407c09a..06e560d9c1deda605e131d0d4da499f9
3262732627
}
3262832628
});
3262932629
generationChunkHolder.replaceProtoChunk(new ImposterProtoChunk(wrapped, false));
32630-
@@ -209,7 +209,7 @@ public class ChunkStatusTasks {
32630+
@@ -209,12 +209,12 @@ public class ChunkStatusTasks {
3263132631
}, worldGenContext.mainThreadExecutor());
3263232632
}
3263332633

3263432634
- public static void postLoadProtoChunk(ServerLevel level, ValueInput.ValueInputList input) {
3263532635
+ public static void postLoadProtoChunk(ServerLevel level, ValueInput.ValueInputList input, ChunkPos pos) { // Paper - rewrite chunk system - add ChunkPos param
3263632636
if (!input.isEmpty()) {
32637-
// CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
32637+
// Paper start - duplicate uuid resolving
3263832638
level.addWorldGenChunkEntities(EntityType.loadEntitiesRecursive(input, level, EntitySpawnReason.LOAD).filter((entity) -> {
32639-
@@ -221,7 +221,7 @@ public class ChunkStatusTasks {
32640-
}
32641-
checkDupeUUID(level, entity); // Paper - duplicate uuid resolving
32642-
return !needsRemoval;
32639+
return !checkDupeUUID(level, entity);
3264332640
- }));
3264432641
+ }), pos); // Paper - rewrite chunk system
32645-
// CraftBukkit end
32642+
// Paper end - duplicate uuid resolving
3264632643
}
3264732644
}
3264832645
diff --git a/net/minecraft/world/level/chunk/status/ChunkStep.java b/net/minecraft/world/level/chunk/status/ChunkStep.java

paper-server/patches/sources/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java.patch

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,18 @@
99
worldGenContext.generator()
1010
.createStructures(
1111
serverLevel.registryAccess(),
12-
@@ -211,7 +_,58 @@
12+
@@ -211,7 +_,51 @@
1313

1414
public static void postLoadProtoChunk(ServerLevel level, ValueInput.ValueInputList input) {
1515
if (!input.isEmpty()) {
1616
- level.addWorldGenChunkEntities(EntityType.loadEntitiesRecursive(input, level, EntitySpawnReason.LOAD));
1717
- }
1818
- }
19-
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
19+
+ // Paper start - duplicate uuid resolving
2020
+ level.addWorldGenChunkEntities(EntityType.loadEntitiesRecursive(input, level, EntitySpawnReason.LOAD).filter((entity) -> {
21-
+ boolean needsRemoval = false;
22-
+ net.minecraft.server.dedicated.DedicatedServer server = level.getCraftServer().getServer();
23-
+ if (!level.getChunkSource().spawnFriendlies && (entity instanceof net.minecraft.world.entity.animal.Animal || entity instanceof net.minecraft.world.entity.animal.WaterAnimal)) {
24-
+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
25-
+ needsRemoval = true;
26-
+ }
27-
+ checkDupeUUID(level, entity); // Paper - duplicate uuid resolving
28-
+ return !needsRemoval;
21+
+ return !checkDupeUUID(level, entity);
2922
+ }));
30-
+ // CraftBukkit end
23+
+ // Paper end - duplicate uuid resolving
3124
+ }
3225
+ }
3326
+

paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,6 @@ public static boolean doEntityAddEventCalling(Level world, Entity entity, SpawnR
588588

589589
org.bukkit.event.Cancellable event = null;
590590
if (entity instanceof net.minecraft.world.entity.LivingEntity && !(entity instanceof ServerPlayer)) {
591-
boolean isAnimal = entity instanceof Animal || entity instanceof WaterAnimal || entity instanceof AbstractGolem;
592-
boolean isMonster = entity instanceof Monster || entity instanceof Ghast || entity instanceof Slime;
593-
594-
if (spawnReason != SpawnReason.CUSTOM) {
595-
if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters()) {
596-
entity.discard(null); // Add Bukkit remove cause
597-
return false;
598-
}
599-
}
600-
601591
event = CraftEventFactory.callCreatureSpawnEvent((net.minecraft.world.entity.LivingEntity) entity, spawnReason);
602592
} else if (entity instanceof ItemEntity) {
603593
event = CraftEventFactory.callItemSpawnEvent((ItemEntity) entity);

0 commit comments

Comments
 (0)