fabric client-side commands

This commit is contained in:
creeper123123321 2021-04-09 15:39:21 -03:00
parent cfa0c89178
commit 2b843d24b9
5 changed files with 11 additions and 27 deletions

View File

@ -65,8 +65,8 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:0.32.7+1.17")
modImplementation("io.github.prospector:modmenu:1.14.5+build.30")
modImplementation("io.github.cottonmc:cotton-client-commands:1.0.1+1.16-rc1")
include("io.github.cottonmc:cotton-client-commands:1.0.1+1.16-rc1")
//modImplementation("io.github.cottonmc:cotton-client-commands:1.0.1+1.16-rc1")
//include("io.github.cottonmc:cotton-client-commands:1.0.1+1.16-rc1")
}
if (!System.getenv()["curse_api_key"].isNullOrBlank() && branch.startsWith("mc-")) {

View File

@ -15,6 +15,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.loader.api.FabricLoader;
@ -99,6 +100,7 @@ public class ViaFabric implements ModInitializer {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
ClientCommandManager.DISPATCHER.register(command("viafabricclient"));
}
@SuppressWarnings("deprecation")

View File

@ -1,8 +1,7 @@
package com.github.creeper123123321.viafabric.commands;
import com.github.creeper123123321.viafabric.platform.VRPlatform;
import io.github.cottonmc.clientcommands.CottonClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.server.command.ServerCommandSource;
@ -28,8 +27,8 @@ public class NMSCommandSender implements ViaCommandSender {
public void sendMessage(String s) {
if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(VRPlatform.legacyToJson(s)), false);
} else if (source instanceof CottonClientCommandSource) {
((CottonClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(VRPlatform.legacyToJson(s)), false);
} else if (source instanceof FabricClientCommandSource) {
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(VRPlatform.legacyToJson(s)));
}
}
@ -38,8 +37,8 @@ public class NMSCommandSender implements ViaCommandSender {
if (source instanceof ServerCommandSource) {
Entity entity = ((ServerCommandSource) source).getEntity();
if (entity != null) return entity.getUuid();
} else if (source instanceof CottonClientCommandSource) {
return MinecraftClient.getInstance().player.getUuid();
} else if (source instanceof FabricClientCommandSource) {
return ((FabricClientCommandSource) source).getPlayer().getUuid();
}
return UUID.fromString(getName());
}
@ -48,8 +47,8 @@ public class NMSCommandSender implements ViaCommandSender {
public String getName() {
if (source instanceof ServerCommandSource) {
return ((ServerCommandSource) source).getName();
} else if (source instanceof CottonClientCommandSource) {
return MinecraftClient.getInstance().player.getEntityName();
} else if (source instanceof FabricClientCommandSource) {
return ((FabricClientCommandSource) source).getPlayer().getEntityName();
}
return "?";
}

View File

@ -1,13 +0,0 @@
package com.github.creeper123123321.viafabric.commands;
import com.github.creeper123123321.viafabric.ViaFabric;
import com.mojang.brigadier.CommandDispatcher;
import io.github.cottonmc.clientcommands.ClientCommandPlugin;
import io.github.cottonmc.clientcommands.CottonClientCommandSource;
public class VRClientCommands implements ClientCommandPlugin {
@Override
public void registerCommands(CommandDispatcher<CottonClientCommandSource> commandDispatcher) {
commandDispatcher.register(ViaFabric.command("viafabricclient"));
}
}

View File

@ -61,15 +61,11 @@
"main": [
"com.github.creeper123123321.viafabric.ViaFabric"
],
"cotton-client-commands": [
"com.github.creeper123123321.viafabric.commands.VRClientCommands"
],
"modmenu": [
"com.github.creeper123123321.viafabric.gui.ModMenuConfig"
]
},
"depends": {
"cotton-client-commands": "*",
"fabricloader": ">=0.4.0",
"fabric-resource-loader-v0": "*",
"minecraft": ">1.16.50",