Search in sources :

Example 1 with IGuideItem

use of amerifrance.guideapi.api.IGuideItem 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 IGuideItem

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

the class PacketSyncCategory method onMessage.

@Override
public IMessage onMessage(PacketSyncCategory message, MessageContext ctx) {
    ItemStack book = ctx.getServerHandler().player.getHeldItemOffhand();
    if (book.isEmpty() || !(book.getItem() instanceof IGuideItem))
        book = ctx.getServerHandler().player.getHeldItemMainhand();
    if (!book.isEmpty() && book.getItem() instanceof IGuideItem) {
        if (message.category != -1 && message.page != -1) {
            if (!book.hasTagCompound())
                book.setTagCompound(new NBTTagCompound());
            book.getTagCompound().setInteger(NBTBookTags.CATEGORY_TAG, message.category);
            book.getTagCompound().setInteger(NBTBookTags.ENTRY_PAGE_TAG, message.page);
            book.getTagCompound().removeTag(NBTBookTags.ENTRY_TAG);
        }
    }
    return null;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem)

Example 3 with IGuideItem

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

the class PacketSyncEntry method onMessage.

@Override
public IMessage onMessage(PacketSyncEntry message, MessageContext ctx) {
    ItemStack book = ctx.getServerHandler().player.getHeldItemOffhand();
    if (book.isEmpty() || !(book.getItem() instanceof IGuideItem))
        book = ctx.getServerHandler().player.getHeldItemMainhand();
    if (!book.isEmpty() && book.getItem() instanceof IGuideItem) {
        if (message.category != -1 && !message.entry.equals(new ResourceLocation("guideapi", "none")) && message.page != -1) {
            if (!book.hasTagCompound())
                book.setTagCompound(new NBTTagCompound());
            book.getTagCompound().setInteger(NBTBookTags.CATEGORY_TAG, message.category);
            book.getTagCompound().setString(NBTBookTags.ENTRY_TAG, message.entry.toString());
            book.getTagCompound().setInteger(NBTBookTags.PAGE_TAG, message.page);
        }
    }
    return null;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem)

Example 4 with IGuideItem

use of amerifrance.guideapi.api.IGuideItem 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)

Example 5 with IGuideItem

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

the class PacketSyncHome method onMessage.

@Override
public IMessage onMessage(PacketSyncHome message, MessageContext ctx) {
    ItemStack book = ctx.getServerHandler().player.getHeldItemOffhand();
    if (book.isEmpty() || !(book.getItem() instanceof IGuideItem))
        book = ctx.getServerHandler().player.getHeldItemMainhand();
    if (!book.isEmpty() && book.getItem() instanceof IGuideItem && message.page != -1) {
        if (!book.hasTagCompound())
            book.setTagCompound(new NBTTagCompound());
        book.getTagCompound().setInteger(NBTBookTags.CATEGORY_PAGE_TAG, message.page);
        book.getTagCompound().removeTag(NBTBookTags.CATEGORY_TAG);
        book.getTagCompound().removeTag(NBTBookTags.ENTRY_TAG);
    }
    return null;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem)

Aggregations

IGuideItem (amerifrance.guideapi.api.IGuideItem)5 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ResourceLocation (net.minecraft.util.ResourceLocation)3 Book (amerifrance.guideapi.api.impl.Book)2 CategoryAbstract (amerifrance.guideapi.api.impl.abstraction.CategoryAbstract)2 IGuideLinked (amerifrance.guideapi.api.IGuideLinked)1 IInfoRenderer (amerifrance.guideapi.api.IInfoRenderer)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 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumHand (net.minecraft.util.EnumHand)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 World (net.minecraft.world.World)1