Search in sources :

Example 1 with EntryAbstract

use of amerifrance.guideapi.api.impl.abstraction.EntryAbstract 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 EntryAbstract

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

the class GuiEntry method onGuiClosed.

@Override
public void onGuiClosed() {
    super.onGuiClosed();
    ResourceLocation key = null;
    for (Map.Entry<ResourceLocation, EntryAbstract> mapEntry : category.entries.entrySet()) if (mapEntry.getValue().equals(entry))
        key = mapEntry.getKey();
    if (key != null)
        PacketHandler.INSTANCE.sendToServer(new PacketSyncEntry(book.getCategoryList().indexOf(category), key, pageNumber));
}
Also used : EntryAbstract(amerifrance.guideapi.api.impl.abstraction.EntryAbstract) ResourceLocation(net.minecraft.util.ResourceLocation) PacketSyncEntry(amerifrance.guideapi.network.PacketSyncEntry) Map(java.util.Map)

Example 3 with EntryAbstract

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

the class GuiCategory method initGui.

@Override
public void initGui() {
    super.initGui();
    this.buttonList.clear();
    this.entryWrapperMap.clear();
    guiLeft = (this.width - this.xSize) / 2;
    guiTop = (this.height - this.ySize) / 2;
    this.buttonList.add(buttonBack = new ButtonBack(0, guiLeft + xSize / 6, guiTop, this));
    this.buttonList.add(buttonNext = new ButtonNext(1, guiLeft + 4 * xSize / 6, guiTop + 5 * ySize / 6, this));
    this.buttonList.add(buttonPrev = new ButtonPrev(2, guiLeft + xSize / 5, guiTop + 5 * ySize / 6, this));
    int eX = guiLeft + 37;
    int eY = guiTop + 15;
    int i = 0;
    int pageNumber = 0;
    List<EntryAbstract> entries = Lists.newArrayList(category.entries.values());
    for (EntryAbstract entry : entries) {
        entry.onInit(book, category, this, player, bookStack);
        entryWrapperMap.put(pageNumber, new EntryWrapper(this, book, category, entry, eX, eY, 4 * xSize / 6, 10, player, this.fontRenderer, bookStack));
        eY += 13;
        i++;
        if (i >= 11) {
            i = 0;
            eY = guiTop + 15;
            pageNumber++;
        }
    }
}
Also used : ButtonBack(amerifrance.guideapi.button.ButtonBack) EntryAbstract(amerifrance.guideapi.api.impl.abstraction.EntryAbstract) EntryWrapper(amerifrance.guideapi.wrapper.EntryWrapper) ButtonPrev(amerifrance.guideapi.button.ButtonPrev) ButtonNext(amerifrance.guideapi.button.ButtonNext)

Example 4 with EntryAbstract

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

the class TestBook method buildBook.

@Nullable
@Override
public Book buildBook() {
    book = new Book();
    book.setAuthor("TehNut");
    book.setColor(Color.BLUE);
    book.setDisplayName("Display Name");
    book.setTitle("Title message");
    book.setWelcomeMessage("Is this still a thing?");
    List<CategoryAbstract> categories = Lists.newArrayList();
    Map<ResourceLocation, EntryAbstract> entries = Maps.newHashMap();
    List<IPage> pages = Lists.newArrayList();
    pages.add(new PageText("Hello, this is\nsome text"));
    pages.add(new PageFurnaceRecipe(Blocks.COBBLESTONE));
    pages.add(new PageIRecipe(new ShapedOreRecipe(Items.ACACIA_BOAT, "X X", "XXX", 'X', "plankWood")));
    Entry entry = new EntryItemStack(pages, "test.entry.name", new ItemStack(Items.POTATO));
    entries.put(new ResourceLocation("guideapi", "entry"), entry);
    categories.add(new CategoryItemStack(entries, "test.category.name", new ItemStack(Items.BANNER)));
    book.setCategoryList(categories);
    book.setRegistryName(new ResourceLocation("guideapi", "test_book"));
    return book;
}
Also used : EntryAbstract(amerifrance.guideapi.api.impl.abstraction.EntryAbstract) PageFurnaceRecipe(amerifrance.guideapi.page.PageFurnaceRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) PageText(amerifrance.guideapi.page.PageText) EntryItemStack(amerifrance.guideapi.entry.EntryItemStack) CategoryItemStack(amerifrance.guideapi.category.CategoryItemStack) Entry(amerifrance.guideapi.api.impl.Entry) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) PageIRecipe(amerifrance.guideapi.page.PageIRecipe) Book(amerifrance.guideapi.api.impl.Book) ResourceLocation(net.minecraft.util.ResourceLocation) EntryItemStack(amerifrance.guideapi.entry.EntryItemStack) ItemStack(net.minecraft.item.ItemStack) CategoryItemStack(amerifrance.guideapi.category.CategoryItemStack) Nullable(javax.annotation.Nullable)

Aggregations

EntryAbstract (amerifrance.guideapi.api.impl.abstraction.EntryAbstract)4 ResourceLocation (net.minecraft.util.ResourceLocation)3 Book (amerifrance.guideapi.api.impl.Book)2 CategoryAbstract (amerifrance.guideapi.api.impl.abstraction.CategoryAbstract)2 ItemStack (net.minecraft.item.ItemStack)2 IGuideItem (amerifrance.guideapi.api.IGuideItem)1 Entry (amerifrance.guideapi.api.impl.Entry)1 ButtonBack (amerifrance.guideapi.button.ButtonBack)1 ButtonNext (amerifrance.guideapi.button.ButtonNext)1 ButtonPrev (amerifrance.guideapi.button.ButtonPrev)1 CategoryItemStack (amerifrance.guideapi.category.CategoryItemStack)1 EntryItemStack (amerifrance.guideapi.entry.EntryItemStack)1 GuiCategory (amerifrance.guideapi.gui.GuiCategory)1 GuiEntry (amerifrance.guideapi.gui.GuiEntry)1 GuiHome (amerifrance.guideapi.gui.GuiHome)1 PacketSyncEntry (amerifrance.guideapi.network.PacketSyncEntry)1 PageFurnaceRecipe (amerifrance.guideapi.page.PageFurnaceRecipe)1 PageIRecipe (amerifrance.guideapi.page.PageIRecipe)1 PageText (amerifrance.guideapi.page.PageText)1 EntryWrapper (amerifrance.guideapi.wrapper.EntryWrapper)1