forked from public-mirrors/Uniform
feat: add Fabric 1.20.1/6 support
parent
e5c8975339
commit
e1e39927f3
@ -0,0 +1,19 @@
|
|||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '1.6-SNAPSHOT'
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api project(path: ':common')
|
||||||
|
|
||||||
|
minecraft 'com.mojang:minecraft:1.20.1'
|
||||||
|
mappings 'net.fabricmc:yarn:1.20.1+build.10:v2'
|
||||||
|
|
||||||
|
modCompileOnly 'net.fabricmc:fabric-loader:0.15.11'
|
||||||
|
modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.92.2+1.20.1'
|
||||||
|
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
|
|
||||||
|
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) Tofaa2
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.uniform.fabric;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.InvalidIdentifierException;
|
||||||
|
import net.william278.uniform.Command;
|
||||||
|
import net.william278.uniform.element.ArgumentElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class FabricCommand extends Command<ServerCommandSource> {
|
||||||
|
|
||||||
|
public FabricCommand(@NotNull String name, @NotNull String... aliases) {
|
||||||
|
super(name, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ArgumentElement<ServerCommandSource, Item> itemArg(String name) {
|
||||||
|
return registryArg(name, Registries.ITEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ArgumentElement<ServerCommandSource, Block> blockArg(String name) {
|
||||||
|
return registryArg(name, Registries.BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static <T> ArgumentElement<ServerCommandSource, T> registryArg(String name, Registry<T> registry) {
|
||||||
|
return new ArgumentElement<>(name, reader -> {
|
||||||
|
String itemId = reader.readString();
|
||||||
|
final Identifier id;
|
||||||
|
try {
|
||||||
|
id = Identifier.tryParse(itemId);
|
||||||
|
} catch (InvalidIdentifierException e) {
|
||||||
|
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||||
|
}
|
||||||
|
if (registry.getOrEmpty(id).isEmpty()) {
|
||||||
|
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||||
|
}
|
||||||
|
return registry.get(id);
|
||||||
|
}, (context, builder) -> {
|
||||||
|
registry.getIds().forEach(id -> builder.suggest(id.toString()));
|
||||||
|
return builder.buildFuture();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) Tofaa2
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.uniform.fabric;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for registering commands with the Fabric (1.20.1) server
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public final class FabricUniform {
|
||||||
|
|
||||||
|
private static FabricUniform INSTANCE;
|
||||||
|
|
||||||
|
private final Set<FabricCommand> commands = Sets.newHashSet();
|
||||||
|
|
||||||
|
private FabricUniform() {
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) ->
|
||||||
|
commands.forEach(command -> dispatcher.register(command.build().createBuilder()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the FabricUniform instance for registering commands
|
||||||
|
*
|
||||||
|
* @return The FabricUniform instance
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static FabricUniform getInstance() {
|
||||||
|
return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a command to be added to the server's command manager
|
||||||
|
*
|
||||||
|
* @param commands The commands to register
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public void register(@NotNull FabricCommand... commands) {
|
||||||
|
Collections.addAll(this.commands, commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '1.6-SNAPSHOT'
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api project(path: ':common')
|
||||||
|
|
||||||
|
minecraft 'com.mojang:minecraft:1.20.6'
|
||||||
|
mappings 'net.fabricmc:yarn:1.20.6+build.3:v2'
|
||||||
|
|
||||||
|
modCompileOnly 'net.fabricmc:fabric-loader:0.15.11'
|
||||||
|
modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.100.0+1.20.6'
|
||||||
|
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
|
|
||||||
|
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) Tofaa2
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.uniform.fabric;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.InvalidIdentifierException;
|
||||||
|
import net.william278.uniform.Command;
|
||||||
|
import net.william278.uniform.element.ArgumentElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class FabricCommand extends Command<ServerCommandSource> {
|
||||||
|
|
||||||
|
public FabricCommand(@NotNull String name, @NotNull String... aliases) {
|
||||||
|
super(name, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ArgumentElement<ServerCommandSource, Item> itemArg(String name) {
|
||||||
|
return registryArg(name, Registries.ITEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ArgumentElement<ServerCommandSource, Block> blockArg(String name) {
|
||||||
|
return registryArg(name, Registries.BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static <T> ArgumentElement<ServerCommandSource, T> registryArg(String name, Registry<T> registry) {
|
||||||
|
return new ArgumentElement<>(name, reader -> {
|
||||||
|
String itemId = reader.readString();
|
||||||
|
final Identifier id;
|
||||||
|
try {
|
||||||
|
id = Identifier.tryParse(itemId);
|
||||||
|
} catch (InvalidIdentifierException e) {
|
||||||
|
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||||
|
}
|
||||||
|
if (registry.getOrEmpty(id).isEmpty()) {
|
||||||
|
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||||
|
}
|
||||||
|
return registry.get(id);
|
||||||
|
}, (context, builder) -> {
|
||||||
|
registry.getIds().forEach(id -> builder.suggest(id.toString()));
|
||||||
|
return builder.buildFuture();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) Tofaa2
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.uniform.fabric;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for registering commands with the Fabric (1.20.6) server
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public final class FabricUniform {
|
||||||
|
|
||||||
|
private static FabricUniform INSTANCE;
|
||||||
|
|
||||||
|
private final Set<FabricCommand> commands = Sets.newHashSet();
|
||||||
|
|
||||||
|
private FabricUniform() {
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) ->
|
||||||
|
commands.forEach(command -> dispatcher.register(command.build().createBuilder()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the FabricUniform instance for registering commands
|
||||||
|
*
|
||||||
|
* @return The FabricUniform instance
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static FabricUniform getInstance() {
|
||||||
|
return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a command to be added to the server's command manager
|
||||||
|
*
|
||||||
|
* @param commands The commands to register
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public void register(@NotNull FabricCommand... commands) {
|
||||||
|
Collections.addAll(this.commands, commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,24 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
|
maven { url 'https://maven.fabricmc.net/' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = 'Uniform'
|
rootProject.name = 'Uniform'
|
||||||
include(
|
include(
|
||||||
'common',
|
'common',
|
||||||
|
|
||||||
|
// Server Plugins
|
||||||
'paper',
|
'paper',
|
||||||
|
|
||||||
|
// Proxy Plugins
|
||||||
'velocity',
|
'velocity',
|
||||||
|
|
||||||
|
// Fabric Server-Side Mods
|
||||||
|
'fabric-1.20.1',
|
||||||
|
'fabric-1.20.6',
|
||||||
|
|
||||||
|
// Example plugin
|
||||||
'example-plugin'
|
'example-plugin'
|
||||||
)
|
)
|
Loading…
Reference in New Issue