Compare commits

..
3 Commits
Author SHA1 Message Date
Kiritiop 58d5478b30 Edit CHANGELOG.md 2026-10-11 09:00:34 +00:00
Kiritiop 2bde3058dc Fixed spectating not being cancelled when the spectator enters a battle
Closes #1955
2026-10-11 08:53:43 +00:00
Kiritiop ffdbbe0e21 Fixed /spectatebattle not starting the battle theme music
Closes #2047
2026-10-11 08:53:43 +00:00
8 changed files with 21 additions and 53 deletions

No files matched your search

+2 -3
View File
@@ -28,9 +28,8 @@
- Fixed the Pokédex evolution tree crashing with a stack overflow on evolutions that loop back on themselves.
- Fixed form-changing evolutions sometimes resolving to the source form in the Pokédex evolution tree.
- Broken datapack evolutions are now logged and skipped in the Pokédex evolution tree instead of crashing.
- Fixed Illusion, Imposter and Transform overwriting the species, form and EXP group of the owner's party Pokémon on the client, which made its level and HP display incorrectly and could leave the copied form showing in the party after battle
- Fixed Illusion, Imposter and Transform not copying the size and alpha status of the Pokémon they turn into, which made disguises keep their original size
- Fixed `/spectatebattle` not starting the battle theme music, unlike spectating through the interaction wheel
- Fixed spectating not being cancelled when a battle starts for the spectator, which merged the two battles into an unplayable state, and fixed spectating a second battle leaving the first one still sending updates
### Developer
@@ -202,6 +202,7 @@ object BattleRegistry {
): BattleStartResult {
val battle = PokemonBattle(battleFormat, side1, side2)
val start: () -> Unit = {
battle.playerUUIDs.forEach { stopSpectating(it) }
battleMap[battle.battleId] = battle
startShowdown(battle)
}
@@ -224,6 +225,11 @@ object BattleRegistry {
ShowdownService.service.endBattle(battle)
}
@JvmStatic
fun stopSpectating(playerId: UUID) {
battleMap.values.forEach { it.spectators.remove(playerId) }
}
@JvmStatic
fun getBattle(id: UUID): PokemonBattle? {
return battleMap[id]
@@ -64,8 +64,6 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate {
const val SHINY_PARTICLE_COOLDOWN = 3.5F
}
var storedPokemon: Pokemon? = null
override val schedulingTracker: SchedulingTracker
get() = currentEntity.schedulingTracker
@@ -110,18 +108,8 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate {
if (this::currentEntity.isInitialized) {
if (data == PokemonEntity.SPECIES) {
val identifier = ResourceLocation.parse(currentEntity.entityData.get(PokemonEntity.SPECIES))
val species = PokemonSpecies.getByIdentifier(identifier)!! // TODO exception handling
val stored = storedPokemon
if (stored != null) {
val disguised = species != stored.species && currentEntity.battleId != null
if (disguised) {
if (currentEntity.pokemon === stored) currentEntity.pokemon = renderCopy(stored)
} else if (currentEntity.pokemon !== stored) {
currentEntity.pokemon = stored
}
}
currentPose = null
currentEntity.pokemon.species = species
currentEntity.pokemon.species = PokemonSpecies.getByIdentifier(identifier)!! // TODO exception handling
// force a model update - handles edge case where the PosableState's tracked PosableModel isn't updated until the LivingEntityRenderer render is run
currentModel = VaryingModelRepository.getPoser(identifier, this)
currentEntity.refreshRiding()
@@ -367,22 +355,6 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate {
pokemon.isClient = true
}
private fun renderCopy(source: Pokemon) = Pokemon().apply {
isClient = true
uuid = source.uuid
scaleModifier = source.scaleModifier
species = source.species
form = source.form
gender = source.gender
shiny = source.shiny
forcedAspects = source.forcedAspects
nickname = source.nickname
activeMark = source.activeMark
caughtBall = source.caughtBall
isAlpha = source.isAlpha
level = source.level
}
override fun addToStruct(struct: QueryStruct) {
super.addToStruct(struct)
struct.addFunctions(ClientMoLangFunctions.clientFunctions)
@@ -232,15 +232,14 @@ class PokemonServerDelegate : PokemonSideDelegate {
val trackedAspects = mock?.aspects ?: entity.pokemon.aspects
val trackedBall = mock?.pokeball ?: entity.pokemon.caughtBall.name.toString()
val trackedScaleModifier = mock?.scaleModifier ?: entity.pokemon.effectiveScale
val trackedAlpha = mock?.let { it.isAlpha == true } ?: entity.pokemon.isAlpha
entity.ownerUUID = entity.pokemon.getOwnerUUID()
entity.entityData.set(PokemonEntity.SPECIES, trackedSpecies)
if (entity.entityData.get(PokemonEntity.NICKNAME) != trackedNickname) {
entity.entityData.set(PokemonEntity.NICKNAME, trackedNickname)
}
if (entity.entityData.get(PokemonEntity.IS_ALPHA) != trackedAlpha) {
entity.entityData.set(PokemonEntity.IS_ALPHA, trackedAlpha)
if (entity.entityData.get(PokemonEntity.IS_ALPHA) != entity.pokemon.isAlpha) {
entity.entityData.set(PokemonEntity.IS_ALPHA, entity.pokemon.isAlpha)
}
entity.entityData.set(PokemonEntity.ASPECTS, trackedAspects)
entity.entityData.set(PokemonEntity.LABEL_LEVEL, entity.pokemon.level)
@@ -38,8 +38,7 @@ class IllusionEffect(
) : BattleEffect(), MocKEffect {
constructor(disguise: Pokemon) : this(
// effectiveScale is used instead of scaleModifier so alpha sized disguises are copied without copying the alpha flag itself
mock = disguise.createPokemonProperties(PokemonPropertyExtractor.ILLUSION).also { it.scaleModifier = disguise.effectiveScale },
mock = disguise.createPokemonProperties(PokemonPropertyExtractor.ILLUSION),
scale = disguise.form.baseScale * disguise.effectiveScale
)
@@ -35,8 +35,7 @@ class TransformEffect(
) : BattleEffect(), MocKEffect {
constructor(mimic: Pokemon, doCry: Boolean = true) : this(
// effectiveScale is used instead of scaleModifier so alpha sized targets are copied without copying the alpha flag itself
mock = mimic.createPokemonProperties(PokemonPropertyExtractor.TRANSFORM).also { it.scaleModifier = mimic.effectiveScale },
mock = mimic.createPokemonProperties(PokemonPropertyExtractor.TRANSFORM),
scale = mimic.form.baseScale * mimic.effectiveScale,
doCry = doCry
)
@@ -14,7 +14,6 @@ import com.cobblemon.mod.common.api.pokeball.PokeBalls
import com.cobblemon.mod.common.api.pokemon.PokemonSpecies
import com.cobblemon.mod.common.api.riding.stats.RidingStat
import com.cobblemon.mod.common.client.CobblemonClient
import com.cobblemon.mod.common.client.entity.PokemonClientDelegate
import com.cobblemon.mod.common.entity.PlatformType
import com.cobblemon.mod.common.entity.PoseType
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
@@ -75,7 +74,7 @@ class SpawnPokemonPacket(
entity.ownerUUID,
entity.pokemon.uuid,
entity.pokemon.storeCoordinates.get()?.store?.uuid,
entity.entityData.get(PokemonEntity.SCALE_MODIFIER),
entity.pokemon.scaleModifier,
entity.exposedSpecies.resourceIdentifier,
entity.pokemon.gender,
entity.pokemon.shiny,
@@ -148,13 +147,7 @@ class SpawnPokemonPacket(
this@SpawnPokemonPacket.storageUUID?.let {
val storedPokemon = CobblemonClient.storage.locatePokemon(it, this@SpawnPokemonPacket.pokemonUUID)
if (storedPokemon != null) {
(entity.delegate as? PokemonClientDelegate)?.storedPokemon = storedPokemon
val disguised = this@SpawnPokemonPacket.battleId != null &&
(storedPokemon.species.resourceIdentifier != this@SpawnPokemonPacket.speciesId ||
storedPokemon.form.formOnlyShowdownId() != this@SpawnPokemonPacket.formName)
if (!disguised) {
entity.pokemon = storedPokemon
}
entity.pokemon = storedPokemon
}
}
@@ -35,8 +35,6 @@ object SpectateBattleHandler : ServerNetworkPacketHandler<SpectateBattlePacket>
) {
val battle = BattleRegistry.getBattleByParticipatingPlayerId(packet.targetedEntityId)
if (battle != null && Cobblemon.config.allowSpectating) {
val target = battle.actors.filterIsInstance<PlayerBattleActor>().firstOrNull { it.uuid == packet.targetedEntityId }
// Check los and range
val targetedPlayerEntity = packet.targetedEntityId.getPlayer() ?: return
if (player.traceFirstEntityCollision(
@@ -49,9 +47,6 @@ object SpectateBattleHandler : ServerNetworkPacketHandler<SpectateBattlePacket>
}
this.spectateBattle(targetedPlayerEntity, player)
// Handle music
target?.battleTheme?.let { player.sendPacket(BattleMusicPacket(it)) }
}
else {
LOGGER.error("Battle of player id ${packet.targetedEntityId} not found (${player.uuid} tried spectating)")
@@ -76,9 +71,15 @@ object SpectateBattleHandler : ServerNetworkPacketHandler<SpectateBattlePacket>
val battle = BattleRegistry.getBattleByParticipatingPlayer(target) ?: return
BattleRegistry.stopSpectating(player.uuid)
battle.spectators.add(player.uuid)
player.sendPacket(BattleInitializePacket(battle, null))
player.sendPacket(BattleMessagePacket(battle.chatLog))
battle.actors.filterIsInstance<PlayerBattleActor>()
.firstOrNull { it.uuid == target.uuid }
?.battleTheme
?.let { player.sendPacket(BattleMusicPacket(it)) }
}
}