From 8a4b8707fac599ba11e83d0586bc9d5acdea0b42 Mon Sep 17 00:00:00 2001 From: kabou Date: Tue, 10 May 2022 23:38:28 +0200 Subject: [PATCH] Add new compass API. * Add API.md * Update mcl_itemframes to use the new API. * Revert old exported function back to original API. --- mods/ITEMS/mcl_compass/API.md | 20 ++++++++++++++++++++ mods/ITEMS/mcl_compass/init.lua | 15 +++++---------- mods/ITEMS/mcl_itemframes/init.lua | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 mods/ITEMS/mcl_compass/API.md diff --git a/mods/ITEMS/mcl_compass/API.md b/mods/ITEMS/mcl_compass/API.md new file mode 100644 index 000000000..8a8e7247e --- /dev/null +++ b/mods/ITEMS/mcl_compass/API.md @@ -0,0 +1,20 @@ +# mcl_compass + +# Compass API + +##mcl_compass.stereotype = "mcl_compass:" .. stereotype_frame +Default compass craftitem. This is also the image that is shown in the inventory. + +##mcl_compass/init.lua:function mcl_compass.get_compass_itemname(pos, dir, itemstack) +Returns the itemname of a compass with needle direction matching the +current compass position. + + pos: position of the compass; + dir: rotational orientation of the compass; + itemstack: the compass including its optional lodestone metadata. + +##mcl_compass/init.lua:function mcl_compass.get_compass_image(pos, dir) +-- Returns partial itemname of a compass with needle direction matching compass position. +-- Legacy compatibility function for mods using older api. + + diff --git a/mods/ITEMS/mcl_compass/init.lua b/mods/ITEMS/mcl_compass/init.lua index 5c237aeba..89231709c 100644 --- a/mods/ITEMS/mcl_compass/init.lua +++ b/mods/ITEMS/mcl_compass/init.lua @@ -118,20 +118,18 @@ local function get_compass_frame(pos, dir, itemstack) end end +-- Export stereotype item for other mods to use +mcl_compass.stereotype = "mcl_compass:" .. stereotype_frame + --- Get partial compass itemname. -- Returns partial itemname of a compass with needle direction matching compass position. -- Legacy compatibility function for mods using older api. -- -function mcl_compass.get_compass_image(pos, dir, itemstack) +function mcl_compass.get_compass_image(pos, dir) minetest.log("warning", "mcl_compass: deprecated function " .. "get_compass_image() called, use get_compass_itemname().") - local itemstack = ItemStack("mcl_compass:" .. stereotype_frame) + local itemstack = ItemStack(mcl_compass.stereotype) local frame = get_compass_frame(pos, dir, itemstack) - if itemstack:get_meta():get_string("pointsto") ~= "" then - return frame .. "_lodestone" - else - return frame - end end --- Get compass itemname. @@ -248,9 +246,6 @@ minetest.register_craft({ minetest.register_alias("mcl_compass:compass", "mcl_compass:" .. stereotype_frame) --- Export stereotype item for other mods to use -mcl_compass.stereotype = "mcl_compass:" .. stereotype_frame - minetest.register_node("mcl_compass:lodestone",{ description=S("Lodestone"), diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index e2cf9da62..364bffee6 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -222,7 +222,7 @@ minetest.register_node("mcl_itemframes:item_frame",{ put_itemstack:set_count(1) local itemname = put_itemstack:get_name() if minetest.get_item_group(itemname, "compass") > 0 then - put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2)), put_itemstack)) + put_itemstack:set_name(mcl_compass.get_compass_itemname(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2)), put_itemstack)) end if minetest.get_item_group(itemname, "clock") > 0 then minetest.get_node_timer(pos):start(1.0)