Update command registration API to reflect 1.19 vanilla changes (#2227)

* Update command registration API to reflect vanilla changes

* Allow module versions in impl+mixin packages

* Use v2 module, keeping v1 for server commands at least

* update, address review

Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
Player 2022-05-20 17:39:10 +00:00 committed by GitHub
parent 51821d6d14
commit f71b366fb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 209 additions and 85 deletions

View file

@ -168,7 +168,7 @@
+ api/implementation/mixin subpackage: api/impl/mixin
+ client/dedicated server/common env subpackage: client/server/<nothing>
+ module name subpackage, singular, may contain multiple .-separated parts
+ api only: module major version with v prefix (e.g. v1)
+ api mandatory: module major version with v prefix (e.g. v1)
+ other subpackages as needed, all singular
The regex works as follows:
@ -176,9 +176,9 @@
- net.fabricmc.fabric.api.client.<module-name>.v<version>[.<extra packages...>]
- net.fabricmc.fabric.api.server.<module-name>.v<version>[.<extra packages...>]
- net.fabricmc.fabric.api.<module-name>.v<version>[.<extra packages...>]
- net.fabricmc.fabric.(impl|mixin).client.<module-name>[.<extra packages...>]
- net.fabricmc.fabric.(impl|mixin).server.<module-name>[.<extra packages...>]
- net.fabricmc.fabric.(impl|mixin).<module-name>[.<extra packages...>]
- net.fabricmc.fabric.(impl|mixin).client.<module-name>[.v<version>][.<extra packages...>]
- net.fabricmc.fabric.(impl|mixin).server.<module-name>[.v<version>][.<extra packages...>]
- net.fabricmc.fabric.(impl|mixin).<module-name>[.v<version>][.<extra packages...>]
- <any legacy package>
where <module-name> is a set of '.'-separated words, all in singular (not ending with s except for ss) and not starting with client. or server.
and <version> is a positive integer (1, 2, 3, ...)
@ -194,7 +194,7 @@
- largely unconstained trailing subpackages
-->
<property name="format"
value="^net\.fabricmc\.fabric\.(api(?!\.common\.)(\.client|\.server|)(\.(?!client\.|server\.)[a-z]+([a-rt-z]|ss))+\.v[1-9][0-9]*|(impl|mixin|test)(?!\.common\.)(\.client|\.server|)(\.(?!client\.|server\.)[a-z]+[a-rt-z])+|api\.(event|util|biomes\.v1|registry|client\.screen|container|block|entity|client\.itemgroup|client\.keybinding|tag|tools|client\.model|network|server|client\.render|resource|client\.texture))(|\.[a-z]+(\.[a-z0-9]+)*)$"/>
value="^net\.fabricmc\.fabric\.(api(?!\.common\.)(\.client|\.server|)(\.(?!client\.|server\.)[a-z]+([a-rt-z]|ss))+\.v[1-9][0-9]*|(impl|mixin|test)(?!\.common\.)(\.client|\.server|)(\.(?!client\.|server\.)[a-z]+([a-rt-z]|ss))+(\.v[1-9][0-9]*)?|api\.(event|util|biomes\.v1|registry|client\.screen|container|block|entity|client\.itemgroup|client\.keybinding|tag|tools|client\.model|network|server|client\.render|resource|client\.texture))(|\.[a-z]+(\.[a-z0-9]+)*)$"/>
</module>
<!--<module name="InvalidJavadocPosition"/>-->

View file

@ -0,0 +1,7 @@
archivesBaseName = "fabric-command-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base',
'fabric-command-api-v2'
])

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* 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 net.fabricmc.fabric.api.command.v1;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.server.command.ServerCommandSource;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
/**
* @deprecated Please migrate to v2. Please use {@link net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback} instead.
*/
@Deprecated
public interface CommandRegistrationCallback {
Event<CommandRegistrationCallback> EVENT = EventFactory.createArrayBacked(CommandRegistrationCallback.class, (callbacks) -> (dispatcher, dedicated) -> {
for (CommandRegistrationCallback callback : callbacks) {
callback.register(dispatcher, dedicated);
}
});
void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated);
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* 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 net.fabricmc.fabric.impl.command.v1;
import net.minecraft.server.command.CommandManager.RegistrationEnvironment;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
public final class LegacyHandler implements ModInitializer {
@Override
@SuppressWarnings("deprecation")
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback.EVENT.invoker().register(dispatcher, environment == RegistrationEnvironment.DEDICATED));
}
}

View file

@ -17,13 +17,16 @@
],
"depends": {
"fabricloader": ">=0.10.5",
"fabric-api-base": "*"
"fabric-api-base": "*",
"fabric-command-api-v2": "*"
},
"description": "Deprecated. Please migrate to v2",
"entrypoints": {
"main": [
"net.fabricmc.fabric.impl.command.v1.LegacyHandler"
]
},
"description": "Adds command-related hooks.",
"mixins": [
"fabric-command-api-v1.mixins.json"
],
"custom": {
"fabric-api:module-lifecycle": "stable"
"fabric-api:module-lifecycle": "deprecated"
}
}

View file

@ -3,5 +3,10 @@ version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base',
'fabric-command-api-v1'
'fabric-command-api-v2'
])
loom {
// workaround for lack of cross-project taw propagation in loom
accessWidenerPath = file("fabric-commands-v0.accesswidener")
}

View file

@ -0,0 +1,4 @@
accessWidener v2 named
# workaround for lack of cross-project taw propagation in loom
accessible field net/minecraft/server/command/CommandManager$RegistrationEnvironment dedicated Z

View file

@ -22,10 +22,10 @@ import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.server.command.ServerCommandSource;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
/**
* @deprecated Please migrate to v1. Please use {@link CommandRegistrationCallback} instead.
* @deprecated Please migrate to v2. Please use {@link CommandRegistrationCallback} instead.
*/
@Deprecated
public class CommandRegistry {
@ -38,8 +38,8 @@ public class CommandRegistry {
* @param consumer The command provider, consuming {@link CommandDispatcher}.
*/
public void register(boolean dedicated, Consumer<CommandDispatcher<ServerCommandSource>> consumer) {
CommandRegistrationCallback.EVENT.register(((dispatcher, isDedicated) -> {
if (dedicated && !isDedicated) {
CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> {
if (dedicated && !environment.dedicated) {
return;
}

View file

@ -18,9 +18,9 @@
"depends": {
"fabricloader": ">=0.4.0",
"fabric-api-base": "*",
"fabric-command-api-v1": "*"
"fabric-command-api-v2": "*"
},
"description": "Deprecated. Please migrate to v1",
"description": "Deprecated. Please migrate to v2",
"mixins": [
],
"custom": {

View file

@ -2,6 +2,6 @@ archivesBaseName = "fabric-api-base"
version = getSubprojectVersion(project)
dependencies {
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-command-api-v2', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-lifecycle-events-v1', configuration: 'namedElements')
}

View file

@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment;
import net.minecraft.text.Text;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
public class FabricApiBaseTestInit implements ModInitializer {
@ -43,7 +43,7 @@ public class FabricApiBaseTestInit implements ModInitializer {
}
// Command to call audit the mixin environment
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(literal("audit_mixins").executes(context -> {
context.getSource().sendFeedback(Text.literal("Auditing mixin environment"), false);

View file

@ -1,4 +1,4 @@
archivesBaseName = "fabric-command-api-v1"
archivesBaseName = "fabric-command-api-v2"
version = getSubprojectVersion(project)
dependencies {
@ -8,3 +8,7 @@ dependencies {
moduleDependencies(project, [
'fabric-api-base'
])
loom {
accessWidenerPath = file('src/main/resources/fabric-command-api-v2.accesswidener')
}

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package net.fabricmc.fabric.api.client.command.v1;
package net.fabricmc.fabric.api.client.command.v2;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package net.fabricmc.fabric.api.client.command.v1;
package net.fabricmc.fabric.api.client.command.v2;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;

View file

@ -17,6 +17,6 @@
/**
* API for creating client-sided commands.
*
* @see net.fabricmc.fabric.api.client.command.v1.ClientCommandManager
* @see net.fabricmc.fabric.api.client.command.v2.ClientCommandManager
*/
package net.fabricmc.fabric.api.client.command.v1;
package net.fabricmc.fabric.api.client.command.v2;

View file

@ -14,10 +14,12 @@
* limitations under the License.
*/
package net.fabricmc.fabric.api.command.v1;
package net.fabricmc.fabric.api.command.v2;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.fabricmc.fabric.api.event.Event;
@ -29,24 +31,25 @@ import net.fabricmc.fabric.api.event.EventFactory;
* <p>To register some commands, you would register an event listener and implement the callback.
*
* <pre><code>
* CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
* // For example, this command is only registered on an integrated server
* if (!dedicated) dispatcher.register(CommandManager.literal("integrated_command").executes(context -> {...}));
* CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
* // For example, this command is only registered on an integrated server like the vanilla publish command
* if (environment.integrated) dispatcher.register(CommandManager.literal("integrated_command").executes(context -> {...}));
* })};
* </code></pre>
*/
public interface CommandRegistrationCallback {
Event<CommandRegistrationCallback> EVENT = EventFactory.createArrayBacked(CommandRegistrationCallback.class, (callbacks) -> (dispatcher, dedicated) -> {
Event<CommandRegistrationCallback> EVENT = EventFactory.createArrayBacked(CommandRegistrationCallback.class, (callbacks) -> (dispatcher, registryAccess, environment) -> {
for (CommandRegistrationCallback callback : callbacks) {
callback.register(dispatcher, dedicated);
callback.register(dispatcher, registryAccess, environment);
}
});
/**
* Called when the server is registering commands.
*
* @param dispatcher the command dispatcher to register commands to.
* @param dedicated whether the server this command is being registered on is a dedicated server.
* @param dispatcher the command dispatcher to register commands to
* @param registryAccess object exposing access to the game's registries
* @param environment environment the registrations should be done for, used for commands that are dedicated or integrated server only
*/
void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated);
void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment);
}

View file

@ -16,9 +16,9 @@
package net.fabricmc.fabric.impl.command.client;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.DISPATCHER;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.DISPATCHER;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
import java.util.HashMap;
import java.util.List;
@ -47,13 +47,13 @@ import net.minecraft.text.Texts;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.mixin.command.HelpCommandAccessor;
@Environment(EnvType.CLIENT)
public final class ClientCommandInternals {
private static final Logger LOGGER = LoggerFactory.getLogger(ClientCommandInternals.class);
private static final String API_COMMAND_NAME = "fabric-command-api-v1:client";
private static final String API_COMMAND_NAME = "fabric-command-api-v2:client";
private static final String SHORT_API_COMMAND_NAME = "fcc";
/**

View file

@ -28,7 +28,7 @@ import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
@Mixin(CommandManager.class)
public abstract class CommandManagerMixin {
@ -45,6 +45,6 @@ public abstract class CommandManagerMixin {
*/
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;setConsumer(Lcom/mojang/brigadier/ResultConsumer;)V"), method = "<init>")
private void fabric_addCommands(CommandManager.RegistrationEnvironment environment, CommandRegistryAccess registryAccess, CallbackInfo ci) {
CommandRegistrationCallback.EVENT.invoker().register(this.dispatcher, environment == CommandManager.RegistrationEnvironment.DEDICATED);
CommandRegistrationCallback.EVENT.invoker().register(this.dispatcher, registryAccess, environment);
}
}

View file

@ -32,7 +32,7 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.Util;
import net.minecraft.util.registry.Registry;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
@Mixin(ClientCommandSource.class)
abstract class ClientCommandSourceMixin implements FabricClientCommandSource {

View file

@ -29,7 +29,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.command.CommandSource;
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.impl.command.client.ClientCommandInternals;
@Mixin(ClientPlayNetworkHandler.class)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,5 @@
accessWidener v2 named
# fields for mods to check whether the environment is as desired for registration
transitive-accessible field net/minecraft/server/command/CommandManager$RegistrationEnvironment dedicated Z
transitive-accessible field net/minecraft/server/command/CommandManager$RegistrationEnvironment integrated Z

View file

@ -0,0 +1,31 @@
{
"schemaVersion": 1,
"id": "fabric-command-api-v2",
"name": "Fabric Command API (v2)",
"version": "${version}",
"environment": "*",
"license": "Apache-2.0",
"icon": "assets/fabric-command-api-v2/icon.png",
"contact": {
"homepage": "https://fabricmc.net",
"irc": "irc://irc.esper.net:6667/fabric",
"issues": "https://github.com/FabricMC/fabric/issues",
"sources": "https://github.com/FabricMC/fabric"
},
"authors": [
"FabricMC"
],
"depends": {
"fabricloader": ">=0.10.5",
"fabric-api-base": "*",
"minecraft": "~1.19-alpha.22.11.a"
},
"description": "Adds command-related hooks.",
"accessWidener": "fabric-command-api-v2.accesswidener",
"mixins": [
"fabric-command-api-v2.mixins.json"
],
"custom": {
"fabric-api:module-lifecycle": "stable"
}
}

View file

@ -30,7 +30,7 @@ import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
public final class CommandTest implements ModInitializer {
@ -40,14 +40,16 @@ public final class CommandTest implements ModInitializer {
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// A command that exists on both types of servers
dispatcher.register(literal("fabric_common_test_command").executes(this::executeCommonCommand));
if (dedicated) {
if (environment.dedicated) {
// The command here should only be present on a dedicated server
dispatcher.register(literal("fabric_dedicated_test_command").executes(this::executeDedicatedCommand));
} else {
}
if (environment.integrated) {
// The command here should only be present on a integrated server
dispatcher.register(literal("fabric_integrated_test_command").executes(this::executeIntegratedCommand));
}

View file

@ -31,8 +31,8 @@ import net.minecraft.text.Text;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;

View file

@ -1,6 +1,6 @@
{
"replace": false,
"values":[
"fabric_command_api_v1_testmod:load"
"fabric_command_api_v2_testmod:load"
]
}

View file

@ -1,6 +1,6 @@
{
"replace": false,
"values":[
"fabric_command_api_v1_testmod:tick"
"fabric_command_api_v2_testmod:tick"
]
}

View file

@ -1,12 +1,12 @@
{
"schemaVersion": 1,
"id": "fabric-command-api-v1-testmod",
"name": "Fabric Command API (v1) Test Mod",
"id": "fabric-command-api-v2-testmod",
"name": "Fabric Command API (v2) Test Mod",
"version": "1.0.0",
"environment": "*",
"license": "Apache-2.0",
"depends": {
"fabric-command-api-v1": "*"
"fabric-command-api-v2": "*"
},
"entrypoints": {
"main": [

View file

@ -2,7 +2,7 @@ archivesBaseName = "fabric-dimensions-v1"
version = getSubprojectVersion(project)
dependencies {
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-command-api-v2', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-lifecycle-events-v1', configuration: 'namedElements')
}

View file

@ -40,27 +40,18 @@ import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
public class FabricDimensionTest implements ModInitializer {
// The dimension options refer to the JSON-file in the dimension subfolder of the datapack,
// which will always share it's ID with the world that is created from it
private static final RegistryKey<DimensionOptions> DIMENSION_KEY = RegistryKey.of(
Registry.DIMENSION_KEY,
new Identifier("fabric_dimension", "void")
);
private static final RegistryKey<DimensionOptions> DIMENSION_KEY = RegistryKey.of(Registry.DIMENSION_KEY, new Identifier("fabric_dimension", "void"));
private static RegistryKey<World> WORLD_KEY = RegistryKey.of(
Registry.WORLD_KEY,
DIMENSION_KEY.getValue()
);
private static RegistryKey<World> WORLD_KEY = RegistryKey.of(Registry.WORLD_KEY, DIMENSION_KEY.getValue());
private static final RegistryKey<DimensionType> DIMENSION_TYPE_KEY = RegistryKey.of(
Registry.DIMENSION_TYPE_KEY,
new Identifier("fabric_dimension", "void_type")
);
private static final RegistryKey<DimensionType> DIMENSION_TYPE_KEY = RegistryKey.of(Registry.DIMENSION_TYPE_KEY, new Identifier("fabric_dimension", "void_type"));
@Override
public void onInitialize() {
@ -99,9 +90,8 @@ public class FabricDimensionTest implements ModInitializer {
if (!teleported.getPos().equals(target.position)) throw new AssertionError("Target Position not reached.");
});
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) ->
dispatcher.register(literal("fabric_dimension_test").executes(FabricDimensionTest.this::swapTargeted))
);
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("fabric_dimension_test")
.executes(FabricDimensionTest.this::swapTargeted)));
}
private int swapTargeted(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {

View file

@ -6,7 +6,7 @@ moduleDependencies(project, [
])
dependencies {
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-command-api-v2', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-networking-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-registry-sync-v0', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-rendering-v1', configuration: 'namedElements')

View file

@ -40,7 +40,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.entity.event.v1.EntityElytraEvents;
import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents;
@ -169,7 +169,7 @@ public final class EntityEventTests implements ModInitializer {
return wakeUpPos;
});
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("addsleeptestwools").executes(context -> {
addSleepWools(context.getSource().getPlayer());
return 0;

View file

@ -7,7 +7,7 @@
"license": "Apache-2.0",
"depends": {
"fabric-entity-events-v1": "*",
"fabric-command-api-v1": "*",
"fabric-command-api-v2": "*",
"fabric-registry-sync-v0": "*"
},
"entrypoints": {

View file

@ -6,7 +6,7 @@ moduleDependencies(project, [
])
dependencies {
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-command-api-v2', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-lifecycle-events-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-key-binding-api-v1', configuration: 'namedElements')
}

View file

@ -41,13 +41,13 @@ import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
public final class NetworkingChannelTest implements ModInitializer {
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
final LiteralCommandNode<ServerCommandSource> channelTestCommand = literal("network_channel_test").build();
// Info

View file

@ -31,7 +31,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.test.networking.NetworkingTestmods;
@ -60,7 +60,7 @@ public final class NetworkingPlayPacketTest implements ModInitializer {
public void onInitialize() {
NetworkingTestmods.LOGGER.info("Hello from networking user!");
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
NetworkingPlayPacketTest.registerCommand(dispatcher);
});
}

View file

@ -2,7 +2,7 @@ archivesBaseName = "fabric-object-builder-api-v1"
version = getSubprojectVersion(project)
dependencies {
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-command-api-v2', configuration: 'namedElements')
}
moduleDependencies(project, [

View file

@ -34,7 +34,7 @@ import net.minecraft.village.TradeOffers;
import net.minecraft.village.VillagerProfession;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
public class VillagerTypeTest1 implements ModInitializer {
@ -48,7 +48,7 @@ public class VillagerTypeTest1 implements ModInitializer {
factories.add(new SimpleTradeFactory(new TradeOffer(new ItemStack(Items.GOLD_INGOT, 3), new ItemStack(Items.NETHERITE_SCRAP, 4), new ItemStack(Items.NETHERITE_INGOT), 2, 6, 0.35F)));
});
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(literal("fabric_refreshtrades").executes(context -> {
TradeOfferHelper.refreshOffers();
context.getSource().sendFeedback(Text.literal("Refreshed trades"), false);

View file

@ -13,6 +13,7 @@ fabric-api-lookup-api-v1-version=1.6.3
fabric-biome-api-v1-version=9.0.7
fabric-blockrenderlayer-v1-version=1.1.15
fabric-command-api-v1-version=1.1.18
fabric-command-api-v2-version=1.0.0
fabric-commands-v0-version=0.2.17
fabric-containers-v0-version=0.1.24
fabric-content-registries-v0-version=3.0.11

View file

@ -16,7 +16,7 @@ include 'fabric-api-base'
include 'fabric-api-lookup-api-v1'
include 'fabric-biome-api-v1'
include 'fabric-blockrenderlayer-v1'
include 'fabric-command-api-v1'
include 'fabric-command-api-v2'
include 'fabric-content-registries-v0'
include 'fabric-crash-report-info-v1'
include 'fabric-data-generation-api-v1'
@ -53,6 +53,7 @@ include 'fabric-transitive-access-wideners-v1'
include 'deprecated'
include 'deprecated:fabric-commands-v0'
include 'deprecated:fabric-command-api-v1'
include 'deprecated:fabric-containers-v0'
include 'deprecated:fabric-events-lifecycle-v0'
include 'deprecated:fabric-keybindings-v0'