public static void init() { BookLoader.registerPageType(ContentMaterial.ID, ContentMaterial.class); BookLoader.registerPageType(ContentModifier.ID, ContentModifier.class); BookLoader.registerPageType(ContentModifierFortify.ID, ContentModifierFortify.class); BookLoader.registerPageType(ContentTool.ID, ContentTool.class); BookLoader.registerPageType(ContentSingleStatMultMaterial.ID, ContentSingleStatMultMaterial.class); BookLoader.registerPageType(ContentImageText2.ID, ContentImageText2.class); INSTANCE.addRepository(new FileRepository(Util.resource("book"))); INSTANCE.addTransformer(new ToolSectionTransformer()); INSTANCE.addTransformer(new MaterialSectionTransformer()); INSTANCE.addTransformer(new ModifierSectionTransformer()); INSTANCE.addTransformer(new BowMaterialSectionTransformer()); INSTANCE.addTransformer(BookTransformer.IndexTranformer()); } }
@Override public IMessage handleServer(NetHandlerPlayServer netHandler) { if (netHandler.player != null && pageName != null) { EntityPlayer player = netHandler.player; ItemStack is = player.getHeldItem(EnumHand.MAIN_HAND); if(!is.isEmpty()) { BookHelper.writeSavedPage(is, pageName); } } return null; }
public void step() { int start = blockIndex; do { if(++blockIndex >= maxBlockIndex) { blockIndex = 0; } } while(isEmpty(blockIndex) && blockIndex != start); }
initialized = true; sections.clear(); appearance = new AppearanceData(); itemLinks.clear(); List<SectionData> repoContents = repo.getSections(); sections.addAll(repoContents); SectionData error = new SectionData(); error.name = "errorenous"; PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load repository " + repo.toString() + ".", e); error.pages.add(page); sections.add(error); ResourceLocation appearanceLocation = repo.getResourceLocation("appearance.json"); if(repo.resourceExists(appearanceLocation)) { try { appearance = BookLoader.GSON .fromJson(repo.resourceToString(repo.getResource(appearanceLocation)), AppearanceData.class); } catch(Exception e) { e.printStackTrace(); appearance.load(); ResourceLocation itemLinkLocation = repo.getResourceLocation("items.json");
/** * Adds a book to the loader, and returns a reference object * Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded * * @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added * @param appendIndex Whether an index should be added to the front of the book using a BookTransformer * @param appendContentTable Whether a table of contents should be added to the front of each section using a BookTransformer * @param repositories All the repositories the book will load the sections from * @return The book object, not immediately populated */ public static BookData registerBook(String name, boolean appendIndex, boolean appendContentTable, BookRepository... repositories) { BookData info = new BookData(repositories); books.put(name.contains(":") ? name : Loader.instance().activeModContainer().getModId() + ":" + name, info); if(appendIndex) { info.addTransformer(BookTransformer.IndexTranformer()); } if(appendContentTable) { info.addTransformer(BookTransformer.contentTableTransformer()); } return info; }
IResource pageInfo = source.getResource(source.getResourceLocation(data)); if(pageInfo != null) { String data = source.resourceToString(pageInfo); if(!data.isEmpty()) { Class<? extends PageContent> ctype = BookLoader.getPageType(type); content = new ContentError(ctype == null ? "Failed to create a page of type \"" + type + "\", perhaps the type is not registered?" : "Failed to create a page of type \"" + type + "\", perhaps the page file \"" + this.data + "\" is missing or invalid?", e); content = BookLoader.getPageType(type).newInstance(); } catch(InstantiationException | IllegalAccessException | NullPointerException e) { content = new ContentError("Failed to create a page of type \"" + type + "\", perhaps the type is not registered?"); content.load(); } catch(Exception e) { content = new ContentError("Failed to load page " + parent.name + "." + name + ".", e); e.printStackTrace(); swap.swap(source, ob); Object o = f.get(content); swap.swap(source, o); } catch(IllegalAccessException e) { e.printStackTrace();
int fullPageCount = book.getFullPageCount(advancementCache); if((page < fullPageCount - 1 || fullPageCount % 2 != 0) && page < fullPageCount) { drawModalRectWithCustomSizedTexture(width / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); nextArrow.visible = page < book.getFullPageCount(advancementCache) - (book.getPageCount(advancementCache) % 2 != 0 ? 0 : 1); backArrow.visible = oldPage >= -1; indexArrow.visible = book.findSection("index") != null && (page - 1) * 2 + 2 > book.findSection("index") .getPageCount(); public void actionPerformed(GuiButton button) { if(button instanceof GuiBookmark) { openPage(book.findPageNumber(((GuiBookmark) button).data.page, advancementCache)); int fullPageCount = book.getFullPageCount(advancementCache); if(page > fullPageCount - (fullPageCount % 2 != 0 ? 0 : 1)) { page = fullPageCount - 1; openPage(book.findPageNumber("index.page1")); PageData page = this.page == 0 ? book.findPage(0, advancementCache) : book.findPage((this.page - 1) * 2 + 1, advancementCache); page = book.findPage((this.page - 1) * 2 + 2, advancementCache); BookLoader.updateSavedPage(mc.player, item, ""); } else if(page != null && page.parent != null) { BookLoader.updateSavedPage(mc.player, item, page.parent.name + "." + page.name);
public BookLoader() { wrapper.registerPacketServer(PacketUpdateSavedPage.class); // Register page types registerPageType("blank", ContentBlank.class); registerPageType("text", ContentText.class); registerPageType("image", ContentImage.class); registerPageType("image with text below", ContentImageText.class); registerPageType("text with image below", ContentTextImage.class); registerPageType("text with left image etch", ContentTextLeftImage.class); registerPageType("text with right image etch", ContentTextRightImage.class); registerPageType("crafting", ContentCrafting.class); registerPageType("smelting", ContentSmelting.class); registerPageType("smithing", ContentSmithing.class); registerPageType("block interaction", ContentBlockInteraction.class); registerPageType("structure", ContentStructure.class); // Register action protocols StringActionProcessor.registerProtocol(new ProtocolGoToPage()); StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, ProtocolGoToPage.GO_TO_RTN)); }
if(structureData.canStep() || ++fullStructureSteps >= 5) { structureData.step(); fullStructureSteps = 0; structureData.reset(); structureData.setShowLayer(9);
public StructureInfo(int length, int height, int width, BlockData[] blockData) { this.structureWidth = width; this.structureHeight = height; this.structureLength = length; IBlockState[][][] states = new IBlockState[height][length][width]; for(int y = 0; y < height; y++) { for(int x = 0; x < length; x++) { for(int z = 0; z < width; z++) { for(BlockData data : blockData) { if(inside(x, y, z, data.pos, data.endPos)) { states[y][x][z] = convert(data); break; } } } } } data = states; maxBlockIndex = blockIndex = structureHeight * structureLength * structureWidth; }
public void init(int[] size, BlockData[] data) { int yOff = 0; structureData = new StructureInfo(size[0], size[1], size[2], data); blockAccess = new StructureBlockAccess(structureData);
public GuiBook(BookData book, @Nullable ItemStack item) { this.book = book; this.item = item; this.mc = Minecraft.getMinecraft(); this.fontRenderer = mc.fontRenderer; init(); advancementCache = new AdvancementCache(); this.mc.player.connection.getAdvancementManager().setListener(advancementCache); openPage(book.findPageNumber(BookHelper.getSavedPage(item), advancementCache)); }
/** * Adds a book to the loader, and returns a reference object * Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded * * @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added * @param repositories All the repositories the book will load the sections from * @return The book object, not immediately populated */ public static BookData registerBook(String name, BookRepository... repositories) { return registerBook(name, true, true, repositories); }
@Override public void preInit() { bookLoader = new BookLoader(); }
public static BookTransformer contentTableTransformerForSection(String sectionName) { return new ContentTableTransformer(sectionName); }
if(z >= 0 && z < structure[y][x].length) { int index = y * (data.structureLength * data.structureWidth) + x * data.structureWidth + z; if(index <= data.getLimiter()) { return structure[y][x][z] != null ? structure[y][x][z] : Blocks.AIR.getDefaultState();
private IBlockState convert(BlockData data) { Block block = Block.getBlockFromName(data.block); if(block == null) { return Blocks.AIR.getDefaultState(); } IBlockState state; if(data.state == null || data.state.isEmpty()) { state = block.getStateFromMeta(data.meta); } else { state = block.getDefaultState(); for(Map.Entry<String, String> entry : data.state.entrySet()) { Optional<IProperty<?>> property = state.getPropertyKeys().stream().filter(iProperty -> entry.getKey().equals(iProperty.getName())).findFirst(); if(property.isPresent()) { state = setProperty(state, property.get(), entry.getValue()); } } } return state; }
public static void integrate() { INSTANCE.addRepository(new FileRepository(EnderIO.DOMAIN + ":eiobook")); INSTANCE.addTransformer(BookTransformer.IndexTranformer()); }
public static void updateSavedPage(EntityPlayer player, ItemStack item, String page) { if(player == null) { return; } if(player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) { return; } BookHelper.writeSavedPage(item, page); wrapper.network.sendToServer(new PacketUpdateSavedPage(page)); }
public boolean canStep() { int index = blockIndex; do { if(++index >= maxBlockIndex) { return false; } } while(isEmpty(index)); return true; }