diff --git a/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java b/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java index d4ff61b9..80610974 100644 --- a/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java +++ b/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java @@ -41,6 +41,7 @@ public class WorldImportWrapper { public void stopImporter() { if (this.isImporterRunning()) { this.importer.shutdown(); + this.importer = null; } } @@ -64,17 +65,17 @@ public class WorldImportWrapper { long start = System.currentTimeMillis(); factory.create(this.importer, (a, b)-> MinecraftClient.getInstance().executeSync(()-> { - Taskbar.INSTANCE.setProgress(a, b); - bossBar.setPercent(((float) a)/((float) b)); + Taskbar.INSTANCE.setProgress(a, Math.max(1,b)); + bossBar.setPercent(((float) a)/((float) Math.max(1,b))); bossBar.setName(Text.of("Voxy import: "+ a+"/"+b + " chunks")); }), chunkCount -> { MinecraftClient.getInstance().executeSync(()-> { MinecraftClient.getInstance().inGameHud.getBossBarHud().bossBars.remove(this.importerBossBarUUID); 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)); Logger.info(msg); Taskbar.INSTANCE.setIsNone(); diff --git a/src/main/java/me/cortex/voxy/client/terrain/WorldImportCommand.java b/src/main/java/me/cortex/voxy/client/terrain/WorldImportCommand.java index 693367e0..20b1d068 100644 --- a/src/main/java/me/cortex/voxy/client/terrain/WorldImportCommand.java +++ b/src/main/java/me/cortex/voxy/client/terrain/WorldImportCommand.java @@ -40,7 +40,7 @@ public class WorldImportCommand { .then(ClientCommandManager.argument("innerPath", StringArgumentType.string()) .executes(WorldImportCommand::importZip)))) .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;})) ); } @@ -65,10 +65,31 @@ public class WorldImportCommand { return fileDirectorySuggester(MinecraftClient.getInstance().runDirectory.toPath().resolve("saves"), sb); } private static CompletableFuture importBobbySuggester(CommandContext ctx, SuggestionsBuilder sb) { - return fileDirectorySuggester(new File(".bobby").toPath(), sb); + return fileDirectorySuggester(MinecraftClient.getInstance().runDirectory.toPath().resolve(".bobby"), sb); } private static CompletableFuture 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 { var worlds = Files.list(dir).toList(); for (var world : worlds) { @@ -76,23 +97,30 @@ public class WorldImportCommand { continue; } var wn = world.getFileName().toString(); - if (CommandSource.shouldSuggest(sb.getRemaining(), wn) || CommandSource.shouldSuggest(sb.getRemaining(), '"'+wn)) { - if (wn.contains(" ")) { - wn = '"' + wn + '"'; - } - sb.suggest(wn); + if (wn.equals(remaining)) { + continue; + } + if (CommandSource.shouldSuggest(remaining, wn) || CommandSource.shouldSuggest(remaining, '"'+wn)) { + wn = str+wn + "/"; + sb.suggest(StringArgumentType.escapeIfRequired(wn)); } } - } catch (IOException e) { - throw new RuntimeException(e); - } + } catch (IOException e) {} return sb.buildFuture(); } private static int importWorld(CommandContext ctx) { - var file = new File("saves").toPath().resolve(ctx.getArgument("world_name", String.class)).resolve("region").toFile(); - return fileBasedImporter(file)?0:1; + var name = ctx.getArgument("world_name", String.class); + 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 ctx) {