Skip to content
Open
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
1 change: 1 addition & 0 deletions src/main/kotlin/com/lambda/config/blocks/BreakConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface BreakConfig : ActionConfig {
//ToDo: Needs a more advanced player simulation implementation to predict the next ticks onGround / submerged status
// abstract val desyncFix: Boolean
val breakDelay: Int
val pauseWhenEating: Boolean

val swapMode: SwapMode

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/lambda/config/blocks/BreakSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BreakSettings(override val c: Config) : BreakConfig, ConfigBlock {
override val serverSwapTicks by c.setting("Server Swap", 0, 0..5, 1, "The number of ticks to give the server time to recognize the player attributes on the swapped item", " tick(s)")
// @Group(GeneralGroup) override val desyncFix by c.setting("Desync Fix", false, "Predicts if the players breaking will be slowed next tick as block break packets are processed using the players next position") { page == Page.General }
override val breakDelay by c.setting("Break Delay", 0, 0..6, 1, "The delay between breaking blocks", " tick(s)")
override val pauseWhenEating by c.setting("Pause When Eating", false, "Keeps progressing block breaks while eating, but won't finish them until eating ends")
// Timing
override val tickStageMask by c.setting("Break Stage Mask", setOf(TickEvent.Input.Post), ALL_STAGES.toSet(), "The sub-tick timing at which break actions can be performed", displayClassName = true)
override val swapMode by c.setting("Break Swap Mode", BreakConfig.SwapMode.End, "Decides when to swap to the best suited tool when breaking a block")
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/lambda/config/blocks/InteractConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface InteractConfig : ActionConfig {
val axisRotateSetting: Boolean
val axisRotate get() = rotate && airPlace.isEnabled && axisRotateSetting
val interactConfirmationMode: InteractConfirmationMode
val pauseWhenEating: Boolean
val interactDelay: Int
val interactionsPerTick: Int
val swing: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InteractSettings(override val c: Config) : InteractConfig, ConfigBlock {
override val sorter by c.setting("Interaction Sorter", ActionConfig.SortMode.Tool, "The order in which placements are performed")
override val tickStageMask by c.setting("Interaction Stage Mask", setOf(TickEvent.Input.Post), ALL_STAGES.toSet(), "The sub-tick timing at which place actions are performed", displayClassName = true)
override val interactConfirmationMode by c.setting("Interact Confirmation", InteractConfig.InteractConfirmationMode.PlaceThenAwait, "Wait for block placement confirmation")
override val pauseWhenEating by c.setting("Pause When Eating", false, "Pauses block interactions while eating")
override val interactDelay by c.setting("Interact Delay", 0, 0..3, 1, "Tick delay between interacting with another block")
override val interactionsPerTick by c.setting("Interactions Per Tick", 9, 1..30, 1, "Maximum instant block places per tick")
override val swing by c.setting("Swing On Interact", true, "Swings the players hand when placing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import com.lambda.util.extension.tickDelta
import com.lambda.util.item.ItemUtils.block
import com.lambda.util.math.lerp
import com.lambda.util.player.PlayerUtils.gamemode
import com.lambda.util.player.PlayerUtils.isEating
import com.lambda.util.player.PlayerUtils.swingHand
import net.minecraft.block.BlockState
import net.minecraft.client.sound.PositionedSoundInstance
Expand Down Expand Up @@ -747,6 +748,7 @@ object BreakManager : Manager<BreakRequest>(

val swing = breakConfig.swing
if (progress >= info.getBreakThreshold()) {
if (breakConfig.pauseWhenEating && player.isEating) return
if (info.swapInfo.swap && !swapped) return
if (info.type == Primary && !PacketLimitHandler.canSendPackets(1, PacketType.PlayerAction)) return

Expand Down Expand Up @@ -815,7 +817,7 @@ object BreakManager : Manager<BreakRequest>(

val blockState = blockState(ctx.blockPos)
val progress = blockState.calcBreakDelta(ctx.blockPos)
val instantBreakable = progress >= info.getBreakThreshold()
val instantBreakable = progress >= info.getBreakThreshold() && !(breakConfig.pauseWhenEating && player.isEating)

var packetCount = 1
if (breakConfig.breakMode == BreakMode.Packet) packetCount++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.lambda.interaction.managers.breaking.BreakInfo.BreakType.Primary
import com.lambda.interaction.managers.breaking.BreakInfo.BreakType.Secondary
import com.lambda.interaction.managers.breaking.BreakManager.calcBreakDelta
import com.lambda.threading.runSafeAutomated
import com.lambda.util.player.PlayerUtils.isEating

/**
* A simple data class to store info about when the [BreakManager] should swap tool.
Expand Down Expand Up @@ -63,7 +64,7 @@ data class SwapInfo(
swapTickProgress >= threshold
}

val swap = when (breakConfig.swapMode) {
val swap = !(breakConfig.pauseWhenEating && player.isEating) && when (breakConfig.swapMode) {
BreakConfig.SwapMode.None -> false
BreakConfig.SwapMode.Start -> !breaking
BreakConfig.SwapMode.End -> swapAtEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.lambda.util.PacketUtils.sendPacket
import com.lambda.util.item.ItemUtils.blockItem
import com.lambda.util.player.MovementUtils.sneaking
import com.lambda.util.player.PlayerUtils.gamemode
import com.lambda.util.player.PlayerUtils.isEating
import com.lambda.util.player.PlayerUtils.isItemOnCooldown
import com.lambda.util.player.PlayerUtils.swingHand
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -155,6 +156,7 @@ object InteractManager : Manager<InteractRequest>(
* @see populateFrom
*/
fun AutomatedSafeContext.processRequest(request: InteractRequest) {
if (interactConfig.pauseWhenEating && player.isEating) return
if (request.fresh) populateFrom(request)

if (potentialInteractions.isNotEmpty()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/com/lambda/util/player/PlayerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import net.minecraft.entity.LivingEntity
import net.minecraft.entity.effect.StatusEffects
import net.minecraft.entity.projectile.FireworkRocketEntity
import net.minecraft.item.ItemStack
import net.minecraft.item.consume.UseAction
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
import net.minecraft.util.Hand
import net.minecraft.world.GameMode
Expand All @@ -45,6 +46,9 @@ object PlayerUtils {
val ClientPlayerEntity.canStartGliding: Boolean
get() = !isGliding && !isClimbing && !isTouchingWater && canGlide()

val ClientPlayerEntity.isEating: Boolean
get() = isUsingItem && (activeItem.useAction == UseAction.EAT || activeItem.useAction == UseAction.DRINK)

context(_: SafeContext)
val ClientPlayerEntity.canTakeoff: Boolean
get() = (isOnGround || !isGliding) &&
Expand Down