mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-24 17:18:54 -05:00
finalizeSpawn for PokemonEntity's
This commit is contained in:
1 parent
ebc7f67655
commit
720eef5e75
5 files changed
+14
-1
No files matched your search
@@ -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)
|
||||
|
||||
+5
@@ -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<T : Entity>(
|
||||
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
|
||||
})
|
||||
|
||||
@@ -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<CommandSourceStack>) {
|
||||
@@ -43,13 +44,15 @@ object SpawnAllPokemon {
|
||||
|
||||
private fun execute(context: CommandContext<CommandSourceStack>, 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user