2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Editable books
|
|
|
|
-- Code based off the books_plus mod
|
|
|
|
-- By Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
":default:book",
|
|
|
|
{
|
|
|
|
description = "Book",
|
|
|
|
inventory_image = "default_book.png",
|
|
|
|
stack_max = 1,
|
|
|
|
on_use = function(itemstack, player, pointed_thing)
|
|
|
|
local name = player:get_player_name()
|
2017-05-12 04:29:55 +02:00
|
|
|
local data = minetest.deserialize(itemstack:get_metadata())
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
local title = ""
|
|
|
|
local text = ""
|
|
|
|
|
|
|
|
if data then
|
|
|
|
text = data.text
|
|
|
|
title = data.title
|
|
|
|
end
|
|
|
|
|
2017-05-13 20:50:15 +02:00
|
|
|
local form = default.ui.get_page("default:notabs")
|
2017-05-12 04:29:55 +02:00
|
|
|
form = form .. "field[0.5,1.25;8,0;title;Title:;"..minetest.formspec_escape(title).."]"
|
|
|
|
form = form .. "textarea[0.5,1.75;8,6.75;text;Contents:;"..minetest.formspec_escape(text).."]"
|
2015-09-01 17:15:24 +02:00
|
|
|
form = form .. default.ui.button_exit(2.75, 7.75, 3, 1, "write", "Write")
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.show_formspec(name, "book:book", form)
|
2015-09-01 17:15:24 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_on_player_receive_fields(
|
2015-09-01 17:15:24 +02:00
|
|
|
function(player, form_name, fields)
|
|
|
|
if form_name ~= "book:book" or not fields.write then return end
|
|
|
|
|
|
|
|
local itemstack = player:get_wielded_item()
|
2017-05-12 04:29:55 +02:00
|
|
|
local data = minetest.deserialize(itemstack:get_metadata())
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
if not data then data = {} end
|
|
|
|
data.text = fields.text
|
|
|
|
data.title = fields.title
|
2017-05-13 20:50:15 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
itemstack:set_metadata(minetest.serialize(data))
|
2015-09-01 17:15:24 +02:00
|
|
|
player:set_wielded_item(itemstack)
|
2015-10-25 22:18:54 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Achievements
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"scribe",
|
|
|
|
{
|
|
|
|
title = "Scribe",
|
|
|
|
description = "Craft a book",
|
|
|
|
times = 1,
|
2015-11-11 21:36:58 +01:00
|
|
|
craftitem = "default:book",
|
2015-10-25 22:18:54 +01:00
|
|
|
})
|
|
|
|
|
2017-05-13 20:50:15 +02:00
|
|
|
default.log("mod:book", "loaded")
|