Search in sources :

Example 1 with Book

use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.

the class CommonProxy method getClientGuiElement.

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    ItemStack bookStack = player.getHeldItem(EnumHand.values()[x]);
    if (!bookStack.isEmpty() && bookStack.getItem() instanceof IGuideItem) {
        Book book = GuideAPI.getIndexedBooks().get(ID);
        try {
            if (bookStack.hasTagCompound()) {
                NBTTagCompound tagCompound = bookStack.getTagCompound();
                if (tagCompound.hasKey(NBTBookTags.ENTRY_TAG) && tagCompound.hasKey(NBTBookTags.CATEGORY_TAG)) {
                    CategoryAbstract category = book.getCategoryList().get(tagCompound.getInteger(NBTBookTags.CATEGORY_TAG));
                    EntryAbstract entry = category.entries.get(new ResourceLocation(tagCompound.getString(NBTBookTags.ENTRY_TAG)));
                    int pageNumber = tagCompound.getInteger(NBTBookTags.PAGE_TAG);
                    GuiEntry guiEntry = new GuiEntry(book, category, entry, player, bookStack);
                    guiEntry.pageNumber = pageNumber;
                    return guiEntry;
                } else if (tagCompound.hasKey(NBTBookTags.CATEGORY_TAG)) {
                    CategoryAbstract category = book.getCategoryList().get(tagCompound.getInteger(NBTBookTags.CATEGORY_TAG));
                    int entryPage = tagCompound.getInteger(NBTBookTags.ENTRY_PAGE_TAG);
                    GuiCategory guiCategory = new GuiCategory(book, category, player, bookStack);
                    guiCategory.entryPage = entryPage;
                    return guiCategory;
                } else {
                    int categoryNumber = tagCompound.getInteger(NBTBookTags.CATEGORY_PAGE_TAG);
                    GuiHome guiHome = new GuiHome(book, player, bookStack);
                    guiHome.categoryPage = categoryNumber;
                    return guiHome;
                }
            }
        } catch (Exception e) {
        // No-op: If the linked content doesn't exist anymore
        }
        return new GuiHome(book, player, bookStack);
    }
    return null;
}
Also used : GuiHome(amerifrance.guideapi.gui.GuiHome) EntryAbstract(amerifrance.guideapi.api.impl.abstraction.EntryAbstract) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) GuiCategory(amerifrance.guideapi.gui.GuiCategory) Book(amerifrance.guideapi.api.impl.Book) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem) GuiEntry(amerifrance.guideapi.gui.GuiEntry)

Example 2 with Book

use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.

the class TestBook2 method buildBook.

@Nullable
@Override
public Book buildBook() {
    book = new Book();
    book.setAuthor("TehNut");
    book.setColor(Color.GREEN);
    book.setDisplayName("Display Name");
    book.setTitle("Title message");
    book.setWelcomeMessage("Is this still a thing?");
    CategoryAbstract testCategory = new CategoryItemStack("test.category.name", new ItemStack(Items.BANNER)).withKeyBase("guideapi");
    testCategory.addEntry("entry", new EntryItemStack("test.entry.name", new ItemStack(Items.POTATO)));
    testCategory.getEntry("entry").addPage(new PageText("Hello, this is\nsome text"));
    testCategory.getEntry("entry").addPage(new PageFurnaceRecipe(Blocks.COBBLESTONE));
    testCategory.getEntry("entry").addPage(new PageIRecipe(new ShapedOreRecipe(Items.ACACIA_BOAT, "X X", "XXX", 'X', "plankWood")));
    testCategory.getEntry("entry").addPage(new PageBrewingRecipe(new BrewingRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.AWKWARD), new ItemStack(Items.SPECKLED_MELON), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.HEALING))));
    book.addCategory(testCategory);
    book.setRegistryName(new ResourceLocation("guideapi", "test_book2"));
    return book;
}
Also used : CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) PageIRecipe(amerifrance.guideapi.page.PageIRecipe) Book(amerifrance.guideapi.api.impl.Book) GuideBook(amerifrance.guideapi.api.GuideBook) IGuideBook(amerifrance.guideapi.api.IGuideBook) PageFurnaceRecipe(amerifrance.guideapi.page.PageFurnaceRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ResourceLocation(net.minecraft.util.ResourceLocation) PageText(amerifrance.guideapi.page.PageText) EntryItemStack(amerifrance.guideapi.entry.EntryItemStack) CategoryItemStack(amerifrance.guideapi.category.CategoryItemStack) PageBrewingRecipe(amerifrance.guideapi.page.PageBrewingRecipe) EntryItemStack(amerifrance.guideapi.entry.EntryItemStack) ItemStack(net.minecraft.item.ItemStack) CategoryItemStack(amerifrance.guideapi.category.CategoryItemStack) PageBrewingRecipe(amerifrance.guideapi.page.PageBrewingRecipe) BrewingRecipe(net.minecraftforge.common.brewing.BrewingRecipe) Nullable(javax.annotation.Nullable)

Example 3 with Book

use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.

the class APISetter method registerBook.

public static void registerBook(Book book) {
    try {
        sanityCheck();
    } catch (IllegalAccessException e) {
        Throwables.propagate(e);
        return;
    }
    try {
        Field books = GuideAPI.class.getDeclaredField("BOOKS");
        books.setAccessible(true);
        Map<ResourceLocation, Book> BOOKS = (Map<ResourceLocation, Book>) books.get(null);
        BOOKS.put(book.getRegistryName(), book);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Book(amerifrance.guideapi.api.impl.Book) ResourceLocation(net.minecraft.util.ResourceLocation) Map(java.util.Map)

Example 4 with Book

use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.

the class EventHandler method onPlayerJoinWorld.

@SubscribeEvent
public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntity();
        NBTTagCompound tag = getModTag(player, GuideMod.ID);
        if (ConfigHandler.canSpawnWithBooks) {
            for (Book book : GuideAPI.getBooks().values()) {
                if (book.isSpawnWithBook() && !tag.getBoolean("hasInitial" + book.getTitle())) {
                    ItemHandlerHelper.giveItemToPlayer(player, GuideAPI.getStackFromBook(book));
                    tag.setBoolean("hasInitial" + book.getTitle(), true);
                }
            }
        }
    }
}
Also used : Book(amerifrance.guideapi.api.impl.Book) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with Book

use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.

the class ConfigHandler method handleBookConfigs.

public static void handleBookConfigs() {
    for (Book book : GuideAPI.getBooks().values()) book.setSpawnWithBook(config.get("Books.Spawn", book.getRegistryName().toString(), book.isSpawnWithBook()).getBoolean());
    config.setCategoryComment("Books.Spawn", "If true, the user will spawn with the book.\nThis defaults to the value the book owner has set and is overridden by this config.");
    config.save();
}
Also used : Book(amerifrance.guideapi.api.impl.Book)

Aggregations

Book (amerifrance.guideapi.api.impl.Book)10 ItemStack (net.minecraft.item.ItemStack)6 ResourceLocation (net.minecraft.util.ResourceLocation)5 CategoryAbstract (amerifrance.guideapi.api.impl.abstraction.CategoryAbstract)4 IGuideBook (amerifrance.guideapi.api.IGuideBook)3 GuideBook (amerifrance.guideapi.api.GuideBook)2 IGuideItem (amerifrance.guideapi.api.IGuideItem)2 EntryAbstract (amerifrance.guideapi.api.impl.abstraction.EntryAbstract)2 CategoryItemStack (amerifrance.guideapi.category.CategoryItemStack)2 EntryItemStack (amerifrance.guideapi.entry.EntryItemStack)2 PageFurnaceRecipe (amerifrance.guideapi.page.PageFurnaceRecipe)2 PageIRecipe (amerifrance.guideapi.page.PageIRecipe)2 PageText (amerifrance.guideapi.page.PageText)2 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)2