diff options
author | inglettronald <inglettronald@gmail.com> | 2023-07-17 03:27:35 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-07-17 03:27:35 -0500 |
commit | d21dad73e37c1aaba1933a52b094534865594dc7 (patch) | |
tree | 33e825fe82ea3435a2c49c2ff8063e2f5d75752d | |
parent | 1a8e45d8519a8ae69e14db8ea103a7fdf7b80923 (diff) | |
download | DulkirMod-Fabric-d21dad73e37c1aaba1933a52b094534865594dc7.tar.gz DulkirMod-Fabric-d21dad73e37c1aaba1933a52b094534865594dc7.tar.bz2 DulkirMod-Fabric-d21dad73e37c1aaba1933a52b094534865594dc7.zip |
finished infrastructure for Durability-based cooldown displays that use sounds
3 files changed, 18 insertions, 8 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/ItemMixin.java b/src/main/java/com/dulkirfabric/mixin/ItemMixin.java index 53e637e..13e1456 100644 --- a/src/main/java/com/dulkirfabric/mixin/ItemMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/ItemMixin.java @@ -1,5 +1,6 @@ package com.dulkirfabric.mixin; +import com.dulkirfabric.config.DulkirConfig; import com.dulkirfabric.features.CooldownDisplays; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -14,11 +15,13 @@ public class ItemMixin { @Inject(method = "isItemBarVisible(Lnet/minecraft/item/ItemStack;)Z", at = @At("HEAD"), cancellable = true) public void shouldDisplayDurabilityBar(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { - CooldownDisplays.INSTANCE.shouldDisplay(stack, cir); + if (DulkirConfig.ConfigVars.getConfigOptions().getDuraCooldown()) + CooldownDisplays.INSTANCE.shouldDisplay(stack, cir); } @Inject(method = "getItemBarStep(Lnet/minecraft/item/ItemStack;)I", at = @At("HEAD"), cancellable = true) public void calculateItemHealth(ItemStack stack, CallbackInfoReturnable<Integer> cir) { - CooldownDisplays.INSTANCE.calcDurability(stack, cir); + if (DulkirConfig.ConfigVars.getConfigOptions().getDuraCooldown()) + CooldownDisplays.INSTANCE.calcDurability(stack, cir); } } diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index 75bd592..3407738 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -104,6 +104,9 @@ class DulkirConfig { general.addEntry( entryBuilder.mkToggle(Text.literal("Disable Explosion Particles"), configOptions::disableExplosionParticles) ) + general.addEntry( + entryBuilder.mkToggle(Text.literal("Durability-Based Cooldown Display"), configOptions::duraCooldown) + ) val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts")) shortcuts.addEntry( @@ -160,7 +163,8 @@ class DulkirConfig { var tooltipScale: Float = 1f, var statusEffectHidden: Boolean = false, var inactiveEffigyDisplay: Boolean = false, - var disableExplosionParticles: Boolean = false + var disableExplosionParticles: Boolean = false, + var duraCooldown: Boolean = false ) @Serializable diff --git a/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt index 86a3863..2188bf4 100644 --- a/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt +++ b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt @@ -1,5 +1,6 @@ package com.dulkirfabric.features +import com.dulkirfabric.config.DulkirConfig import com.dulkirfabric.events.PlaySoundEvent import com.dulkirfabric.events.WorldLoadEvent import com.dulkirfabric.util.SoundInfo @@ -7,31 +8,32 @@ import com.dulkirfabric.util.TrackedCooldown import meteordevelopment.orbit.EventHandler import net.minecraft.item.ItemStack import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable +import kotlin.math.round object CooldownDisplays { private val trackedCooldowns: Map<SoundInfo, TrackedCooldown> = mapOf( Pair( - SoundInfo("mob.zombie.remedy", 1f, .5f), + SoundInfo("entity.zombie_villager.cure", 1f, .5f), TrackedCooldown("(REAPER_CHESTPLATE)|(REAPER_LEGGINGS)|(REAPER_BOOTS)".toRegex(), 25000, 0) ), Pair( - SoundInfo("mob.zombie.remedy", 0.6984127f, 1f), + SoundInfo("entity.zombie_villager.cure", 0.6984127f, 1f), TrackedCooldown("(HYPERION|ASTRAEA|SCYLLA|VALKYRIE)".toRegex(), 5000, 0) ) ) fun shouldDisplay(stack: ItemStack, cir: CallbackInfoReturnable<Boolean>) { val cooldown = fetchCooldownItem(stack) ?: return - cir.returnValue = true - // cir.returnValue = System.currentTimeMillis() - cooldown.lastUsage < cooldown.cooldownDuration + cir.returnValue = System.currentTimeMillis() - cooldown.lastUsage < cooldown.cooldownDuration } fun calcDurability(stack: ItemStack, cir: CallbackInfoReturnable<Int>) { val cooldown = fetchCooldownItem(stack) ?: return - cir.returnValue = 300 + cir.returnValue = round(13f * (System.currentTimeMillis() - cooldown.lastUsage) / cooldown.cooldownDuration).toInt() } @EventHandler fun onSound(event: PlaySoundEvent) { + if (!DulkirConfig.configOptions.duraCooldown) return val path = event.sound.id.path val pitch = event.sound.pitch val volume = event.sound.volume @@ -43,6 +45,7 @@ object CooldownDisplays { @EventHandler fun onWorldLoad(event: WorldLoadEvent) { + if (!DulkirConfig.configOptions.duraCooldown) return trackedCooldowns.forEach { it.value.lastUsage = 0 } |