Skip to content

Commit

Permalink
Add recipe type mapping as a ServiceLoader interface, and fix a searc…
Browse files Browse the repository at this point in the history
…h issue.
  • Loading branch information
shartte committed Jan 29, 2025
1 parent 80202bf commit 37b7080
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
5 changes: 5 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

# Changelog

## 2.5.0

- Added an extension point for mods to add support for [custom recipe types](./integration/recipe-types.md) to all guides.
- Fixed an issue with navigating to the search screen.

## 2.4.0

- Add missing Markdown node classes to API jar
Expand Down
File renamed without changes.
40 changes: 40 additions & 0 deletions docs/docs/integration/recipe-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Custom Recipe Types

## Registering Custom Recipe Types

To display your custom recipe types in mods, you can implement
the [RecipeTypeMappingSupplier](https://guideme.appliedenergistics.org/javadoc/guideme/compiler/tags/RecipeTypeMappingSupplier.html).

While it can be added to guides using the standard GuideME extension mechanism, this interface can also be
exposed as a Java ServiceLoader service, which enables its use in all guides.

This is important since your recipe types can show up in other guides through the use of data packs.

The following example adds custom recipe layout implementations for the AE2 custom recipe types.
You do not need to use a custom block subclass necessarily, since `RecipeTypeMappings` just expects a
factory of the form `Function<RecipeHolder<T>, LytBlock>` for each recipe type.

```java
package appeng.client.guidebook;

// ...

public class RecipeTypeContributions implements RecipeTypeMappingSupplier {
@Override
public void collect(RecipeTypeMappings mappings) {
mappings.add(AERecipeTypes.INSCRIBER, LytInscriberRecipe::new);
mappings.add(AERecipeTypes.CHARGER, LytChargerRecipe::new);
mappings.add(AERecipeTypes.TRANSFORM, LytTransformRecipe::new);
}
}
```

To make GuideME load this extension, add its fully qualified class name to a file with the following path in your
project:
`src/main/resources/META-INF/services/guideme.compiler.tags.RecipeTypeMappingSupplier`.

## Custom Layout Blocks

If your recipe requires a custom layout block, you can use the
existing [recipe layouts in GuideME](https://github.com/AppliedEnergistics/GuideME/tree/main/src/main/java/guideme/document/block/recipes)
as a starting point.
1 change: 1 addition & 0 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const config: Config = {
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
additionalLanguages: ["java", "scala"],
},
} satisfies Preset.ThemeConfig,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
/**
* Allows mods to register mappings between recipe type and their custom recipe blocks for use in {@code <RecipeFor/>}
* and similar tags.
* <p/>
* **NOTE:** In addition to being an extension point, implementations of this interface are also retrieved through the
* Java Service-Loader to enable use of mod recipes cross-guide. Specific instances registered through
* {@link guideme.GuideBuilder#extension} will have higher priority than instances discovered through service-loader.
*/
public interface RecipeTypeMappingSupplier extends Extension {
ExtensionPoint<RecipeTypeMappingSupplier> EXTENSION_POINT = new ExtensionPoint<>(RecipeTypeMappingSupplier.class);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/guideme/internal/screen/GuideNavigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public static void navigateTo(Guide guide, PageAnchor anchor) {
screenToReturnTo = searchScreen.getReturnToOnClose();
}

// Handle built-in pages
if (GuideSearchScreen.PAGE_ID.equals(anchor.pageId())) {
var guiScreen = GuideSearchScreen.open(guide, anchor.anchor());
guiScreen.setReturnToOnClose(screenToReturnTo);
Minecraft.getInstance().setScreen(guiScreen);
return;
}

// Handle navigation within the same guide
if (currentScreen instanceof GuideScreen guideScreen && guideScreen.getGuide() == guide) {
if (Objects.equals(guideScreen.getCurrentPageId(), anchor.pageId())) {
Expand All @@ -45,14 +53,6 @@ public static void navigateTo(Guide guide, PageAnchor anchor) {
return;
}

// Handle built-in pages
if (GuideSearchScreen.PAGE_ID.equals(anchor.pageId())) {
var guiScreen = GuideSearchScreen.open(guide, anchor.anchor());
guiScreen.setReturnToOnClose(screenToReturnTo);
Minecraft.getInstance().setScreen(guiScreen);
return;
}

GuideScreen guideScreen = GuideScreen.openNew(guide, anchor, history);
guideScreen.setReturnToOnClose(screenToReturnTo);
Minecraft.getInstance().setScreen(guideScreen);
Expand Down

0 comments on commit 37b7080

Please sign in to comment.