From 996ecb55b71c7b5c0d276a8bc7ed3a8dadbdfdaa Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Sun, 22 Mar 2026 19:31:35 +0100 Subject: [PATCH] Add AutoLevel module --- .../managers/hotbar/HotbarManager.kt | 4 + .../lambda/module/modules/player/AutoLevel.kt | 83 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/main/kotlin/com/lambda/module/modules/player/AutoLevel.kt diff --git a/src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarManager.kt b/src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarManager.kt index 4bc8bcca9..22e00e5ec 100644 --- a/src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarManager.kt +++ b/src/main/kotlin/com/lambda/interaction/managers/hotbar/HotbarManager.kt @@ -28,6 +28,7 @@ import com.lambda.interaction.managers.hotbar.HotbarManager.activeSlot import com.lambda.interaction.managers.hotbar.HotbarManager.checkResetSwap import com.lambda.interaction.managers.hotbar.HotbarManager.setActiveRequest import com.lambda.interaction.managers.hotbar.HotbarManager.setActiveSlot +import com.lambda.interaction.material.container.containers.HotbarContainer import com.lambda.threading.runSafe import net.minecraft.item.ItemStack @@ -54,6 +55,9 @@ object HotbarManager : Manager( val serverSlot get() = runSafe { interaction.lastSelectedSlot } ?: -1 + val currentSlot get() = runSafe { + if (serverSlot != -1) HotbarContainer.slots[serverSlot] else null + } //ToDo: something to manage stacks so the hotbar manager is strictly index based private var previousStack: ItemStack? = null private var swappedTicks = 0 diff --git a/src/main/kotlin/com/lambda/module/modules/player/AutoLevel.kt b/src/main/kotlin/com/lambda/module/modules/player/AutoLevel.kt new file mode 100644 index 000000000..381ef7dc2 --- /dev/null +++ b/src/main/kotlin/com/lambda/module/modules/player/AutoLevel.kt @@ -0,0 +1,83 @@ +/* + * Copyright 2026 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.module.modules.player + +import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig +import com.lambda.config.applyEdits +import com.lambda.context.SafeContext +import com.lambda.event.events.TickEvent +import com.lambda.event.listener.SafeListener.Companion.listen +import com.lambda.interaction.managers.hotbar.HotbarManager +import com.lambda.interaction.managers.hotbar.HotbarRequest +import com.lambda.interaction.material.StackSelection +import com.lambda.interaction.material.container.containers.HotbarContainer +import com.lambda.module.Module +import com.lambda.module.tag.ModuleTag +import com.lambda.util.Timer +import net.minecraft.item.ExperienceBottleItem +import net.minecraft.item.Items +import net.minecraft.util.Hand +import kotlin.time.Duration.Companion.milliseconds + + +object AutoLevel : Module( + name = "AutoLevel", + description = "Automatically uses xp bottles to level up to a certain level", + tag = ModuleTag.PLAYER +) { + var targetLevel by setting("Target Level", 2, 1..100) + var burstAmount by setting("Burst Amount", 5, 1..100) + var interval by setting("Interval", 5, 0..100, unit = "ticks") + + val timer = Timer() + + init { + setDefaultAutomationConfig { + applyEdits { + hideGroup(eatConfig) + hotbarConfig::tickStageMask.edit { + defaultValue(mutableSetOf(TickEvent.Pre, TickEvent.Input.Post)) + } + } + } + listen { + if (player.experienceLevel >= targetLevel) return@listen + + if (timer.timePassed((50 * interval).milliseconds)) { + withXp { + repeat(burstAmount) { + interaction.interactItem(mc.player, Hand.MAIN_HAND) + } + timer.reset() + } + } + } + } + + private fun SafeContext.withXp(block: () -> Unit) { + if (HotbarManager.currentSlot?.stack?.item == Items.EXPERIENCE_BOTTLE) { + block() + return + } + val hotbarSlot = StackSelection.selectStack(count = 1) { isItem() }.filterSlots(HotbarContainer.slots).firstOrNull() ?: return + HotbarRequest( + hotbarSlot.index, + this@AutoLevel + ).submit(queueIfMismatchedStage = false).also { if (it.done) block() } + } +} \ No newline at end of file