Skip to content

Commit

Permalink
Merge branch 'QuiltMC:1.18' into 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Platymemo committed Jan 25, 2022
2 parents fe97c54 + 229fedc commit 72db1c7
Show file tree
Hide file tree
Showing 111 changed files with 2,912 additions and 243 deletions.
2 changes: 1 addition & 1 deletion build-logic/src/main/java/qsl/internal/Versions.java
Expand Up @@ -24,7 +24,7 @@ public final class Versions {
/**
* The target Minecraft version.
*/
public static final String MINECRAFT_VERSION = "1.18.1";
public static final String MINECRAFT_VERSION = "22w03a";

/**
* The target Quilt Mappings build.
Expand Down
@@ -1,13 +1,5 @@
package qsl.internal.extension;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.inject.Inject;

import groovy.util.Node;
import org.gradle.api.Action;
import org.gradle.api.Project;
Expand All @@ -25,6 +17,9 @@
import qsl.internal.task.ApplyLicenseTask;
import qsl.internal.task.CheckLicenseTask;

import javax.inject.Inject;
import java.util.*;

public class QslModuleExtension extends QslExtension {
private final Property<String> library;
private final Property<String> moduleName;
Expand Down Expand Up @@ -92,17 +87,31 @@ public void coreTestmodDependencies(Iterable<String> dependencies) {
}
}

public void interLibraryDependencies(Iterable<String> dependencies) {
public void intraLibraryDependencies(Iterable<String> dependencies) {
this.addIntraLibraryDependencies(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, dependencies);
}

public void intraLibraryTestmodDependencies(Iterable<String> dependencies) {
this.addIntraLibraryDependencies("testmodImplementation", dependencies);
}

private void addIntraLibraryDependencies(String configuration, Iterable<String> dependencies) {
String library = this.getLibrary().get();
}

public void interLibraryTestmodDependencies(String library, Iterable<String> dependencies) {
this.addInterLibraryDependencies("testmodImplementation", library, dependencies);
}

private void addInterLibraryDependencies(String configuration, String library, Iterable<String> dependencies) {
for (String dependency : dependencies) {
Map<String, String> map = new LinkedHashMap<>(2);
var map = new LinkedHashMap<String, String>(2);
map.put("path", ":" + library + ":" + dependency);
map.put("configuration", "dev");

Dependency project = this.project.getDependencies().project(map);
this.moduleDependencies.add(project);
this.project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, project);
this.project.getDependencies().add(configuration, project);
}
}

Expand Down
Expand Up @@ -80,7 +80,7 @@ private static String getLineSeparator(String text) {

private static Pattern getValidator(String headerFormat) {
String pattern = escapeRegexControl(headerFormat)
.replace(YEAR_KEY, "(\\d{4}(, \\d{4})*)");
.replace(YEAR_KEY, "(\\d{4}(-\\d{4})?)");
var lineSeparator = getLineSeparator(headerFormat);
String[] lines = getHeaderLines(pattern.split(lineSeparator));
var patternBuilder = new StringBuilder("\\/\\*" + lineSeparator);
Expand Down Expand Up @@ -283,8 +283,8 @@ private String getYearString(Project project, String source) {

var matcher = this.validator.matcher(source);

if (matcher.matches()) {
String[] serializedYears = matcher.group(1).split("\n");
if (matcher.find()) {
String[] serializedYears = matcher.group(1).split("-");

int min = -1;
for (var serializedYear : serializedYears) {
Expand All @@ -301,7 +301,7 @@ private String getYearString(Project project, String source) {

if (min == -1) {
return String.valueOf(lastModifiedYear);
} else {
} else if (min != lastModifiedYear) {
return min + "-" + lastModifiedYear;
}
}
Expand Down
Expand Up @@ -16,7 +16,7 @@
],
"depends": {
"fabricloader": ">=0.12",
"minecraft": ">=1.18.1",
"minecraft": ">=1.18.2-alpha.22.3.a",
"quilt_base": "*"
},
"description": "Extensions for creating and working with blocks.",
Expand Down
8 changes: 8 additions & 0 deletions library/command/build.gradle
@@ -0,0 +1,8 @@
plugins {
id("qsl.library")
}

qslLibrary {
libraryName = "command"
version = "1.0.0"
}
12 changes: 12 additions & 0 deletions library/command/client_command/build.gradle
@@ -0,0 +1,12 @@
plugins {
id("qsl.module")
}

qslModule {
moduleName = "client_command"
version = "1.0.0"
library = "command"
coreDependencies([
"qsl_base"
])
}
@@ -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);
}
}
@@ -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);
}
@@ -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);
}

0 comments on commit 72db1c7

Please sign in to comment.