From 40163aed91b5764e394b3d8ee708e0b07dcbc095 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 2 Feb 2018 05:13:26 +0100 Subject: [PATCH] Forbid renaming of written books --- GROUPS.md | 1 + mods/ITEMS/mcl_anvils/init.lua | 21 +++++++++++++-------- mods/ITEMS/mcl_books/init.lua | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/GROUPS.md b/GROUPS.md index cdfd2c07b6..d400be01a1 100644 --- a/GROUPS.md +++ b/GROUPS.md @@ -52,6 +52,7 @@ Please read to learn how digging times * `can_eat_when_full=1`: Only for foodstuffs. This item can be eaten when the user has a full hunger bar * `attached_node_facedir=1`: Like `attached_node`, but for facedir nodes * `cauldron`: Cauldron. 1: Empty. 2-4: Water height +* `no_rename=1`: Item cannot be renamed by anvil #### Footnotes diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index 3b307f96e5..fbc223aaff 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -38,14 +38,19 @@ local function update_anvil_slots(meta) else name_item = input1 end - local meta = name_item:get_meta() - -- Limit name length - new_name = string.sub(new_name, 1, 30) - -- Rename item - meta:set_string("description", new_name) - -- Double-save the name internally, too - meta:set_string("name", new_name) - new_output = name_item + -- No renaming allowed with group no_rename=1 + if minetest.get_item_group(name_item:get_name(), "no_rename") == 1 then + new_output = "" + else + local meta = name_item:get_meta() + -- Limit name length + new_name = string.sub(new_name, 1, 30) + -- Rename item + meta:set_string("description", new_name) + -- Double-save the name internally, too + meta:set_string("name", new_name) + new_output = name_item + end else new_output = "" end diff --git a/mods/ITEMS/mcl_books/init.lua b/mods/ITEMS/mcl_books/init.lua index 875037050f..29ae2a028f 100644 --- a/mods/ITEMS/mcl_books/init.lua +++ b/mods/ITEMS/mcl_books/init.lua @@ -179,7 +179,7 @@ minetest.register_craftitem("mcl_books:written_book", { To copy the text of the written book, place it into the crafting grid together with a book and quill (or multiple of those) and craft. The written book will not be consumed. Copies of copies can not be copied.]], inventory_image = "mcl_books_book_written.png", - groups = { not_in_creative_inventory=1, book=1 }, + groups = { not_in_creative_inventory=1, book=1, no_rename=1 }, stack_max = 16, on_place = read, on_secondary_use = read