Added in the API Doc file, and adjusted the created items' names.

Added the ":" to the front of the item creation so that it can be called from an external mod.
Put in an optional inventory and wield image parameter to add in colorized inventory / wield images.
This commit is contained in:
Michieal 2022-11-04 22:54:06 +00:00 committed by cora
parent c4981d894c
commit b62f61db10
3 changed files with 50 additions and 9 deletions

@ -12,13 +12,13 @@ mcl_itemframes.create_base_definitions()
-- necessary to maintain compatibility amongst older versions.
mcl_itemframes.backwards_compatibility()
-- test for the create custom frame
-- Define the standard frames.
mcl_itemframes.create_custom_frame("false", "item_frame", false,
"mcl_itemframes_item_frame.png", mcl_colors.WHITE, "Item Frame",
"Can hold an item.")
"Can hold an item.","")
mcl_itemframes.create_custom_frame("false", "glow_item_frame", true,
"mcl_itemframes_glow_item_frame.png", mcl_colors.WHITE, "Glowing Item Frame",
"Can hold an item and glows.")
"Can hold an item and glows.","")
-- Register the base frame's recipes.
-- was going to make it a specialized function, but minetest refuses to play nice.

@ -445,8 +445,8 @@ function mcl_itemframes.create_custom_items(name, has_glow)
minetest.log("action", "[mcl_itemframes] create_custom_item_entity: name: " .. name .. "_map\n")
end
end
minetest.register_entity(name .. "_item", custom_frame_item)
minetest.register_entity(name .. "_map", custom_frame_map_item)
minetest.register_entity(":" .. name .. "_item", custom_frame_item)
minetest.register_entity(":" .. name .. "_map", custom_frame_map_item)
end
function mcl_itemframes.update_frame_registry(modname, name, has_glow)
@ -470,8 +470,8 @@ function mcl_itemframes.update_frame_registry(modname, name, has_glow)
end
--- name: The name used to distinguish the item frame. Prepends "mcl_itemframes:" to the name. Example usage:
--- "glow_item_frame" creates a node named "mcl_itemframes:glow_item_frame".
function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, color, ttframe, description)
--- "glow_item_frame" creates a node named ":mcl_itemframes:glow_item_frame".
function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, color, ttframe, description, inv_wield_image)
local mod_name_pass = false
if modname ~= "" and modname ~= "false" then
if minetest.get_modpath(modname) then
@ -517,11 +517,16 @@ function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, colo
custom_itemframe_definition = table.copy(mcl_itemframes.glow_frame_base)
end
if inv_wield_image ~= nil and inv_wield_image ~= "" then
custom_itemframe_definition.glow_frame_base.inventory_image = { "(" .. inv_wield_image .. "^[multiply:" .. color .. ")" }
custom_itemframe_definition.glow_frame_base.wield_image = { "(" .. inv_wield_image .. "^[multiply:" .. color .. ")" }
end
custom_itemframe_definition.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
custom_itemframe_definition._tt_help = ttframe
custom_itemframe_definition.description = description
minetest.register_node(working_name, custom_itemframe_definition)
minetest.register_node(":" .. working_name, custom_itemframe_definition)
mcl_itemframes.update_frame_registry(modname, working_name, has_glow)
mcl_itemframes.custom_register_lbm(working_name)
@ -802,7 +807,7 @@ function mcl_itemframes.backwards_compatibility ()
})
minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame")
-- To be installed when complete; adds backwards compatibility
-- adds backwards compatibility
minetest.register_alias("mcl_itemframes:item", "mcl_itemframes:item_frame_item")
minetest.register_alias("mcl_itemframes:map", "mcl_itemframes:item_frame_map")
minetest.register_alias("mcl_itemframes:glow_item", "mcl_itemframes:glow_item_frame_item")

@ -0,0 +1,36 @@
The item frames use case is a very specific one, but... in the event that there is need for a new item frame then that
is where this api will shine.
As long as the api has been initialized (which it does in its own init.lua) then you really only need to call one
function. That function being mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, color, ttframe,
description, inv_wield_image). Note: unlike the Signs API, this API does not automatically create the recipe for you.
Here's an explanation of create_custom_frame and an example of using it.
This function is responsible for creating each frame, and handling the creation of its underlying entities.
Parameters:
* modname: Used to make sure that a specific module is installed before running the code contained within. Set to "" or
false, if there's not a mod to check for.
* name: The name used to distinguish the item frame. Prepends "mcl_itemframes:" to the name. Example usage:
"glow_item_frame" creates a node named "mcl_itemframes:glow_item_frame".
* has_glow: Does the frame cause the item within to glow? true / false.
* tiles: The image files used for the item frame's object texturing.
* color: Colorizes the frame / wield / inventory image to a specific color. Use White (#FFFFFF) to ignore.
* ttframe: The tooltip to show for the frame.
* description: The frame's description.
* inv_wield_image: Optionally the image to use as the inventory and the wield image. Colorized. set to "" or nil to use
the default frame / glow frame images. Note: must be set if you want the inventory / wield image to be colored.
example:
-- Register the Glow Frame
mcl_itemframes.create_custom_frame("false", "glow_item_frame", true,
"mcl_itemframes_glow_item_frame.png", mcl_colors.WHITE, "Glowing Item Frame",
"Can hold an item and glows.","")
-- Register the Glow Frame's recipe
minetest.register_craft({
type = "shapeless",
output = 'mcl_itemframes:glow_item_frame',
recipe = { 'mcl_mobitems:glow_ink_sac', 'mcl_itemframes:item_frame' },
})