diff options
-rwxr-xr-x | depends.txt | 1 | ||||
-rwxr-xr-x | description.txt | 1 | ||||
-rwxr-xr-x | init.lua | 76 | ||||
-rwxr-xr-x | textures/engrave_side.png | bin | 0 -> 740 bytes | |||
-rwxr-xr-x | textures/engrave_top.png | bin | 0 -> 823 bytes |
5 files changed, 78 insertions, 0 deletions
diff --git a/depends.txt b/depends.txt new file mode 100755 index 0000000..21c2521 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default?
\ No newline at end of file diff --git a/description.txt b/description.txt new file mode 100755 index 0000000..d18ba4f --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Adds an "Engraving Table" that allows to change the description of items
\ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100755 index 0000000..4554b0e --- /dev/null +++ b/init.lua @@ -0,0 +1,76 @@ + + +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() + 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"}, + }, +}) diff --git a/textures/engrave_side.png b/textures/engrave_side.png Binary files differnew file mode 100755 index 0000000..0707b8b --- /dev/null +++ b/textures/engrave_side.png diff --git a/textures/engrave_top.png b/textures/engrave_top.png Binary files differnew file mode 100755 index 0000000..e6627f6 --- /dev/null +++ b/textures/engrave_top.png |