use of amerifrance.guideapi.api.IInfoRenderer 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);
}
Aggregations