Skip to content

Commit

Permalink
fix: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jan 4, 2025
1 parent de4ad5d commit 17de4a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.debug=false


# Version
mod_version=1.2.09
mod_version=1.2.10

# Mod
mod_id=zenith
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/net/zepalesque/zenith/api/packconfig/PackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ public class PackConfig {
private final PackType type;
private final HashMap<Supplier<Boolean>, PackResources> resources = new HashMap<>();
private final String folder;
private final boolean hideInMenu;
private boolean locked = false;

public PackConfig(ResourceLocation id, PackType type) {
public PackConfig(ResourceLocation id, PackType type, boolean hideInMenu) {
this.id = id;
this.type = type;
this.folder = switch (type) {
case SERVER_DATA -> "data/";
case CLIENT_RESOURCES -> "resource/";
};
this.hideInMenu = hideInMenu;
}

public PackConfig(ResourceLocation id, PackType type) {
this(id, type, true);
}

public ConfigAssembledPackResources.AssembledResourcesSupplier generate(Path path) {
Expand All @@ -43,17 +49,17 @@ public ConfigAssembledPackResources.AssembledResourcesSupplier generate(Path pat
}

public PathPackResources createPack(String path, String id) {
Path resource = ModList.get().getModFileById(this.id.getNamespace()).getFile().findResource("packs/" + path + id);
Path resource = ModList.get().getModFileById(this.id.getNamespace()).getFile().findResource("packs/" + this.folder + path + id);
PackLocationInfo loc = new PackLocationInfo(id, Component.empty(), PackSource.BUILT_IN, Optional.empty());
return new PathPackResources(loc, resource);
}

public <B, T extends ModConfigSpec.ConfigValue<B>> T register(T config, String path, String id, Predicate<B> predicate) {
if (!locked) {
resources.putIfAbsent(() -> predicate.test(config.get()), createPack(path, id));
Zenith.LOGGER.info("Registered config {}{} for pack {}...", path, id, this.id);
Zenith.LOGGER.info("Registered config {}{}{} for pack {}...", this.folder, path, id, this.id);
} else {
Zenith.LOGGER.warn("Attempted to register pack config for pack {}{} after locking was already complete!", path, id);
Zenith.LOGGER.warn("Attempted to register config {}{}{} for pack {} after locking was already complete!", this.folder, path, id, this.id);
}
return config;
}
Expand Down Expand Up @@ -81,7 +87,7 @@ public <T extends ModConfigSpec.ConfigValue<Boolean>> T register(T config, Strin

public void setup(AddPackFindersEvent event) {
if (event.getPackType() == this.type) {
PackUtils.setupPack(event, this.id, this.folder, true, this::generate);
PackUtils.setupPack(event, this.id, this.folder, true, this.hideInMenu, this::generate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

public class PackUtils {

public static void setupPack(AddPackFindersEvent event, String modid, String path, String id, boolean required, Function<Path, Pack.ResourcesSupplier> packBuilder) {
public static void setupPack(AddPackFindersEvent event, String modid, String path, String id, boolean required, boolean hidden, Function<Path, Pack.ResourcesSupplier> packBuilder) {
PackLocationInfo loc = new PackLocationInfo(id, Component.translatable("pack." + modid + "." + id + ".title"), PackSource.BUILT_IN, Optional.empty());
String folder = (event.getPackType() == PackType.SERVER_DATA ? "data/" : "resource/");
Path resourcePath = ModList.get().getModFileById(modid).getFile().findResource("packs/" + folder + path);
Path resourcePath = ModList.get().getModFileById(modid).getFile().findResource("packs/" + path);
PackMetadataSection metadata = new PackMetadataSection(Component.translatable("pack." + modid + "." + id + ".description"),
SharedConstants.getCurrentVersion().getPackVersion(event.getPackType()));
Pack.Metadata meta = new Pack.Metadata(metadata.description(), PackCompatibility.COMPATIBLE, FeatureFlagSet.of(), List.of(), true);
Pack.Metadata meta = new Pack.Metadata(metadata.description(), PackCompatibility.COMPATIBLE, FeatureFlagSet.of(), List.of(), hidden);
Pack.ResourcesSupplier resources = packBuilder.apply(resourcePath);
event.addRepositorySource((source) ->
source.accept(new Pack(
Expand All @@ -40,12 +39,12 @@ public static void setupPack(AddPackFindersEvent event, String modid, String pat

}

public static void setupPack(AddPackFindersEvent event, String modid, String path, String id, boolean required) {
setupPack(event, modid, path, id, required, PathPackResources.PathResourcesSupplier::new);
public static void setupPack(AddPackFindersEvent event, String modid, String path, String id, boolean required, boolean hidden) {
setupPack(event, modid, path, id, required, hidden, PathPackResources.PathResourcesSupplier::new);
}

public static void setupPack(AddPackFindersEvent event, ResourceLocation location, String folder, boolean required, Function<Path, Pack.ResourcesSupplier> packBuilder) {
public static void setupPack(AddPackFindersEvent event, ResourceLocation location, String folder, boolean required, boolean hidden, Function<Path, Pack.ResourcesSupplier> packBuilder) {
String path = location.getPath();
setupPack(event, location.getNamespace(), folder + path, path, required, packBuilder);
setupPack(event, location.getNamespace(), folder + path, path, required, hidden, packBuilder);
}
}

0 comments on commit 17de4a0

Please sign in to comment.