|
4 | 4 | import com.google.gson.*;
|
5 | 5 | import com.mojang.brigadier.StringReader;
|
6 | 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
| 7 | +import com.mojang.serialization.JsonOps; |
7 | 8 | import io.wispforest.lavender.Lavender;
|
8 | 9 | import io.wispforest.owo.ui.component.Components;
|
9 | 10 | import io.wispforest.owo.ui.container.Containers;
|
10 | 11 | import io.wispforest.owo.ui.core.Component;
|
11 | 12 | import io.wispforest.owo.ui.core.Sizing;
|
12 | 13 | import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
13 | 14 | import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
| 15 | +import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition; |
| 16 | +import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions; |
14 | 17 | import net.minecraft.client.MinecraftClient;
|
15 | 18 | import net.minecraft.command.argument.ItemStringReader;
|
16 | 19 | import net.minecraft.item.Item;
|
@@ -204,9 +207,13 @@ private static void forResourceOfBook(Map<String, Map<String, Resource>> resourc
|
204 | 207 | meta = GSON.fromJson(content.substring(0, frontmatterEnd), JsonObject.class);
|
205 | 208 | content = content.substring(frontmatterEnd + 3).stripLeading();
|
206 | 209 |
|
207 |
| -// return ResourceConditions.objectMatchesConditions(meta) |
208 |
| -// ? new MarkdownResource(meta, book.expandMacros(resourceId, content.replaceAll("\\r\\n?", "\n"))) |
209 |
| -// : null; |
| 210 | + if (meta.has(ResourceConditions.CONDITIONS_KEY)) { |
| 211 | + var conditions = ResourceCondition.CONDITION_CODEC.parse(JsonOps.INSTANCE, meta.get(ResourceConditions.CONDITIONS_KEY)); |
| 212 | + if (conditions.isSuccess() && !conditions.getOrThrow().test(MinecraftClient.getInstance().world.getRegistryManager())) { |
| 213 | + return null; |
| 214 | + } |
| 215 | + } |
| 216 | + |
210 | 217 | return new MarkdownResource(meta, book.expandMacros(resourceId, content.replaceAll("\\r\\n?", "\n")));
|
211 | 218 | } else {
|
212 | 219 | throw new RuntimeException("Missing markdown meta");
|
|
0 commit comments