1
0
Fork 0

Anvils: Don't allow rename if name is unchanged

This commit is contained in:
Wuzzy 2018-02-03 03:53:31 +01:00
parent 0b80b60cf1
commit ef471a67fa
1 changed files with 14 additions and 8 deletions

View File

@ -60,6 +60,7 @@ local function update_anvil_slots(meta)
local new_wear = calculate_repair(input1:get_wear(), input2:get_wear(), SAME_TOOL_REPAIR_BOOST) local new_wear = calculate_repair(input1:get_wear(), input2:get_wear(), SAME_TOOL_REPAIR_BOOST)
input1:set_wear(new_wear) input1:set_wear(new_wear)
name_item = input1 name_item = input1
new_output = name_item
-- Tool + repair item -- Tool + repair item
else else
-- Any tool can have a repair item. This may be defined in the tool's item definition -- Any tool can have a repair item. This may be defined in the tool's item definition
@ -90,6 +91,7 @@ local function update_anvil_slots(meta)
local new_wear = calculate_repair(tool:get_wear(), MAX_WEAR, MATERIAL_TOOL_REPAIR_BOOST) local new_wear = calculate_repair(tool:get_wear(), MAX_WEAR, MATERIAL_TOOL_REPAIR_BOOST)
tool:set_wear(new_wear) tool:set_wear(new_wear)
name_item = tool name_item = tool
new_output = name_item
else else
new_output = "" new_output = ""
end end
@ -100,9 +102,6 @@ local function update_anvil_slots(meta)
-- Exactly 1 input slot occupied -- Exactly 1 input slot occupied
elseif (not input1:is_empty() and input2:is_empty()) or (input1:is_empty() and not input2:is_empty()) then elseif (not input1:is_empty() and input2:is_empty()) or (input1:is_empty() and not input2:is_empty()) then
-- Just rename item -- Just rename item
if new_name == nil then
new_name = ""
end
if input1:is_empty() then if input1:is_empty() then
name_item = input2 name_item = input2
else else
@ -118,14 +117,21 @@ local function update_anvil_slots(meta)
if minetest.get_item_group(name_item:get_name(), "no_rename") == 1 then if minetest.get_item_group(name_item:get_name(), "no_rename") == 1 then
new_output = "" new_output = ""
else else
if new_name == nil then
new_name = ""
end
local meta = name_item:get_meta() local meta = name_item:get_meta()
local old_name = meta:get_string("name")
-- Limit name length -- Limit name length
new_name = string.sub(new_name, 1, MAX_NAME_LENGTH) new_name = string.sub(new_name, 1, MAX_NAME_LENGTH)
-- Rename item -- Don't rename if names are identical
meta:set_string("description", new_name) if new_name ~= old_name then
-- Double-save the name internally, too -- Rename item
meta:set_string("name", new_name) meta:set_string("description", new_name)
new_output = name_item -- Double-save the name internally, too
meta:set_string("name", new_name)
new_output = name_item
end
end end
end end