Solved Working with books - how to split a wall of text into book pages?

Discussion in 'Spigot Plugin Development' started by LEOcab, Jan 14, 2020.

  1. Hey guys! Today I'm working with BOOKS. I'm needing to import some old books from the BookWorm plugin. That plugin pre-dates Minecraft books, instead it outputs book contents to chat, so its books were never designed to fit into Minecraft book pages.

    BookMeta#setLine(...) almost works fine, ALMOST. If it weren't for the fact that it cuts off the last string in a page and doesn't page-wrap it to the next page. And I don't seem to have a way of knowing at which point the line was cut off to begin printing the next page.

    All I have is line breaks denoted by :: which I turn into \n and that part works as expected. I just need to make it page break since it doesn't automatically, but I don't know how. I'm sure there's a way. The font isn't monospace so that complicates things in my tiny square brain.

    Thanks in advance!

    PS: modern day cover of BookWorm coming soon in 2020 lol, long live BookWorm
  2. 255 chars per page with line brakes counting as 2.
    No page may be longer than 14 lines.
    Each line can have an average of 19 characters, determined by the width of the used characters.

    So im assuming you got the text in this format:
    "Some line::and the next line::and so on"
    If you replace "::" with "\n" and everything works you can just count how many lines you added to your page and
    get the next page if this amount reaches 14.

    I would scrap the whole formatting with "::" and replace them with blanks.
    Then split the [email protected]" " and create a collection of words.
    Now we can concat the words and count the number of chars (obvsly we need to account for the added " " and "\n")
    As soon as adding a word would exceed the page limit of 255 chars (or the line limit of 14 is reached) we start a new page with the overhead word as the first one.
    • Friendly Friendly x 1
  3. Glad my misfortune could be of benefit to you :ROFLMAO:

    Joke aside, the way I went around doing that is kinda messy. I have always said this, and I will say it again: Minecraft needs to update how books work entirely to work similarly to the Big Books from Bibliocraft. Many issues would be solved from that.