3 --save metadata of text
5 --write to make permenant
7 local open_book_gui = function(itemstack, user)
8 local meta = itemstack:get_meta()
9 local book_text = meta:get_string("book.book_text")
10 if book_text == "" then
11 book_text = "Text here"
13 local book_title = meta:get_string("book.book_title")
14 if book_title == "" then
15 book_title = "Title here"
18 book_writing_formspec = "size[9,8.75]"..
19 "background[-0.19,-0.25;9.41,9.49;gui_hb_bg.png]"..
20 "style[book.book_text,book.book_title;textcolor=black;border=false;noclip=false]"..
21 "textarea[0.3,0;9,0.5;book.book_title;;"..book_title.."]"..
22 "textarea[0.3,0.3;9,9;book.book_text;;"..book_text.."]"..
23 "button[-0.2,8.3;1,1;book.book_write;write]"..
24 "button[8.25,8.3;1,1;book.book_ink;ink ]"
25 minetest.show_formspec(user:get_player_name(), "book.book_gui", book_writing_formspec)
28 local open_book_inked_gui = function(itemstack, user)
29 local meta = itemstack:get_meta()
30 local book_text = meta:get_string("book.book_text")
32 local book_title = meta:get_string("book.book_title")
34 book_writing_formspec = "size[9,8.75]"..
35 "background[-0.19,-0.25;9.41,9.49;gui_hb_bg.png]"..
36 "style[book.book_text,book.book_title;textcolor=black;border=false;noclip=false]"..
37 "textarea[0.3,0;9,0.5;book.book_title;;"..book_title.."]"..
38 "textarea[0.3,0.3;9,9;book.book_text;;"..book_text.."]"..
39 "button_exit[4,8.3;1,1;close;close]"
41 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 elseif fields["book.book_ink"] and fields["book.book_text"] and fields["book.book_text"] then
57 local itemstack = ItemStack("book:book_written")
58 local meta = itemstack:get_meta()
59 meta:set_string("book.book_text", fields["book.book_text"])
60 meta:set_string("book.book_title", fields["book.book_title"])
61 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")
70 minetest.register_craftitem("book:book",{
72 groups = {book = 1, written = 0},
74 inventory_image = "book.png",
76 on_place = function(itemstack, user, pointed_thing)
77 print("make books placable on the ground")
78 open_book_gui(itemstack, user)
81 on_secondary_use = function(itemstack, user, pointed_thing)
82 open_book_gui(itemstack, user)
86 minetest.register_craftitem("book:book_written",{
88 groups = {book = 1, written = 1},
90 inventory_image = "book_written.png",
92 on_place = function(itemstack, user, pointed_thing)
93 print("make books placable on the ground")
94 open_book_inked_gui(itemstack, user)
97 on_secondary_use = function(itemstack, user, pointed_thing)
98 open_book_inked_gui(itemstack, user)
102 minetest.register_craft({
103 output = "book:book",
105 {"main:wood","weather:snowball","main:wood"},
106 {"main:wood","weather:snowball","main:wood"},
107 {"main:wood","weather:snowball","main:wood"},