Search in sources :

Example 1 with CategoryAbstract

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

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

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

the class GuiHome method initGui.

@Override
public void initGui() {
    this.buttonList.clear();
    this.categoryWrapperMap.clear();
    guiLeft = (this.width - this.xSize) / 2;
    guiTop = (this.height - this.ySize) / 2;
    addButton(buttonNext = new ButtonNext(0, guiLeft + 4 * xSize / 6, guiTop + 5 * ySize / 6, this));
    addButton(buttonPrev = new ButtonPrev(1, guiLeft + xSize / 5, guiTop + 5 * ySize / 6, this));
    addButton(buttonSearch = new ButtonSearch(2, guiLeft + xSize / 6, guiTop, this));
    int cX = guiLeft + 45;
    int cY = guiTop + 40;
    int drawLoc = 0;
    int i = 0;
    int pageNumber = 0;
    for (CategoryAbstract category : book.getCategoryList()) {
        category.onInit(book, this, player, bookStack);
        switch(drawLoc) {
            case 0:
                {
                    categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
                    cX += 27;
                    drawLoc = 1;
                    break;
                }
            case 1:
                {
                    categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
                    cX += 27;
                    drawLoc = 2;
                    break;
                }
            case 2:
                {
                    categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
                    cX += 27;
                    drawLoc = 3;
                    break;
                }
            case 3:
                {
                    categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
                    drawLoc = 0;
                    cX = guiLeft + 45;
                    cY += 30;
                    break;
                }
        }
        i++;
        if (i >= 16) {
            i = 0;
            cX = guiLeft + 45;
            cY = guiTop + 40;
            pageNumber++;
        }
    }
}
Also used : ButtonSearch(amerifrance.guideapi.button.ButtonSearch) CategoryWrapper(amerifrance.guideapi.wrapper.CategoryWrapper) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) ButtonPrev(amerifrance.guideapi.button.ButtonPrev) ButtonNext(amerifrance.guideapi.button.ButtonNext)

Example 4 with CategoryAbstract

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

the class ItemGuideBook method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!world.isRemote || !player.isSneaking())
        return EnumActionResult.PASS;
    ItemStack stack = player.getHeldItem(hand);
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() instanceof IGuideLinked) {
        IGuideLinked guideLinked = (IGuideLinked) state.getBlock();
        ResourceLocation entryKey = guideLinked.getLinkedEntry(world, pos, player, stack);
        if (entryKey == null)
            return EnumActionResult.FAIL;
        for (CategoryAbstract category : book.getCategoryList()) {
            if (category.entries.containsKey(entryKey)) {
                GuideMod.proxy.openEntry(book, category, category.entries.get(entryKey), player, stack);
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return EnumActionResult.PASS;
}
Also used : IGuideLinked(amerifrance.guideapi.api.IGuideLinked) IBlockState(net.minecraft.block.state.IBlockState) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) ItemStack(net.minecraft.item.ItemStack)

Example 5 with CategoryAbstract

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

the class EventHandler method renderOverlay.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Pre event) {
    if (event.getType() != RenderGameOverlayEvent.ElementType.CROSSHAIRS)
        return;
    RayTraceResult rayTrace = Minecraft.getMinecraft().objectMouseOver;
    if (rayTrace == null || rayTrace.typeOfHit != RayTraceResult.Type.BLOCK)
        return;
    EntityPlayer player = Minecraft.getMinecraft().player;
    World world = Minecraft.getMinecraft().world;
    ItemStack held = ItemStack.EMPTY;
    Book book = null;
    for (EnumHand hand : EnumHand.values()) {
        ItemStack heldStack = player.getHeldItem(hand);
        if (heldStack.getItem() instanceof IGuideItem) {
            held = heldStack;
            book = ((IGuideItem) heldStack.getItem()).getBook(heldStack);
            break;
        }
    }
    if (book == null)
        return;
    IBlockState state = world.getBlockState(rayTrace.getBlockPos());
    String linkedEntry = null;
    if (state.getBlock() instanceof IGuideLinked) {
        IGuideLinked linked = (IGuideLinked) state.getBlock();
        ResourceLocation entryKey = linked.getLinkedEntry(world, rayTrace.getBlockPos(), player, held);
        if (entryKey != null) {
            for (CategoryAbstract category : book.getCategoryList()) {
                if (category.entries.containsKey(entryKey)) {
                    linkedEntry = category.getEntry(entryKey).getLocalizedName();
                    break;
                }
            }
        }
    }
    if (!Strings.isNullOrEmpty(linkedEntry)) {
        FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
        ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
        int drawX = scaledResolution.getScaledWidth() / 2 + 10;
        int drawY = scaledResolution.getScaledHeight() / 2 - 8;
        Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(held, drawX, drawY);
        drawY -= 2;
        drawX += 20;
        fontRenderer.drawStringWithShadow(TextFormatting.WHITE + linkedEntry, drawX, drawY, 0);
        fontRenderer.drawStringWithShadow(TextFormatting.WHITE.toString() + TextFormatting.ITALIC.toString() + TextHelper.localize("text.linked.open"), drawX, drawY + 12, 0);
    }
    if (state.getBlock() instanceof IInfoRenderer.Block) {
        IInfoRenderer infoRenderer = ((IInfoRenderer.Block) state.getBlock()).getInfoRenderer(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
        if (book == ((IInfoRenderer.Block) state.getBlock()).getBook() && infoRenderer != null)
            infoRenderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
    }
    Multimap<Class<? extends Block>, IInfoRenderer> bookRenderers = GuideAPI.getInfoRenderers().get(book);
    if (bookRenderers == null)
        return;
    Collection<IInfoRenderer> renderers = bookRenderers.get(state.getBlock().getClass());
    for (IInfoRenderer renderer : renderers) renderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
}
Also used : IGuideLinked(amerifrance.guideapi.api.IGuideLinked) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) IInfoRenderer(amerifrance.guideapi.api.IInfoRenderer) ScaledResolution(net.minecraft.client.gui.ScaledResolution) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) Book(amerifrance.guideapi.api.impl.Book) EnumHand(net.minecraft.util.EnumHand) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

CategoryAbstract (amerifrance.guideapi.api.impl.abstraction.CategoryAbstract)6 ItemStack (net.minecraft.item.ItemStack)5 Book (amerifrance.guideapi.api.impl.Book)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 IGuideItem (amerifrance.guideapi.api.IGuideItem)2 IGuideLinked (amerifrance.guideapi.api.IGuideLinked)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 Nullable (javax.annotation.Nullable)2 IBlockState (net.minecraft.block.state.IBlockState)2 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)2 GuideBook (amerifrance.guideapi.api.GuideBook)1 IGuideBook (amerifrance.guideapi.api.IGuideBook)1 IInfoRenderer (amerifrance.guideapi.api.IInfoRenderer)1 Entry (amerifrance.guideapi.api.impl.Entry)1 ButtonNext (amerifrance.guideapi.button.ButtonNext)1