Skip to content

Commit 65dd303

Browse files
committed
Add mob spawn category overrides
1 parent ea32508 commit 65dd303

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- a/net/minecraft/server/level/ChunkMap.java
2+
+++ b/net/minecraft/server/level/ChunkMap.java
3+
@@ -249,7 +_,16 @@
4+
return;
5+
}
6+
7+
- final int index = entity.getType().getCategory().ordinal();
8+
+ // Papyrus start
9+
+ net.minecraft.world.entity.MobCategory category = entity.getType().getCategory();
10+
+ if (entity instanceof de.erethon.papyrus.entities.MobSpawnCategoryOverrideProvider custom) {
11+
+ category = custom.getEffectiveMobCategory();
12+
+ }
13+
+ if (category == net.minecraft.world.entity.MobCategory.MISC) {
14+
+ return;
15+
+ }
16+
+ final int index = category.ordinal();
17+
+ // Papyrus end
18+
final ca.spottedleaf.moonrise.common.list.ReferenceList<ServerPlayer> inRange =
19+
this.level.moonrise$getNearbyPlayers().getPlayers(entity.chunkPosition(), ca.spottedleaf.moonrise.common.misc.NearbyPlayers.NearbyMapType.TICK_VIEW_DISTANCE);
20+
if (inRange == null) {

papyrus-server/minecraft-patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
import it.unimi.dsi.fastutil.objects.Object2IntMap;
1111
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
1212
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
13+
@@ -79,7 +_,11 @@
14+
15+
for (Entity entity : entities) {
16+
if (!(entity instanceof Mob mob && (mob.isPersistenceRequired() || mob.requiresCustomPersistence()))) {
17+
- MobCategory category = entity.getType().getCategory();
18+
+ // Papyrus start
19+
+ final MobCategory category = (entity instanceof de.erethon.papyrus.entities.MobSpawnCategoryOverrideProvider custom)
20+
+ ? custom.getEffectiveMobCategory()
21+
+ : entity.getType().getCategory();
22+
+ // Papyrus end
23+
if (category != MobCategory.MISC) {
24+
// Paper start - Only count natural spawns
25+
if (!entity.level().paperConfig().entities.spawning.countAllMobsForSpawning &&
1326
@@ -235,9 +_,21 @@
1427
spawnCategoryForPosition(category, level, chunk, pos, filter, callback, Integer.MAX_VALUE, null);
1528
}
@@ -64,3 +77,16 @@
6477
}
6578

6679
public static boolean isInNetherFortressBounds(BlockPos pos, ServerLevel level, MobCategory category, StructureManager structureManager) {
80+
@@ -626,7 +_,11 @@
81+
}
82+
83+
this.spawnPotential.addCharge(blockPos, d);
84+
- MobCategory category = type.getCategory();
85+
+ // Papyrus start
86+
+ final MobCategory category = (mob instanceof de.erethon.papyrus.entities.MobSpawnCategoryOverrideProvider custom)
87+
+ ? custom.getEffectiveMobCategory()
88+
+ : mob.getType().getCategory();
89+
+ // Papyrus end
90+
this.mobCategoryCounts.addTo(category, 1);
91+
if (this.localMobCapCalculator != null) this.localMobCapCalculator.addMob(new ChunkPos(blockPos), category); // Paper - Optional per player mob spawns
92+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package de.erethon.papyrus.entities;
2+
3+
import net.minecraft.world.entity.MobCategory;
4+
5+
public interface MobSpawnCategoryOverrideProvider {
6+
7+
/**
8+
* @return The MobCategory this entity should count towards for mob caps.
9+
*/
10+
MobCategory getEffectiveMobCategory();
11+
}

0 commit comments

Comments
 (0)