Skip to content

Commit

Permalink
Fixed datapack zip loading
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jun 28, 2024
1 parent 7aa5372 commit 9f56ffb
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.nio.file.Files;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -112,8 +113,22 @@ public static void addPacksFirst(AddPackFindersEvent event) {
var fileName = file.getName();

if (file.isFile() && fileName.endsWith(".zip")) {
var packName = new StringBuilder();

for (var c : fileName.toCharArray()) {
if (c == '_' || c == '.' || c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
packName.append(c);
}
}

long lastModified = 0L;

if (file.exists()) {
lastModified = file.lastModified();
}

var zipPack = new Pack(
new PackLocationInfo(fileName, Component.literal(fileName), PackSource.BUILT_IN, Optional.of(new KnownPack(KubeJS.MOD_ID, "kubejs_generated", "1"))),
new PackLocationInfo(fileName, Component.literal(fileName), PackSource.BUILT_IN, Optional.of(new KnownPack(KubeJS.MOD_ID, "kubejs_file_" + packName.toString().toLowerCase(Locale.ROOT), lastModified <= 0L ? "1" : Long.toUnsignedString(lastModified)))),
new FilePackResources.FileResourcesSupplier(file),
new Pack.Metadata(GEN_PACK_NAME, PackCompatibility.COMPATIBLE, FeatureFlagSet.of(), List.of(), true),
new PackSelectionConfig(true, Pack.Position.BOTTOM, true)
Expand Down

0 comments on commit 9f56ffb

Please sign in to comment.