Skip to content

Commit a854f40

Browse files
committed
Fix creative related issues and more clear transfer command
1 parent 1ce6971 commit a854f40

File tree

10 files changed

+25
-12
lines changed

10 files changed

+25
-12
lines changed

common/src/main/kotlin/com/lambda/command/commands/TransferCommand.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ object TransferCommand : LambdaCommand(
3030
isItem(stack(ctx).value().item)
3131
}
3232
containerMatchSelection(selection).forEach {
33-
builder.suggest("\"${it.name} with ${it.available(selection)}\"")
33+
val available = it.available(selection)
34+
val availableMsg = if (available == Int.MAX_VALUE) "" else available.toString()
35+
builder.suggest("\"${it.name} with $availableMsg\"")
3436
}
3537
builder.buildFuture()
3638
}
@@ -41,7 +43,8 @@ object TransferCommand : LambdaCommand(
4143
}
4244
ContainerManager.container().forEach {
4345
val space = it.spaceLeft(selection)
44-
if (space > 0) builder.suggest("\"${it.name} with $space space left\"")
46+
val spaceMsg = if (space == Int.MAX_VALUE) "" else space.toString()
47+
if (space > 0) builder.suggest("\"${it.name} with $spaceMsg space left\"")
4548
}
4649
builder.buildFuture()
4750
}
@@ -59,9 +62,11 @@ object TransferCommand : LambdaCommand(
5962

6063
when (val result = fromContainer.transfer(selection, toContainer)) {
6164
is TransferResult.Success -> {
62-
info("Transferring $selection from ${fromContainer.name} to ${toContainer.name}")
65+
info("$result started.")
6366
lastTransfer = result
64-
result.solve.start(null)
67+
result.solve.onSuccess { _, _ ->
68+
info("$lastTransfer completed.")
69+
}.start(null)
6570
return@executeWithResult success()
6671
}
6772
is TransferResult.MissingItems -> {
@@ -84,6 +89,7 @@ object TransferCommand : LambdaCommand(
8489
lastTransfer?.solve?.cancel() ?: run {
8590
return@executeWithResult failure("No transfer to cancel")
8691
}
92+
info("$lastTransfer cancelled")
8793
lastTransfer = null
8894
success()
8995
}
@@ -94,6 +100,7 @@ object TransferCommand : LambdaCommand(
94100
lastTransfer?.undo ?: run {
95101
return@executeWithResult failure("No transfer to undo")
96102
}
103+
info("Undoing $lastTransfer")
97104
success()
98105
}
99106
}

common/src/main/kotlin/com/lambda/config/groups/RotationSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class RotationSettings(
1313
override val keepTicks by c.setting("Keep Rotation", 3, 1..10, 1, "Ticks to keep rotation", " ticks", vis)
1414
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks", vis)
1515
override var instant by c.setting("Instant Rotation", true, "Instantly rotate", vis)
16-
override var mean by c.setting("Mean", 20.0, 1.0..80.0, 0.1, "Average rotation speed") { vis() && !instant }
17-
override var derivation by c.setting("Standard Deviation", 5.0, 0.0..20.0, 0.1, "Spread of rotation speeds") { vis() && !instant }
16+
override var mean by c.setting("Mean", 20.0, 1.0..80.0, 0.1, "Average rotation speed", unit = "°") { vis() && !instant }
17+
override var derivation by c.setting("Standard Deviation", 5.0, 0.0..20.0, 0.1, "Spread of rotation speeds", unit = "°") { vis() && !instant }
1818

1919
override val turnSpeed get() = abs(nextGaussian(mean, derivation))
2020

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ object BuildSimulator {
397397
)
398398

399399
/* player has a better tool for the job available */
400-
findBestAvailableTool(state)?.let { bestTool ->
400+
if (!player.isCreative) findBestAvailableTool(state)?.let { bestTool ->
401401
Hand.entries.firstOrNull {
402402
val stack = player.getStackInHand(it)
403403
stack.item == bestTool

common/src/main/kotlin/com/lambda/interaction/material/MaterialContainer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ abstract class MaterialContainer(
7676
}
7777

7878
enum class Rank {
79-
CREATIVE,
8079
MAIN_HAND,
8180
OFF_HAND,
8281
HOTBAR,
8382
INVENTORY,
83+
CREATIVE,
8484
SHULKER_BOX,
8585
ENDER_CHEST,
8686
CHEST,

common/src/main/kotlin/com/lambda/interaction/material/container/CreativeContainer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lambda.interaction.material.container
22

33
import com.lambda.Lambda.mc
4+
import com.lambda.interaction.construction.result.ComparableResult
45
import com.lambda.interaction.material.MaterialContainer
56
import com.lambda.interaction.material.StackSelection
67
import com.lambda.task.Task.Companion.buildTask
@@ -14,6 +15,8 @@ data object CreativeContainer : MaterialContainer(Rank.CREATIVE) {
1415
override fun available(selection: StackSelection): Int =
1516
if (mc.player?.isCreative == true && selection.optimalStack != null) Int.MAX_VALUE else 0
1617

18+
override fun spaceLeft(selection: StackSelection) = Int.MAX_VALUE
19+
1720
override fun deposit(selection: StackSelection) = buildTask("CreativeDeposit") {
1821
if (!player.isCreative) {
1922
// ToDo: Maybe switch gamemode?

common/src/main/kotlin/com/lambda/interaction/material/transfer/TransferResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class TransferResult {
1717
override val solve = ContainerTransfer(selection, from, to)
1818
val undo = ContainerTransfer(selection, to, from)
1919

20-
override fun toString() = "Transfer of [$selection] from [$from] to [$to]"
20+
override fun toString() = "Transfer of [$selection] from [${from.name}] to [${to.name}]"
2121
}
2222

2323
data object NoSpace : TransferResult() {

common/src/main/kotlin/com/lambda/module/modules/player/HighwayTools.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.lambda.module.Module
77
import com.lambda.module.tag.ModuleTag
88
import com.lambda.task.Task
99
import com.lambda.task.tasks.BuildStructure.Companion.buildStructure
10+
import com.lambda.util.BaritoneUtils
1011
import com.lambda.util.BaritoneUtils.primary
1112
import com.lambda.util.Communication.info
1213
import com.lambda.util.KeyCode
@@ -51,6 +52,7 @@ object HighwayTools : Module(
5152
runningTask?.cancel()
5253
runningTask = null
5354
distanceMoved = 0
55+
BaritoneUtils.cancel()
5456
}
5557
}
5658

common/src/main/kotlin/com/lambda/task/tasks/BreakBlock.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class BreakBlock @Ta5kBuilder constructor(
9898

9999
private fun SafeContext.breakBlock(side: Direction) {
100100
if (interaction.updateBlockBreakingProgress(blockPos, side)) {
101+
if (player.isCreative) interaction.blockBreakingCooldown = 0
101102
if (swingHand) player.swingHand(ctx.hand)
102103
}
103104
}

common/src/main/kotlin/com/lambda/util/BlockUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ object BlockUtils {
102102
fun BlockPos.blockEntity(world: ClientWorld) = world.getBlockEntity(this)
103103
fun SafeContext.instantBreakable(blockState: BlockState, blockPos: BlockPos): Boolean {
104104
val ticksNeeded = 1 / blockState.calcBlockBreakingDelta(player, world, blockPos)
105-
// info("State: $blockState Ticks to break: $ticksNeeded")
106-
return ticksNeeded <= 1 && ticksNeeded != 0f
105+
return (ticksNeeded <= 1 && ticksNeeded != 0f) || player.isCreative
107106
}
108107
val Vec3i.blockPos: BlockPos get() = BlockPos(this)
109108
val Block.item: Item get() = asItem()

common/src/main/resources/lambda.accesswidener

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ accessible class net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPa
4848
# Other
4949
accessible field net/minecraft/world/explosion/Explosion behavior Lnet/minecraft/world/explosion/ExplosionBehavior;
5050
accessible field net/minecraft/structure/StructureTemplate blockInfoLists Ljava/util/List;
51-
accessible method net/minecraft/item/BlockItem getPlacementState (Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/block/BlockState;
51+
accessible method net/minecraft/item/BlockItem getPlacementState (Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/block/BlockState;
52+
accessible field net/minecraft/client/network/ClientPlayerInteractionManager blockBreakingCooldown I

0 commit comments

Comments
 (0)