aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features
diff options
context:
space:
mode:
authorOwen <64725743+Ownwn@users.noreply.github.com>2023-04-17 20:27:15 +1200
committerOwen <64725743+Ownwn@users.noreply.github.com>2023-04-17 20:27:15 +1200
commit7e04cb28e30978f58519ad95d82ea33ea719fa29 (patch)
treea32a1a9dbe7892444385efa0c5cfb809805b5518 /src/main/kotlin/dulkirmod/features
parente933913ebe88f6b465ee862374bbd26c57906cae (diff)
downloadDulkirMod-7e04cb28e30978f58519ad95d82ea33ea719fa29.tar.gz
DulkirMod-7e04cb28e30978f58519ad95d82ea33ea719fa29.tar.bz2
DulkirMod-7e04cb28e30978f58519ad95d82ea33ea719fa29.zip
Added an option to play a sound when clicking a secret in dungeons
Diffstat (limited to 'src/main/kotlin/dulkirmod/features')
-rw-r--r--src/main/kotlin/dulkirmod/features/SecretSounds.kt60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/kotlin/dulkirmod/features/SecretSounds.kt b/src/main/kotlin/dulkirmod/features/SecretSounds.kt
new file mode 100644
index 0000000..5bbbb48
--- /dev/null
+++ b/src/main/kotlin/dulkirmod/features/SecretSounds.kt
@@ -0,0 +1,60 @@
+package dulkirmod.features
+
+import dulkirmod.DulkirMod.Companion.mc
+import dulkirmod.config.DulkirConfig
+import dulkirmod.utils.TabListUtils.isInDungeons
+import net.minecraft.block.Block
+import net.minecraft.init.Blocks
+import net.minecraft.tileentity.TileEntitySkull
+import net.minecraftforge.event.entity.player.PlayerInteractEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object SecretSounds {
+ private var lastSound: Long = 0L
+ @SubscribeEvent
+ fun onInteract(event: PlayerInteractEvent) {
+ if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
+ return
+ }
+ if (!DulkirConfig.secretClickSounds) {
+ return
+ }
+ if (!isInDungeons) {
+ return
+ }
+
+
+ val blockType: Block = mc.theWorld.getBlockState(event.pos).block ?: return // get the type of block
+
+ if (blockType != Blocks.chest && blockType != Blocks.trapped_chest && blockType != Blocks.skull && blockType != Blocks.lever) { // check if it's a secret
+ return
+ }
+
+ if (blockType == Blocks.skull) { // it may be a wither essence skull
+ var skullId: String? = null
+
+ try {
+ skullId = (mc.theWorld.getTileEntity(event.pos) as TileEntitySkull).playerProfile.id.toString()
+
+ } catch (ignored: NullPointerException) {} // it doesn't have a playerID
+
+
+ if (skullId == null || skullId != "26bb1a8d-7c66-31c6-82d5-a9c04c94fb02") { // check if it is a wither essence player head
+ return
+ }
+
+ }
+ playSound()
+ }
+
+ private fun playSound() {
+ if (System.currentTimeMillis() - lastSound > 50) { // don't kill ears
+ mc.thePlayer.playSound(
+ "random.break",
+ 1f * DulkirConfig.secretSoundVolume,
+ 1f
+ )
+ lastSound = System.currentTimeMillis()
+ }
+ }
+} \ No newline at end of file