Merge branch 'command-anim' into 'main'

[Enhancement] Let NPCBattleActors trigger the "Command" animation in battle

See merge request cable-mc/cobblemon!2152
This commit is contained in:
Polymeta
2026-04-30 23:39:25 +00:00
5 changed files with 19 additions and 0 deletions
+5
View File
@@ -237,6 +237,11 @@
- Added `q.world.spawn_loot_table_items(loot_table_id, x, y, z)` which spawns the items from the loot table at the position. (Use type: "minecraft:chest" for the loot table.)
- Added `q.pokemon.entity` to access the entity of Pokémon.
- Flamethrower and Seismic Toss had their action effect JSON cleaned up
- Ride sounds can now be set as exclusive to passengers
- Ride sounds no longer play when submerged unless specified with a new setting
- NPC Trainers can now call a `command` animation when issuing a command in battle.
### Particles
### Localization
- Updated translations for:
@@ -152,6 +152,11 @@ abstract class BattleActor(
open fun sendMessage(component: Component) {
sendUpdate(BattleMessagePacket(component))
}
/**
* Called when this actor's Pokemon uses a move. Default implementation does nothing.
* Subclasses (NPC-backed actors, players, etc) may override to trigger animations or UI.
*/
open fun onUseMove(user: BattlePokemon, target: BattlePokemon?) {}
open fun awardExperience(battlePokemon: BattlePokemon, experience: Int) {}
open fun sendUpdate(packet: NetworkPacket<*>) {}
@@ -100,6 +100,8 @@ class MoveInstruction(
battleLang("used_move", pokemonName, move.displayName)
}
battle.broadcastChatMessage(lang)
// Notify the actor that one of their Pokemon used a move so they can react (eg. NPC play animation)
userPokemon.actor.onUseMove(userPokemon, targetPokemon)
battle.majorBattleActions[userPokemon.uuid] = message
val runtime = MoLangRuntime().also {
@@ -22,6 +22,7 @@ import com.cobblemon.mod.common.util.battleLang
import com.cobblemon.mod.common.util.chainFutures
import com.cobblemon.mod.common.util.effectiveName
import com.cobblemon.mod.common.util.update
import net.minecraft.network.chat.Component
import java.util.concurrent.CompletableFuture
open class NPCBattleActor(
@@ -72,6 +73,11 @@ open class NPCBattleActor(
}
}
override fun onUseMove(user: BattlePokemon, target: BattlePokemon?) {
// Play NPC command animation when one of this actor's Pokemon uses a move.
npc.playAnimation(NPCEntity.COMMAND_ANIMATION)
}
override fun win(otherWinners: List<BattleActor>, losers: List<BattleActor>) {
super.win(otherWinners, losers)
npc.playAnimation(NPCEntity.WIN_ANIMATION)
@@ -309,6 +309,7 @@ class NPCEntity(world: Level) : AgeableMob(CobblemonEntities.NPC, world), Posabl
const val RECALL_ANIMATION = "recall"
const val LOSE_ANIMATION = "lose"
const val WIN_ANIMATION = "win"
const val COMMAND_ANIMATION = "command"
}
override fun brainProvider() = Brain.provider<NPCEntity>(emptySet(), emptySet())