-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
15 changed files
with
599 additions
and
48 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
99 changes: 99 additions & 0 deletions
99
common/src/main/java/com/xtracr/realcamera/command/ClientCommand.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,99 @@ | ||
package com.xtracr.realcamera.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.arguments.BoolArgumentType; | ||
import com.mojang.brigadier.arguments.IntegerArgumentType; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.xtracr.realcamera.RealCamera; | ||
import com.xtracr.realcamera.config.ConfigFile; | ||
import com.xtracr.realcamera.config.ModConfig; | ||
import com.xtracr.realcamera.utils.VertexDataAnalyser; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.command.CommandRegistryAccess; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.text.Text; | ||
|
||
import java.util.List; | ||
|
||
public class ClientCommand<S extends CommandSource>{ | ||
private static final String KEY_COMMAND = "message.xtracr_" + RealCamera.MODID + "_command_"; | ||
private static final ModConfig config = ConfigFile.modConfig; | ||
|
||
public void register(CommandDispatcher<S> dispatcher, CommandRegistryAccess access) { | ||
final LiteralArgumentBuilder<S> builder = literal(RealCamera.MODID); | ||
builder.then(literal("analyse").executes(context -> this.startAnalysis(context, 0)) | ||
.then(argument("targetIndex", IntegerArgumentType.integer(0)) | ||
.then(argument("accuracy", IntegerArgumentType.integer(10, 10000000)).executes(context -> this.startAnalysis(context, 1))))); | ||
builder.then(literal("autoBind") | ||
.then(argument("name", StringArgumentType.string()).executes(this::autoBind))); | ||
builder.then(literal("config") | ||
.then(literal("delete") | ||
.then(argument("name", StringArgumentType.string()).executes(this::deleteList))) | ||
.then(literal("listAll").executes(this::listAll))); | ||
builder.then(literal("showResult") | ||
.then(argument("number", IntegerArgumentType.integer(1)).executes(this::showResult))); | ||
|
||
dispatcher.register(builder); | ||
} | ||
|
||
private int startAnalysis(CommandContext<S> context, int mode) { | ||
if (mode == 1) mode += IntegerArgumentType.getInteger(context, "targetIndex"); | ||
final float accuracy = mode == 0 ? 100 : IntegerArgumentType.getInteger(context, "accuracy"); | ||
VertexDataAnalyser.start(mode, mode == 0 ? 80 : 120, 1 / accuracy); | ||
return 1; | ||
} | ||
|
||
private int autoBind(CommandContext<S> context) { | ||
List<Integer> list = VertexDataAnalyser.getFinalResults(-1); | ||
if (list == null) return 0; | ||
config.binding.indexListMap.put(StringArgumentType.getString(context, "name"), list); | ||
ConfigFile.save(); | ||
printGameMessage(Text.translatable(KEY_COMMAND + "autoBind", list.get(0), list.get(0), list.get(1), list.get(2))); | ||
return 1; | ||
} | ||
|
||
private int deleteList(CommandContext<S> context) { | ||
final String name = StringArgumentType.getString(context, "name"); | ||
if (!config.binding.indexListMap.containsKey(name)) { | ||
printGameMessage(Text.translatable(KEY_COMMAND + "delete_failure", name)); | ||
return 0; | ||
} | ||
config.binding.indexListMap.remove(name); | ||
ConfigFile.save(); | ||
printGameMessage(Text.translatable(KEY_COMMAND + "delete_success", name)); | ||
return 1; | ||
} | ||
|
||
private int listAll(CommandContext<S> context) { | ||
StringBuffer buffer = new StringBuffer(); | ||
config.binding.indexListMap.forEach((name, list) -> { | ||
buffer.append("\n'").append(name).append("' -> [ "); | ||
list.forEach(i -> buffer.append(i).append(" ")); | ||
buffer.append("]"); | ||
}); | ||
printGameMessage(Text.translatable(KEY_COMMAND + "listAll", config.binding.indexListMap.size(), buffer.toString())); | ||
return 1; | ||
} | ||
|
||
private int showResult(CommandContext<S> context) { | ||
final int number = IntegerArgumentType.getInteger(context, "number"); | ||
VertexDataAnalyser.showResult(number, true); | ||
return 1; | ||
} | ||
|
||
private static void printGameMessage(Text text) { | ||
MinecraftClient.getInstance().getMessageHandler().onGameMessage(text, false); | ||
} | ||
|
||
private <T> RequiredArgumentBuilder<S, T> argument(final String name, final ArgumentType<T> type) { | ||
return RequiredArgumentBuilder.argument(name, type); | ||
} | ||
|
||
private LiteralArgumentBuilder<S> literal(final String name) { | ||
return LiteralArgumentBuilder.literal(name); | ||
} | ||
} |
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
Oops, something went wrong.