Skip to content

Commit fc6f6bc

Browse files
committed
Merge branch 'feature/taskflow' into feature/packetmine
# Conflicts: # common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt
2 parents 880d66a + 36f1034 commit fc6f6bc

File tree

153 files changed

+4528
-2179
lines changed

Some content is hidden

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

153 files changed

+4528
-2179
lines changed

build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
118
import org.gradle.internal.jvm.*
219
import net.fabricmc.loom.api.LoomGradleExtensionAPI
320
import org.apache.tools.ant.taskdefs.condition.Os

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.ClientEvent;
23-
import com.lambda.event.events.ScreenHandlerEvent;
23+
import com.lambda.event.events.InventoryEvent;
2424
import com.lambda.event.events.TickEvent;
2525
import com.lambda.module.modules.player.Interact;
2626
import net.minecraft.client.MinecraftClient;
@@ -78,15 +78,15 @@ private void onStartup(CallbackInfo ci) {
7878
private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
7979
if (screen == null) return;
8080
if (screen instanceof ScreenHandlerProvider<?> handledScreen) {
81-
EventFlow.post(new ScreenHandlerEvent.Open(handledScreen.getScreenHandler()));
81+
EventFlow.post(new InventoryEvent.Open(handledScreen.getScreenHandler()));
8282
}
8383
}
8484

8585
@Inject(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;removed()V", shift = At.Shift.AFTER))
8686
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
8787
if (currentScreen == null) return;
8888
if (currentScreen instanceof ScreenHandlerProvider<?> handledScreen) {
89-
EventFlow.post(new ScreenHandlerEvent.Close(handledScreen.getScreenHandler()));
89+
EventFlow.post(new InventoryEvent.Close(handledScreen.getScreenHandler()));
9090
}
9191
}
9292

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.mixin.network;
19+
20+
import com.lambda.event.EventFlow;
21+
import com.lambda.event.events.InventoryEvent;
22+
import net.minecraft.client.network.ClientPlayNetworkHandler;
23+
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
24+
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
29+
30+
@Mixin(ClientPlayNetworkHandler.class)
31+
public class ClientPlayNetworkHandlerMixin {
32+
@Inject(method = "onUpdateSelectedSlot", at = @At(value = "TAIL"))
33+
private void onUpdateSelectedSlot(UpdateSelectedSlotS2CPacket packet, CallbackInfo ci) {
34+
EventFlow.post(new InventoryEvent.SelectedHotbarSlotUpdate(packet.getSlot()));
35+
}
36+
37+
@Inject(method = "onScreenHandlerSlotUpdate", at = @At(value = "TAIL"))
38+
private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet, CallbackInfo ci) {
39+
EventFlow.post(new InventoryEvent.SlotUpdate(packet.getSyncId(), packet.getRevision(), packet.getSlot(), packet.getStack()));
40+
}
41+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.mixin.render;
1919

20-
import com.lambda.task.RootTask;
20+
import com.lambda.task.TaskFlow;
2121
import com.lambda.util.DebugInfoHud;
2222
import net.minecraft.client.gui.hud.DebugHud;
2323
import org.spongepowered.asm.mixin.Mixin;
@@ -36,6 +36,6 @@ private void onGetRightText(CallbackInfoReturnable<List<String>> cir) {
3636

3737
@Inject(method = "getLeftText", at = @At(value = "TAIL"))
3838
private void onGetLeftText(CallbackInfoReturnable<List<String>> cir) {
39-
RootTask.INSTANCE.addInfo(cir.getReturnValue());
39+
cir.getReturnValue().addAll(List.of(TaskFlow.INSTANCE.toString().split("\n")));
4040
}
4141
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package com.lambda.mixin.render;
1919

2020
import com.lambda.event.EventFlow;
21-
import com.lambda.event.events.ScreenHandlerEvent;
21+
import com.lambda.event.events.InventoryEvent;
2222
import net.minecraft.item.ItemStack;
2323
import net.minecraft.screen.ScreenHandler;
2424
import org.spongepowered.asm.mixin.Mixin;
@@ -32,6 +32,6 @@
3232
public class ScreenHandlerMixin {
3333
@Inject(method = "updateSlotStacks", at = @At("TAIL"))
3434
private void onUpdateSlotStacksHead(int revision, List<ItemStack> stacks, ItemStack cursorStack, CallbackInfo ci) {
35-
EventFlow.post(new ScreenHandlerEvent.Update(revision, stacks, cursorStack));
35+
EventFlow.post(new InventoryEvent.FullUpdate(revision, stacks, cursorStack));
3636
}
3737
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@
3434

3535
@Mixin(ClientWorld.class)
3636
public class ClientWorldMixin {
37-
@Inject(method = "handleBlockUpdate", at = @At("HEAD"), cancellable = true)
38-
private void handleBlockUpdateInject(BlockPos pos, BlockState state, int flags, CallbackInfo ci) {
39-
if (EventFlow.post(new WorldEvent.BlockUpdate(pos, state, flags)).isCanceled()) {
40-
ci.cancel();
41-
}
42-
}
43-
4437
@Inject(method = "addEntity", at = @At("HEAD"), cancellable = true)
4538
private void addEntity(Entity entity, CallbackInfo ci) {
4639
if (EventFlow.post(new WorldEvent.EntitySpawn(entity)).isCanceled()) ci.cancel();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.mixin.world;
19+
20+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
21+
import net.minecraft.block.Block;
22+
import net.minecraft.nbt.NbtCompound;
23+
import net.minecraft.registry.RegistryEntryLookup;
24+
import net.minecraft.structure.StructureTemplate;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.Shadow;
27+
import org.spongepowered.asm.mixin.injection.At;
28+
import org.spongepowered.asm.mixin.injection.Inject;
29+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
30+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
31+
32+
import java.util.Objects;
33+
34+
@Mixin(StructureTemplate.class)
35+
public class StructureTemplateMixin {
36+
@Shadow
37+
private String author;
38+
39+
@ModifyReturnValue(method = "getAuthor()Ljava/lang/String;", at = @At("RETURN"))
40+
public String getAuthor(String original) {
41+
return Objects.equals(original, "?") || Objects.equals(original, "") ? "Unknown" : original;
42+
}
43+
44+
@Inject(method = "writeNbt(Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/nbt/NbtCompound;", at = @At("TAIL"))
45+
public void writeNbt(NbtCompound nbt, CallbackInfoReturnable<NbtCompound> cir) {
46+
nbt.putString("author", author);
47+
}
48+
49+
@Inject(method = "readNbt(Lnet/minecraft/registry/RegistryEntryLookup;Lnet/minecraft/nbt/NbtCompound;)V", at = @At("TAIL"))
50+
public void readNbt(RegistryEntryLookup<Block> blockLookup, NbtCompound nbt, CallbackInfo ci) {
51+
author = nbt.getString("author");
52+
}
53+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.mixin.world;
19+
20+
import com.lambda.event.EventFlow;
21+
import com.lambda.event.events.WorldEvent;
22+
import net.minecraft.block.BlockState;
23+
import net.minecraft.util.math.BlockPos;
24+
import net.minecraft.world.World;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
29+
30+
@Mixin(World.class)
31+
public abstract class WorldMixin {
32+
@Inject(method = "onBlockChanged", at = @At("TAIL"))
33+
void onBlockChanged(BlockPos pos, BlockState oldBlock, BlockState newBlock, CallbackInfo ci) {
34+
EventFlow.post(new WorldEvent.BlockChange(pos, oldBlock, newBlock));
35+
}
36+
}

common/src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ object Lambda {
6363
.registerTypeAdapter(Optional::class.java, OptionalSerializer)
6464
.create()
6565

66-
fun initialize(block: () -> Unit) {
66+
fun initialize(block: (Long) -> Unit) {
6767
recordRenderCall {
68-
Loader.initialize()
69-
block()
68+
block(Loader.initialize())
7069
}
7170
}
7271
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2024 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+
package com.lambda.brigadier.argument
18+
19+
import com.lambda.brigadier.*
20+
import com.lambda.brigadier.assumeSourceNotUsed
21+
import net.minecraft.advancement.AdvancementEntry
22+
import net.minecraft.command.argument.IdentifierArgumentType
23+
import net.minecraft.loot.condition.LootCondition
24+
import net.minecraft.loot.function.LootFunction
25+
import net.minecraft.recipe.RecipeEntry
26+
import net.minecraft.server.command.ServerCommandSource
27+
import net.minecraft.util.Identifier
28+
29+
/**
30+
* Reads the [Identifier] value from the
31+
* argument in the receiver [ArgumentReader].
32+
*
33+
* @see IdentifierArgumentType.getIdentifier
34+
*/
35+
@JvmName("valueIdentifierArg")
36+
@BrigadierDsl
37+
fun DefaultArgumentReader<IdentifierArgumentType>.value(): Identifier {
38+
return IdentifierArgumentType.getIdentifier(context.assumeSourceNotUsed(), name)
39+
}
40+
41+
/**
42+
* Reads the [Identifier] value from the
43+
* argument in the receiver [ArgumentReader]
44+
* as an [AdvancementEntry].
45+
*
46+
* @see IdentifierArgumentType.getAdvancementArgument
47+
*/
48+
@BrigadierDsl
49+
fun ArgumentReader<
50+
ServerCommandSource,
51+
DefaultArgumentDescriptor<
52+
IdentifierArgumentType
53+
>
54+
>.asAdvancement(): AdvancementEntry {
55+
return IdentifierArgumentType.getAdvancementArgument(context, name)
56+
}
57+
58+
/**
59+
* Reads the [Identifier] value from the
60+
* argument in the receiver [ArgumentReader]
61+
* as a [LootCondition].
62+
*
63+
* @see IdentifierArgumentType.getPredicateArgument
64+
*/
65+
@BrigadierDsl
66+
fun ArgumentReader<
67+
ServerCommandSource,
68+
DefaultArgumentDescriptor<
69+
IdentifierArgumentType
70+
>
71+
>.asPredicate(): LootCondition {
72+
return IdentifierArgumentType.getPredicateArgument(context, name)
73+
}
74+
75+
/**
76+
* Reads the [Identifier] value from the
77+
* argument in the receiver [ArgumentReader]
78+
* as a [LootFunction].
79+
*
80+
* @see IdentifierArgumentType.getItemModifierArgument
81+
*/
82+
@BrigadierDsl
83+
fun ArgumentReader<
84+
ServerCommandSource,
85+
DefaultArgumentDescriptor<
86+
IdentifierArgumentType
87+
>
88+
>.asItemModifier(): LootFunction {
89+
return IdentifierArgumentType.getItemModifierArgument(context, name)
90+
}
91+
92+
/**
93+
* Reads the [Identifier] value from the
94+
* argument in the receiver [ArgumentReader]
95+
* as a [RecipeEntry].
96+
*
97+
* @see IdentifierArgumentType.getRecipeArgument
98+
*/
99+
@BrigadierDsl
100+
fun ArgumentReader<
101+
ServerCommandSource,
102+
DefaultArgumentDescriptor<
103+
IdentifierArgumentType
104+
>
105+
>.asRecipe(): RecipeEntry<*> {
106+
return IdentifierArgumentType.getRecipeArgument(context, name)
107+
}
108+
109+
/**
110+
* Creates an identifier argument with [name] as the parameter name.
111+
*/
112+
@BrigadierDsl
113+
fun <S> identifier(
114+
name: String
115+
): DefaultArgumentConstructor<S, IdentifierArgumentType> {
116+
return argument(name, IdentifierArgumentType.identifier())
117+
}

0 commit comments

Comments
 (0)