Properly update diff in NaturalSpawner

This commit is contained in:
Nassim Jahnke 2024-12-19 11:30:22 +01:00
parent 8f5d9953f5
commit 0eb8f95dec
No known key found for this signature in database
GPG key ID: EF6771C01F6EF02F
3 changed files with 29 additions and 39 deletions

View file

@ -4,7 +4,7 @@
public final Container container1; public final Container container1;
public final Container container2; public final Container container2;
+ // Paper start - add fields and methods + // CraftBukkit start - add fields and methods
+ public java.util.List<org.bukkit.entity.HumanEntity> transaction = new java.util.ArrayList<>(); + public java.util.List<org.bukkit.entity.HumanEntity> transaction = new java.util.ArrayList<>();
+ +
+ public java.util.List<ItemStack> getContents() { + public java.util.List<ItemStack> getContents() {
@ -44,7 +44,7 @@
+ public org.bukkit.Location getLocation() { + public org.bukkit.Location getLocation() {
+ return this.container1.getLocation(); // TODO: right? + return this.container1.getLocation(); // TODO: right?
+ } + }
+ // Paper end + // CraftBukkit end
+ +
public CompoundContainer(Container container1, Container container2) { public CompoundContainer(Container container1, Container container2) {
this.container1 = container1; this.container1 = container1;
@ -54,7 +54,7 @@
@Override @Override
public int getMaxStackSize() { public int getMaxStackSize() {
- return this.container1.getMaxStackSize(); - return this.container1.getMaxStackSize();
+ return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // Paper - check both sides + return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // CraftBukkit - check both sides
} }
@Override @Override

View file

@ -7,7 +7,7 @@
- default int getMaxStackSize() { - default int getMaxStackSize() {
- return 99; - return 99;
- } - }
+ int getMaxStackSize(); // Paper + int getMaxStackSize(); // CraftBukkit
default int getMaxStackSize(ItemStack stack) { default int getMaxStackSize(ItemStack stack) {
return Math.min(this.getMaxStackSize(), stack.getMaxStackSize()); return Math.min(this.getMaxStackSize(), stack.getMaxStackSize());
@ -16,7 +16,7 @@
return level != null && level.getBlockEntity(blockPos) == blockEntity && player.canInteractWithBlock(blockPos, distance); return level != null && level.getBlockEntity(blockPos) == blockEntity && player.canInteractWithBlock(blockPos, distance);
} }
+ +
+ // Paper start + // CraftBukkit start
+ java.util.List<ItemStack> getContents(); + java.util.List<ItemStack> getContents();
+ +
+ void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity player); + void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity player);
@ -25,12 +25,12 @@
+ +
+ java.util.List<org.bukkit.entity.HumanEntity> getViewers(); + java.util.List<org.bukkit.entity.HumanEntity> getViewers();
+ +
+ org.bukkit.inventory.@org.jetbrains.annotations.Nullable InventoryHolder getOwner(); // Paper - annotation + org.bukkit.inventory.@org.jetbrains.annotations.Nullable InventoryHolder getOwner();
+ +
+ void setMaxStackSize(int size); + void setMaxStackSize(int size);
+ +
+ org.bukkit.Location getLocation(); + org.bukkit.Location getLocation();
+ +
+ int MAX_STACK = Item.ABSOLUTE_MAX_STACK_SIZE; + int MAX_STACK = Item.ABSOLUTE_MAX_STACK_SIZE;
+ // Paper end + // CraftBukkit end
} }

View file

@ -28,7 +28,7 @@
BlockPos blockPos = entity.blockPosition(); BlockPos blockPos = entity.blockPosition();
chunkGetter.query(ChunkPos.asLong(blockPos), chunk -> { chunkGetter.query(ChunkPos.asLong(blockPos), chunk -> {
MobSpawnSettings.MobSpawnCost mobSpawnCost = getRoughBiome(blockPos, chunk).getMobSettings().getMobSpawnCost(entity.getType()); MobSpawnSettings.MobSpawnCost mobSpawnCost = getRoughBiome(blockPos, chunk).getMobSettings().getMobSpawnCost(entity.getType());
@@ -96,17 +_,37 @@ @@ -96,17 +_,34 @@
return chunk.getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ())).value(); return chunk.getNoiseBiome(QuartPos.fromBlock(pos.getX()), QuartPos.fromBlock(pos.getY()), QuartPos.fromBlock(pos.getZ())).value();
} }
@ -40,22 +40,12 @@
+ LevelData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate + LevelData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate
+ // CraftBukkit end + // CraftBukkit end
List<MobCategory> list = new ArrayList<>(SPAWNING_CATEGORIES.length); List<MobCategory> list = new ArrayList<>(SPAWNING_CATEGORIES.length);
-
- for (MobCategory mobCategory : SPAWNING_CATEGORIES) { for (MobCategory mobCategory : SPAWNING_CATEGORIES) {
- if ((spawnFriendlies || !mobCategory.isFriendly())
- && (spawnEnemies || mobCategory.isFriendly())
- && (spawnPassives || !mobCategory.isPersistent())
- && spawnState.canSpawnForCategoryGlobal(mobCategory)) {
- list.add(mobCategory);
+ MobCategory[] aenumcreaturetype = NaturalSpawner.SPAWNING_CATEGORIES;
+ int i = aenumcreaturetype.length;
+
+ for (int j = 0; j < i; ++j) {
+ MobCategory enumcreaturetype = SPAWNING_CATEGORIES[j];
+ // CraftBukkit start - Use per-world spawn limits + // CraftBukkit start - Use per-world spawn limits
+ boolean spawnThisTick = true; + boolean spawnThisTick = true;
+ int limit = enumcreaturetype.getMaxInstancesPerChunk(); + int limit = mobCategory.getMaxInstancesPerChunk();
+ SpawnCategory spawnCategory = CraftSpawnCategory.toBukkit(enumcreaturetype); + SpawnCategory spawnCategory = CraftSpawnCategory.toBukkit(mobCategory);
+ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) { + if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
+ spawnThisTick = worldserver.ticksPerSpawnCategory.getLong(spawnCategory) != 0 && worlddata.getGameTime() % worldserver.ticksPerSpawnCategory.getLong(spawnCategory) == 0; + spawnThisTick = worldserver.ticksPerSpawnCategory.getLong(spawnCategory) != 0 && worlddata.getGameTime() % worldserver.ticksPerSpawnCategory.getLong(spawnCategory) == 0;
+ limit = worldserver.getWorld().getSpawnLimit(spawnCategory); + limit = worldserver.getWorld().getSpawnLimit(spawnCategory);
@ -65,11 +55,12 @@
+ continue; + continue;
+ } + }
+ +
+ if ((spawnFriendlies || !enumcreaturetype.isFriendly()) if ((spawnFriendlies || !mobCategory.isFriendly())
+ && (spawnEnemies || enumcreaturetype.isFriendly()) && (spawnEnemies || mobCategory.isFriendly())
+ && (spawnPassives || !enumcreaturetype.isPersistent()) && (spawnPassives || !mobCategory.isPersistent())
+ && spawnState.canSpawnForCategoryGlobal(enumcreaturetype, limit)) { // Paper - Optional per player mob spawns; remove global check, check later during the local one - && spawnState.canSpawnForCategoryGlobal(mobCategory)) {
+ list.add(enumcreaturetype); + && spawnState.canSpawnForCategoryGlobal(mobCategory, limit)) { // Paper - Optional per player mob spawns; remove global check, check later during the local one
list.add(mobCategory);
+ // CraftBukkit end + // CraftBukkit end
} }
} }
@ -164,20 +155,11 @@
ServerLevel level, ServerLevel level,
MobCategory category, MobCategory category,
StructureManager structureManager, StructureManager structureManager,
@@ -235,16 +_,20 @@ @@ -235,7 +_,20 @@
double distance double distance
) { ) {
EntityType<?> entityType = data.type; EntityType<?> entityType = data.type;
- return entityType.getCategory() != MobCategory.MISC - return entityType.getCategory() != MobCategory.MISC
- && (
- entityType.canSpawnFarFromPlayer()
- || !(distance > entityType.getCategory().getDespawnDistance() * entityType.getCategory().getDespawnDistance())
- )
- && entityType.canSummon()
- && canSpawnMobAt(level, structureManager, generator, category, data, pos)
- && SpawnPlacements.isSpawnPositionOk(entityType, level, pos)
- && SpawnPlacements.checkSpawnRules(entityType, level, EntitySpawnReason.NATURAL, pos, level.random)
- && level.noCollision(entityType.getSpawnAABB(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5));
+ +
+ // Paper start - PreCreatureSpawnEvent + // Paper start - PreCreatureSpawnEvent
+ com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent( + com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
@ -190,8 +172,16 @@
+ } + }
+ return PreSpawnStatus.CANCELLED; + return PreSpawnStatus.CANCELLED;
+ } + }
+ final boolean success = entityType.getCategory() != MobCategory.MISC
+ // Paper end - PreCreatureSpawnEvent + // Paper end - PreCreatureSpawnEvent
+ return entityType.getCategory() == MobCategory.MISC ? PreSpawnStatus.FAIL : (!entityType.canSpawnFarFromPlayer() && distance > (double) (entityType.getCategory().getDespawnDistance() * entityType.getCategory().getDespawnDistance()) ? PreSpawnStatus.FAIL : (entityType.canSummon() && NaturalSpawner.canSpawnMobAt(level, structureManager, generator, category, data, pos) ? (!SpawnPlacements.isSpawnPositionOk(entityType, level, pos) ? PreSpawnStatus.FAIL : (!SpawnPlacements.checkSpawnRules(entityType, level, EntitySpawnReason.NATURAL, pos, level.random) ? PreSpawnStatus.FAIL : level.noCollision(entityType.getSpawnAABB((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D)) ? PreSpawnStatus.SUCCESS : PreSpawnStatus.FAIL)) : PreSpawnStatus.FAIL)); // Paper - PreCreatureSpawnEvent && (
entityType.canSpawnFarFromPlayer()
|| !(distance > entityType.getCategory().getDespawnDistance() * entityType.getCategory().getDespawnDistance())
@@ -245,6 +_,7 @@
&& SpawnPlacements.isSpawnPositionOk(entityType, level, pos)
&& SpawnPlacements.checkSpawnRules(entityType, level, EntitySpawnReason.NATURAL, pos, level.random)
&& level.noCollision(entityType.getSpawnAABB(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5));
+ return success ? PreSpawnStatus.SUCCESS : PreSpawnStatus.FAIL; // Paper - PreCreatureSpawnEvent
} }
@Nullable @Nullable