Skip to content

Commit

Permalink
reimplement resource condition matching on book contents
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Jul 3, 2024
1 parent 652b3ca commit 449e58c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.15.11

# Mod Properties
mod_version = 0.1.10
mod_version = 0.1.11
maven_group = io.wispforest
archives_base_name = lavender

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/wispforest/lavender/book/BookContentLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.google.gson.*;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.JsonOps;
import io.wispforest.lavender.Lavender;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.container.Containers;
import io.wispforest.owo.ui.core.Component;
import io.wispforest.owo.ui.core.Sizing;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.argument.ItemStringReader;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -204,9 +207,13 @@ private static void forResourceOfBook(Map<String, Map<String, Resource>> resourc
meta = GSON.fromJson(content.substring(0, frontmatterEnd), JsonObject.class);
content = content.substring(frontmatterEnd + 3).stripLeading();

// return ResourceConditions.objectMatchesConditions(meta)
// ? new MarkdownResource(meta, book.expandMacros(resourceId, content.replaceAll("\\r\\n?", "\n")))
// : null;
if (meta.has(ResourceConditions.CONDITIONS_KEY)) {
var conditions = ResourceCondition.CONDITION_CODEC.parse(JsonOps.INSTANCE, meta.get(ResourceConditions.CONDITIONS_KEY));
if (conditions.isSuccess() && !conditions.getOrThrow().test(MinecraftClient.getInstance().world.getRegistryManager())) {
return null;
}
}

return new MarkdownResource(meta, book.expandMacros(resourceId, content.replaceAll("\\r\\n?", "\n")));
} else {
throw new RuntimeException("Missing markdown meta");
Expand Down

0 comments on commit 449e58c

Please sign in to comment.