Skip to content

Commit

Permalink
Properly play momentum sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Apr 3, 2022
1 parent 4e6b77e commit 27ddc43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
21 changes: 16 additions & 5 deletions src/main/kotlin/world/cepi/momentum/ability/DoubleJump.kt
Expand Up @@ -7,13 +7,18 @@ import net.minestom.server.event.EventCallback
import net.minestom.server.event.player.PlayerMoveEvent
import net.minestom.server.event.player.PlayerStartFlyingEvent
import net.minestom.server.sound.SoundEvent
import world.cepi.energy.energy
import world.cepi.kstom.event.listenOnly
import world.cepi.kstom.util.playSound
import world.cepi.kstom.util.playSoundToViewersAndSelf
import world.cepi.kstom.util.viewersAndSelfAsAudience
import world.cepi.momentum.cooldown.Cooldown
import world.cepi.momentum.cooldown.PredicateCooldown
import world.cepi.particle.Particle
import world.cepi.particle.ParticleType
import world.cepi.particle.data.Color
import world.cepi.particle.data.OffsetAndSpeed
import world.cepi.particle.extra.Dust
import world.cepi.particle.renderer.Renderer
import world.cepi.particle.renderer.render
import world.cepi.particle.renderer.translate
Expand All @@ -35,9 +40,6 @@ object DoubleJump : MovementAbility(), EventCallback<PlayerStartFlyingEvent> {

override fun initialise() {
node.listenOnly(::run)
node.listenOnly<PlayerMoveEvent> {
if (player.isOnGround) player.isAllowFlying = true
}
}

override fun apply(player: Player) {
Expand All @@ -51,12 +53,21 @@ object DoubleJump : MovementAbility(), EventCallback<PlayerStartFlyingEvent> {
override fun run(event: PlayerStartFlyingEvent) = with(event) {
// cancel the flying first
player.isFlying = false
player.isAllowFlying = false

player.viewersAndSelfAsAudience.playSound(Sound.sound(SoundEvent.ENTITY_BAT_TAKEOFF, Sound.Source.MASTER, 1f, 2f))
val circle = Renderer.circle(1.0).translate(player.position.asVec())

if (player.energy < 8) {
val failParticle = Particle.particle(ParticleType.DUST, 1, OffsetAndSpeed(), Dust(1f, 0f, 0f, 1f))
player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.BLOCK_NOTE_BLOCK_DIDGERIDOO, Sound.Source.MASTER, 1f, 0.5f), player.position)
circle.render(failParticle, player.viewersAndSelfAsAudience)
return
}

player.energy -= 8

val particle = Particle.particle(ParticleType.CLOUD, 1, OffsetAndSpeed())

player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.ENTITY_BAT_TAKEOFF, Sound.Source.MASTER, 1f, 2f), player.position)
circle.render(particle, player.viewersAndSelfAsAudience)

player.velocity = player.position.direction().mul(12.0).withY(10.0)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/world/cepi/momentum/ability/JumpSmash.kt
Expand Up @@ -11,6 +11,7 @@ import net.minestom.server.sound.SoundEvent
import net.minestom.server.utils.time.TimeUnit
import world.cepi.kstom.Manager
import world.cepi.kstom.event.listenOnly
import world.cepi.kstom.util.playSoundToViewersAndSelf
import world.cepi.kstom.util.viewersAndSelfAsAudience
import world.cepi.momentum.cooldown.PredicateCooldown

Expand Down Expand Up @@ -40,7 +41,7 @@ object JumpSmash : MovementAbility(), EventCallback<PlayerStartFlyingEvent> {
player.isAllowFlying = false

player.velocity = player.position.direction().mul(5.0).withY(15.0)
player.viewersAndSelfAsAudience.playSound(Sound.sound(SoundEvent.ENTITY_ENDER_DRAGON_SHOOT, Sound.Source.MASTER, 1f, 2f))
player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.ENTITY_ENDER_DRAGON_SHOOT, Sound.Source.MASTER, 1f, 2f))

Manager.scheduler.buildTask {
player.velocity = player.position.direction().mul(5.0).withY(-15.0)
Expand Down
12 changes: 5 additions & 7 deletions src/main/kotlin/world/cepi/momentum/ability/RockPillar.kt
Expand Up @@ -12,9 +12,7 @@ import net.minestom.server.tag.Tag
import net.minestom.server.utils.time.TimeUnit
import world.cepi.energy.energy
import world.cepi.kstom.event.listenOnly
import world.cepi.kstom.util.toBlockPosition
import world.cepi.kstom.util.toExactBlockPosition
import world.cepi.kstom.util.viewersAndSelfAsAudience
import world.cepi.kstom.util.*
import world.cepi.particle.Particle
import world.cepi.particle.ParticleType
import world.cepi.particle.data.Color
Expand Down Expand Up @@ -69,15 +67,15 @@ object RockPillar : MovementAbility() {
Dust(1f, 0f, 0f, 1f)
), player.viewersAndSelfAsAudience)

player.viewersAndSelfAsAudience.playSound(Sound.sound(SoundEvent.BLOCK_NOTE_BLOCK_DIDGERIDOO, Sound.Source.MASTER, 1f, 0.5f))
player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.BLOCK_NOTE_BLOCK_DIDGERIDOO, Sound.Source.MASTER, 1f, 0.5f))

return
}

// start off by throwing the player up in the air
player.velocity = Vec(0.0, 16.0, 0.0)

player.viewersAndSelfAsAudience.playSound(Sound.sound(SoundEvent.ENTITY_IRON_GOLEM_ATTACK, Sound.Source.MASTER, 2f, 0.5f))
player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.ENTITY_IRON_GOLEM_ATTACK, Sound.Source.MASTER, 2f, 0.5f), player.position)

rectangle.render(Particle.particle(
ParticleType.BLOCK,
Expand All @@ -104,7 +102,7 @@ object RockPillar : MovementAbility() {

player.energy -= 14

player.viewersAndSelfAsAudience.playSound(Sound.sound(SoundEvent.ENTITY_IRON_GOLEM_DAMAGE, Sound.Source.MASTER, 1f, 0.5f))
player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.ENTITY_IRON_GOLEM_DAMAGE, Sound.Source.MASTER, 1f, 0.5f) )

// schedule a task to remove the pillar later
MinecraftServer.getSchedulerManager().buildTask {
Expand All @@ -115,7 +113,7 @@ object RockPillar : MovementAbility() {
player.instance!!.setBlock(it, Block.AIR)
}

player.viewersAndSelfAsAudience.playSound(Sound.sound(SoundEvent.ENTITY_IRON_GOLEM_REPAIR, Sound.Source.MASTER, 1f, 0.5f))
player.playSoundToViewersAndSelf(Sound.sound(SoundEvent.ENTITY_IRON_GOLEM_REPAIR, Sound.Source.MASTER, 1f, 0.5f))

rectangle.render(Particle.particle(
ParticleType.BLOCK,
Expand Down

0 comments on commit 27ddc43

Please sign in to comment.