Command improvements

This commit is contained in:
mcrcortex
2025-02-05 15:15:29 +10:00
parent 49aa9c2dd9
commit d77addb416
2 changed files with 45 additions and 16 deletions

View File

@@ -41,6 +41,7 @@ public class WorldImportWrapper {
public void stopImporter() { public void stopImporter() {
if (this.isImporterRunning()) { if (this.isImporterRunning()) {
this.importer.shutdown(); this.importer.shutdown();
this.importer = null;
} }
} }
@@ -64,17 +65,17 @@ public class WorldImportWrapper {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
factory.create(this.importer, (a, b)-> factory.create(this.importer, (a, b)->
MinecraftClient.getInstance().executeSync(()-> { MinecraftClient.getInstance().executeSync(()-> {
Taskbar.INSTANCE.setProgress(a, b); Taskbar.INSTANCE.setProgress(a, Math.max(1,b));
bossBar.setPercent(((float) a)/((float) b)); bossBar.setPercent(((float) a)/((float) Math.max(1,b)));
bossBar.setName(Text.of("Voxy import: "+ a+"/"+b + " chunks")); bossBar.setName(Text.of("Voxy import: "+ a+"/"+b + " chunks"));
}), }),
chunkCount -> { chunkCount -> {
MinecraftClient.getInstance().executeSync(()-> { MinecraftClient.getInstance().executeSync(()-> {
MinecraftClient.getInstance().inGameHud.getBossBarHud().bossBars.remove(this.importerBossBarUUID); MinecraftClient.getInstance().inGameHud.getBossBarHud().bossBars.remove(this.importerBossBarUUID);
this.importerBossBarUUID = null; this.importerBossBarUUID = null;
long delta = System.currentTimeMillis() - start; long delta = Math.max(System.currentTimeMillis() - start, 1);
String msg = "Voxy world import finished in " + (delta/1000) + " seconds, averaging " + (chunkCount/(delta/1000)) + " chunks per second"; String msg = "Voxy world import finished in " + (delta/1000) + " seconds, averaging " + (int)(chunkCount/(delta/1000f)) + " chunks per second";
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal(msg)); MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal(msg));
Logger.info(msg); Logger.info(msg);
Taskbar.INSTANCE.setIsNone(); Taskbar.INSTANCE.setIsNone();

View File

@@ -40,7 +40,7 @@ public class WorldImportCommand {
.then(ClientCommandManager.argument("innerPath", StringArgumentType.string()) .then(ClientCommandManager.argument("innerPath", StringArgumentType.string())
.executes(WorldImportCommand::importZip)))) .executes(WorldImportCommand::importZip))))
.then(ClientCommandManager.literal("cancel") .then(ClientCommandManager.literal("cancel")
.requires((ctx)->((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.isImporterRunning()) //.requires((ctx)->((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.isImporterRunning())
.executes((ctx)->{((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.stopImporter(); return 0;})) .executes((ctx)->{((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.stopImporter(); return 0;}))
); );
} }
@@ -65,10 +65,31 @@ public class WorldImportCommand {
return fileDirectorySuggester(MinecraftClient.getInstance().runDirectory.toPath().resolve("saves"), sb); return fileDirectorySuggester(MinecraftClient.getInstance().runDirectory.toPath().resolve("saves"), sb);
} }
private static CompletableFuture<Suggestions> importBobbySuggester(CommandContext<FabricClientCommandSource> ctx, SuggestionsBuilder sb) { private static CompletableFuture<Suggestions> importBobbySuggester(CommandContext<FabricClientCommandSource> ctx, SuggestionsBuilder sb) {
return fileDirectorySuggester(new File(".bobby").toPath(), sb); return fileDirectorySuggester(MinecraftClient.getInstance().runDirectory.toPath().resolve(".bobby"), sb);
} }
private static CompletableFuture<Suggestions> fileDirectorySuggester(Path dir, SuggestionsBuilder sb) { private static CompletableFuture<Suggestions> fileDirectorySuggester(Path dir, SuggestionsBuilder sb) {
var str = sb.getRemaining().replace("\\\\", "\\").replace("\\", "/");
if (str.startsWith("\"")) {
str = str.substring(1);
}
if (str.endsWith("\"")) {
str = str.substring(0,str.length()-1);
}
var remaining = str;
if (str.contains("/")) {
int idx = str.lastIndexOf('/');
remaining = str.substring(idx+1);
try {
dir = dir.resolve(str.substring(0, idx));
} catch (Exception e) {
return Suggestions.empty();
}
str = str.substring(0, idx+1);
} else {
str = "";
}
try { try {
var worlds = Files.list(dir).toList(); var worlds = Files.list(dir).toList();
for (var world : worlds) { for (var world : worlds) {
@@ -76,23 +97,30 @@ public class WorldImportCommand {
continue; continue;
} }
var wn = world.getFileName().toString(); var wn = world.getFileName().toString();
if (CommandSource.shouldSuggest(sb.getRemaining(), wn) || CommandSource.shouldSuggest(sb.getRemaining(), '"'+wn)) { if (wn.equals(remaining)) {
if (wn.contains(" ")) { continue;
wn = '"' + wn + '"';
} }
sb.suggest(wn); if (CommandSource.shouldSuggest(remaining, wn) || CommandSource.shouldSuggest(remaining, '"'+wn)) {
wn = str+wn + "/";
sb.suggest(StringArgumentType.escapeIfRequired(wn));
} }
} }
} catch (IOException e) { } catch (IOException e) {}
throw new RuntimeException(e);
}
return sb.buildFuture(); return sb.buildFuture();
} }
private static int importWorld(CommandContext<FabricClientCommandSource> ctx) { private static int importWorld(CommandContext<FabricClientCommandSource> ctx) {
var file = new File("saves").toPath().resolve(ctx.getArgument("world_name", String.class)).resolve("region").toFile(); var name = ctx.getArgument("world_name", String.class);
return fileBasedImporter(file)?0:1; var file = new File("saves").toPath().resolve(name);
name = name.toLowerCase();
if (name.endsWith("/")) {
name = name.substring(0, name.length()-1);
}
if (!(name.endsWith("region"))) {
file = file.resolve("region");
}
return fileBasedImporter(file.toFile())?0:1;
} }
private static int importZip(CommandContext<FabricClientCommandSource> ctx) { private static int importZip(CommandContext<FabricClientCommandSource> ctx) {