1
0
Fork 0

Add new compass API.

* Add API.md
* Update mcl_itemframes to use the new API.
* Revert old exported function back to original API.
This commit is contained in:
kabou 2022-05-10 23:38:28 +02:00
parent a8c231da34
commit 8a4b8707fa
3 changed files with 26 additions and 11 deletions

View File

@ -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.

View File

@ -118,20 +118,18 @@ local function get_compass_frame(pos, dir, itemstack)
end end
end end
-- Export stereotype item for other mods to use
mcl_compass.stereotype = "mcl_compass:" .. stereotype_frame
--- Get partial compass itemname. --- Get partial compass itemname.
-- Returns partial itemname of a compass with needle direction matching compass position. -- Returns partial itemname of a compass with needle direction matching compass position.
-- Legacy compatibility function for mods using older api. -- 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 " .. minetest.log("warning", "mcl_compass: deprecated function " ..
"get_compass_image() called, use get_compass_itemname().") "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) local frame = get_compass_frame(pos, dir, itemstack)
if itemstack:get_meta():get_string("pointsto") ~= "" then
return frame .. "_lodestone"
else
return frame
end
end end
--- Get compass itemname. --- Get compass itemname.
@ -248,9 +246,6 @@ minetest.register_craft({
minetest.register_alias("mcl_compass:compass", "mcl_compass:" .. stereotype_frame) 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",{ minetest.register_node("mcl_compass:lodestone",{
description=S("Lodestone"), description=S("Lodestone"),

View File

@ -222,7 +222,7 @@ minetest.register_node("mcl_itemframes:item_frame",{
put_itemstack:set_count(1) put_itemstack:set_count(1)
local itemname = put_itemstack:get_name() local itemname = put_itemstack:get_name()
if minetest.get_item_group(itemname, "compass") > 0 then 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 end
if minetest.get_item_group(itemname, "clock") > 0 then if minetest.get_item_group(itemname, "clock") > 0 then
minetest.get_node_timer(pos):start(1.0) minetest.get_node_timer(pos):start(1.0)