Skip to content

Commit

Permalink
chore: a few tweaks here and there
Browse files Browse the repository at this point in the history
- builtin docs now mention data components instead of NBT
- added a `/ftbguides setguide` command to set up guide book items
  • Loading branch information
desht committed Jun 18, 2024
1 parent cfd4df8 commit 467bba9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2100.0.0]

### Changed
* Ported to Minecraft 1.21. Support for Fabric and NeoForge.
* Forge support may be re-added if/when Architectury adds support for Forge
2 changes: 2 additions & 0 deletions common/src/main/java/dev/ftb/mods/ftbguides/FTBGuides.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.architectury.utils.EnvExecutor;
import dev.ftb.mods.ftbguides.client.FTBGuidesClient;
import dev.ftb.mods.ftbguides.commands.OpenGuiCommand;
import dev.ftb.mods.ftbguides.commands.SetGuideCommand;
import dev.ftb.mods.ftbguides.docs.DocsLoader;
import dev.ftb.mods.ftbguides.net.FTBGuidesNet;
import dev.ftb.mods.ftbguides.registry.GuideBookData;
Expand Down Expand Up @@ -73,6 +74,7 @@ private static CompoundEventResult<ItemStack> rightClickItem(Player player, Inte
private static void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext buildContext, Commands.CommandSelection selection) {
dispatcher.register(Commands.literal(MOD_ID)
.then(OpenGuiCommand.register())
.then(SetGuideCommand.register())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.ftb.mods.ftbguides.FTBGuides;
import dev.ftb.mods.ftbguides.client.FTBGuidesClient;
import dev.ftb.mods.ftbguides.client.gui.widgets.Anchorable;
Expand Down Expand Up @@ -52,18 +51,12 @@ public class GuideScreen extends BaseScreen implements ClickEventHandler, GuideT

// TODO persist these across client invocations?
private static DocsLoader.NodeWithMeta activeNode = null;
// private static boolean indexPinned = true;

public GuideScreen() {
toolbarPanel = new ToolbarPanel();
indexPanel = new IndexPanel();
docsPanel = new DocsPanel();
docsScrollbar = new PanelScrollBar(this, ScrollBar.Plane.VERTICAL, docsPanel) {
@Override
public boolean shouldDraw() {
return getScrollBarSize() > 0;
}
};
docsScrollbar = new PanelScrollBar(this, ScrollBar.Plane.VERTICAL, docsPanel);
expandIndexButton = new ExpandIndexButton();
collapsedCategories = new HashSet<>();
theme = new FTBGuidesTheme(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.ftb.mods.ftbguides.commands;

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.ftb.mods.ftbguides.registry.GuideBookData;
import dev.ftb.mods.ftbguides.registry.ModItems;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;

import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;

public class SetGuideCommand {
public static LiteralArgumentBuilder<CommandSourceStack> register() {
return literal("setguide")
.requires(source -> source.hasPermission(2))
.then(argument("id", StringArgumentType.greedyString())
.executes(ctx -> setGuide(ctx.getSource(), StringArgumentType.getString(ctx, "id")))
);
}

private static int setGuide(CommandSourceStack source, String id) throws CommandSyntaxException {
ItemStack stack = source.getPlayerOrException().getMainHandItem();
if (!stack.isEmpty()) {
stack.set(ModItems.GUIDE_DATA.get(), new GuideBookData(id));
source.sendSuccess(() -> Component.translatable("ftbguides.message.set_data", stack.getDisplayName(), id), false);
return 1;
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ For example, to open the viewer to the **Viewing Markdown Files** heading in thi

## Items

Any item with the top-level NBT string tag `ftbguides:page` will open the viewer to the value of that tag when right-clicked.
For convenience, FTB Guides provides a book item, item ID `ftbguides:book`. This is intended to be used as a trigger for opening a guide.

You can set the guide ID on any item (doesn't need to be the FTB Guides book item) by holding the item, and using the `/ftbguides setguide <id>` command. This set the data component `ftbguides:guidebook` to the given ID.

Right-clicking any item (again, doesn't need to be the FTB Guides book item) which has the `ftbguides:guidebook` component will open the viewer to the page ID of that component, as if the `/ftbguides open ...` command were run with that argument.

### Mod Developers

You are completely free to create your own guide book items, setting up the appropriate NBT when constructing your itemstack for your creative tab.
You are completely free to create your own guidebook items, setting up the appropriate data component when constructing your itemstack for your creative tab. The data component can be accessed in Java via `ModItems.GUIDE_BOOK`, and is of type `GuideBookData` (note that this is a record rather than a simple string to make future extensibility easier). E.g.

ItemStack stack = new ItemStack(ModItems.BOOK.get()); // or some other item
stack.set(ModItems.GUIDE_DATA.get(), new GuideBookData("mymod:index_page"));

### Modpack Developers

As a convenience, FTB Guides also provides a guidebook item (with no NBT by default), which pack developers can use (e.g. by adding recipes for, or using mods like KubeJS to create instances). This guidebook item dynamically colors itself based on the value of the `ftbguides:page` NBT tag (specifically, the _namespace_ of the page ID referred to).
As a convenience, FTB Guides also provides a guidebook item (with no data component by default), which pack developers can use (e.g. by adding recipes for, or using mods like KubeJS to create instances). This guidebook item dynamically colors itself based on the value of the `ftbguides:guidebook` component (specifically, the _namespace_ of the page ID referred to). You are also welcome to use any other item, although something resembling a book is recommended...

3 changes: 2 additions & 1 deletion common/src/main/resources/assets/ftbguides/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"ftbguides.gui.matches": "%s match(es) for '%s'",
"ftbguides.gui.no_matches": "No matches for '%s'",
"item.ftbguides.book": "Guide Book",
"itemGroup.ftbguides.ftbguides": "FTB Guides"
"itemGroup.ftbguides.ftbguides": "FTB Guides",
"ftbguides.message.set_data": "Set guide data for %s to '%s'"
}

0 comments on commit 467bba9

Please sign in to comment.