use of amerifrance.guideapi.api.impl.Book 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.Book 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.Book in project Guide-API by TeamAmeriFrance.
the class APISetter method registerBook.
public static void registerBook(Book book) {
try {
sanityCheck();
} catch (IllegalAccessException e) {
Throwables.propagate(e);
return;
}
try {
Field books = GuideAPI.class.getDeclaredField("BOOKS");
books.setAccessible(true);
Map<ResourceLocation, Book> BOOKS = (Map<ResourceLocation, Book>) books.get(null);
BOOKS.put(book.getRegistryName(), book);
} catch (Exception e) {
e.printStackTrace();
}
}
use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.
the class EventHandler method onPlayerJoinWorld.
@SubscribeEvent
public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntity();
NBTTagCompound tag = getModTag(player, GuideMod.ID);
if (ConfigHandler.canSpawnWithBooks) {
for (Book book : GuideAPI.getBooks().values()) {
if (book.isSpawnWithBook() && !tag.getBoolean("hasInitial" + book.getTitle())) {
ItemHandlerHelper.giveItemToPlayer(player, GuideAPI.getStackFromBook(book));
tag.setBoolean("hasInitial" + book.getTitle(), true);
}
}
}
}
}
use of amerifrance.guideapi.api.impl.Book in project Guide-API by TeamAmeriFrance.
the class ConfigHandler method handleBookConfigs.
public static void handleBookConfigs() {
for (Book book : GuideAPI.getBooks().values()) book.setSpawnWithBook(config.get("Books.Spawn", book.getRegistryName().toString(), book.isSpawnWithBook()).getBoolean());
config.setCategoryComment("Books.Spawn", "If true, the user will spawn with the book.\nThis defaults to the value the book owner has set and is overridden by this config.");
config.save();
}
Aggregations