Skip to content

Commit 55b64ef

Browse files
committed
import current
1 parent cca4c9d commit 55b64ef

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/main/java/me/cortex/voxy/client/VoxyCommands.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import net.minecraft.resources.Identifier;
2222
import net.minecraft.resources.ResourceKey;
2323
import net.minecraft.world.level.dimension.DimensionType;
24+
import net.minecraft.world.level.storage.LevelResource;
2425

2526
import java.io.File;
2627
import java.io.IOException;
@@ -50,6 +51,8 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> register() {
5051
.executes(VoxyCommands::importZip)
5152
.then(ClientCommandManager.argument("innerPath", StringArgumentType.string())
5253
.executes(VoxyCommands::importZip))))
54+
.then(ClientCommandManager.literal("current")
55+
.executes(VoxyCommands::importCurrentWorldIn))
5356
.then(ClientCommandManager.literal("cancel")
5457
.executes(VoxyCommands::cancelImport));
5558

@@ -196,6 +199,26 @@ private static CompletableFuture<Suggestions> fileDirectorySuggester(Path dir, S
196199
return sb.buildFuture();
197200
}
198201

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+
199222
private static int importWorld(CommandContext<FabricClientCommandSource> ctx) {
200223
if (VoxyCommon.getInstance() == null) {
201224
ctx.getSource().sendError(Component.translatable("Voxy must be enabled in settings to use this"));

0 commit comments

Comments
 (0)