Skip to content

Commit

Permalink
fix: sound related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Sep 12, 2024
1 parent 29c0c0b commit ff4b1a5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,35 @@ object VanillaSoundEntries {

val blockyRegistry = resourcePack.soundRegistry("blocky") ?: SoundRegistry.soundRegistry("blocky", emptyList())
SoundRegistry.soundRegistry(blockyRegistry.namespace(), blockyRegistry.sounds().plus(listOf(
SoundEvent.soundEvent(Key.key("blocky:block.stone.place"), false, "subtitles.block.generic.place", VanillaSoundEntries.stoneDig),
SoundEvent.soundEvent(Key.key("blocky:block.stone.break"), false, "subtitles.block.generic.break", VanillaSoundEntries.stoneDig),
SoundEvent.soundEvent(Key.key("blocky:block.stone.hit"), false, "subtitles.block.generic.hit", VanillaSoundEntries.stoneStep),
SoundEvent.soundEvent(Key.key("blocky:block.stone.fall"), false, null, VanillaSoundEntries.stoneStep),
SoundEvent.soundEvent(Key.key("blocky:block.stone.step"), false, "subtitles.block.generic.footsteps", VanillaSoundEntries.stoneStep),

SoundEvent.soundEvent(Key.key("blocky:block.wood.place"), false, "subtitles.block.generic.place", VanillaSoundEntries.woodDig),
SoundEvent.soundEvent(Key.key("blocky:block.wood.break"), false, "subtitles.block.generic.break", VanillaSoundEntries.woodDig),
SoundEvent.soundEvent(Key.key("blocky:block.wood.hit"), false, "subtitles.block.generic.hit", VanillaSoundEntries.woodStep),
SoundEvent.soundEvent(Key.key("blocky:block.wood.fall"), false, null, VanillaSoundEntries.woodStep),
SoundEvent.soundEvent(Key.key("blocky:block.wood.step"), false, "subtitles.block.generic.footsteps", VanillaSoundEntries.woodStep),

SoundEvent.soundEvent(Key.key("blocky:block.copper.place"), false, "subtitles.block.generic.place", VanillaSoundEntries.copperDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper.break"), false, "subtitles.block.generic.break", VanillaSoundEntries.copperDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper.hit"), false, "subtitles.block.generic.hit", VanillaSoundEntries.copperStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper.fall"), false, null, VanillaSoundEntries.copperStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper.step"), false, "subtitles.block.generic.footsteps", VanillaSoundEntries.copperStep),

SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.place"), false, "subtitles.block.generic.place", VanillaSoundEntries.copperGrateDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.break"), false, "subtitles.block.generic.break", VanillaSoundEntries.copperGrateDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.hit"), false, "subtitles.block.generic.hit", VanillaSoundEntries.copperGrateStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.fall"), false, null, VanillaSoundEntries.copperGrateStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.step"), false, "subtitles.block.generic.footsteps", VanillaSoundEntries.copperGrateStep),

SoundEvent.soundEvent(Key.key("blocky:block.copper_door.open"), false, null, VanillaSoundEntries.copperDoor),
SoundEvent.soundEvent(Key.key("blocky:block.copper_door.close"), false, "subtitles.block.generic.footsteps", VanillaSoundEntries.copperDoor),

SoundEvent.soundEvent(Key.key("blocky:block.copper_trapdoor.open"), false, null, VanillaSoundEntries.copperTrapDoor),
SoundEvent.soundEvent(Key.key("blocky:block.copper_trapdoor.close"), false, "subtitles.block.generic.footsteps", VanillaSoundEntries.copperTrapDoor),
SoundEvent.soundEvent(Key.key("blocky:block.stone.place"), false, "subtitles.block.generic.place", stoneDig),
SoundEvent.soundEvent(Key.key("blocky:block.stone.break"), false, "subtitles.block.generic.break", stoneDig),
SoundEvent.soundEvent(Key.key("blocky:block.stone.hit"), false, "subtitles.block.generic.hit", stoneStep),
SoundEvent.soundEvent(Key.key("blocky:block.stone.fall"), false, null, stoneStep),
SoundEvent.soundEvent(Key.key("blocky:block.stone.step"), false, "subtitles.block.generic.footsteps", stoneStep),

SoundEvent.soundEvent(Key.key("blocky:block.wood.place"), false, "subtitles.block.generic.place", woodDig),
SoundEvent.soundEvent(Key.key("blocky:block.wood.break"), false, "subtitles.block.generic.break", woodDig),
SoundEvent.soundEvent(Key.key("blocky:block.wood.hit"), false, "subtitles.block.generic.hit", woodStep),
SoundEvent.soundEvent(Key.key("blocky:block.wood.fall"), false, null, woodStep),
SoundEvent.soundEvent(Key.key("blocky:block.wood.step"), false, "subtitles.block.generic.footsteps", woodStep),

SoundEvent.soundEvent(Key.key("blocky:block.copper.place"), false, "subtitles.block.generic.place", copperDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper.break"), false, "subtitles.block.generic.break", copperDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper.hit"), false, "subtitles.block.generic.hit", copperStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper.fall"), false, null, copperStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper.step"), false, "subtitles.block.generic.footsteps", copperStep),

SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.place"), false, "subtitles.block.generic.place", copperGrateDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.break"), false, "subtitles.block.generic.break", copperGrateDig),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.hit"), false, "subtitles.block.generic.hit", copperGrateStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.fall"), false, null, copperGrateStep),
SoundEvent.soundEvent(Key.key("blocky:block.copper_grate.step"), false, "subtitles.block.generic.footsteps", copperGrateStep),

SoundEvent.soundEvent(Key.key("blocky:block.copper_door.open"), false, null, copperDoor),
SoundEvent.soundEvent(Key.key("blocky:block.copper_door.close"), false, "subtitles.block.generic.footsteps", copperDoor),

SoundEvent.soundEvent(Key.key("blocky:block.copper_trapdoor.open"), false, null, copperTrapDoor),
SoundEvent.soundEvent(Key.key("blocky:block.copper_trapdoor.close"), false, "subtitles.block.generic.footsteps", copperTrapDoor),
))).let(resourcePack::soundRegistry)
}

Expand Down Expand Up @@ -108,10 +108,10 @@ object VanillaSoundEntries {
SoundEntry.soundEntry().key(Key.key("step/wood6")).build(),
)
val copperDig = listOf(
SoundEntry.soundEntry().key(Key.key("block/copper/dig1")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper/dig2")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper/dig3")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper/dig4")).build()
SoundEntry.soundEntry().key(Key.key("block/copper/break1")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper/break2")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper/break3")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper/break4")).build()
)
val copperStep = listOf(
SoundEntry.soundEntry().key(Key.key("block/copper/step1")).build(),
Expand All @@ -122,10 +122,10 @@ object VanillaSoundEntries {
SoundEntry.soundEntry().key(Key.key("block/copper/step6")).build(),
)
val copperGrateDig = listOf(
SoundEntry.soundEntry().key(Key.key("block/copper_grate/dig1")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_grate/dig2")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_grate/dig3")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_grate/dig4")).build()
SoundEntry.soundEntry().key(Key.key("block/copper_grate/break1")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_grate/break2")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_grate/break3")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_grate/break4")).build()
)
val copperGrateStep = listOf(
SoundEntry.soundEntry().key(Key.key("block/copper_grate/step1")).build(),
Expand All @@ -141,9 +141,9 @@ object VanillaSoundEntries {
SoundEntry.soundEntry().key(Key.key("block/copper_door/toggle3")).build(),
)
val copperTrapDoor = listOf(
SoundEntry.soundEntry().key(Key.key("block/copper_door/toggle1")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_door/toggle2")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_door/toggle3")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_door/toggle4")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_trapdoor/toggle1")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_trapdoor/toggle2")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_trapdoor/toggle3")).build(),
SoundEntry.soundEntry().key(Key.key("block/copper_trapdoor/toggle4")).build(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ class BlockySoundListener : Listener {

@EventHandler
fun BlockPlaceEvent.onPlace() {
val soundGroup = Registry.SOUNDS.get(block.blockSoundGroup.placeSound.key())?.takeUnless { it.isNotCustomBlockGroup() } ?: return
val soundGroup = Registry.SOUNDS.get(block.blockSoundGroup.placeSound.key())?.takeUnless { it.isNotCustomBlockGroup() }?.key()?.value() ?: return
val sound = block.toGearyOrNull()?.get<BlockySound>()?.placeSound ?: ("blocky:$soundGroup")
block.world.playSound(block.location, sound, SoundCategory.BLOCKS, DEFAULT_HIT_VOLUME, DEFAULT_HIT_PITCH)
}

@EventHandler
fun BlockBreakProgressUpdateEvent.onBreakProgress() {
if ((entity as? Player)?.gameMode == GameMode.CREATIVE) return
val soundGroup = Registry.SOUNDS.get(block.blockSoundGroup.hitSound.key())?.takeUnless { it.isNotCustomBlockGroup() } ?: return
val soundGroup = Registry.SOUNDS.get(block.blockSoundGroup.hitSound.key())?.takeUnless { it.isNotCustomBlockGroup() }?.key()?.value() ?: return
val sound = block.toGearyOrNull()?.get<BlockySound>()?.hitSound ?: ("blocky:$soundGroup")
block.world.playSound(block.location, sound, SoundCategory.BLOCKS, DEFAULT_HIT_VOLUME, DEFAULT_HIT_PITCH)
}

@EventHandler
fun BlockBreakEvent.onBreak() {
val soundGroup = Registry.SOUNDS.get(block.blockSoundGroup.breakSound.key())?.takeUnless { it.isNotCustomBlockGroup() } ?: return
val soundGroup = Registry.SOUNDS.get(block.blockSoundGroup.breakSound.key())?.takeUnless { it.isNotCustomBlockGroup() }?.key()?.value() ?: return
val sound = block.toGearyOrNull()?.get<BlockySound>()?.breakSound ?: ("blocky:$soundGroup")
block.world.playSound(block.location, sound, SoundCategory.BLOCKS, DEFAULT_HIT_VOLUME, DEFAULT_HIT_PITCH)
}
Expand All @@ -53,7 +53,7 @@ class BlockySoundListener : Listener {
if (!location.isWorldLoaded || !location.world.isChunkLoaded(location.chunk)) return

val (entity, standingOn) = (entity as? LivingEntity ?: return) to GenericHelpers.blockStandingOn(entity as LivingEntity)
val soundGroup = Registry.SOUNDS.get(standingOn.blockSoundGroup.stepSound.key())?.takeUnless { it.isNotCustomBlockGroup() } ?: return
val soundGroup = Registry.SOUNDS.get(standingOn.blockSoundGroup.stepSound.key())?.takeUnless { it.isNotCustomBlockGroup() }?.key()?.value() ?: return
if (event != GameEvent.STEP && event != GameEvent.HIT_GROUND) return
if (event == GameEvent.HIT_GROUND && entity.lastDamageCause?.cause != EntityDamageEvent.DamageCause.FALL) return

Expand Down Expand Up @@ -103,10 +103,10 @@ class BlockySoundListener : Listener {
}

private fun Sound.isNotCustomBlockGroup() = when (this) {
Sound.BLOCK_WOOD_PLACE, Sound.BLOCK_WOOD_BREAK, Sound.BLOCK_WOOD_HIT, Sound.BLOCK_WOOD_FALL, Sound.BLOCK_WOOD_STEP -> true
Sound.BLOCK_STONE_PLACE, Sound.BLOCK_STONE_BREAK, Sound.BLOCK_STONE_HIT, Sound.BLOCK_STONE_FALL, Sound.BLOCK_STONE_STEP -> true
Sound.BLOCK_COPPER_PLACE, Sound.BLOCK_COPPER_BREAK, Sound.BLOCK_COPPER_HIT, Sound.BLOCK_COPPER_FALL, Sound.BLOCK_COPPER_STEP -> true
Sound.BLOCK_COPPER_GRATE_PLACE, Sound.BLOCK_COPPER_GRATE_BREAK, Sound.BLOCK_COPPER_GRATE_HIT, Sound.BLOCK_COPPER_GRATE_FALL, Sound.BLOCK_COPPER_GRATE_STEP -> true
else -> false
Sound.BLOCK_WOOD_PLACE, Sound.BLOCK_WOOD_BREAK, Sound.BLOCK_WOOD_HIT, Sound.BLOCK_WOOD_FALL, Sound.BLOCK_WOOD_STEP -> false
Sound.BLOCK_STONE_PLACE, Sound.BLOCK_STONE_BREAK, Sound.BLOCK_STONE_HIT, Sound.BLOCK_STONE_FALL, Sound.BLOCK_STONE_STEP -> false
Sound.BLOCK_COPPER_PLACE, Sound.BLOCK_COPPER_BREAK, Sound.BLOCK_COPPER_HIT, Sound.BLOCK_COPPER_FALL, Sound.BLOCK_COPPER_STEP -> false
Sound.BLOCK_COPPER_GRATE_PLACE, Sound.BLOCK_COPPER_GRATE_BREAK, Sound.BLOCK_COPPER_GRATE_HIT, Sound.BLOCK_COPPER_GRATE_FALL, Sound.BLOCK_COPPER_GRATE_STEP -> false
else -> true
}
}

0 comments on commit ff4b1a5

Please sign in to comment.