Skip to content

Commit 22caa28

Browse files
committed
Merge remote-tracking branch 'origin/1.19.2' into 1.20
Signed-off-by: shedaniel <[email protected]> # Conflicts: # fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java # forge/src/main/java/dev/architectury/event/forge/EventHandlerImplClient.java # gradle.properties
2 parents ac1bd64 + cd74016 commit 22caa28

File tree

9 files changed

+236
-8
lines changed

9 files changed

+236
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This file is part of architectury.
3+
* Copyright (C) 2020, 2021, 2022 architectury
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
package dev.architectury.event.events.client;
21+
22+
import com.mojang.brigadier.CommandDispatcher;
23+
import com.mojang.brigadier.arguments.ArgumentType;
24+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
25+
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
26+
import dev.architectury.event.Event;
27+
import dev.architectury.event.EventFactory;
28+
import net.minecraft.client.multiplayer.ClientLevel;
29+
import net.minecraft.client.player.LocalPlayer;
30+
import net.minecraft.commands.CommandBuildContext;
31+
import net.minecraft.commands.SharedSuggestionProvider;
32+
import net.minecraft.network.chat.Component;
33+
import net.minecraft.world.phys.Vec2;
34+
import net.minecraft.world.phys.Vec3;
35+
36+
import java.util.function.Supplier;
37+
38+
public interface ClientCommandRegistrationEvent {
39+
/**
40+
* @see ClientCommandRegistrationEvent#register(CommandDispatcher, CommandBuildContext)
41+
*/
42+
Event<ClientCommandRegistrationEvent> EVENT = EventFactory.createLoop();
43+
44+
/**
45+
* This event is invoked after the client initializes.
46+
* Equivalent to Forge's {@code RegisterClientCommandsEvent} and Fabric's {@code ClientCommandManager}.
47+
*
48+
* @param dispatcher The command dispatcher to register commands to.
49+
* @param context The command build context.
50+
*/
51+
void register(CommandDispatcher<ClientCommandSourceStack> dispatcher, CommandBuildContext context);
52+
53+
static LiteralArgumentBuilder<ClientCommandSourceStack> literal(String name) {
54+
return LiteralArgumentBuilder.literal(name);
55+
}
56+
57+
static <T> RequiredArgumentBuilder<ClientCommandSourceStack, T> argument(String name, ArgumentType<T> type) {
58+
return RequiredArgumentBuilder.argument(name, type);
59+
}
60+
61+
interface ClientCommandSourceStack extends SharedSuggestionProvider {
62+
void arch$sendSuccess(Supplier<Component> message, boolean broadcastToAdmins);
63+
64+
void arch$sendFailure(Component message);
65+
66+
LocalPlayer arch$getPlayer();
67+
68+
Vec3 arch$getPosition();
69+
70+
Vec2 arch$getRotation();
71+
72+
ClientLevel arch$getLevel();
73+
}
74+
}

fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919

2020
package dev.architectury.event.fabric;
2121

22-
import dev.architectury.event.events.client.ClientGuiEvent;
23-
import dev.architectury.event.events.client.ClientLifecycleEvent;
24-
import dev.architectury.event.events.client.ClientTickEvent;
25-
import dev.architectury.event.events.client.ClientTooltipEvent;
22+
import com.mojang.brigadier.CommandDispatcher;
23+
import dev.architectury.event.events.client.*;
2624
import dev.architectury.event.events.common.*;
2725
import dev.architectury.impl.fabric.ChatComponentImpl;
2826
import net.fabricmc.api.EnvType;
2927
import net.fabricmc.api.Environment;
28+
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
3029
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
3130
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
3231
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
@@ -58,6 +57,11 @@ public static void registerClient() {
5857

5958
ItemTooltipCallback.EVENT.register((itemStack, tooltipFlag, list) -> ClientTooltipEvent.ITEM.invoker().append(itemStack, list, tooltipFlag));
6059
HudRenderCallback.EVENT.register((graphics, tickDelta) -> ClientGuiEvent.RENDER_HUD.invoker().renderHud(graphics, tickDelta));
60+
61+
ClientCommandRegistrationCallback.EVENT.register((dispatcher, access) -> {
62+
ClientCommandRegistrationEvent.EVENT.invoker().register((CommandDispatcher<ClientCommandRegistrationEvent.ClientCommandSourceStack>)
63+
(CommandDispatcher<?>) dispatcher, access);
64+
});
6165
}
6266

6367
public static void registerCommon() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* This file is part of architectury.
3+
* Copyright (C) 2020, 2021, 2022 architectury
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
package dev.architectury.mixin.fabric.client;
21+
22+
import dev.architectury.event.events.client.ClientCommandRegistrationEvent;
23+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
24+
import net.minecraft.client.multiplayer.ClientLevel;
25+
import net.minecraft.client.player.LocalPlayer;
26+
import net.minecraft.network.chat.Component;
27+
import net.minecraft.world.phys.Vec2;
28+
import net.minecraft.world.phys.Vec3;
29+
import org.spongepowered.asm.mixin.Mixin;
30+
31+
import java.util.function.Supplier;
32+
33+
@Mixin(FabricClientCommandSource.class)
34+
public interface MixinFabricClientCommandSource extends ClientCommandRegistrationEvent.ClientCommandSourceStack {
35+
@Override
36+
default void arch$sendSuccess(Supplier<Component> message, boolean broadcastToAdmins) {
37+
((FabricClientCommandSource) this).sendFeedback(message.get());
38+
}
39+
40+
@Override
41+
default void arch$sendFailure(Component message) {
42+
((FabricClientCommandSource) this).sendError(message);
43+
}
44+
45+
@Override
46+
default LocalPlayer arch$getPlayer() {
47+
return ((FabricClientCommandSource) this).getPlayer();
48+
}
49+
50+
@Override
51+
default Vec3 arch$getPosition() {
52+
return ((FabricClientCommandSource) this).getPosition();
53+
}
54+
55+
@Override
56+
default Vec2 arch$getRotation() {
57+
return ((FabricClientCommandSource) this).getRotation();
58+
}
59+
60+
@Override
61+
default ClientLevel arch$getLevel() {
62+
return ((FabricClientCommandSource) this).getWorld();
63+
}
64+
}

fabric/src/main/resources/architectury.mixins.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"client.MixinClientPacketListener",
1313
"client.MixinDebugScreenOverlay",
1414
"client.MixinEffectInstance",
15+
"client.MixinFabricClientCommandSource",
1516
"client.MixinGameRenderer",
1617
"client.MixinGuiGraphics",
1718
"client.MixinIntegratedServer",

forge/src/main/java/dev/architectury/event/forge/EventHandlerImplClient.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package dev.architectury.event.forge;
2121

22+
import com.mojang.brigadier.CommandDispatcher;
2223
import dev.architectury.event.CompoundEventResult;
2324
import dev.architectury.event.EventResult;
2425
import dev.architectury.event.events.client.ClientChatEvent;
@@ -323,6 +324,12 @@ public static void eventInputEvent(InputEvent.Key event) {
323324
ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(Minecraft.getInstance(), event.getKey(), event.getScanCode(), event.getAction(), event.getModifiers());
324325
}
325326

327+
@SubscribeEvent(priority = EventPriority.HIGH)
328+
public static void event(RegisterClientCommandsEvent event) {
329+
ClientCommandRegistrationEvent.EVENT.invoker().register((CommandDispatcher<ClientCommandRegistrationEvent.ClientCommandSourceStack>)
330+
(CommandDispatcher<?>) event.getDispatcher(), event.getBuildContext());
331+
}
332+
326333
@OnlyIn(Dist.CLIENT)
327334
public static class ModBasedEventHandler {
328335
@SubscribeEvent(priority = EventPriority.HIGH)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* This file is part of architectury.
3+
* Copyright (C) 2020, 2021, 2022 architectury
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
package dev.architectury.mixin.forge.client;
21+
22+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
23+
import dev.architectury.event.events.client.ClientCommandRegistrationEvent;
24+
import net.minecraft.client.multiplayer.ClientLevel;
25+
import net.minecraft.client.player.LocalPlayer;
26+
import net.minecraft.commands.CommandSourceStack;
27+
import net.minecraft.network.chat.Component;
28+
import net.minecraft.world.phys.Vec2;
29+
import net.minecraft.world.phys.Vec3;
30+
import org.spongepowered.asm.mixin.Mixin;
31+
32+
import java.util.function.Supplier;
33+
34+
@Mixin(CommandSourceStack.class)
35+
public abstract class MixinCommandSourceStack implements ClientCommandRegistrationEvent.ClientCommandSourceStack {
36+
@Override
37+
public void arch$sendSuccess(Supplier<Component> message, boolean broadcastToAdmins) {
38+
((CommandSourceStack) (Object) this).sendSuccess(message, broadcastToAdmins);
39+
}
40+
41+
@Override
42+
public void arch$sendFailure(Component message) {
43+
((CommandSourceStack) (Object) this).sendFailure(message);
44+
}
45+
46+
@Override
47+
public LocalPlayer arch$getPlayer() {
48+
try {
49+
return (LocalPlayer) ((CommandSourceStack) (Object) this).getEntityOrException();
50+
} catch (CommandSyntaxException e) {
51+
throw new RuntimeException(e);
52+
}
53+
}
54+
55+
@Override
56+
public Vec3 arch$getPosition() {
57+
return ((CommandSourceStack) (Object) this).getPosition();
58+
}
59+
60+
@Override
61+
public Vec2 arch$getRotation() {
62+
return ((CommandSourceStack) (Object) this).getRotation();
63+
}
64+
65+
@Override
66+
public ClientLevel arch$getLevel() {
67+
return (ClientLevel) ((CommandSourceStack) (Object) this).getUnsidedLevel();
68+
}
69+
}

forge/src/main/resources/architectury.mixins.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"compatibilityLevel": "JAVA_16",
66
"minVersion": "0.8",
77
"client": [
8+
"client.MixinCommandSourceStack",
89
"MixinClientLevel",
910
"MixinMinecraft"
1011
],

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ artifact_type=release
1010

1111
archives_base_name=architectury
1212
archives_base_name_snapshot=architectury-snapshot
13-
base_version=9.1
13+
base_version=9.2
1414
maven_group=dev.architectury
1515

1616
fabric_loader_version=0.14.21

testmod-common/src/main/java/dev/architectury/test/TestMod.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
package dev.architectury.test;
2121

22+
import com.mojang.brigadier.arguments.StringArgumentType;
23+
import dev.architectury.event.events.client.ClientCommandRegistrationEvent;
2224
import dev.architectury.event.events.client.ClientLifecycleEvent;
2325
import dev.architectury.registry.client.gui.ClientTooltipComponentRegistry;
2426
import dev.architectury.registry.client.level.entity.EntityRendererRegistry;
2527
import dev.architectury.test.debug.ConsoleMessageSink;
2628
import dev.architectury.test.debug.MessageSink;
2729
import dev.architectury.test.debug.client.ClientOverlayMessageSink;
28-
import dev.architectury.test.entity.TestEntity;
2930
import dev.architectury.test.events.DebugEvents;
3031
import dev.architectury.test.gamerule.TestGameRules;
3132
import dev.architectury.test.item.TestBlockInteractions;
@@ -43,8 +44,6 @@
4344
import net.fabricmc.api.EnvType;
4445
import net.fabricmc.api.Environment;
4546
import net.minecraft.client.renderer.entity.CowRenderer;
46-
import net.minecraft.client.renderer.entity.PigRenderer;
47-
import net.minecraft.world.entity.animal.Cow;
4847

4948
public class TestMod {
5049
public static final MessageSink SINK = EnvExecutor.getEnvSpecific(() -> ClientOverlayMessageSink::new, () -> ConsoleMessageSink::new);
@@ -75,6 +74,15 @@ public static void initializeClient() {
7574
EntityRendererRegistry.register(TestRegistries.TEST_ENTITY, CowRenderer::new);
7675
EntityRendererRegistry.register(TestRegistries.TEST_ENTITY_2, CowRenderer::new);
7776
ClientTooltipComponentRegistry.register(ItemWithTooltip.MyTooltipComponent.class, ItemWithTooltip.MyClientTooltipComponent::new);
77+
ClientCommandRegistrationEvent.EVENT.register((dispatcher, access) -> {
78+
dispatcher.register(ClientCommandRegistrationEvent.literal("cool_client")
79+
.then(ClientCommandRegistrationEvent.argument("string", StringArgumentType.string())
80+
.executes(context -> {
81+
String string = StringArgumentType.getString(context, "string");
82+
SINK.accept("Cool client command for " + string);
83+
return 0;
84+
})));
85+
});
7886
}
7987
}
8088
}

0 commit comments

Comments
 (0)