use of amerifrance.guideapi.api.impl.abstraction.CategoryAbstract 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.impl.abstraction.CategoryAbstract in project Guide-API by TeamAmeriFrance.
the class TestBook2 method buildBook.
@Nullable
@Override
public Book buildBook() {
book = new Book();
book.setAuthor("TehNut");
book.setColor(Color.GREEN);
book.setDisplayName("Display Name");
book.setTitle("Title message");
book.setWelcomeMessage("Is this still a thing?");
CategoryAbstract testCategory = new CategoryItemStack("test.category.name", new ItemStack(Items.BANNER)).withKeyBase("guideapi");
testCategory.addEntry("entry", new EntryItemStack("test.entry.name", new ItemStack(Items.POTATO)));
testCategory.getEntry("entry").addPage(new PageText("Hello, this is\nsome text"));
testCategory.getEntry("entry").addPage(new PageFurnaceRecipe(Blocks.COBBLESTONE));
testCategory.getEntry("entry").addPage(new PageIRecipe(new ShapedOreRecipe(Items.ACACIA_BOAT, "X X", "XXX", 'X', "plankWood")));
testCategory.getEntry("entry").addPage(new PageBrewingRecipe(new BrewingRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.AWKWARD), new ItemStack(Items.SPECKLED_MELON), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.HEALING))));
book.addCategory(testCategory);
book.setRegistryName(new ResourceLocation("guideapi", "test_book2"));
return book;
}
use of amerifrance.guideapi.api.impl.abstraction.CategoryAbstract in project Guide-API by TeamAmeriFrance.
the class GuiHome method initGui.
@Override
public void initGui() {
this.buttonList.clear();
this.categoryWrapperMap.clear();
guiLeft = (this.width - this.xSize) / 2;
guiTop = (this.height - this.ySize) / 2;
addButton(buttonNext = new ButtonNext(0, guiLeft + 4 * xSize / 6, guiTop + 5 * ySize / 6, this));
addButton(buttonPrev = new ButtonPrev(1, guiLeft + xSize / 5, guiTop + 5 * ySize / 6, this));
addButton(buttonSearch = new ButtonSearch(2, guiLeft + xSize / 6, guiTop, this));
int cX = guiLeft + 45;
int cY = guiTop + 40;
int drawLoc = 0;
int i = 0;
int pageNumber = 0;
for (CategoryAbstract category : book.getCategoryList()) {
category.onInit(book, this, player, bookStack);
switch(drawLoc) {
case 0:
{
categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
cX += 27;
drawLoc = 1;
break;
}
case 1:
{
categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
cX += 27;
drawLoc = 2;
break;
}
case 2:
{
categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
cX += 27;
drawLoc = 3;
break;
}
case 3:
{
categoryWrapperMap.put(pageNumber, new CategoryWrapper(book, category, cX, cY, 23, 23, player, this.fontRenderer, itemRender, false, bookStack));
drawLoc = 0;
cX = guiLeft + 45;
cY += 30;
break;
}
}
i++;
if (i >= 16) {
i = 0;
cX = guiLeft + 45;
cY = guiTop + 40;
pageNumber++;
}
}
}
use of amerifrance.guideapi.api.impl.abstraction.CategoryAbstract in project Guide-API by TeamAmeriFrance.
the class ItemGuideBook method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!world.isRemote || !player.isSneaking())
return EnumActionResult.PASS;
ItemStack stack = player.getHeldItem(hand);
IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof IGuideLinked) {
IGuideLinked guideLinked = (IGuideLinked) state.getBlock();
ResourceLocation entryKey = guideLinked.getLinkedEntry(world, pos, player, stack);
if (entryKey == null)
return EnumActionResult.FAIL;
for (CategoryAbstract category : book.getCategoryList()) {
if (category.entries.containsKey(entryKey)) {
GuideMod.proxy.openEntry(book, category, category.entries.get(entryKey), player, stack);
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
use of amerifrance.guideapi.api.impl.abstraction.CategoryAbstract 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