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();
}
}
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()));
}
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);
}
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;
}
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();
}
Aggregations