Skip to content

Commit 307b57c

Browse files
committed
Better Datapack Handling
1 parent 2ee5b63 commit 307b57c

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

buildSrc/src/main/java/dev/xpple/seedmapper/buildscript/CreateJavaBindingsTask.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ public abstract class CreateJavaBindingsTask extends Exec {
1313

1414
this.setWorkingDir(this.getProject().getRootDir());
1515
this.setStandardOutput(System.out);
16-
this.commandLine("./jextract/build/jextract/bin/jextract" + EXTENSION, "--include-dir", "src/main/c/cubiomes", "--output", "src/main/java", "--use-system-load-library", "--target-package", "com.github.cubiomes", "--header-class-name", "Cubiomes", "@src/main/c/cubiomes/includes.txt", "biomenoise.h", "biomes.h", "finders.h", "generator.h", "layers.h", "noise.h", "terrainnoise.h", "rng.h", "util.h", "quadbase.h", "xrms.h", "features/stronghold.h", "loot/items.h", "loot/logging.h", "loot/loot_functions.h", "loot/loot_table_context.h", "loot/loot_table_parser.h", "loot/loot_tables.h", "loot/mc_loot.h");
16+
this.commandLine(
17+
"./jextract/build/jextract/bin/jextract" + EXTENSION,
18+
"--include-dir", "src/main/c/cubiomes/jextract-compat",
19+
"--include-dir", "src/main/c/cubiomes",
20+
"--output", "src/main/java",
21+
"--use-system-load-library",
22+
"-l", "cubiomes",
23+
"--target-package", "com.github.cubiomes",
24+
"--header-class-name", "Cubiomes",
25+
"@src/main/c/cubiomes/includes.txt",
26+
"biomenoise.h", "biomes.h", "finders.h", "generator.h", "layers.h", "noise.h", "terrainnoise.h", "rng.h", "util.h", "quadbase.h", "xrms.h", "features/stronghold.h", "loot/items.h", "loot/logging.h", "loot/loot_functions.h", "loot/loot_table_context.h", "loot/loot_table_parser.h", "loot/loot_tables.h", "loot/mc_loot.h"
27+
);
1728
}
1829
}

src/main/java/dev/xpple/seedmapper/datapack/DatapackStructureManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ private static String summarizeImportFailure(Throwable throwable) {
248248
if (joined.contains("c:has_wolf_variant/")) {
249249
return "Datapack references unresolved wolf variant biome tags.";
250250
}
251+
if (joined.contains("Datapack URL must end with .zip")) {
252+
return "Datapack URL must be a .zip file. Please use a .zip datapack URL.";
253+
}
254+
if (joined.contains("Datapack has no structures")) {
255+
return "Datapack world generation is not supported, only structures.";
256+
}
251257
for (int i = messages.size() - 1; i >= 0; i--) {
252258
String message = sanitizeImportFailureMessage(messages.get(i));
253259
if (!message.equalsIgnoreCase("Registry Loading") && !message.equalsIgnoreCase("Failed to load registries due to errors")) {
@@ -271,7 +277,7 @@ private static void loadDatapack(WorldIdentifier identifier, Path datapackRoot,
271277
} catch (Exception e) {
272278
LOGGER.warn("Failed to close datapack worldgen", e);
273279
}
274-
throw new IOException("No structures");
280+
throw new IOException("Datapack has no structures");
275281
}
276282
DatapackStructureCollection collection = new DatapackStructureCollection(worldgen, sets);
277283
synchronized (COLLECTIONS) {
@@ -294,6 +300,9 @@ private static Path downloadDatapack(String urlString) throws IOException {
294300
} catch (MalformedURLException e) {
295301
throw new IOException("Invalid URL", e);
296302
}
303+
if (!isZipUrl(url)) {
304+
throw new IOException("Datapack URL must end with .zip");
305+
}
297306
URLConnection connection = url.openConnection();
298307
connection.setRequestProperty("User-Agent", "SeedMapper/" + SeedMapper.MOD_ID);
299308
connection.setConnectTimeout(15000);
@@ -305,6 +314,11 @@ private static Path downloadDatapack(String urlString) throws IOException {
305314
return tempFile;
306315
}
307316

317+
private static boolean isZipUrl(URL url) {
318+
String path = url.getPath();
319+
return path != null && path.toLowerCase(Locale.ROOT).endsWith(".zip");
320+
}
321+
308322
private static Path prepareDatapack(Path zippedFile) throws IOException {
309323
Path cacheRoot = SeedMapper.modConfigPath.resolve("datapacks");
310324
Files.createDirectories(cacheRoot);

src/main/java/dev/xpple/seedmapper/util/CubiomesCompat.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static String biomeName(int version, int biome) {
3939
}
4040

4141
public static String structureName(int structure) {
42+
if (structure == Cubiomes.Stronghold()) {
43+
return "Stronghold";
44+
}
4245
return safeCString(Cubiomes.struct2str(structure), "structure:" + structure);
4346
}
4447

0 commit comments

Comments
 (0)