1 --this is the gui for un-inked books
2 local open_book_gui = function(itemstack, user)
3 minetest.sound_play("book_open", {to_player=user:get_player_name()})
4 local meta = itemstack:get_meta()
5 local book_text = meta:get_string("book.book_text")
6 if book_text == "" then
7 book_text = "Text here"
9 local book_title = meta:get_string("book.book_title")
10 if book_title == "" then
11 book_title = "Title here"
14 book_writing_formspec = "size[9,8.75]"..
15 "background[-0.19,-0.25;9.41,9.49;gui_hb_bg.png]"..
16 "style[book.book_text,book.book_title;textcolor=black;border=false;noclip=false]"..
17 "textarea[0.3,0;9,0.5;book.book_title;;"..book_title.."]"..
18 "textarea[0.3,0.3;9,9;book.book_text;;"..book_text.."]"..
19 "button[-0.2,8.3;1,1;book.book_write;write]"..
20 "button[8.25,8.3;1,1;book.book_ink;ink ]"
21 minetest.show_formspec(user:get_player_name(), "book.book_gui", book_writing_formspec)
25 --this is the gui for permenantly written books
26 local open_book_inked_gui = function(itemstack, user)
27 minetest.sound_play("book_open", {to_player=user:get_player_name()})
28 local meta = itemstack:get_meta()
29 local book_text = meta:get_string("book.book_text")
31 local book_title = meta:get_string("book.book_title")
33 book_writing_formspec = "size[9,8.75]"..
34 "background[-0.19,-0.25;9.41,9.49;gui_hb_bg.png]"..
35 "style_type[textarea;textcolor=black;border=false;noclip=false]"..
36 "textarea[0.3,0;9,0.5;;;"..book_title.."]"..
37 "textarea[0.3,0.3;9,9;;;"..book_text.."]"..
38 "button_exit[4,8.3;1,1;book.book_close;close]"
39 minetest.show_formspec(user:get_player_name(), "book.book_gui", book_writing_formspec)
44 minetest.register_on_player_receive_fields(function(player, formname, fields)
45 if not formname == "book.book_gui" then return end
47 if fields["book.book_write"] and fields["book.book_text"] and fields["book.book_text"] then
48 local itemstack = ItemStack("book:book")
49 local meta = itemstack:get_meta()
50 meta:set_string("book.book_text", fields["book.book_text"])
51 meta:set_string("book.book_title", fields["book.book_title"])
52 meta:set_string("description", fields["book.book_title"])
54 player:set_wielded_item(itemstack)
55 minetest.close_formspec(player:get_player_name(), "book.book_gui")
56 minetest.sound_play("book_write", {to_player=player:get_player_name()})
57 elseif fields["book.book_ink"] and fields["book.book_text"] and fields["book.book_text"] then
58 local itemstack = ItemStack("book:book_written")
59 local meta = itemstack:get_meta()
60 meta:set_string("book.book_text", fields["book.book_text"])
61 meta:set_string("book.book_title", fields["book.book_title"])
62 meta:set_string("description", fields["book.book_title"])
63 player:set_wielded_item(itemstack)
64 minetest.close_formspec(player:get_player_name(), "book.book_gui")
65 minetest.sound_play("book_close", {to_player=player:get_player_name()})
66 elseif fields["book.book_close"] then
67 minetest.sound_play("book_close", {to_player=player:get_player_name()})
72 --this is the book item
73 minetest.register_craftitem("book:book",{
75 groups = {book = 1, written = 0},
77 inventory_image = "book.png",
79 on_place = function(itemstack, user, pointed_thing)
80 print("make books placable on the ground")
81 open_book_gui(itemstack, user)
84 on_secondary_use = function(itemstack, user, pointed_thing)
85 open_book_gui(itemstack, user)
89 --permenantly written books
90 minetest.register_craftitem("book:book_written",{
92 groups = {book = 1, written = 1},
94 inventory_image = "book_written.png",
96 on_place = function(itemstack, user, pointed_thing)
97 print("make books placable on the ground")
98 open_book_inked_gui(itemstack, user)
101 on_secondary_use = function(itemstack, user, pointed_thing)
102 open_book_inked_gui(itemstack, user)
106 --change this to paper
107 minetest.register_craft({
108 output = "book:book",
110 {"main:wood","weather:snowball","main:wood"},
111 {"main:wood","weather:snowball","main:wood"},
112 {"main:wood","weather:snowball","main:wood"},