Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/guideme/compiler/tags/OptionalSectionCompiler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package guideme.compiler.tags;

import guideme.compiler.PageCompiler;
import guideme.document.block.LytBlockContainer;
import guideme.libs.mdast.mdx.model.MdxJsxElementFields;
import java.util.Set;
import net.neoforged.fml.ModList;

public class OptionalSectionCompiler extends BlockTagCompiler {
@Override
public Set<String> getTagNames() {
return Set.of("OptionalSection");
}

@Override
protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxElementFields el) {
var modId = MdxAttrs.getString(compiler, parent, el, "modId", null);
if (modId == null) {
parent.appendError(compiler, "Missing modId attribute.", el);
return;
}

boolean invert = false;
if (modId.startsWith("!")) {
modId = modId.substring(1);
invert = true;
}
if (ModList.get().isLoaded(modId) ^ invert) {
compiler.compileBlockContext(el.children(), parent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import guideme.compiler.tags.ItemGridCompiler;
import guideme.compiler.tags.ItemLinkCompiler;
import guideme.compiler.tags.KeyBindTagCompiler;
import guideme.compiler.tags.OptionalSectionCompiler;
import guideme.compiler.tags.PlayerNameTagCompiler;
import guideme.compiler.tags.RecipeCompiler;
import guideme.compiler.tags.RecipeTypeMappingSupplier;
Expand Down Expand Up @@ -85,7 +86,8 @@ private static List<TagCompiler> tagCompilers() {
new SubPagesCompiler(),
new CommandLinkCompiler(),
new PlayerNameTagCompiler(),
new KeyBindTagCompiler());
new KeyBindTagCompiler(),
new OptionalSectionCompiler());
}

private static List<SceneElementTagCompiler> sceneElementTagCompilers() {
Expand Down
16 changes: 16 additions & 0 deletions src/testmod/resources/assets/testmod/guides/testmod/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,19 @@ You may ~~need~~ a <Color color="#ff0000">door</Color> <Color id="test_color">do
</Row>

<ItemImage id="minecraft:recovery_compass" />

## Optional content

<OptionalSection modId="not_installed">
This text must not be visible because no mod with ID `not_installed` is loaded!
</OptionalSection>

<OptionalSection modId="!guideme">
This text must not be visible because GuideME is loaded!
</OptionalSection>

<OptionalSection modId="minecraft">
This text is visible because Minecraft is loaded!
</OptionalSection>

End of optional content