Skip to content

Commit c895f16

Browse files
committed
item ability selection remembers index on reopen
1 parent 6e2b01b commit c895f16

File tree

3 files changed

+7
-49
lines changed

3 files changed

+7
-49
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class ItemAbilityScreen(stack: ItemStack) : Screen(Component.literal("Ability Se
3737
val compatibleAbilities = ItemAbility.getAvailableAbilitiesFromItem(stack.item)
3838
val unlockedAbilities = VoidBoundComponentRegistry.VOID_BOUND_REVELATION_COMPONENT.get(minecraft!!.player!!).unlockedItemAbilities
3939
abilities = compatibleAbilities.intersect(unlockedAbilities)
40+
41+
val activeAbility = VoidBoundApi.getActiveAbility(stack)
42+
if (activeAbility != null && abilities!!.isNotEmpty()) {
43+
selection = abilities!!.indexOfFirst { it.name == activeAbility.name }.takeIf { it >= 0 } ?: 0
44+
}
4045
}
4146

4247
fun cycle(direction: Int) {
@@ -120,7 +125,7 @@ class ItemAbilityScreen(stack: ItemStack) : Screen(Component.literal("Ability Se
120125

121126
matrixStack.popPose()
122127
}
123-
128+
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
124129
RenderSystem.disableBlend()
125130
matrixStack.popPose()
126131
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class VoidBoundRevelationComponent(private val player: Player) : AutoSyncedCompo
2020
var unlockedItemAbilities = defaultAbilities()
2121

2222
private fun defaultAbilities(): MutableSet<ItemAbility> {
23-
return mutableSetOf(ItemAbility.NONE, ItemAbility.MINING_3X3, ItemAbility.HARVEST)
23+
return mutableSetOf(ItemAbility.NONE, ItemAbility.MINING_3X3, ItemAbility.HARVEST, ItemAbility.AUTOSMELT)
2424
}
2525

2626
fun addUnlockedItemAbility(ability: ItemAbility) {

Diff for: src/main/kotlin/dev/sterner/registry/VoidBoundEvents.kt

-47
Original file line numberDiff line numberDiff line change
@@ -42,54 +42,7 @@ object VoidBoundEvents {
4242
BlockEvents.BLOCK_BREAK.register(VoidBoundWorldComponent.Companion::removeWard)
4343
BlockEvents.BLOCK_BREAK.register(TidecutterItem.Companion::breakBlock)
4444

45-
BlockEvents.BLOCK_BREAK.register { event ->
46-
val player = event?.player
4745

48-
if (player?.level() is ServerLevel) {
49-
val level = player.level() as? ServerLevel
50-
val pos = event.pos
51-
if (VoidBoundApi.getActiveAbility(player.mainHandItem) == ItemAbility.AUTOSMELT) {
52-
val blockState = level!!.getBlockState(pos)
53-
val blockEntity = level.getBlockEntity(pos)
54-
55-
// Get the list of dropped items from the block
56-
val drops: MutableList<ItemStack> = Block.getDrops(blockState, level, pos, blockEntity)
57-
58-
// Retrieve all smelting recipes
59-
val allSmeltingRecipes = level.recipeManager.getAllRecipesFor(RecipeType.SMELTING)
60-
61-
// Create a map of ItemStack to its smelted result
62-
val smeltedResults = mutableMapOf<ItemStack, ItemStack>()
63-
64-
// Populate the smeltedResults map
65-
for (recipe in allSmeltingRecipes) {
66-
if (recipe is SmeltingRecipe) {
67-
for (ingredient in recipe.ingredients) {
68-
val smeltedResult = recipe.getResultItem(level.registryAccess())
69-
for (item in drops) {
70-
if (ingredient.test(item)) {
71-
smeltedResults[item] = smeltedResult
72-
}
73-
}
74-
}
75-
}
76-
}
77-
78-
// Drop smelted items instead of original items
79-
for ((item, smeltedResult) in smeltedResults) {
80-
// Remove the original item from the list
81-
drops.remove(item)
82-
// Drop the smelted result
83-
Block.popResource(level, pos, smeltedResult)
84-
}
85-
86-
// Drop the original items that didn't have a smelting recipe
87-
for (item in drops) {
88-
Block.popResource(level, pos, item)
89-
}
90-
}
91-
}
92-
}
9346

9447
/**
9548
* Add extra damage to UpgradableTools when it has extra damage

0 commit comments

Comments
 (0)