1
1
package dev.sterner.client.screen
2
2
3
+ import com.mojang.blaze3d.systems.RenderSystem
4
+ import dev.sterner.VoidBound
3
5
import dev.sterner.api.VoidBoundApi
4
6
import dev.sterner.api.item.ItemAbility
5
7
import net.minecraft.client.Minecraft
8
+ import net.minecraft.client.gui.GuiGraphics
6
9
import net.minecraft.client.gui.screens.Screen
7
10
import net.minecraft.network.chat.Component
8
11
import net.minecraft.world.item.ItemStack
@@ -27,8 +30,8 @@ class ItemAbilityScreen(stack: ItemStack) : Screen(Component.literal("Ability Se
27
30
selection = 0
28
31
initialized = false
29
32
30
- w = max((abilities !! .size * 50 + 30 ).toDouble(), 220.0 ).toInt()
31
- h = 30
33
+ w = 180
34
+ h = 37
32
35
}
33
36
34
37
fun cycle (direction : Int ) {
@@ -38,9 +41,80 @@ class ItemAbilityScreen(stack: ItemStack) : Screen(Component.literal("Ability Se
38
41
39
42
fun update () {
40
43
if (focus) {
41
- yOffset + = (40 - yOffset) * .1f
44
+ yOffset + = (85 - yOffset) * .1f
42
45
} else {
43
46
yOffset * = .9f
44
47
}
45
48
}
49
+
50
+ fun render (guiGraphics : GuiGraphics , partialTick : Float ) {
51
+
52
+ if (abilities == null ) {
53
+ return
54
+ }
55
+
56
+ val matrixStack = guiGraphics.pose()
57
+ val mainWindow = minecraft!! .window
58
+ val x = (mainWindow.guiScaledWidth - w) / 2 + 15
59
+ val y = mainWindow.guiScaledHeight - h + 20
60
+
61
+ matrixStack.pushPose()
62
+ matrixStack.translate(0f , 20 - yOffset, (if (focus) 100 else 0 ).toFloat())
63
+
64
+ val gray = VoidBound .id(" textures/gui/ability_selection.png" )
65
+ RenderSystem .enableBlend()
66
+ RenderSystem .setShaderColor(1f , 1f , 1f , if (focus) 7 / 8f else 0f )
67
+
68
+ guiGraphics.blit(
69
+ gray,
70
+ x - 15 ,
71
+ y,
72
+ 0f ,
73
+ 0f ,
74
+ w,
75
+ h,
76
+ 256 ,
77
+ 256
78
+ )
79
+
80
+ val abilityWidth = 50 // Width of one ability + some space
81
+ val totalWidth = abilities!! .size * abilityWidth
82
+
83
+ val startX = (mainWindow.guiScaledWidth - totalWidth) / 2
84
+
85
+ for (i in abilities!! .indices) {
86
+ RenderSystem .enableBlend()
87
+ matrixStack.pushPose()
88
+
89
+ val alpha = if (focus) 1f else 0.2f
90
+
91
+ if (i == selection) {
92
+ matrixStack.translate(0f , - 10f , 0f )
93
+ } else {
94
+ matrixStack.translate(0f , - 5f , 0f )
95
+ }
96
+
97
+ RenderSystem .setShaderColor(1f , 1f , 1f , alpha)
98
+
99
+ val abilityX = startX + i * abilityWidth
100
+
101
+ if (i == selection) {
102
+ guiGraphics.drawCenteredString(
103
+ minecraft!! .font,
104
+ abilities!! [i].name.lowercase().replaceFirstChar { it.uppercase() },
105
+ abilityX + 24 ,
106
+ y + 32 ,
107
+ 0xDDCCFF
108
+ )
109
+ }
110
+
111
+ val texture = VoidBound .id(" textures/gui/" + abilities!! [i].name.lowercase() + " .png" )
112
+ guiGraphics.blit(texture, abilityX + 16 , y + 16 , 0 , 0f , 0f , 16 , 16 , 16 , 16 )
113
+
114
+ matrixStack.popPose()
115
+ }
116
+
117
+ RenderSystem .disableBlend()
118
+ matrixStack.popPose()
119
+ }
46
120
}
0 commit comments