Skip to content

Commit d605966

Browse files
Avanatikeremyfops
andauthored
[1.20.x] [All]: Stability improvements for TaskFlow (#48)
- More coherent task hierarchy - Removed generic screen events - Build command added - Task control command added - Dynamic disposable material use - Iterative inventory transactions - TaskFlow HUD - InventoryTweaks module added - Fixed rotation timings --------- Co-authored-by: Kamigen <46357922+Edouard127@users.noreply.github.com>
1 parent 782815b commit d605966

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+708
-490
lines changed

common/src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private void onStartup(CallbackInfo ci) {
5757
private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
5858
if (screen == null) return;
5959
if (screen instanceof ScreenHandlerProvider<?> handledScreen) {
60-
EventFlow.post(new ScreenHandlerEvent.Open<>(handledScreen.getScreenHandler()));
60+
EventFlow.post(new ScreenHandlerEvent.Open(handledScreen.getScreenHandler()));
6161
}
6262

6363
EventFlow.post(new ScreenEvent.Open<>(screen));
@@ -67,7 +67,7 @@ private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
6767
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
6868
if (currentScreen == null) return;
6969
if (currentScreen instanceof ScreenHandlerProvider<?> handledScreen) {
70-
EventFlow.post(new ScreenHandlerEvent.Close<>(handledScreen.getScreenHandler()));
70+
EventFlow.post(new ScreenHandlerEvent.Close(handledScreen.getScreenHandler()));
7171
}
7272

7373
EventFlow.post(new ScreenEvent.Close<>(currentScreen));

common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.client.network.ClientPlayerInteractionManager;
99
import net.minecraft.entity.Entity;
1010
import net.minecraft.entity.player.PlayerEntity;
11+
import net.minecraft.screen.slot.SlotActionType;
1112
import net.minecraft.util.ActionResult;
1213
import net.minecraft.util.Hand;
1314
import net.minecraft.util.hit.BlockHitResult;
@@ -37,6 +38,13 @@ public void interactBlockHead(final ClientPlayerEntity player, final Hand hand,
3738
EventFlow.post(new InteractionEvent.Block(client.world, hitResult));
3839
}
3940

41+
@Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true)
42+
public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) {
43+
if (syncId != player.currentScreenHandler.syncId) return;
44+
var click = new InteractionEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler);
45+
if (EventFlow.post(click).isCanceled()) ci.cancel();
46+
}
47+
4048
@Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true)
4149
void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) {
4250
if (EventFlow.post(new AttackEvent.Pre(target)).isCanceled()) ci.cancel();

common/src/main/java/com/lambda/mixin/entity/EntityMixin.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import com.lambda.Lambda;
44
import com.lambda.event.EventFlow;
55
import com.lambda.event.events.EntityEvent;
6+
import com.lambda.event.events.WorldEvent;
67
import com.lambda.interaction.RotationManager;
78
import com.lambda.util.math.Vec2d;
89
import net.minecraft.entity.Entity;
910
import net.minecraft.entity.MovementType;
11+
import net.minecraft.entity.data.TrackedData;
1012
import net.minecraft.util.math.Vec3d;
1113
import org.spongepowered.asm.mixin.Mixin;
1214
import org.spongepowered.asm.mixin.Shadow;
@@ -70,4 +72,11 @@ float fixDirectionPitch2(Entity entity) {
7072
private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) {
7173
if (EventFlow.post(new EntityEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel();
7274
}
73-
}
75+
76+
@Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL"))
77+
public void onTrackedDataSet(TrackedData<?> data, CallbackInfo ci) {
78+
Entity entity = (Entity) (Object) this;
79+
80+
EventFlow.post(new WorldEvent.EntityUpdate(entity, data));
81+
}
82+
}

common/src/main/java/com/lambda/mixin/render/ScreenHandlerMixin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.lambda.mixin.render;
22

33
import com.lambda.event.EventFlow;
4-
import com.lambda.event.events.ScreenEvent;
54
import com.lambda.event.events.ScreenHandlerEvent;
65
import net.minecraft.item.ItemStack;
76
import net.minecraft.screen.ScreenHandler;
@@ -16,6 +15,6 @@
1615
public class ScreenHandlerMixin {
1716
@Inject(method = "updateSlotStacks", at = @At("TAIL"))
1817
private void onUpdateSlotStacksHead(int revision, List<ItemStack> stacks, ItemStack cursorStack, CallbackInfo ci) {
19-
EventFlow.post(new ScreenHandlerEvent.Loaded(revision, stacks, cursorStack));
18+
EventFlow.post(new ScreenHandlerEvent.Update(revision, stacks, cursorStack));
2019
}
2120
}

common/src/main/kotlin/com/lambda/command/LambdaCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class LambdaCommand(
2222
// ToDo: Include usage and description in the help command
2323
init {
2424
(listOf(name) + aliases).forEach {
25-
val argument = LiteralArgumentBuilder.literal<CommandSource>(it)
25+
val argument = LiteralArgumentBuilder.literal<CommandSource>(it.lowercase())
2626
argument.create()
2727
dispatcher.register(argument)
2828
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.lambda.command.commands
2+
3+
import com.lambda.brigadier.argument.literal
4+
import com.lambda.brigadier.execute
5+
import com.lambda.brigadier.required
6+
import com.lambda.command.LambdaCommand
7+
import com.lambda.interaction.construction.Blueprint.Companion.toStructure
8+
import com.lambda.interaction.construction.DynamicBlueprint.Companion.toBlueprint
9+
import com.lambda.interaction.construction.verify.TargetState
10+
import com.lambda.task.tasks.BuildTask.Companion.build
11+
import com.lambda.threading.runSafe
12+
import com.lambda.util.extension.CommandBuilder
13+
import net.minecraft.block.Blocks
14+
import net.minecraft.util.math.BlockBox
15+
16+
object BuildCommand : LambdaCommand(
17+
name = "Build",
18+
description = "Builds a structure",
19+
usage = "build <structure>"
20+
) {
21+
override fun CommandBuilder.create() {
22+
required(literal("place")) {
23+
execute {
24+
runSafe {
25+
val materials = setOf(
26+
TargetState.Block(Blocks.NETHERRACK),
27+
TargetState.Block(Blocks.AIR),
28+
TargetState.Block(Blocks.COBBLESTONE),
29+
TargetState.Block(Blocks.AIR),
30+
)
31+
val facing = player.horizontalFacing
32+
val pos = player.blockPos.add(facing.vector.multiply(2))
33+
34+
BlockBox.create(pos, pos.add(facing.rotateYClockwise().vector.multiply(3)))
35+
.toStructure(TargetState.Block(Blocks.NETHERRACK))
36+
.toBlueprint {
37+
it.mapValues { (_, _) ->
38+
materials.elementAt((System.currentTimeMillis() / 5000).toInt() % materials.size)
39+
}
40+
}
41+
.build(finishOnDone = false)
42+
.start(null)
43+
}
44+
}
45+
}
46+
}
47+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.lambda.command.commands
2+
3+
import com.lambda.brigadier.argument.literal
4+
import com.lambda.brigadier.execute
5+
import com.lambda.brigadier.required
6+
import com.lambda.command.LambdaCommand
7+
import com.lambda.task.RootTask
8+
import com.lambda.util.Communication.info
9+
import com.lambda.util.extension.CommandBuilder
10+
11+
object TaskCommand : LambdaCommand(
12+
name = "task",
13+
usage = "task <cancel>",
14+
description = "Control tasks"
15+
) {
16+
override fun CommandBuilder.create() {
17+
required(literal("cancel")) {
18+
execute {
19+
this@TaskCommand.info("Cancelling all tasks")
20+
RootTask.cancel()
21+
}
22+
}
23+
}
24+
}

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object TransferCommand : LambdaCommand(
1818
usage = "transfer <move|cancel|undo> <item> <amount> <to>",
1919
description = "Transfer items from anywhere to anywhere",
2020
) {
21-
private var lastTransfer: TransferResult.Success? = null
21+
private var lastTransfer: TransferResult.Transfer? = null
2222

2323
override fun CommandBuilder.create() {
2424
required(itemStack("stack", registry)) { stack ->
@@ -61,10 +61,10 @@ object TransferCommand : LambdaCommand(
6161
} ?: return@executeWithResult failure("To container not found")
6262

6363
when (val result = fromContainer.transfer(selection, toContainer)) {
64-
is TransferResult.Success -> {
64+
is TransferResult.Transfer -> {
6565
info("$result started.")
6666
lastTransfer = result
67-
result.solve.onSuccess { _, _ ->
67+
result.onSuccess { _, _ ->
6868
info("$lastTransfer completed.")
6969
}.start(null)
7070
return@executeWithResult success()
@@ -86,23 +86,13 @@ object TransferCommand : LambdaCommand(
8686

8787
required(literal("cancel")) {
8888
executeWithResult {
89-
lastTransfer?.solve?.cancel() ?: run {
89+
lastTransfer?.cancel() ?: run {
9090
return@executeWithResult failure("No transfer to cancel")
9191
}
9292
info("$lastTransfer cancelled")
9393
lastTransfer = null
9494
success()
9595
}
9696
}
97-
98-
required(literal("undo")) {
99-
executeWithResult {
100-
lastTransfer?.undo ?: run {
101-
return@executeWithResult failure("No transfer to undo")
102-
}
103-
info("Undoing $lastTransfer")
104-
success()
105-
}
106-
}
10797
}
10898
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.lambda.config.groups
22

33
interface BuildConfig {
4-
val breakCoolDown: Int
5-
val placeCooldown: Int
64
val breakConfirmation: Boolean
75
val placeConfirmation: Boolean
86
val collectDrops: Boolean
@@ -11,5 +9,4 @@ interface BuildConfig {
119
val breaksPerTick: Int
1210
val rotateForBreak: Boolean
1311
val rotateForPlace: Boolean
14-
val pingTimeout: Boolean
1512
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ class BuildSettings(
77
vis: () -> Boolean = { true }
88
) : BuildConfig {
99
enum class Page {
10-
BREAK, PLACE, GENERAL
10+
GENERAL, BREAK, PLACE
1111
}
1212

13-
private val page by c.setting("Build Page", Page.BREAK, "Current page", vis)
13+
private val page by c.setting("Build Page", Page.GENERAL, "Current page", vis)
14+
15+
override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.GENERAL }
1416

15-
override val breakCoolDown by c.setting("Break Cooldown", 0, 0..1000, 1, "Delay between breaking blocks", " ms") { vis() && page == Page.BREAK }
1617
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation") { vis() && page == Page.BREAK }
1718
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.BREAK }
1819
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 10, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.BREAK }
19-
override val rotateForBreak by c.setting("Rotate For Break", false, "Rotate towards block while breaking") { vis() && page == Page.BREAK }
20+
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.BREAK }
21+
2022
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks") { vis() && page == Page.BREAK }
2123

22-
override val placeCooldown by c.setting("Place Cooldown", 0, 0..1000, 1, "Delay between placing blocks", " ms") { vis() && page == Page.PLACE }
2324
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.PLACE }
2425

2526
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.PLACE }
26-
27-
override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.GENERAL }
28-
override val pingTimeout by c.setting("Ping Timeout", true, "Timeout on high ping") { vis() && page == Page.GENERAL }
2927
}

0 commit comments

Comments
 (0)