Search in sources :

Example 6 with Book

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

the class APISetter method setBookForStack.

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

Example 7 with Book

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

the class AnnotationHandler method registerBooks.

public static void registerBooks(ASMDataTable dataTable) {
    for (ASMDataTable.ASMData data : dataTable.getAll(GuideBook.class.getCanonicalName())) {
        try {
            Class<?> genericClass = Class.forName(data.getClassName());
            if (!IGuideBook.class.isAssignableFrom(genericClass))
                continue;
            IGuideBook guideBook = (IGuideBook) genericClass.newInstance();
            Book book = guideBook.buildBook();
            if (book == null)
                continue;
            APISetter.registerBook(book);
            BOOK_CLASSES.add(Pair.of(book, guideBook));
        } catch (Exception e) {
            LogHelper.error("Error registering book for class " + data.getClassName());
            e.printStackTrace();
        }
    }
    APISetter.setIndexedBooks(Lists.newArrayList(GuideAPI.getBooks().values()));
}
Also used : GuideBook(amerifrance.guideapi.api.GuideBook) IGuideBook(amerifrance.guideapi.api.IGuideBook) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) GuideBook(amerifrance.guideapi.api.GuideBook) IGuideBook(amerifrance.guideapi.api.IGuideBook) Book(amerifrance.guideapi.api.impl.Book) IGuideBook(amerifrance.guideapi.api.IGuideBook)

Example 8 with Book

use of amerifrance.guideapi.api.impl.Book 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 9 with Book

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

Example 10 with Book

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

the class GuideMod method preInit.

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
    configDir = new File(event.getModConfigurationDirectory(), NAME);
    configDir.mkdirs();
    ConfigHandler.init(new File(configDir, NAME + ".cfg"));
    GuideAPI.initialize();
    AnnotationHandler.registerBooks(event.getAsmData());
    for (Book book : GuideAPI.getBooks().values()) {
        Item guideBook = new ItemGuideBook(book);
        guideBook.setRegistryName(book.getRegistryName().toString().replace(":", "-"));
        GameRegistry.register(guideBook);
        APISetter.setBookForStack(book, new ItemStack(guideBook));
    }
    proxy.handleModels();
    NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy);
    MinecraftForge.EVENT_BUS.register(new EventHandler());
    PacketHandler.registerPackets();
}
Also used : Item(net.minecraft.item.Item) ItemGuideBook(amerifrance.guideapi.item.ItemGuideBook) Book(amerifrance.guideapi.api.impl.Book) ItemGuideBook(amerifrance.guideapi.item.ItemGuideBook) IGuideBook(amerifrance.guideapi.api.IGuideBook) EventHandler(amerifrance.guideapi.util.EventHandler) ItemStack(net.minecraft.item.ItemStack) File(java.io.File)

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