diff --git a/CHANGELOG.md b/CHANGELOG.md index 52f2f81bdf..58e2f30322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -312,6 +312,7 @@ - Added `Pokemon#hyperTrainIV()` and `IVs#setHyperTrainedIV(Stat, Int)`. - Added `HyperTrainedIvEvent.Pre` and `HyperTrainedIvEvent.Post`. - Added a `hoverText` option to PartySelectCallback, to display a tooltip on hovering over a Pokémon in the selection screen. +- `PokemonEntity` instances spawned into the world now appropriately finalize the spawn for mod compatibility. ### MoLang & Datapacks - The following usages for item predicates can now use item conditions like advancements do, you can learn about them in the [Minecraft wiki](https://minecraft.wiki/w/Advancement_definition#minecraft:filled_bucket) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/spawning/detail/SingleEntitySpawnAction.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/spawning/detail/SingleEntitySpawnAction.kt index 10bcf2e22d..e86e0c8f1d 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/spawning/detail/SingleEntitySpawnAction.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/spawning/detail/SingleEntitySpawnAction.kt @@ -15,6 +15,8 @@ import com.cobblemon.mod.common.api.spawning.SpawnBucket import com.cobblemon.mod.common.api.spawning.position.SpawnablePosition import com.cobblemon.mod.common.util.toVec3d import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.Mob +import net.minecraft.world.entity.MobSpawnType /** * A spawn action that spawns a single entity. This is the most common type of spawn action. @@ -35,6 +37,9 @@ abstract class SingleEntitySpawnAction( var shouldSpawn = false CobblemonEvents.ENTITY_SPAWN.postThen(SpawnEvent(e, spawnablePosition), ifSucceeded = { this.entity.emit(e) + if (e is Mob) { + e.finalizeSpawn(spawnablePosition.world, spawnablePosition.world.getCurrentDifficultyAt(spawnablePosition.position), MobSpawnType.NATURAL, null) + } spawnablePosition.world.addFreshEntity(e) shouldSpawn = true }) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnAllPokemon.kt b/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnAllPokemon.kt index 1504f6db4a..a94a85b850 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnAllPokemon.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnAllPokemon.kt @@ -21,6 +21,7 @@ import com.mojang.brigadier.context.CommandContext import net.minecraft.commands.CommandSourceStack import net.minecraft.commands.Commands import net.minecraft.server.level.ServerLevel +import net.minecraft.world.entity.MobSpawnType object SpawnAllPokemon { fun register(dispatcher: CommandDispatcher) { @@ -43,13 +44,15 @@ object SpawnAllPokemon { private fun execute(context: CommandContext, range: IntRange) : Int { val player = context.source.playerOrException - + val world = context.source.level for (species in PokemonSpecies.implemented) { if (species.nationalPokedexNumber in range) { LOGGER.debug(species.name) val pokemonEntity = PokemonProperties.parse("species=${species.name} level=10").createEntity(context.source.level) + val blockPos = player.blockPosition() pokemonEntity.moveTo(player.x, player.y, player.z, pokemonEntity.yRot, pokemonEntity.xRot) pokemonEntity.entityData.set(PokemonEntity.SPAWN_DIRECTION, pokemonEntity.random.nextFloat() * 360F) + pokemonEntity.finalizeSpawn(world, world.getCurrentDifficultyAt(blockPos), MobSpawnType.COMMAND, null) context.source.level.addFreshEntity(pokemonEntity) } } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnPokemon.kt b/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnPokemon.kt index 27e9bb3e72..c132eebc7f 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnPokemon.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/command/SpawnPokemon.kt @@ -25,6 +25,7 @@ import net.minecraft.commands.Commands.argument import net.minecraft.commands.Commands.literal import net.minecraft.commands.arguments.coordinates.Vec3Argument import net.minecraft.network.chat.Component +import net.minecraft.world.entity.MobSpawnType import net.minecraft.world.phys.Vec3 import net.minecraft.world.level.Level @@ -73,6 +74,7 @@ object SpawnPokemon { val pokemonEntity = properties.createEntity(world) pokemonEntity.moveTo(pos.x, pos.y, pos.z, pokemonEntity.yRot, pokemonEntity.xRot) pokemonEntity.entityData.set(PokemonEntity.SPAWN_DIRECTION, pokemonEntity.random.nextFloat() * 360F) + pokemonEntity.finalizeSpawn(world, world.getCurrentDifficultyAt(blockPos), MobSpawnType.COMMAND, null) if (world.addFreshEntity(pokemonEntity)) { return Command.SINGLE_SUCCESS } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt index 6f7fae56b2..b1a7169a21 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt @@ -147,6 +147,7 @@ import net.minecraft.util.Mth.clamp import net.minecraft.util.StringRepresentable import net.minecraft.world.InteractionHand import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.MobSpawnType import net.minecraft.world.entity.player.Player import net.minecraft.world.item.ItemStack import net.minecraft.world.level.Level @@ -673,6 +674,7 @@ open class Pokemon : ShowdownIdentifiable { val adjustedPosition = entity.getAdjustedSendoutPosition(position) entity.setPositionSafely(adjustedPosition) mutation(entity) + entity.finalizeSpawn(level, level.getCurrentDifficultyAt(adjustedPosition.toBlockPos()), MobSpawnType.EVENT, null) level.addFreshEntity(entity) state = SentOutState(entity) return entity