Skip to content

Commit 43d02b4

Browse files
committed
ability activation and utils
1 parent 70087c9 commit 43d02b4

File tree

8 files changed

+36
-46
lines changed

8 files changed

+36
-46
lines changed

Diff for: src/main/kotlin/dev/sterner/api/item/ItemAbility.kt

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ enum class ItemAbility(private val equipmentSlot: EquipmentSlot?, private val cl
1919
return this.name.lowercase()
2020
}
2121

22-
23-
2422
fun writeNbt(): CompoundTag {
2523
val tag = CompoundTag()
2624
tag.putString("Ability", name)

Diff for: src/main/kotlin/dev/sterner/api/item/UpgradableAbilityItem.kt

-36
This file was deleted.

Diff for: src/main/kotlin/dev/sterner/client/screen/ItemAbilityScreen.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ItemAbilityScreen(stack: ItemStack) : Screen(Component.literal("Ability Se
7070

7171
val gray = VoidBound.id("textures/gui/ability_selection.png")
7272
RenderSystem.enableBlend()
73-
RenderSystem.setShaderColor(1f, 1f, 1f, if (focus) 7 / 8f else 0f)
73+
RenderSystem.setShaderColor(1f, 1f, 1f, if (focus) 7 / 8f else 0.2f)
7474

7575
guiGraphics.blit(
7676
gray,
@@ -108,7 +108,7 @@ class ItemAbilityScreen(stack: ItemStack) : Screen(Component.literal("Ability Se
108108
if (index == selection) {
109109
guiGraphics.drawCenteredString(
110110
minecraft!!.font,
111-
ability.name.lowercase().replaceFirstChar { it.uppercase() }, // Access ability directly
111+
"voidbound.ability." + ability.name.lowercase(),
112112
abilityX + 24,
113113
y + 34,
114114
0xDDCCFF

Diff for: src/main/kotlin/dev/sterner/common/ItemAbilityHandler.kt

+21-6
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,46 @@ class ItemAbilityHandler {
1515
var selectionScreen: ItemAbilityScreen? = null
1616
var currentAbility: ItemAbility? = ItemAbility.NONE
1717
var active: Boolean = false
18+
private var lastMainHandItem: ItemStack? = null // Track the previous main hand item
1819

1920
init {
2021
currentAbility = ItemAbility.NONE
21-
2222
}
2323

2424
fun tick() {
2525
val mc = Minecraft.getInstance()
26+
27+
// Disable if the player is in spectator mode
2628
if (mc.gameMode != null && mc.gameMode!!.playerMode == GameType.SPECTATOR) {
2729
if (active) {
2830
active = false
2931
}
3032
return
3133
}
32-
val player = mc.player
33-
if (player != null && selectionScreen == null) {
34-
selectionScreen = ItemAbilityScreen(player.mainHandItem)
34+
35+
val player = mc.player ?: return // Return if player is null
36+
val stack = player.mainHandItem
37+
38+
// If the current main hand item has changed, update the selection screen
39+
if (stack != lastMainHandItem) {
40+
lastMainHandItem = stack
41+
42+
// Only create a new screen if the item is not null
43+
if (stack != null) {
44+
selectionScreen = ItemAbilityScreen(stack)
45+
} else {
46+
selectionScreen = null
47+
}
3548
}
36-
val stack = player?.mainHandItem
49+
50+
// If no stack, deactivate the handler
3751
if (stack == null) {
3852
active = false
3953
return
4054
}
55+
4156
init(player)
57+
4258
if (!active) {
4359
return
4460
}
@@ -87,5 +103,4 @@ class ItemAbilityHandler {
87103
}
88104
return false
89105
}
90-
91106
}

Diff for: src/main/kotlin/dev/sterner/common/item/tool/ichor/IchoriumPickaxeItem.kt

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class IchoriumPickaxeItem(material: Tier, damage: Int, speed: Float, magicDamage
3030
return 1
3131
}
3232

33+
override fun use(level: Level, player: Player, usedHand: InteractionHand): InteractionResultHolder<ItemStack> {
34+
//VoidBoundComponentRegistry.VOID_BOUND_REVELATION_COMPONENT.get(player).addUnlockedItemAbility(ItemAbility.DISPERSED_STRIKE)
35+
return super.use(level, player, usedHand)
36+
}
37+
3338
override fun appendHoverText(
3439
stack: ItemStack,
3540
level: Level?,

Diff for: src/main/kotlin/dev/sterner/common/item/tool/ichor/IchoriumSwordItem.kt

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class IchoriumSwordItem(
2323
properties
2424
) {
2525

26+
27+
2628
override fun appendHoverText(
2729
stack: ItemStack,
2830
level: Level?,

Diff for: src/main/resources/assets/voidbound/lang/en_us.json

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
"block.voidbound.osmotic_enchanter": "Osmotic Enchanter",
6060
"itemGroup.voidbound": "Void Bound",
6161

62+
"voidbound.ability.vampirism": "Vampirism",
63+
"voidbound.ability.dispersed_strike": "Dispersed Strike",
64+
"voidbound.ability.autosmelt": "Autosmelt",
65+
"voidbound.ability.quickdraw": "Quickdraw",
66+
"voidbound.ability.slow_fall": "Slow fall",
67+
6268
"entity.voidbound.particle_entity": "Particle",
6369
"entity.voidbound.soul_steel_golem": "Soul Steel Golem",
6470
"entity.voidbound.grimcult_knight": "Grimcult Knight",
Loading

0 commit comments

Comments
 (0)