|
21 | 21 | import net.minecraft.resources.Identifier; |
22 | 22 | import net.minecraft.resources.ResourceKey; |
23 | 23 | import net.minecraft.world.level.dimension.DimensionType; |
| 24 | +import net.minecraft.world.level.storage.LevelResource; |
24 | 25 |
|
25 | 26 | import java.io.File; |
26 | 27 | import java.io.IOException; |
@@ -50,6 +51,8 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> register() { |
50 | 51 | .executes(VoxyCommands::importZip) |
51 | 52 | .then(ClientCommandManager.argument("innerPath", StringArgumentType.string()) |
52 | 53 | .executes(VoxyCommands::importZip)))) |
| 54 | + .then(ClientCommandManager.literal("current") |
| 55 | + .executes(VoxyCommands::importCurrentWorldIn)) |
53 | 56 | .then(ClientCommandManager.literal("cancel") |
54 | 57 | .executes(VoxyCommands::cancelImport)); |
55 | 58 |
|
@@ -196,6 +199,26 @@ private static CompletableFuture<Suggestions> fileDirectorySuggester(Path dir, S |
196 | 199 | return sb.buildFuture(); |
197 | 200 | } |
198 | 201 |
|
| 202 | + |
| 203 | + private static int importCurrentWorldIn(CommandContext<FabricClientCommandSource> ctx) { |
| 204 | + if (VoxyCommon.getInstance() == null) { |
| 205 | + ctx.getSource().sendError(Component.translatable("Voxy must be enabled in settings to use this")); |
| 206 | + return 1; |
| 207 | + } |
| 208 | + |
| 209 | + var localServer = Minecraft.getInstance().getSingleplayerServer(); |
| 210 | + if (localServer == null) { |
| 211 | + ctx.getSource().sendError(Component.translatable("You must be in single player to use this command")); |
| 212 | + return 1; |
| 213 | + } |
| 214 | + var regionPath = DimensionType.getStorageFolder(Minecraft.getInstance().level.dimension(), localServer.getWorldPath(LevelResource.ROOT)).resolve("region"); |
| 215 | + if ((!regionPath.toFile().exists())||!regionPath.toFile().isDirectory()) { |
| 216 | + ctx.getSource().sendError(Component.translatable("Cannot find region folder for current dimension")); |
| 217 | + return 1; |
| 218 | + } |
| 219 | + return fileBasedImporter(regionPath.toFile())?0:1; |
| 220 | + } |
| 221 | + |
199 | 222 | private static int importWorld(CommandContext<FabricClientCommandSource> ctx) { |
200 | 223 | if (VoxyCommon.getInstance() == null) { |
201 | 224 | ctx.getSource().sendError(Component.translatable("Voxy must be enabled in settings to use this")); |
|
0 commit comments