Make pressing enter in essence storage text field also set player level right away

This commit is contained in:
DBotThePony 2023-07-26 17:06:36 +07:00
parent 138627f8de
commit 0724d35b50
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 22 additions and 0 deletions

View File

@ -650,6 +650,10 @@ open class TextInputPanel<out S : Screen>(
return true return true
} }
open fun onEnter() {
}
override fun keyPressedInternal(key: Int, scancode: Int, mods: Int): Boolean { override fun keyPressedInternal(key: Int, scancode: Int, mods: Int): Boolean {
if (key == InputConstants.KEY_ESCAPE || !isActive) { if (key == InputConstants.KEY_ESCAPE || !isActive) {
killFocus() killFocus()
@ -706,6 +710,7 @@ open class TextInputPanel<out S : Screen>(
} else { } else {
killFocus() killFocus()
triggerChangeCallback() triggerChangeCallback()
onEnter()
return true return true
} }
} }

View File

@ -7,6 +7,7 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.client.isShiftDown import ru.dbotthepony.mc.otm.client.isShiftDown
import ru.dbotthepony.mc.otm.client.playGuiClickSound
import ru.dbotthepony.mc.otm.client.render.sprites.MatteryAtlas import ru.dbotthepony.mc.otm.client.render.sprites.MatteryAtlas
import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
@ -205,6 +206,22 @@ class EssenceStorageScreen(menu: EssenceStorageMenu, inventory: Inventory, title
text = customDispense.toString() text = customDispense.toString()
} }
override fun onEnter() {
val player = minecraft?.player ?: return
if (player.experienceLevel == customDispense) {
if (player.experienceProgress > 0f) {
menu.storeLevels.input(1)
}
} else if (player.experienceLevel > customDispense) {
menu.storeLevels.input(player.experienceLevel - customDispense)
} else {
menu.dispenseLevels.input(customDispense - player.experienceLevel)
}
playGuiClickSound()
}
override fun onTextChanged(old: String, new: String) { override fun onTextChanged(old: String, new: String) {
customDispense = (new.toIntOrNull() ?: 30).coerceAtLeast(1) customDispense = (new.toIntOrNull() ?: 30).coerceAtLeast(1)
} }