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