Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'QuiltMC:1.18' into 1.18
- Loading branch information
Showing
111 changed files
with
2,912 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id("qsl.library") | ||
} | ||
|
||
qslLibrary { | ||
libraryName = "command" | ||
version = "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id("qsl.module") | ||
} | ||
|
||
qslModule { | ||
moduleName = "client_command" | ||
version = "1.0.0" | ||
library = "command" | ||
coreDependencies([ | ||
"qsl_base" | ||
]) | ||
} |
96 changes: 96 additions & 0 deletions
96
...client_command/src/main/java/org/quiltmc/qsl/command/api/client/ClientCommandManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2016, 2017, 2018, 2019 FabricMC | ||
* Copyright 2022 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.qsl.command.api.client; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
/** | ||
* Manages client-sided commands and provides some related helper methods, analogous to | ||
* {@link net.minecraft.server.command.CommandManager CommandManager}. | ||
* <p> | ||
* Client-sided commands are executed wholly on the client, | ||
* so players can use them in both singleplayer and multiplayer. | ||
* <p> | ||
* Command registrations should be done with {@link ClientCommandRegistrationCallback}. | ||
* <p> | ||
* The commands are run on the client game thread by default. | ||
* Avoid doing any heavy calculations here as that can freeze the game's rendering. | ||
* To mitigate this, you can move heavy code to another thread. | ||
* <p> | ||
* This class also has alternatives to the server-side helper methods in | ||
* {@link net.minecraft.server.command.CommandManager CommandManager}: {@link #literal(String)} and | ||
* {@link #argument(String, ArgumentType)}. | ||
* <p> | ||
* Server-sided commands have precedence over client-sided commands. Client-sided commands which are overridden by | ||
* server-sided ones can be run anyway with {@code /qcc run}. | ||
* | ||
* <h2>Example command</h2> | ||
* <pre>{@code | ||
* ClientCommandRegistrationCallback.EVENT.register(dispatcher -> | ||
* dispatcher.register( | ||
* ClientCommandManager.literal("hello").executes(context -> { | ||
* context.getSource().sendFeedback(new LiteralText("Hello, world!")); | ||
* return 0; | ||
* }) | ||
* ) | ||
* ); | ||
* }</pre> | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
public final class ClientCommandManager { | ||
/** | ||
* The command dispatcher that handles client command registration and execution. | ||
*/ | ||
public static final CommandDispatcher<QuiltClientCommandSource> DISPATCHER = new CommandDispatcher<>(); | ||
|
||
private ClientCommandManager() { | ||
} | ||
|
||
/** | ||
* Creates a literal argument builder. | ||
* | ||
* @param name the literal name | ||
* @return the created argument builder | ||
* | ||
* @see LiteralArgumentBuilder#literal(String) | ||
* @see net.minecraft.server.command.CommandManager#literal(String) | ||
*/ | ||
public static LiteralArgumentBuilder<QuiltClientCommandSource> literal(String name) { | ||
return LiteralArgumentBuilder.literal(name); | ||
} | ||
|
||
/** | ||
* Creates a required argument builder. | ||
* | ||
* @param name the name of the argument | ||
* @param type the type of the argument | ||
* @param <T> the type of the parsed argument value | ||
* @return the created argument builder | ||
* | ||
* @see RequiredArgumentBuilder#argument(String, ArgumentType) | ||
* @see net.minecraft.server.command.CommandManager#argument(String, ArgumentType) | ||
*/ | ||
public static <T> RequiredArgumentBuilder<QuiltClientCommandSource, T> argument(String name, ArgumentType<T> type) { | ||
return RequiredArgumentBuilder.argument(name, type); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...d/src/main/java/org/quiltmc/qsl/command/api/client/ClientCommandRegistrationCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2022 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.qsl.command.api.client; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import org.quiltmc.qsl.base.api.event.Event; | ||
import org.quiltmc.qsl.base.api.event.client.ClientEventAwareListener; | ||
|
||
/** | ||
* Callback for registering client-side commands. | ||
* | ||
* @see ClientCommandManager | ||
*/ | ||
@FunctionalInterface | ||
@Environment(EnvType.CLIENT) | ||
public interface ClientCommandRegistrationCallback extends ClientEventAwareListener { | ||
/** | ||
* Event invoked when client-sided commands are registered. | ||
*/ | ||
Event<ClientCommandRegistrationCallback> EVENT = Event.create(ClientCommandRegistrationCallback.class, callbacks -> dispatcher -> { | ||
for (var callback : callbacks) { | ||
callback.registerCommands(dispatcher); | ||
} | ||
}); | ||
|
||
/** | ||
* Called when client-side commands are registered. | ||
* | ||
* @param dispatcher the command dispatcher | ||
*/ | ||
void registerCommands(CommandDispatcher<QuiltClientCommandSource> dispatcher); | ||
} |
119 changes: 119 additions & 0 deletions
119
...nt_command/src/main/java/org/quiltmc/qsl/command/api/client/QuiltClientCommandSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2016, 2017, 2018, 2019 FabricMC | ||
* Copyright 2022 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.qsl.command.api.client; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.math.Vec2f; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
/** | ||
* Extensions to {@link CommandSource}, implemented on {@link net.minecraft.client.network.ClientCommandSource | ||
* ClientCommandSource} for | ||
* client commands - most of these methods are equivalents to methods on | ||
* {@link net.minecraft.server.command.ServerCommandSource ServerCommandSource}, to provide a more familiar API. | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
public interface QuiltClientCommandSource extends CommandSource { | ||
/** | ||
* Sends a feedback message to the player. | ||
* | ||
* @param message the feedback message | ||
*/ | ||
void sendFeedback(Text message); | ||
|
||
/** | ||
* Sends an error message to the player. | ||
* | ||
* @param message the error message | ||
*/ | ||
void sendError(Text message); | ||
|
||
/** | ||
* Gets the client instance used to run the command. | ||
* | ||
* @return the client | ||
*/ | ||
MinecraftClient getClient(); | ||
|
||
/** | ||
* Gets the player that used the command. | ||
* | ||
* @return the player | ||
*/ | ||
ClientPlayerEntity getPlayer(); | ||
|
||
/** | ||
* Gets the entity that used the command. | ||
* | ||
* @return the entity | ||
*/ | ||
default Entity getEntity() { | ||
return getPlayer(); | ||
} | ||
|
||
/** | ||
* Gets the position from where the command has been executed. | ||
* | ||
* @return the position | ||
*/ | ||
default Vec3d getPosition() { | ||
return getPlayer().getPos(); | ||
} | ||
|
||
/** | ||
* Gets the rotation of the entity that used the command. | ||
* | ||
* @return the rotation | ||
*/ | ||
default Vec2f getRotation() { | ||
return getPlayer().getRotationClient(); | ||
} | ||
|
||
/** | ||
* Gets the world where the player used the command. | ||
* | ||
* @return the world | ||
*/ | ||
ClientWorld getWorld(); | ||
|
||
/** | ||
* Gets the meta property under {@code key} that was assigned to this source. | ||
* <p> | ||
* This method should return the same result for every call with the same {@code key}. | ||
* | ||
* @param key the meta key | ||
* | ||
* @return the meta | ||
*/ | ||
Object getMeta(String key); | ||
|
||
/** | ||
* Sets the meta property under key {@code key} with the value {@code value}. | ||
* | ||
* @param key the meta key | ||
* @param value the meta value | ||
*/ | ||
void setMeta(String key, Object value); | ||
} |
Oops, something went wrong.