← 输入框|github.com|刷新
Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ val replacements = file("gradle.properties").inputStream().use { stream ->
}.map { (k, v) -> k.toString() to v.toString() }.toMap().toMutableMap()

plugins {
kotlin("jvm") version "2.3.0"
kotlin("jvm") version "2.3.21"
id("org.jetbrains.dokka") version "2.1.0"
id("fabric-loom") version "1.17-SNAPSHOT"
id("com.gradleup.shadow") version "9.3.0"
Expand Down Expand Up @@ -237,6 +237,8 @@ tasks {
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xcontext-parameters", "-Xconsistent-data-class-copy-visibility", "-Xannotation-default-target=param-property")
// DSL markers on functions are kept for IDE highlighting, https://youtrack.jetbrains.com/issue/KT-83668
freeCompilerArgs.add("-Xwarning-level=DSL_MARKER_APPLIED_TO_WRONG_TARGET:disabled")
}

jvmToolchain(21)
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ modAuthors=Constructor (Avanatiker), Blade, beanbag44, Emy
minecraftVersion=1.21.11
lwjglVersion=3.3.3
mixinExtrasVersion=0.5.0
kotlinVersion=2.3.0
kotlinVersion=2.3.21
pngEncoderVersion=0.16.0
javaVersion=21
baritoneVersion=1.14.0
Expand All @@ -43,7 +43,7 @@ spairVersion=1.90.0
fabricLoaderVersion=0.19.5
yarnMappings=build.6
fabricApiVersion=0.141.6
kotlinFabricVersion=1.13.8+kotlin
kotlinFabricVersion=1.13.11+kotlin
sodiumVersion=mc1.21.11-0.8.7-fabric
litematicaVersion=0.26.11
maLiLibVersion=0.27.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ open class AutomationConfig(

@AutomationConfigMarker
context(module: Module)
fun IMutableAutomationConfig.setDefaultAutomationConfig(
name: String = module.name
) = AutomationConfig("$name Automation Config").also { this.defaultAutomationConfig = it }
fun IMutableAutomationConfig.setDefaultAutomationConfig() = this.setDefaultAutomationConfig(module.name)

@AutomationConfigMarker
fun IMutableAutomationConfig.setDefaultAutomationConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sealed class TargetState : StateMatcher {
ignoredProperties: Collection<Property<*>>
) = state.isEmpty

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getStack(pos: BlockPos): ItemStack = ItemStack.EMPTY

context(automatedSafeContext: AutomatedSafeContext)
Expand All @@ -65,10 +65,10 @@ sealed class TargetState : StateMatcher {
ignoredProperties: Collection<Property<*>>
) = state.isAir

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getStack(pos: BlockPos): ItemStack = ItemStack.EMPTY

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getState(pos: BlockPos): BlockState = Blocks.AIR.defaultState

override fun isEmpty() = true
Expand All @@ -95,7 +95,7 @@ sealed class TargetState : StateMatcher {
) ?: ItemStack(Items.NETHERRACK)
}

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getState(pos: BlockPos): BlockState = getStack(pos).item.block.defaultState

override fun isEmpty() = false
Expand All @@ -121,7 +121,7 @@ sealed class TargetState : StateMatcher {
?: ItemStack(Items.NETHERRACK)
}

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getState(pos: BlockPos): BlockState = getStack(pos).item.block.defaultState

override fun isEmpty() = false
Expand All @@ -141,7 +141,7 @@ sealed class TargetState : StateMatcher {
override fun getStack(pos: BlockPos): ItemStack =
blockState.block.getPickStack(automatedSafeContext.world, pos, blockState, true)

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getState(pos: BlockPos): BlockState = blockState

override fun isEmpty() = blockState.isEmpty
Expand All @@ -161,7 +161,7 @@ sealed class TargetState : StateMatcher {
override fun getStack(pos: BlockPos): ItemStack =
block.getPickStack(automatedSafeContext.world, pos, block.defaultState, true)

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getState(pos: BlockPos): BlockState = block.defaultState

override fun isEmpty() = block.defaultState.isEmpty
Expand All @@ -179,10 +179,10 @@ sealed class TargetState : StateMatcher {
ignoredProperties: Collection<Property<*>>
) = state.block == block

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getStack(pos: BlockPos): ItemStack = itemStack

context(_: AutomatedSafeContext)
context(automatedSafeContext: AutomatedSafeContext)
override fun getState(pos: BlockPos): BlockState = block.defaultState

override fun isEmpty() = block.defaultState.isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface OpenedContainerContext {
open class BasicOpenedContainerContext(
private val isAccessed: () -> Boolean
) : OpenedContainerContext {
context(_: Automated)
context(automated: Automated)
final override fun close() =
if (!isAccessed()) null
else actionTask { player.closeHandledScreen() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object OffhandContainer : Container(ContainerType.OffHand) {

override val description = buildText { literal("OffHand") }

context(_: SafeContext)
context(safeContext: SafeContext)
override fun InvRequestBuilder.swap(fromHere: Slot, toSlot: Slot) {
swapWithHotbar(toSlot.id, 40)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object EnderChestContainer : Container(ContainerType.EnderChest), ExternalContai
class OpenedEnderChestContext(
val blockPos: BlockPos?
) : OpenedContainerContext {
context(_: Automated)
context(automated: Automated)
override fun close() =
taskOrNull {
if (isAccessed) actionTask { player.closeHandledScreen() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.lambda.interaction.manager.managers.breaking.BreakInfo
import com.lambda.interaction.manager.managers.breaking.BreakManager
import com.lambda.interaction.manager.managers.breaking.BreakManager.calcBreakDelta
import com.lambda.interaction.manager.managers.breaking.BreakRequest
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import com.lambda.util.player.PlayerUtils.swingHand
import net.minecraft.util.Hand

Expand Down Expand Up @@ -88,7 +88,7 @@ internal object RebreakHandler {
* @return In what way this block can be rebroken.
*/
context(_: SafeContext)
fun BreakInfo.getRebreakPotential() = request.runSafeAutomated {
fun BreakInfo.getRebreakPotential() = request.withSafeAutomated {
reBreak?.let { reBreak ->
val stack = if (breakConfig.swapMode.isEnabled())
swapStack
Expand All @@ -111,15 +111,15 @@ internal object RebreakHandler {
* @return A [RebreakResult] to indicate how the update has been processed.
*/
context(_: SafeContext)
fun handleUpdate(ctx: BreakContext, request: BreakRequest) = request.runSafeAutomated {
val reBreak = this@RebreakHandler.reBreak ?: return@runSafeAutomated RebreakResult.Ignored
fun handleUpdate(ctx: BreakContext, request: BreakRequest) = request.withSafeAutomated {
val reBreak = this@RebreakHandler.reBreak ?: return@withSafeAutomated RebreakResult.Ignored

reBreak.updateInfo(ctx, request)

val breakDelta = reBreak.calcBreakDelta()
val breakTicks = reBreak.breakingTicks - breakConfig.fudgeFactor
return@runSafeAutomated if (breakTicks * breakDelta >= reBreak.getBreakThreshold()) {
if (!PacketLimitHandler.canSendPackets(1, PacketType.PlayerAction)) return@runSafeAutomated RebreakResult.Ignored
return@withSafeAutomated if (breakTicks * breakDelta >= reBreak.getBreakThreshold()) {
if (!PacketLimitHandler.canSendPackets(1, PacketType.PlayerAction)) return@withSafeAutomated RebreakResult.Ignored
if (breakConfig.breakConfirmation != BreakConfig.BreakConfirmationMode.AwaitThenBreak) {
destroyBlock(reBreak)
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/lambda/interaction/manager/Manager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.lambda.event.events.TickEvent.Companion.ALL_STAGES
import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.interaction.manager.ManagerUtils.accumulatedManagerPriority
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import kotlin.reflect.KClass

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ abstract class Manager<R : Request>(
tickStage = stage
queuedRequest?.let { request ->
if (tickStage !in request.tickStageMask) return@let
request.runSafeAutomated { handleRequest(request) }
request.withSafeAutomated { handleRequest(request) }
request.fresh = false
queuedRequest = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.lambda.interaction.manager.managers.breaking.BreakInfo.BreakType.Rebr
import com.lambda.interaction.manager.managers.breaking.BreakInfo.BreakType.RedundantSecondary
import com.lambda.interaction.manager.managers.breaking.BreakInfo.BreakType.Secondary
import com.lambda.interaction.manager.managers.breaking.BreakManager.calcBreakDelta
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import com.lambda.util.Describable
import com.lambda.util.NamedEnum
import net.minecraft.entity.ItemEntity
Expand Down Expand Up @@ -129,7 +129,7 @@ data class BreakInfo(
val item =
if (breakConfig.swapMode.isEnabled() && breakConfig.swapMode != BreakConfig.SwapMode.Start) swapStack
else player.mainHandStack
val breakDelta = request.runSafeAutomated { calcBreakDelta(item) }
val breakDelta = request.withSafeAutomated { calcBreakDelta(item) }
val progress = (breakDelta * breakingTicks) / (getBreakThreshold() + (breakDelta * breakConfig.fudgeFactor))
return if (progress > 0.0f) (progress * 10.0f).toInt().coerceAtMost(9) else -1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import com.lambda.interaction.manager.managers.interacting.InteractManager
import com.lambda.interaction.manager.managers.rotating.RotationRequest
import com.lambda.threading.runGameScheduled
import com.lambda.threading.runSafe
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
import com.lambda.util.BlockUtils.isEmpty
import com.lambda.util.BlockUtils.isNotBroken
Expand Down Expand Up @@ -238,7 +238,7 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
if (!config.renders) return@immediateRenderer
val swapMode = config.swapMode
val breakDelta =
info.request.runSafeAutomated {
info.request.withSafeAutomated {
val useActiveStack = info.type != RedundantSecondary && swapMode.isEnabled() && swapMode != BreakConfig.SwapMode.Start
info.calcBreakDelta(if (useActiveStack) activeStack else player.mainHandStack).toDouble()
}
Expand Down Expand Up @@ -363,7 +363,7 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
* @see canAccept
* @see BreakInfo.updateInfo
*/
private fun SafeContext.populateFrom(request: BreakRequest) = request.runSafeAutomated {
private fun SafeContext.populateFrom(request: BreakRequest) = request.withSafeAutomated {
// Sanitize the new breaks
val newBreaks = request.contexts
.distinctBy { it.blockPos }
Expand Down Expand Up @@ -461,7 +461,7 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
* @see initNewBreak
*/
private fun SafeContext.processNewBreak(request: BreakRequest): Boolean =
request.runSafeAutomated {
request.withSafeAutomated {
if (tickStage !in request.breakConfig.tickStageMask) return false
if (breakDelay > 0) return false
if (breakConfig.breakMode == BreakMode.OldGrim && !bypassingOldGrimBreakDelay && oldGrimBreakDelay > 0) return false
Expand Down Expand Up @@ -540,7 +540,7 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
// Cancelled but double breaking so requires break manager to continue the simulation
val abandonedInfo = abandonedBreak ?: return

abandonedInfo.request.runSafeAutomated {
abandonedInfo.request.withSafeAutomated {
abandonedInfo.context.blockPos
.toStructure(TargetState.Empty)
.sim()
Expand Down Expand Up @@ -568,7 +568,7 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
info.nullify()
return@forEach
}
info.request.runSafeAutomated {
info.request.withSafeAutomated {
val breakDelta = info.calcBreakDelta()
val ticksToBreak = 1.0 / breakDelta
val ticksPast = info.breakingTicks - ticksToBreak
Expand Down Expand Up @@ -632,12 +632,12 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
}

context(_: SafeContext)
private fun BreakInfo.updatePreProcessing() = request.runSafeAutomated {
private fun BreakInfo.updatePreProcessing() = request.withSafeAutomated {
shouldProgress = !progressedThisTick
&& tickStage in breakConfig.tickStageMask
&& (rotated || type != Primary)

if (updatedPreProcessingThisTick) return@runSafeAutomated
if (updatedPreProcessingThisTick) return@withSafeAutomated
updatedPreProcessingThisTick = true

swapStack = player.inventory.getStack(context.hotbarIndex)
Expand Down Expand Up @@ -694,7 +694,7 @@ object BreakManager : Manager<BreakRequest>(0), PositionBlocking {
* @see net.minecraft.client.network.ClientPlayerInteractionManager.updateBlockBreakingProgress
*/
private fun SafeContext.updateBreakProgress(info: BreakInfo): Unit =
info.request.runSafeAutomated {
info.request.withSafeAutomated {
val ctx = info.context
info.progressedThisTick = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.lambda.interaction.handler.handlers.breaking.RebreakHandler
import com.lambda.interaction.manager.managers.breaking.BreakInfo.BreakType.Primary
import com.lambda.interaction.manager.managers.breaking.BreakInfo.BreakType.Secondary
import com.lambda.interaction.manager.managers.breaking.BreakManager.calcBreakDelta
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated

/**
* A simple data class to store info about when the [BreakManager] should swap tool.
Expand All @@ -43,7 +43,7 @@ data class SwapInfo(
* Calculates the contents and returns a [SwapInfo].
*/
context(_: SafeContext)
fun BreakInfo.getSwapInfo() = request.runSafeAutomated {
fun BreakInfo.getSwapInfo() = request.withSafeAutomated {
val breakDelta = calcBreakDelta(swapStack)

val threshold = getBreakThreshold()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import com.lambda.interaction.manager.managers.interacting.InteractManager.proce
import com.lambda.interaction.manager.managers.inventory.inventoryRequest
import com.lambda.module.modules.world.AutoSign
import com.lambda.threading.runConcurrent
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.runSafeGameScheduled
import com.lambda.threading.withSafeAutomated
import com.lambda.util.BlockUtils.blockState
import com.lambda.util.PacketUtils.sendPacket
import com.lambda.util.item.ItemUtils.blockItem
Expand Down Expand Up @@ -123,7 +123,7 @@ object InteractManager : Manager<InteractRequest>(0), PositionBlocking {

override fun SafeContext.onOpen() {
activeRequest?.let {
it.runSafeAutomated { processRequest(it) }
it.withSafeAutomated { processRequest(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.lambda.interaction.manager.managers.inventory.InventoryManager.onInve
import com.lambda.module.modules.client.Client
import com.lambda.module.modules.client.Client.verboseDebug
import com.lambda.threading.runSafe
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import com.llamalad7.mixinextras.injector.wrapoperation.Operation
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen
import net.minecraft.item.ItemStack
Expand Down Expand Up @@ -149,7 +149,7 @@ object InventoryManager : Manager<InventoryRequest>(1) {
*/
private fun SafeContext.processActiveRequest() {
val active = activeRequest ?: return
active.runSafeAutomated {
active.withSafeAutomated {
if (tickStage !in active.inventoryConfig.tickStageMask && active.nowOrNothing) return
val iterator = actions.iterator()
while (iterator.hasNext()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/lambda/module/modules/combat/AutoTotem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.lambda.interaction.handler.handlers.FriendHandler
import com.lambda.interaction.handler.handlers.moveStack
import com.lambda.module.Module
import com.lambda.module.ModuleTag
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import com.lambda.util.combat.CombatUtils.hasDeadlyCrystal
import com.lambda.util.combat.DamageUtils.isFallDeadly
import com.lambda.util.extension.fullHealth
Expand Down Expand Up @@ -67,7 +67,7 @@ object AutoTotem : Module(

val swapWhileHolding = !ignoreWhenHolding || player.mainHandStack.item != Items.TOTEM_OF_UNDYING
if (swapWhileHolding && player.offHandStack.item != Items.TOTEM_OF_UNDYING) {
runSafeAutomated {
withSafeAutomated {
Items.TOTEM_OF_UNDYING
.select()
.moveStack(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.lambda.interaction.manager.managers.hotbar.hotbarRequest
import com.lambda.interaction.manager.managers.rotating.rotationRequest
import com.lambda.module.Module
import com.lambda.module.ModuleTag
import com.lambda.threading.runSafeAutomated
import com.lambda.threading.withSafeAutomated
import com.lambda.util.NamedEnum
import com.lambda.util.item.ItemStackUtils.attackDamage
import com.lambda.util.item.ItemStackUtils.attackSpeed
Expand Down Expand Up @@ -111,7 +111,7 @@ object KillAura : Module(
target?.let { entity ->
// Wait until the rotation has a hit result on the entity
var rotated = true
if (rotate) runSafeAutomated {
if (rotate) withSafeAutomated {
val rotationRequest = lookAtEntity(entity)?.rotation?.let { rotationRequest { rotation(it) } }?.submit() ?: return@listen
rotated = rotationRequest.done && entity === prevEntity && validServerRot
prevEntity = entity
Expand Down
Loading