Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/main/kotlin/com/lambda/module/modules/player/AutoLevel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

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.HotbarRequest
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
import com.lambda.interaction.managers.rotating.RotationManager
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.network.packet.c2s.play.PlayerInteractItemC2SPacket
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..50, description = "Level to automatically use xp bottles until")
var burstAmount by setting("Burst Amount", 1, 1..10, description = "Amount of xp bottles to use each tick")
var interval by setting("Interval", 5, 0..100, unit = "ticks", description = "Interval between each burst of xp bottles")

var rotate by setting("Rotate", true)
var packetRotate by setting("Packet Rotate", true)

val timer = Timer()

init {
setDefaultAutomationConfig {
applyEdits {
hideGroups(eatConfig, buildConfig, breakConfig, interactConfig, inventoryConfig)
hotbarConfig::tickStageMask.edit {
defaultValue(mutableSetOf(TickEvent.Pre, TickEvent.Input.Post))
}
}
}
listen<TickEvent.Pre> {
if (player.experienceLevel >= targetLevel) return@listen

if (rotate && !packetRotate)
rotationRequest {
pitch(90f)
}.submit()
if (timer.timePassed((50 * interval).milliseconds)) {
withXp {
var pitch = if (rotate) 90f else RotationManager.activeRotation.pitch.toFloat()
var yaw = RotationManager.activeRotation.yaw.toFloat()
repeat(burstAmount) {
interaction.sendSequencedPacket(world) { seq ->
PlayerInteractItemC2SPacket(Hand.MAIN_HAND, seq, yaw, pitch)
}
}
timer.reset()
}
}
}
}

private fun SafeContext.withXp(block: () -> Unit) {
if (player.mainHandStack?.item == Items.EXPERIENCE_BOTTLE) {
block()
return
}
val hotbarSlot = StackSelection.selectStack(count = 1) {
isItem<ExperienceBottleItem>()
}.filterSlots(HotbarContainer.slots).firstOrNull() ?: return
val done = HotbarRequest(
hotbarSlot.index,
this@AutoLevel
).submit(queueIfMismatchedStage = false).done
if (done) block()
}
}