1
+ package dev.sterner.client.event
2
+
3
+ import com.mojang.blaze3d.systems.RenderSystem
4
+ import com.sammy.malum.common.components.MalumComponents
5
+ import com.sammy.malum.common.components.MalumPlayerDataComponent
6
+ import dev.sterner.VoidBound
7
+ import dev.sterner.api.item.ItemAbility
8
+ import dev.sterner.api.util.VoidBoundItemUtils
9
+ import dev.sterner.registry.VoidBoundComponentRegistry
10
+ import net.minecraft.client.Minecraft
11
+ import net.minecraft.client.gui.GuiGraphics
12
+ import net.minecraft.client.renderer.GameRenderer
13
+ import net.minecraft.util.Mth
14
+ import net.minecraft.world.entity.ai.attributes.Attributes
15
+ import team.lodestar.lodestone.systems.rendering.VFXBuilders
16
+ import kotlin.math.max
17
+ import kotlin.math.min
18
+
19
+ object WrathHudRenderEvent {
20
+
21
+ fun renderWrathBar (guiGraphics : GuiGraphics , partialTick : Float ) {
22
+ val minecraft = Minecraft .getInstance()
23
+ if (minecraft.player == null ) {
24
+ return
25
+ }
26
+
27
+ val comp = VoidBoundComponentRegistry .VOID_BOUND_PLAYER_ITEM_ABILITY_COMPONENT .get(minecraft.player!! )
28
+
29
+ val wrath = comp.getWrath()
30
+
31
+ val ability = VoidBoundItemUtils .getActiveAbility(minecraft.player!! .mainHandItem)
32
+ if (ability != ItemAbility .FINALE && ability != ItemAbility .OPENER ) {
33
+ return
34
+ }
35
+
36
+ if (wrath <= 0 ) {
37
+ return
38
+ }
39
+
40
+ val window = minecraft.window
41
+ val player = minecraft.player!!
42
+
43
+ if (player.isCreative() || player.isSpectator()) {
44
+ return
45
+ }
46
+
47
+ val absorb = Mth .ceil(player.absorptionAmount).toFloat()
48
+ val maxHealth: Float = player.getAttribute(Attributes .MAX_HEALTH )!! .getValue().toFloat()
49
+ val armor: Float = player.getAttribute(Attributes .ARMOR )!! .getValue().toFloat()
50
+ val left = window.guiScaledWidth / 2 - 89
51
+ var top = window.guiScaledHeight - 45
52
+ if (armor == 0.0f ) {
53
+ top + = 4
54
+ }
55
+ val soulWardHandler = MalumComponents .MALUM_PLAYER_COMPONENT [player].soulWardHandler
56
+ val soulWard = if (soulWardHandler.soulWard > 0 ) - 9 else 0
57
+
58
+ val poseStack = guiGraphics.pose()
59
+ val healthRows = Mth .ceil((maxHealth + absorb) / 2.0f / 10.0f )
60
+ val rowHeight = max((10 - (healthRows - 2 )).toDouble(), 3.0 ).toInt() + soulWard
61
+
62
+ poseStack.pushPose()
63
+ RenderSystem .setShaderTexture(0 , VoidBound .id(" textures/gui/wrath_empty.png" ))
64
+ RenderSystem .depthMask(true )
65
+ RenderSystem .enableBlend()
66
+ RenderSystem .defaultBlendFunc()
67
+ val builder = VFXBuilders .createScreen().setPosColorTexDefaultFormat()
68
+ .setShader { GameRenderer .getPositionColorTexShader() }
69
+
70
+ for (i in 0 until 10 ) {
71
+ val row = (i.toFloat() / 10.0f ).toInt()
72
+ val x = left + i % 10 * 8
73
+ val y = top - row * 4 + rowHeight * 2 - 15
74
+ builder.setPositionWithWidth((x - 2 ).toFloat(), (y - 2 ).toFloat(), 9f , 9f )
75
+ .setUVWithWidth(0f ,0f ,9f ,9f ,9f ,9f )
76
+ .draw(poseStack)
77
+ }
78
+
79
+ RenderSystem .setShaderTexture(0 , VoidBound .id(" textures/gui/wrath_full.png" ))
80
+ for (i in 0 until wrath) {
81
+ val row = (i.toFloat() / 10.0f ).toInt()
82
+ val x = left + i % 10 * 8
83
+ val y = top - row * 4 + rowHeight * 2 - 15
84
+ builder.setPositionWithWidth((x - 2 ).toFloat(), (y - 2 ).toFloat(), 9f , 9f )
85
+ .setUVWithWidth(0f ,0f ,9f ,9f ,9f ,9f )
86
+ .draw(poseStack)
87
+ }
88
+
89
+ RenderSystem .depthMask(true )
90
+ RenderSystem .disableBlend()
91
+ poseStack.popPose()
92
+ }
93
+ }
0 commit comments