Skip to content
David Quintana edited this page Feb 14, 2023 · 1 revision

Welcome to the Guidebook wiki!

This wiki is a work in progress.

The contents of this wiki are an almost-verbatim copy of the contents of the in-game Guidebook manual.

See the Table of Contents on the right for the main help topics.

Very Incomplete FAQ / Cheat Sheet

How do I give a book a title?

Specify the text in the book tag, like <book title="This is an example">.

How do I give a book a cover image?

Specify the location in the book tag, like <book cover="gbook:test">, the png extension is implied.

How do I format text?

You can use bold, italics, underline, color, indent, scale and align, in either the paragraph elements (<p color="#FF00FF">) or the span elements (<span bold="true">, <link underline="true">, ...).

How do I insert an image?

Use the image tag, as in <image src="minecraft:items/coal" tw="16" th="16"/>

How do I insert a recipe?

Use the recipe tag, as in

<recipe type="gbook:crafting" key="minecraft:quartz_block"/>

or

<recipe type="shaped">
    <recipe.result>
        <stack item="minecraft:comparator"/>
    </recipe.result>
</recipe>

How do I make part of the book show conditionally?

First, declare a condition in the top level of the document (inside <book>):

<conditions>
    <item-exists name="ingot_exists" registry-name="minecraft:iron_ingot"/>
</conditions>

Then, you can use the condition in a chapter, section, or paragraph:

<chapter condition="ingot_exists">

How do I make the book in multiple languages?

The mod will look for files with the right language code in the filename, when trying to load the book.

If the user language is ca_es, the mod will load gbook:demo.ca_es.xml if present, instead of gbook:demo.xml.

How do I add a book into a mod?

Use the BookRegistryEvent. It only gets called on the client.

How do I add a book into a modpack?

Use the configuration folder. The mod looks for XML files in <instance>/config/books/, and it will look for images in <instance>/config/books/resources/textures/. See the page on adding books for more detail.

How do I get the book?

If you want to spawn one book, you can give it to yourself ingame:

/give @p gbook:guidebook{Book:"gbook:demobook.xml"} 1

How do I give the book to all players when they join?

If you want all new players to get the book (or existing players if you added a book after the fact), use the server config file:

[general]
	#List of books to give to the player when they join. Applied retroactively to existing players if a new book is added to the list.
	give_on_first_join = [ "the:book.xml" ]

... And as a mod?

I don't like mods giving people items by default (modpacks can use the config if they want), but since people will inevitably keep asking...

First ask forge to give you an itemstack of the book (ItemStackHolder helps keep this as a soft dependency):

    public static final RegistryObject<GuidebookItem> GUIDEBOOK_ITEM = RegistryObject.of(new ResourceLocation("gbook","guidebook"), ForgeRegistries.ITEMS);
    public static final Lazy<ItemStack> MY_BOOK = Lazy.of(() -> GUIDEBOOK_ITEM.map(item -> {
        ItemStack stack = new ItemStack(item);
        CompoundNBT tag = stack.getOrCreateTag();
        tag.putString("Book", "my:book.xml");
        return stack;
    }).orElse(ItemStack.EMPTY));

Then, give yourself a handler for EntityJoinWorldEvent, and use some system such as the entity tags, to mark the player persistently:

    // Give one gbook per player on first join
    @SubscribeEvent
    public static void checkGbookGiven(EntityJoinWorldEvent event)
    {
        if (MY_BOOK.get().getCount() > 0)
        {
            final Entity entity = event.getEntity();
            final String bookPlayerTag = "MODID:someTagLikeGbookGiven";

            if (entity instanceof PlayerEntity && !entity.getEntityWorld().isRemote && !entity.getTags().contains(bookPlayerTag))
            {
                ItemHandlerHelper.giveItemToPlayer((PlayerEntity) entity, MY_BOOK.get().copy());
                entity.addTag(bookPlayerTag);
            }
        }
    }