Limit book title and text length

This commit is contained in:
Wuzzy 2019-08-29 05:23:23 +02:00
parent 07ef0ef491
commit 1487c7f631
1 changed files with 11 additions and 0 deletions

View File

@ -7,6 +7,9 @@
local S = minetest.get_translator("book")
local F = minetest.formspec_escape
local BOOK_MAX_TITLE_LENGTH = 64
local BOOK_MAX_TEXT_LENGTH = 4500
minetest.register_craftitem(
":default:book",
{
@ -43,6 +46,14 @@ minetest.register_on_player_receive_fields(
local meta = itemstack:get_meta()
-- Limit title and text length
if string.len(fields.title) > BOOK_MAX_TITLE_LENGTH then
fields.title = string.sub(fields.title, 1, BOOK_MAX_TITLE_LENGTH)
end
if string.len(fields.text) > BOOK_MAX_TEXT_LENGTH then
fields.text= string.sub(fields.text, 1, BOOK_MAX_TEXT_LENGTH)
end
meta:set_string("description", S("Book: “@1”", minetest.colorize("#ffff00", fields.title))) -- Set the item description
meta:set_string("book:title", fields.title)