Search in sources :

Example 1 with GuiCategory

use of amerifrance.guideapi.gui.GuiCategory 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)

Aggregations

IGuideItem (amerifrance.guideapi.api.IGuideItem)1 Book (amerifrance.guideapi.api.impl.Book)1 CategoryAbstract (amerifrance.guideapi.api.impl.abstraction.CategoryAbstract)1 EntryAbstract (amerifrance.guideapi.api.impl.abstraction.EntryAbstract)1 GuiCategory (amerifrance.guideapi.gui.GuiCategory)1 GuiEntry (amerifrance.guideapi.gui.GuiEntry)1 GuiHome (amerifrance.guideapi.gui.GuiHome)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1