initial commit - version 1.0.1

master
orwell96 2017-05-11 11:08:28 +02:00
commit 6702e2a75c
5 changed files with 86 additions and 0 deletions

1
depends.txt Normal file
View File

@ -0,0 +1 @@
default?

1
description.txt Normal file
View File

@ -0,0 +1 @@
Adds an "Engraving Table" that allows to change the description of items

84
init.lua Normal file
View File

@ -0,0 +1,84 @@
-- Minetest Mod: engrave - init.lua
-- (c) 2017 orwell96
minetest.register_privilege("engrave_long_names", "When using the Engraving Table, Player can set names that contain more than 40 characters and/or newlines")
minetest.register_node("engrave:table", {
description = "Engraving Table",
tiles = {"engrave_top.png", "engrave_side.png"},
groups = {choppy=2,flammable=3, oddly_breakable_by_hand=2},
sounds = default and default.node_sound_wood_defaults(),
on_rightclick = function(pos, node, player)
local pname=player:get_player_name()
local stack=player:get_wielded_item()
if stack:get_count()==0 then
minetest.chat_send_player(pname, "Please wield the item you want to name, and then click the engraving table again.")
return
end
local idef=minetest.registered_items[stack:get_name()]
if not idef then
minetest.chat_send_player(pname, "You can't name an unknown item!")
return
end
local name=idef.description or stack:get_name()
local what=name or "whatever"
if stack:get_count()>1 then
what="stack of "..what
end
local meta=stack:get_meta()
if meta then
local metaname=meta:get_string("description")
if metaname~="" then
name=metaname
end
end
minetest.show_formspec(pname, "engrave", "field[name;Enter a new name for this "..what..";"..name.."]")
end,
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname=="engrave" and fields.name then
local pname=player:get_player_name()
if (#fields.name>40 or string.match(fields.name, "\n", nil, true)) and not minetest.check_player_privs(pname, {engrave_long_names=true}) then
minetest.chat_send_player(pname, "Insufficient Privileges: Item names that are longer than 40 characters and/or contain newlines require the 'engrave_long_names' privilege")
return
end
local stack=player:get_wielded_item()
if stack:get_count()==0 then
minetest.chat_send_player(pname, "Please wield the item you want to name, and then click the engraving table again.")
return
end
local idef=minetest.registered_items[stack:get_name()]
if not idef then
minetest.chat_send_player(pname, "You can't name an unknown item!")
return
end
local name=idef.description or stack:get_name()
local meta=stack:get_meta()
if not meta then
minetest.chat_send_player(pname, "For some reason, the stack metadata couldn't be acquired. Try again!")
return
end
if fields.name==name then
meta:set_string("description", "")
else
meta:set_string("description", fields.name)
end
--write back
player:set_wielded_item(stack)
end
end)
minetest.register_craft({
output = "engrave:table",
recipe = {
{"group:wood", "group:wood", "group:wood"},
{"group:wood", "default:diamond", "group:wood"},
{"group:wood", "group:wood", "group:wood"},
},
})

BIN
textures/engrave_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B

BIN
textures/engrave_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B