Various map item fixes
- Fix appearance in hand/in item form - Allow placed maps to be dug by punching them - Properly save metadata when creating a new map for the first time
This commit is contained in:
parent
19ca1bf0f1
commit
12b933ea1e
32
items.lua
32
items.lua
@ -102,6 +102,7 @@ end);
|
||||
minetest.register_node("cartographer:map", {
|
||||
description = "Map",
|
||||
inventory_image = "cartographer_map.png",
|
||||
wield_image = "cartographer_map.png",
|
||||
tiles = { "cartographer_map.png" },
|
||||
drawtype = "signlike",
|
||||
paramtype = "light",
|
||||
@ -116,6 +117,11 @@ minetest.register_node("cartographer:map", {
|
||||
},
|
||||
},
|
||||
|
||||
groups = {
|
||||
attached_node = 1,
|
||||
dig_immediate = 3,
|
||||
},
|
||||
|
||||
-- Called when this node is placed in the world. Copies map data from the
|
||||
-- item to the node.
|
||||
-- pos: The position of the node
|
||||
@ -131,6 +137,18 @@ minetest.register_node("cartographer:map", {
|
||||
return false;
|
||||
end,
|
||||
|
||||
-- Called when this node is dug. Turns the node into an item.
|
||||
-- pos: The position of the node
|
||||
on_dig = function(pos, _, _)
|
||||
local node_meta = minetest.get_meta(pos):to_table();
|
||||
local item = ItemStack("cartographer:map");
|
||||
item:get_meta():from_table(node_meta);
|
||||
|
||||
if minetest.add_item(pos, item) then
|
||||
minetest.remove_node(pos);
|
||||
end
|
||||
end,
|
||||
|
||||
-- Called when a player right-clicks this node. Display's the map's
|
||||
-- content, creating it if it doesn't exist.
|
||||
-- pos: The position of the node
|
||||
@ -147,6 +165,20 @@ minetest.register_node("cartographer:map", {
|
||||
on_use = function(stack, player)
|
||||
cartographer.map_sound("cartographer_open_map", player);
|
||||
show_map_meta(stack:get_meta(), player);
|
||||
return stack;
|
||||
end,
|
||||
|
||||
-- Called when a node is about to be turned into an item. Copies all
|
||||
-- metadata into any items matching this node's name.
|
||||
-- oldnode: The old node's data
|
||||
-- oldmeta: A table containing the old node's metadata
|
||||
-- drops: A table containing the new items
|
||||
preserve_metadata = function(_, oldnode, oldmeta, drops)
|
||||
for _,item in ipairs(drops) do
|
||||
if item:get_name() == oldnode.name then
|
||||
item:get_meta():from_table({fields=oldmeta});
|
||||
end
|
||||
end
|
||||
end,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user