forked from mirrors/cobblemon
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44c27be590 | ||
|
|
a704972dea | ||
|
|
0b43342a5c |
@@ -42,7 +42,7 @@ class PlayerBattleActor(
|
||||
/** The [SoundEvent] to play to the player during a battle. Will start playing as soon as the battle starts. */
|
||||
var battleTheme: SoundEvent? = null
|
||||
set(value) {
|
||||
if (this.isInitialized() && this.battle.started) this.sendUpdate(BattleMusicPacket(value))
|
||||
if (this.isInitialized() && this.battle.started) this.sendUpdate(BattleMusicPacket(value?.location))
|
||||
field = value
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ class InitializeInstruction(val instructionSet: InstructionSet, val message: Bat
|
||||
battle.actors.filterIsInstance<PlayerBattleActor>().forEach { actor ->
|
||||
val initializePacket = BattleInitializePacket(battle, actor.getSide())
|
||||
actor.sendUpdate(initializePacket)
|
||||
actor.sendUpdate(BattleMusicPacket(actor.battleTheme))
|
||||
actor.sendUpdate(BattleMusicPacket(actor.battleTheme?.location))
|
||||
}
|
||||
|
||||
battle.actors.forEach { actor ->
|
||||
|
||||
+9
-1
@@ -13,6 +13,7 @@ import com.cobblemon.mod.common.client.sound.BattleMusicController
|
||||
import com.cobblemon.mod.common.client.sound.instances.BattleMusicInstance
|
||||
import com.cobblemon.mod.common.net.messages.client.battle.BattleMusicPacket
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
|
||||
/**
|
||||
* The handler for [BattleMusicPacket]s. Interfaces with [BattleMusicController] to change battle music.
|
||||
@@ -24,9 +25,16 @@ object BattleMusicHandler : ClientNetworkPacketHandler<BattleMusicPacket> {
|
||||
|
||||
override fun handle(packet: BattleMusicPacket, client: Minecraft) {
|
||||
val soundManager = client.soundManager
|
||||
val newMusic = packet.music?.let { BattleMusicInstance(it, packet.volume, packet.pitch) }
|
||||
val loc = packet.music
|
||||
val newMusic = loc?.let {
|
||||
val event = SoundEvent.createVariableRangeEvent(loc)
|
||||
BattleMusicInstance(event, packet.volume, packet.pitch)
|
||||
}
|
||||
val currMusic = BattleMusicController.music
|
||||
|
||||
if (newMusic?.location == currMusic.location) {
|
||||
return
|
||||
}
|
||||
if (newMusic == null)
|
||||
BattleMusicController.endMusic()
|
||||
else if (!soundManager.isActive(currMusic))
|
||||
|
||||
+4
-3
@@ -15,6 +15,7 @@ import com.cobblemon.mod.common.util.readIdentifier
|
||||
import com.cobblemon.mod.common.util.writeIdentifier
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
|
||||
/**
|
||||
@@ -26,11 +27,11 @@ import net.minecraft.sounds.SoundEvent
|
||||
* @author Segfault Guy
|
||||
* @since April 20th, 2023
|
||||
*/
|
||||
class BattleMusicPacket(var music : SoundEvent? = null, var volume: Float = 1.0f, var pitch: Float = 1.0f) : NetworkPacket<BattleMusicPacket> {
|
||||
class BattleMusicPacket(var music : ResourceLocation? = null, var volume: Float = 1.0f, var pitch: Float = 1.0f) : NetworkPacket<BattleMusicPacket> {
|
||||
companion object {
|
||||
val ID = cobblemonResource("battle_music")
|
||||
fun decode(buffer: RegistryFriendlyByteBuf) = BattleMusicPacket(
|
||||
music = BuiltInRegistries.SOUND_EVENT.get(buffer.readIdentifier()),
|
||||
music = buffer.readIdentifier(),
|
||||
volume = buffer.readFloat(),
|
||||
pitch = buffer.readFloat()
|
||||
)
|
||||
@@ -39,7 +40,7 @@ class BattleMusicPacket(var music : SoundEvent? = null, var volume: Float = 1.0f
|
||||
override val id = ID
|
||||
|
||||
override fun encode(buffer: RegistryFriendlyByteBuf) {
|
||||
music?.let { buffer.writeIdentifier(it.location) } ?: buffer.writeIdentifier("".asIdentifierDefaultingNamespace())
|
||||
music?.let { buffer.writeIdentifier(it) } ?: buffer.writeIdentifier("".asIdentifierDefaultingNamespace())
|
||||
buffer.writeFloat(volume)
|
||||
buffer.writeFloat(pitch)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user