draw shields cooldown

This commit is contained in:
YuRaNnNzZZ 2023-10-30 08:30:30 +03:00
parent 55363f5f6a
commit 9d882d2351
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D
2 changed files with 33 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package ru.dbotthepony.mc.otm.client
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.gui.Font
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Button
import net.minecraft.client.gui.screens.DeathScreen
import net.minecraft.client.gui.screens.InBedChatScreen
@ -10,11 +12,14 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.ShieldItem
import net.minecraftforge.client.event.RenderGuiEvent
import net.minecraftforge.client.event.RenderGuiOverlayEvent
import net.minecraftforge.client.event.ScreenEvent
import net.minecraftforge.client.gui.overlay.ForgeGui
import net.minecraftforge.client.gui.overlay.GuiOverlayManager
import net.minecraftforge.common.ToolActions
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.android.feature.NanobotsArmorFeature
import ru.dbotthepony.mc.otm.core.TranslatableComponent
@ -31,6 +36,7 @@ import ru.dbotthepony.mc.otm.core.util.formatPower
import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.*
import kotlin.math.PI
import kotlin.math.ceil
object MatteryGUI {
@ -346,4 +352,22 @@ object MatteryGUI {
renderPlayerHealth(event, gui)
}
}
fun renderShieldCooldownOverlay(graphics: GuiGraphics, font: Font, stack: ItemStack, x: Int, y: Int): Boolean {
if (!stack.isEmpty && stack.item is ShieldItem) {
if (!stack.canPerformAction(ToolActions.SHIELD_BLOCK)) return false
val ply = minecraft.player ?: return false
if (!ply.isUsingItem || stack != ply.useItem || ply.isBlocking) return false
val percent = ((stack.item.getUseDuration(stack) - ply.useItemRemainingTicks) / 5f).coerceIn(0f, 1f)
RenderSystem.setShaderColor(1f, 1f, 1f, 0.5f)
drawArc(graphics, x + 8f, y + 8f, 8f, 0f, PI / 2.0, PI / 2.0 + PI * 2.0 * percent, alignAtCenter = true)
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
return true
}
return false
}
}

View File

@ -5,12 +5,12 @@ import com.google.common.collect.Streams
import net.minecraft.advancements.CriteriaTriggers
import net.minecraft.client.renderer.item.ItemProperties
import net.minecraft.core.BlockPos
import net.minecraft.core.Registry
import net.minecraft.core.registries.Registries
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.ai.village.poi.PoiType
import net.minecraft.world.entity.ai.village.poi.PoiTypes
import net.minecraft.world.item.Items
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.block.*
import net.minecraft.world.level.block.state.BlockBehaviour
@ -19,6 +19,7 @@ import net.minecraft.world.level.block.state.properties.NoteBlockInstrument
import net.minecraft.world.level.material.MapColor
import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.client.event.RegisterColorHandlersEvent
import net.minecraftforge.client.event.RegisterItemDecorationsEvent
import net.minecraftforge.client.model.DynamicFluidContainerModel
import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
@ -37,6 +38,7 @@ import ru.dbotthepony.mc.otm.android.feature.NanobotsArmorFeature
import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock
import ru.dbotthepony.mc.otm.block.decorative.TritaniumPressurePlate
import ru.dbotthepony.mc.otm.capability.matteryEnergy
import ru.dbotthepony.mc.otm.client.MatteryGUI
import ru.dbotthepony.mc.otm.compat.vanilla.MatteryChestMenu
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.data.DecimalProvider
@ -256,6 +258,7 @@ object MRegistry {
bus.addListener(MStats::registerVanilla)
bus.addListener(this::registerEvent)
bus.addListener(this::registerItemColorHandlers)
bus.addListener(this::registerItemDecorators)
MCreativeTabs.initialize(bus)
@ -353,4 +356,9 @@ object MRegistry {
private fun registerItemColorHandlers(event: RegisterColorHandlersEvent.Item) {
event.register(DynamicFluidContainerModel.Colors(), MItems.FLUID_CAPSULE)
}
private fun registerItemDecorators(event: RegisterItemDecorationsEvent) {
event.register(Items.SHIELD, MatteryGUI::renderShieldCooldownOverlay)
event.register(MItems.TRITANIUM_SHIELD, MatteryGUI::renderShieldCooldownOverlay)
}
}