Skip to content

Commit 9a8de30

Browse files
committed
Merge branch 'feature-1.19.2' into nyan-work/dev
Signed-off-by: Hendrix-Shen <[email protected]>
2 parents 123d92a + 64bdf43 commit 9a8de30

30 files changed

+653
-559
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ preprocess {
2020
def mc1201 = createNode("1.20.1", 1_20_01, "mojang")
2121

2222
mc1144.link(mc1152, null)
23-
mc1152.link(mc1165, null)
24-
mc1165.link(mc1171, file("versions/mapping-1.16.5-1.17.1.txt"))
23+
mc1152.link(mc1165, file("versions/mapping-1.15.2-1.16.5.txt"))
24+
mc1165.link(mc1171, null)
2525
mc1171.link(mc1182, null)
2626
mc1182.link(mc1192, file("versions/mapping-1.18.2-1.19.2.txt"))
2727
mc1192.link(mc1193, file("versions/mapping-1.19.2-1.19.3.txt"))
Original file line numberDiff line numberDiff line change
@@ -1,213 +1,4 @@
11
package com.plusls.ommc.api.command;
22

3-
//#if MC <= 11605
4-
//$$ import com.google.common.collect.Iterables;
5-
//$$ import com.mojang.brigadier.AmbiguityConsumer;
6-
//$$ import com.mojang.brigadier.CommandDispatcher;
7-
//$$ import com.mojang.brigadier.ParseResults;
8-
//$$ import com.mojang.brigadier.arguments.StringArgumentType;
9-
//$$ import com.mojang.brigadier.builder.ArgumentBuilder;
10-
//$$ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
11-
//$$ import com.mojang.brigadier.context.CommandContext;
12-
//$$ import com.mojang.brigadier.context.ParsedCommandNode;
13-
//$$ import com.mojang.brigadier.exceptions.BuiltInExceptionProvider;
14-
//$$ import com.mojang.brigadier.exceptions.CommandExceptionType;
15-
//$$ import com.mojang.brigadier.exceptions.CommandSyntaxException;
16-
//$$ import com.mojang.brigadier.tree.CommandNode;
17-
//$$ import com.plusls.ommc.mixin.accessor.AccessorHelpCommand;
18-
//$$ import net.minecraft.client.Minecraft;
19-
//$$ import net.minecraft.network.chat.Component;
20-
//$$ import net.minecraft.network.chat.ComponentUtils;
21-
//$$ import org.apache.logging.log4j.Level;
22-
//$$ import org.apache.logging.log4j.LogManager;
23-
//$$ import org.apache.logging.log4j.Logger;
24-
//$$ import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi;
25-
//$$ import top.hendrixshen.magiclib.language.api.I18n;
26-
//$$
27-
//$$ import java.util.HashMap;
28-
//$$ import java.util.List;
29-
//$$ import java.util.Map;
30-
//#endif
31-
32-
import net.fabricmc.api.EnvType;
33-
import net.fabricmc.api.Environment;
34-
35-
// Code from https://github.com/FabricMC/fabric/blob/1.17/fabric-command-api-v1/src/main/java/net/fabricmc/fabric/impl/command/client/ClientCommandInternals.java
36-
37-
@Environment(EnvType.CLIENT)
383
public final class ClientCommandInternals {
39-
//#if MC <= 11605
40-
//$$ private static final Logger LOGGER = LogManager.getLogger();
41-
//$$ private static final char PREFIX = '/';
42-
//$$ private static final String API_COMMAND_NAME = "fabric-command-api-v1:client";
43-
//$$ private static final String SHORT_API_COMMAND_NAME = "fcc";
44-
//$$
45-
//$$ /**
46-
//$$ * Executes a client-sided command from a message.
47-
//$$ *
48-
//$$ * @param message the command message
49-
//$$ * @return true if the message should not be sent to the server, false otherwise
50-
//$$ */
51-
//$$ public static boolean executeCommand(String message) {
52-
//$$ if (message.isEmpty()) {
53-
//$$ return false; // Nothing to process
54-
//$$ }
55-
//$$
56-
//$$ if (message.charAt(0) != PREFIX) {
57-
//$$ return false; // Incorrect prefix, won't execute anything.
58-
//$$ }
59-
//$$
60-
//$$ Minecraft client = Minecraft.getInstance();
61-
//$$
62-
//$$ // The interface is implemented on ClientCommandSource with a mixin.
63-
//$$ // noinspection ConstantConditions
64-
//$$ FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getConnection().getSuggestionsProvider();
65-
//$$
66-
//$$ client.getProfiler().push(message);
67-
//$$
68-
//$$ try {
69-
//$$ // TODO: Check for server commands before executing.
70-
//$$ // This requires parsing the command, checking if they match a server command
71-
//$$ // and then executing the command with the parse results.
72-
//$$ ClientCommandManager.DISPATCHER.execute(message.substring(1), commandSource);
73-
//$$ return true;
74-
//$$ } catch (CommandSyntaxException e) {
75-
//$$ boolean ignored = isIgnoredException(e.getType());
76-
//$$ LOGGER.log(ignored ? Level.DEBUG : Level.WARN, "Syntax exception for client-sided command '{}'", message, e);
77-
//$$
78-
//$$ if (ignored) {
79-
//$$ return false;
80-
//$$ }
81-
//$$
82-
//$$ commandSource.sendError(getErrorMessage(e));
83-
//$$ return true;
84-
//$$ } catch (RuntimeException e) {
85-
//$$ LOGGER.warn("Error while executing client-sided command '{}'", message, e);
86-
//$$ commandSource.sendError(ComponentCompatApi.literal(e.getMessage()));
87-
//$$ return true;
88-
//$$ } finally {
89-
//$$ client.getProfiler().pop();
90-
//$$ }
91-
//$$ }
92-
//$$
93-
//$$ /**
94-
//$$ * Tests whether a command syntax exception with the type
95-
//$$ * should be ignored and the message sent to the server.
96-
//$$ *
97-
//$$ * @param type the exception type
98-
//$$ * @return true if ignored, false otherwise
99-
//$$ */
100-
//$$ private static boolean isIgnoredException(CommandExceptionType type) {
101-
//$$ BuiltInExceptionProvider builtins = CommandSyntaxException.BUILT_IN_EXCEPTIONS;
102-
//$$
103-
//$$ // Only ignore unknown commands and node parse exceptions.
104-
//$$ // The argument-related dispatcher exceptions are not ignored because
105-
//$$ // they will only happen if the user enters a correct command.
106-
//$$ return type == builtins.dispatcherUnknownCommand() || type == builtins.dispatcherParseException();
107-
//$$ }
108-
//$$
109-
//$$ // See CommandSuggestor.method_30505. That cannot be used directly as it returns an OrderedText instead of a Text.
110-
//$$ private static Component getErrorMessage(CommandSyntaxException e) {
111-
//$$ Component message = ComponentUtils.fromMessage(e.getRawMessage());
112-
//$$ String context = e.getContext();
113-
//$$
114-
//$$ return context != null ? ComponentCompatApi.translatable("command.context.parse_error", message, context) : message;
115-
//$$ }
116-
//$$
117-
//$$ /**
118-
//$$ * Runs final initialization tasks such as {@link CommandDispatcher#findAmbiguities(AmbiguityConsumer)}
119-
//$$ * on the command dispatcher. Also registers a {@code /fcc help} command if there are other commands present.
120-
//$$ */
121-
//$$ public static void finalizeInit() {
122-
//$$ if (!ClientCommandManager.DISPATCHER.getRoot().getChildren().isEmpty()) {
123-
//$$ // Register an API command if there are other commands;
124-
//$$ // these helpers are not needed if there are no client commands
125-
//$$ LiteralArgumentBuilder<FabricClientCommandSource> help = ClientCommandManager.literal("help");
126-
//$$ help.executes(ClientCommandInternals::executeRootHelp);
127-
//$$ help.then(ClientCommandManager.argument("command", StringArgumentType.greedyString()).executes(ClientCommandInternals::executeArgumentHelp));
128-
//$$
129-
//$$ CommandNode<FabricClientCommandSource> mainNode = ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal(API_COMMAND_NAME).then(help));
130-
//$$ ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal(SHORT_API_COMMAND_NAME).redirect(mainNode));
131-
//$$ }
132-
//$$
133-
//$$ // noinspection CodeBlock2Expr
134-
//$$ ClientCommandManager.DISPATCHER.findAmbiguities((parent, child, sibling, inputs) -> {
135-
//$$ LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", ClientCommandManager.DISPATCHER.getPath(child), ClientCommandManager.DISPATCHER.getPath(sibling), inputs);
136-
//$$ });
137-
//$$ }
138-
//$$
139-
//$$ private static int executeRootHelp(CommandContext<FabricClientCommandSource> context) {
140-
//$$ return executeHelp(ClientCommandManager.DISPATCHER.getRoot(), context);
141-
//$$ }
142-
//$$
143-
//$$ private static int executeArgumentHelp(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
144-
//$$ ParseResults<FabricClientCommandSource> parseResults = ClientCommandManager.DISPATCHER.parse(StringArgumentType.getString(context, "command"), context.getSource());
145-
//$$ List<ParsedCommandNode<FabricClientCommandSource>> nodes = parseResults.getContext().getNodes();
146-
//$$
147-
//$$ if (nodes.isEmpty()) {
148-
//$$ throw AccessorHelpCommand.getFailedException().create();
149-
//$$ }
150-
//$$
151-
//$$ return executeHelp(Iterables.getLast(nodes).getNode(), context);
152-
//$$ }
153-
//$$
154-
//$$ private static int executeHelp(CommandNode<FabricClientCommandSource> startNode, CommandContext<FabricClientCommandSource> context) {
155-
//$$ Map<CommandNode<FabricClientCommandSource>, String> commands = ClientCommandManager.DISPATCHER.getSmartUsage(startNode, context.getSource());
156-
//$$
157-
//$$ for (String command : commands.values()) {
158-
//$$ context.getSource().sendFeedback(ComponentCompatApi.literal("/" + command));
159-
//$$ }
160-
//$$
161-
//$$ return commands.size();
162-
//$$ }
163-
//$$
164-
//$$ public static void addCommands(CommandDispatcher<FabricClientCommandSource> target, FabricClientCommandSource source) {
165-
//$$ Map<CommandNode<FabricClientCommandSource>, CommandNode<FabricClientCommandSource>> originalToCopy = new HashMap<>();
166-
//$$ originalToCopy.put(ClientCommandManager.DISPATCHER.getRoot(), target.getRoot());
167-
//$$ copyChildren(ClientCommandManager.DISPATCHER.getRoot(), target.getRoot(), source, originalToCopy);
168-
//$$ }
169-
//$$
170-
//$$ /**
171-
//$$ * Copies the child commands from origin to target, filtered by {@code child.canUse(source)}.
172-
//$$ * Mimics vanilla's CommandManager.makeTreeForSource.
173-
//$$ *
174-
//$$ * @param origin the source command node
175-
//$$ * @param target the target command node
176-
//$$ * @param source the command source
177-
//$$ * @param originalToCopy a mutable map from original command nodes to their copies, used for redirects;
178-
//$$ * should contain a mapping from origin to target
179-
//$$ */
180-
//$$ private static void copyChildren(
181-
//$$ CommandNode<FabricClientCommandSource> origin,
182-
//$$ CommandNode<FabricClientCommandSource> target,
183-
//$$ FabricClientCommandSource source,
184-
//$$ Map<CommandNode<FabricClientCommandSource>, CommandNode<FabricClientCommandSource>> originalToCopy
185-
//$$ ) {
186-
//$$ for (CommandNode<FabricClientCommandSource> child : origin.getChildren()) {
187-
//$$ if (!child.canUse(source)) continue;
188-
//$$
189-
//$$ ArgumentBuilder<FabricClientCommandSource, ?> builder = child.createBuilder();
190-
//$$
191-
//$$ // Reset the unnecessary non-completion stuff from the builder
192-
//$$ builder.requires(s -> true); // This is checked with the if check above.
193-
//$$
194-
//$$ if (builder.getCommand() != null) {
195-
//$$ builder.executes(context -> 0);
196-
//$$ }
197-
//$$
198-
//$$ // Set up redirects
199-
//$$ if (builder.getRedirect() != null) {
200-
//$$ builder.redirect(originalToCopy.get(builder.getRedirect()));
201-
//$$ }
202-
//$$
203-
//$$ CommandNode<FabricClientCommandSource> result = builder.build();
204-
//$$ originalToCopy.put(child, result);
205-
//$$ target.addChild(result);
206-
//$$
207-
//$$ if (!child.getChildren().isEmpty()) {
208-
//$$ copyChildren(child, result, source, originalToCopy);
209-
//$$ }
210-
//$$ }
211-
//$$ }
212-
//#endif
2134
}
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,4 @@
11
package com.plusls.ommc.api.command;
22

3-
import com.mojang.brigadier.arguments.ArgumentType;
4-
import net.fabricmc.api.EnvType;
5-
import net.fabricmc.api.Environment;
6-
7-
//#if MC <= 11605
8-
//$$ import com.mojang.brigadier.CommandDispatcher;
9-
//$$ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
10-
//$$ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
11-
//#endif
12-
13-
// Code from https://github.com/FabricMC/fabric/blob/1.17/fabric-command-api-v1/src/main/java/net/fabricmc/fabric/api/client/command/v1/ClientCommandManager.java
14-
15-
/**
16-
* Manages client-sided commands and provides some related helper methods.
17-
*
18-
* <p>Client-sided commands are fully executed on the client,
19-
* so players can use them in both singleplayer and multiplayer.
20-
*
21-
* <p>Registrations can be done in the {@link #DISPATCHER} during a {@link net.fabricmc.api.ClientModInitializer}'s
22-
* initialization. (See example below.)
23-
*
24-
* <p>The commands are run on the client game thread by default.
25-
* Avoid doing any heavy calculations here as that can freeze the game's rendering.
26-
* For example, you can move heavy code to another thread.
27-
*
28-
* <p>This class also has alternatives to the server-side helper methods in
29-
* {@link net.minecraft.commands.Commands}:
30-
* {@link #literal(String)} and {@link #argument(String, ArgumentType)}.
31-
*
32-
* <p>The precedence rules of client-sided and server-sided commands with the same name
33-
* are an implementation detail that is not guaranteed to remain the same in future versions.
34-
* The aim is to make commands from the server take precedence over client-sided commands
35-
* in a future version of this API.
36-
*
37-
* <h2>Example command</h2>
38-
* <pre>
39-
* {@code
40-
* ClientCommandManager.DISPATCHER.register(
41-
* ClientCommandManager.literal("hello").executes(context -> {
42-
* context.getSource().sendFeedback(new LiteralText("Hello, world!"));
43-
* return 0;
44-
* })
45-
* );
46-
* }
47-
* </pre>
48-
*/
49-
@Environment(EnvType.CLIENT)
503
public final class ClientCommandManager {
51-
//#if MC <= 11605
52-
//$$ /**
53-
//$$ * The command dispatcher that handles client command registration and execution.
54-
//$$ */
55-
//$$ public static final CommandDispatcher<FabricClientCommandSource> DISPATCHER = new CommandDispatcher<>();
56-
//$$
57-
//$$ private ClientCommandManager() {
58-
//$$ }
59-
//$$
60-
//$$ /**
61-
//$$ * Creates a literal argument builder.
62-
//$$ *
63-
//$$ * @param name the literal name
64-
//$$ * @return the created argument builder
65-
//$$ */
66-
//$$ public static LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
67-
//$$ return LiteralArgumentBuilder.literal(name);
68-
//$$ }
69-
//$$
70-
//$$ /**
71-
//$$ * Creates a required argument builder.
72-
//$$ *
73-
//$$ * @param name the name of the argument
74-
//$$ * @param type the type of the argument
75-
//$$ * @param <T> the type of the parsed argument value
76-
//$$ * @return the created argument builder
77-
//$$ */
78-
//$$ public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument(String name, ArgumentType<T> type) {
79-
//$$ return RequiredArgumentBuilder.argument(name, type);
80-
//$$ }
81-
//#endif
824
}

0 commit comments

Comments
 (0)