diff options
author | inglettronald <inglettronald@gmail.com> | 2023-06-13 23:49:28 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-06-13 23:49:28 -0500 |
commit | 819ec8b8355f7400e8cf38a0a5b64c5f6dd0a2f8 (patch) | |
tree | 44b62bd6ef3586110a593bb640ec1008b09e4611 /src/main/kotlin/dulkirmod/features/ReaperDisplay.kt | |
parent | 0cecb959a9ac5b261e9f5f9c855e86393843ab0d (diff) | |
download | DulkirMod-819ec8b8355f7400e8cf38a0a5b64c5f6dd0a2f8.tar.gz DulkirMod-819ec8b8355f7400e8cf38a0a5b64c5f6dd0a2f8.tar.bz2 DulkirMod-819ec8b8355f7400e8cf38a0a5b64c5f6dd0a2f8.zip |
some cooldown displays
Diffstat (limited to 'src/main/kotlin/dulkirmod/features/ReaperDisplay.kt')
-rw-r--r-- | src/main/kotlin/dulkirmod/features/ReaperDisplay.kt | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main/kotlin/dulkirmod/features/ReaperDisplay.kt b/src/main/kotlin/dulkirmod/features/ReaperDisplay.kt new file mode 100644 index 0000000..3fd743d --- /dev/null +++ b/src/main/kotlin/dulkirmod/features/ReaperDisplay.kt @@ -0,0 +1,52 @@ +package dulkirmod.features + +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound +import net.minecraftforge.client.event.sound.PlaySoundEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable +import kotlin.math.min + +object ReaperDisplay { + + var lastReaperUsage = 0L + + fun shouldDisplay(stack: ItemStack, cir: CallbackInfoReturnable<Boolean>) { + if (!isReaper(stack)) return + cir.returnValue = System.currentTimeMillis() - lastReaperUsage < 25000 + } + + fun calcDurability(stack: ItemStack, cir: CallbackInfoReturnable<Double>) { + if (!isReaper(stack)) return + val time = (System.currentTimeMillis() - lastReaperUsage) / 25000.0 + cir.returnValue = min(1.0, 1.0 - time) + } + + @SubscribeEvent + fun onSound(event: PlaySoundEvent) { + if (event.name != "mob.zombie.remedy") return + if (event.sound.pitch != 1.0f) return + if (event.sound.volume != .5f) return + lastReaperUsage = System.currentTimeMillis() + } + + @SubscribeEvent + fun onWorldLoad(event: WorldEvent) { + lastReaperUsage = 0L + } + + private fun isReaper(stack: ItemStack): Boolean { + if (stack.hasTagCompound()) { + val tag: NBTTagCompound = stack.tagCompound + if (tag.hasKey("ExtraAttributes", 10) && tag.hasKey("display", 10)) { + val ea: NBTTagCompound = tag.getCompoundTag("ExtraAttributes") + if (ea.hasKey("id", 8)) { + val id = ea.getString("id") + return id matches "(REAPER_CHESTPLATE)|(REAPER_LEGGINGS)|(REAPER_BOOTS)".toRegex() + } + } + } + return false + } +}
\ No newline at end of file |