Skip to content

Commit f3d00f5

Browse files
authored
Merge pull request #7 from Avanatiker/feature/taskflow
TaskFlow
2 parents b17a1c4 + daf9b13 commit f3d00f5

File tree

121 files changed

+4756
-558
lines changed

Some content is hidden

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

121 files changed

+4756
-558
lines changed

common/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ dependencies {
2727
implementation(kotlin("reflect"))
2828

2929
// Baritone
30-
modImplementation("baritone-api:baritone-api:1.10.2")
30+
// modImplementation("baritone-api:baritone-api:1.10.2")
3131
modImplementation("baritone-api:baritone-unoptimized-fabric:1.10.2")
32+
33+
testImplementation(kotlin("test"))
34+
}
35+
36+
tasks.test {
37+
useJUnitPlatform()
3238
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
import com.lambda.Lambda;
44
import com.lambda.event.EventFlow;
55
import com.lambda.event.events.ClientEvent;
6+
import com.lambda.event.events.ScreenEvent;
7+
import com.lambda.event.events.ScreenHandlerEvent;
68
import com.lambda.event.events.TickEvent;
79
import com.lambda.module.modules.player.Interact;
810
import net.minecraft.client.MinecraftClient;
11+
import net.minecraft.client.gui.screen.Screen;
12+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
13+
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
914
import net.minecraft.client.network.ClientPlayerInteractionManager;
15+
import org.jetbrains.annotations.Nullable;
1016
import org.spongepowered.asm.mixin.Mixin;
17+
import org.spongepowered.asm.mixin.Shadow;
1118
import org.spongepowered.asm.mixin.injection.At;
1219
import org.spongepowered.asm.mixin.injection.Inject;
1320
import org.spongepowered.asm.mixin.injection.Redirect;
1421
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1522

1623
@Mixin(MinecraftClient.class)
1724
public class MinecraftClientMixin {
25+
@Shadow @Nullable public Screen currentScreen;
26+
1827
@Inject(method = "tick", at = @At("HEAD"))
1928
void onTickPre(CallbackInfo ci) {
2029
EventFlow.post(new TickEvent.Pre());
@@ -38,6 +47,26 @@ private void onStartup(CallbackInfo ci) {
3847
EventFlow.post(new ClientEvent.Startup());
3948
}
4049

50+
@Inject(method = "setScreen", at = @At("HEAD"))
51+
private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
52+
if (screen == null) return;
53+
if (screen instanceof ScreenHandlerProvider<?> handledScreen) {
54+
EventFlow.post(new ScreenHandlerEvent.Open<>(handledScreen.getScreenHandler()));
55+
}
56+
57+
EventFlow.post(new ScreenEvent.Open<>(screen));
58+
}
59+
60+
@Inject(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;removed()V", shift = At.Shift.AFTER))
61+
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
62+
if (currentScreen == null) return;
63+
if (currentScreen instanceof ScreenHandlerProvider<?> handledScreen) {
64+
EventFlow.post(new ScreenHandlerEvent.Close<>(handledScreen.getScreenHandler()));
65+
}
66+
67+
EventFlow.post(new ScreenEvent.Close<>(currentScreen));
68+
}
69+
4170
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
4271
boolean injectMultiActon(ClientPlayerInteractionManager instance) {
4372
if (instance == null) return true;

common/src/main/java/com/lambda/mixin/baritone/MixinBaritonePlayerContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void syncRotationWithBaritone(CallbackInfoReturnable<Rotation> cir) {
2424
if (baritone != BaritoneUtils.getPrimary()) return;
2525

2626
RotationManager rm = RotationManager.INSTANCE;
27-
cir.setReturnValue(new Rotation((float) rm.getCurrentRotation().getYaw(), (float) rm.getCurrentRotation().getPitch()));
27+
cir.setReturnValue(new Rotation(
28+
(float) rm.getCurrentRotation().getYaw(), (float) rm.getCurrentRotation().getPitch())
29+
);
2830
}
2931
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.lambda.mixin.entity;
2+
3+
import com.lambda.event.EventFlow;
4+
import com.lambda.event.events.InteractionEvent;
5+
import net.minecraft.client.MinecraftClient;
6+
import net.minecraft.client.network.ClientPlayerEntity;
7+
import net.minecraft.client.network.ClientPlayerInteractionManager;
8+
import net.minecraft.util.ActionResult;
9+
import net.minecraft.util.Hand;
10+
import net.minecraft.util.hit.BlockHitResult;
11+
import org.spongepowered.asm.mixin.Final;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Shadow;
14+
import org.spongepowered.asm.mixin.injection.At;
15+
import org.spongepowered.asm.mixin.injection.Inject;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
17+
18+
@Mixin(ClientPlayerInteractionManager.class)
19+
public class ClientPlayInteractionManagerMixin {
20+
21+
@Final
22+
@Shadow
23+
private MinecraftClient client;
24+
25+
@Inject(method = "interactBlock", at = @At("HEAD"))
26+
public void interactBlockHead(final ClientPlayerEntity player, final Hand hand, final BlockHitResult hitResult, final CallbackInfoReturnable<ActionResult> cir) {
27+
if (client.world == null) return;
28+
EventFlow.post(new InteractionEvent.Block(client.world, hitResult));
29+
}
30+
}

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

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

3+
import com.lambda.task.RootTask;
34
import com.lambda.util.DebugInfoHud;
45
import net.minecraft.client.gui.hud.DebugHud;
56
import org.spongepowered.asm.mixin.Mixin;
@@ -15,4 +16,9 @@ public class DebugHudMixin {
1516
private void onGetRightText(CallbackInfoReturnable<List<String>> cir) {
1617
DebugInfoHud.addDebugInfo(cir.getReturnValue());
1718
}
19+
20+
@Inject(method = "getLeftText", at = @At(value = "TAIL"))
21+
private void onGetLeftText(CallbackInfoReturnable<List<String>> cir) {
22+
RootTask.INSTANCE.addInfo(cir.getReturnValue());
23+
}
1824
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.event.EventFlow;
4+
import com.lambda.event.events.ScreenEvent;
5+
import com.lambda.event.events.ScreenHandlerEvent;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraft.screen.ScreenHandler;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
import java.util.List;
14+
15+
@Mixin(ScreenHandler.class)
16+
public class ScreenHandlerMixin {
17+
@Inject(method = "updateSlotStacks", at = @At("TAIL"))
18+
private void onUpdateSlotStacksHead(int revision, List<ItemStack> stacks, ItemStack cursorStack, CallbackInfo ci) {
19+
EventFlow.post(new ScreenHandlerEvent.Loaded(revision, stacks, cursorStack));
20+
}
21+
}

common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.lambda.event.events.WorldEvent;
55
import net.minecraft.block.BlockState;
66
import net.minecraft.client.world.ClientWorld;
7+
import net.minecraft.entity.Entity;
78
import net.minecraft.util.math.BlockPos;
89
import org.spongepowered.asm.mixin.Mixin;
910
import org.spongepowered.asm.mixin.injection.At;
@@ -18,4 +19,9 @@ private void handleBlockUpdateInject(BlockPos pos, BlockState state, int flags,
1819
ci.cancel();
1920
}
2021
}
21-
}
22+
23+
@Inject(method = "addEntity", at = @At("HEAD"), cancellable = true)
24+
private void addEntity(Entity entity, CallbackInfo ci) {
25+
if (EventFlow.post(new WorldEvent.EntitySpawn(entity)).isCanceled()) ci.cancel();
26+
}
27+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2023 The Quilt Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Preserve binary compatibility when moving extensions between files
19+
*/
20+
@file:JvmMultifileClass
21+
@file:JvmName("ArgumentsKt")
22+
23+
package com.lambda.brigadier.argument
24+
25+
26+
import com.lambda.brigadier.*
27+
import com.lambda.brigadier.assumeSourceNotUsed
28+
import net.minecraft.command.CommandRegistryAccess
29+
import net.minecraft.command.argument.ItemPredicateArgumentType
30+
import net.minecraft.command.argument.ItemSlotArgumentType
31+
import net.minecraft.command.argument.ItemStackArgument
32+
import net.minecraft.command.argument.ItemStackArgumentType
33+
import net.minecraft.item.ItemStack
34+
import java.util.function.Predicate
35+
36+
/**
37+
* Reads the [ItemStack] predicate value from the
38+
* argument in the receiver [ArgumentReader].
39+
*
40+
* @see ItemPredicateArgumentType.getItemPredicate
41+
*/
42+
@JvmName("valueItemPredicateArg")
43+
@BrigadierDsl
44+
fun DefaultArgumentReader<ItemPredicateArgumentType>.value(): Predicate<ItemStack> {
45+
return ItemPredicateArgumentType.getItemStackPredicate(context.assumeSourceNotUsed(), name)
46+
}
47+
48+
/**
49+
* Reads the integer value from the
50+
* argument in the receiver [ArgumentReader].
51+
*
52+
* @see ItemSlotArgumentType.getItemSlot
53+
*/
54+
@JvmName("valueItemSlotArg")
55+
@BrigadierDsl
56+
fun DefaultArgumentReader<ItemSlotArgumentType>.value(): Int {
57+
return ItemSlotArgumentType.getItemSlot(context.assumeSourceNotUsed(), name)
58+
}
59+
60+
/**
61+
* Reads the [ItemStackArgument] value from the
62+
* argument in the receiver [ArgumentReader].
63+
*
64+
* @see ItemStackArgumentType.getItemStackArgument
65+
*/
66+
@JvmName("valueItemStackArg")
67+
@BrigadierDsl
68+
fun DefaultArgumentReader<ItemStackArgumentType>.value(): ItemStackArgument {
69+
return ItemStackArgumentType.getItemStackArgument(context, name)
70+
}
71+
72+
/**
73+
* Creates an item predicate argument with [name] as the parameter name.
74+
*
75+
* @param context The command build context
76+
*/
77+
@BrigadierDsl
78+
fun <S> itemPredicate(
79+
name: String,
80+
context: CommandRegistryAccess
81+
): DefaultArgumentConstructor<S, ItemPredicateArgumentType> {
82+
return argument(name, ItemPredicateArgumentType.itemPredicate(context))
83+
}
84+
85+
/**
86+
* Creates an item slot argument with [name] as the parameter name.
87+
*/
88+
@BrigadierDsl
89+
fun <S> itemSlot(
90+
name: String
91+
): DefaultArgumentConstructor<S, ItemSlotArgumentType> {
92+
return argument(name, ItemSlotArgumentType.itemSlot())
93+
}
94+
95+
/**
96+
* Creates an item stack argument with [name] as the parameter name.
97+
*
98+
* @param context The command build context
99+
*/
100+
@BrigadierDsl
101+
fun <S> itemStack(
102+
name: String,
103+
context: CommandRegistryAccess
104+
): DefaultArgumentConstructor<S, ItemStackArgumentType> {
105+
return argument(name, ItemStackArgumentType.itemStack(context))
106+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ import com.lambda.command.CommandManager.dispatcher
44
import com.lambda.util.Nameable
55
import com.lambda.util.primitives.extension.CommandBuilder
66
import com.mojang.brigadier.builder.LiteralArgumentBuilder
7+
import net.minecraft.command.CommandRegistryAccess
78
import net.minecraft.command.CommandSource
9+
import net.minecraft.registry.BuiltinRegistries
10+
import net.minecraft.server.command.CommandManager
811

912
abstract class LambdaCommand(
1013
final override val name: String,
1114
val aliases: Set<String> = emptySet(),
1215
val usage: String = "",
1316
val description: String = "",
1417
) : Nameable {
18+
val registry: CommandRegistryAccess by lazy {
19+
CommandManager.createRegistryAccess(BuiltinRegistries.createWrapperLookup())
20+
}
21+
1522
// ToDo: Include usage and description in the help command
1623
init {
1724
(listOf(name) + aliases).forEach {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.lambda.command.commands
22

3-
import com.lambda.brigadier.CommandResult.Companion.failure
43
import com.lambda.brigadier.CommandResult.Companion.success
54
import com.lambda.brigadier.argument.literal
65
import com.lambda.brigadier.executeWithResult
@@ -20,19 +19,17 @@ object ConfigCommand : LambdaCommand(
2019
required(literal("save")) {
2120
executeWithResult {
2221
Configuration.configurations.forEach { config ->
23-
config.trySave()?.let { return@executeWithResult failure(it) }
22+
config.trySave(true)
2423
}
25-
2624
this@ConfigCommand.info("Saved ${Configuration.configurations.size} configuration files.")
2725
return@executeWithResult success()
2826
}
2927
}
3028
required(literal("load")) {
3129
executeWithResult {
3230
Configuration.configurations.forEach { config ->
33-
config.tryLoad()?.let { return@executeWithResult failure(it) }
31+
config.tryLoad()
3432
}
35-
3633
this@ConfigCommand.info("Loaded ${Configuration.configurations.size} configuration files.")
3734
return@executeWithResult success()
3835
}

0 commit comments

Comments
 (0)