Created
September 19, 2017 19:34
-
-
Save SilentChaos512/f23e873c615ba1d5efc15be201b8fbda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.silentchaos512.testmod; | |
import net.minecraft.client.gui.GuiScreen; | |
import net.minecraft.init.Items; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraftforge.common.MinecraftForge; | |
import net.minecraftforge.event.RegistryEvent; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.Mod.EventHandler; | |
import net.minecraftforge.fml.common.Mod.Instance; | |
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; | |
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
import net.silentchaos512.lib.guidebook.chapter.GuideChapter; | |
import net.silentchaos512.lib.guidebook.entry.GuideEntry; | |
import net.silentchaos512.lib.guidebook.page.PageCrafting; | |
import net.silentchaos512.lib.guidebook.page.PageTextOnly; | |
import net.silentchaos512.lib.item.ItemGuideBookSL; | |
import net.silentchaos512.lib.registry.SRegistry; | |
/** | |
* Example Silent Lib guide book implementation. Basically just extend the GuideBook class, register an ItemGuideBookSL | |
* with it, and call the GuideBook's preInit and postInit in the appropriate phases. | |
*/ | |
@Mod(modid = TestGuideBook.MOD_ID, name = "Guide Book Test", dependencies = "after:silentlib") | |
public class TestGuideBook { | |
public static final String MOD_ID = "test_guide_book"; | |
// Creating an SRegistry isn't necessary, just a convenience. | |
public static SRegistry registry = new SRegistry(MOD_ID); | |
// The mod creates the book item, but we don't need to extend the Silent Lib class. | |
ItemGuideBookSL book = new ItemGuideBookSL(new TestGuideBook.GuideBook(MOD_ID)); | |
@Instance(MOD_ID) | |
public static TestGuideBook instance; | |
@EventHandler | |
public void preInit(FMLPreInitializationEvent event) { | |
MinecraftForge.EVENT_BUS.register(this); | |
// Guide book pre-init initializes entries. | |
book.book.preInit(); | |
} | |
@EventHandler | |
public void postInit(FMLPostInitializationEvent event) { | |
// Post-init initializes chapters and everything else. | |
book.book.postInit(); | |
} | |
@SubscribeEvent | |
public void registerItems(RegistryEvent.Register<Item> event) { | |
book.giveBookOnFirstLogin = true; // Change if desired. | |
registry.registerItem(book); // Or however you normally register your items. | |
} | |
public static class GuideBook extends net.silentchaos512.lib.guidebook.GuideBook { | |
GuideEntry entryExample; | |
public GuideBook(String modId) { | |
super(modId); | |
// Change resourceGui or resourceGadgets to use custom textures for the book. | |
this.edition = 1; // Typically use the build number here. | |
} | |
@Override | |
public void initEntries() { | |
// Entries are displayed on the main page. Optionally use setImportant or setSpecial to set color. | |
entryExample = new GuideEntry(this, "exampleEntry").setImportant(); | |
} | |
@SuppressWarnings("unused") | |
@Override | |
public void initChapters() { | |
// Entries contain one or more chapters. | |
// All the actual text of the book will be in the localization file. | |
// @formatter:off | |
new GuideChapter(this, "chapter1", entryExample, new ItemStack(Items.COAL), | |
new PageTextOnly(this, 1), | |
new PageTextOnly(this, 2)).setSpecial(); | |
new GuideChapter(this, "chapter2", entryExample, new ItemStack(Items.DIAMOND), | |
new PageTextOnly(this, 1), | |
new PageCrafting(this, 2, registry.recipes.makeShapeless(new ItemStack(Items.DIAMOND), | |
new ItemStack(Items.COAL), new ItemStack(Items.COAL)))); | |
// @formatter:on | |
} | |
@Override | |
public String[] getQuotes() { | |
// Optional quotes for main page. Return an empty array if you don't want any. | |
return new String[] {}; | |
} | |
@Override | |
public GuiScreen getConfigScreen(GuiScreen parent) { | |
// If the mod has a config GUI, you can return it here to add the config button to the book. | |
return null; | |
} | |
@Override | |
public GuiScreen getAchievementScreen(GuiScreen parent) { | |
// If your mod has achievements/advancments, you can return it here to add the achievements | |
// button to the book. I haven't tested this yet, so not sure if it even works. | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment