From 9b37ca460e901efb9eda8beb38833b9ea7967a8e Mon Sep 17 00:00:00 2001 From: Michieal Date: Wed, 26 Oct 2022 11:44:48 +0000 Subject: [PATCH 01/14] Initial code comit --- mods/ITEMS/mcl_itemframes/init.lua | 374 ++---------- mods/ITEMS/mcl_itemframes/item_frames_API.lua | 570 ++++++++++++++++++ 2 files changed, 610 insertions(+), 334 deletions(-) create mode 100644 mods/ITEMS/mcl_itemframes/item_frames_API.lua diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 6fda0176e..f3dd3c214 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -1,348 +1,54 @@ -mcl_itemframes = {} +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + local S = minetest.get_translator(minetest.get_current_modname()) -local VISUAL_SIZE = 0.3 - -minetest.register_entity("mcl_itemframes:item",{ - hp_max = 1, - visual = "wielditem", - visual_size = {x=VISUAL_SIZE, y=VISUAL_SIZE}, - physical = false, - pointable = false, - textures = { "blank.png" }, - _texture = "blank.png", - _scale = 1, - - on_activate = function(self, staticdata) - if staticdata and staticdata ~= "" then - local data = staticdata:split(";") - if data and data[1] and data[2] then - self._nodename = data[1] - self._texture = data[2] - if data[3] then - self._scale = data[3] - else - self._scale = 1 - end - end - end - if self._texture then - self.object:set_properties({ - textures={self._texture}, - visual_size={x=VISUAL_SIZE/self._scale, y=VISUAL_SIZE/self._scale}, - }) - end - end, - get_staticdata = function(self) - if self._nodename and self._texture then - local ret = self._nodename .. ";" .. self._texture - if self._scale then - ret = ret .. ";" .. self._scale - end - return ret - end - return "" - end, - - _update_texture = function(self) - if self._texture then - self.object:set_properties({ - textures={self._texture}, - visual_size={x=VISUAL_SIZE/self._scale, y=VISUAL_SIZE/self._scale}, - }) - end - end, -}) - -minetest.register_entity("mcl_itemframes:map", { - initial_properties = { - visual = "upright_sprite", - visual_size = {x = 1, y = 1}, - pointable = false, - physical = false, - collide_with_objects = false, - textures = {"blank.png"}, - }, - on_activate = function(self, staticdata) - self.id = staticdata - mcl_maps.load_map(self.id, function(texture) - -- will not crash even if self.object is invalid by now - self.object:set_properties({textures = {texture}}) - end) - end, - get_staticdata = function(self) - return self.id - end, -}) - - -local facedir = {} -facedir[0] = {x=0,y=0,z=1} -facedir[1] = {x=1,y=0,z=0} -facedir[2] = {x=0,y=0,z=-1} -facedir[3] = {x=-1,y=0,z=0} - -local remove_item_entity = function(pos, node) - if node.name == "mcl_itemframes:item_frame" then - for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do - local entity = obj:get_luaentity() - if entity and (entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:map") then - obj:remove() - end - end - end +if 1 == 1 then + minetest.log("action", "[mcl_itemframes] initialized.") end -local update_item_entity = function(pos, node, param2) - remove_item_entity(pos, node) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - if not param2 then - param2 = node.param2 - end - if node.name == "mcl_itemframes:item_frame" then - local posad = facedir[param2] - pos.x = pos.x + posad.x*6.5/16 - pos.y = pos.y + posad.y*6.5/16 - pos.z = pos.z + posad.z*6.5/16 - end - local yaw = math.pi*2 - param2 * math.pi/2 - local map_id = item:get_meta():get_string("mcl_maps:id") - if map_id == "" then - local e = minetest.add_entity(pos, "mcl_itemframes:item") - local lua = e:get_luaentity() - lua._nodename = node.name - local itemname = item:get_name() - if itemname == "" or itemname == nil then - lua._texture = "blank.png" - lua._scale = 1 - else - lua._texture = itemname - local def = minetest.registered_items[itemname] - lua._scale = def and def.wield_scale and def.wield_scale.x or 1 - end - lua:_update_texture() - if node.name == "mcl_itemframes:item_frame" then - e:set_yaw(yaw) - end - else - local e = minetest.add_entity(pos, "mcl_itemframes:map", map_id) - e:set_yaw(yaw) - end - end -end -mcl_itemframes.update_item_entity = update_item_entity +-- mcl_itemframes API +dofile(modpath .. "/item_frames_API.lua") -local drop_item = function(pos, node, meta, clicker) - local cname = "" - if clicker and clicker:is_player() then - cname = clicker:get_player_name() - end - if node.name == "mcl_itemframes:item_frame" and not minetest.is_creative_enabled(cname) then - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - minetest.add_item(pos, item) - end - end - meta:set_string("infotext", "") - remove_item_entity(pos, node) -end +mcl_itemframes.create_base_frames() -minetest.register_node("mcl_itemframes:item_frame",{ - description = S("Item Frame"), - _tt_help = S("Can hold an item"), - _doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."), - _doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."), - drawtype = "mesh", - is_ground_content = false, - mesh = "mcl_itemframes_itemframe1facedir.obj", - selection_box = { type = "fixed", fixed = {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} }, - collision_box = { type = "fixed", fixed = {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} }, - tiles = {"mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "default_wood.png", "mcl_itemframes_itemframe_background.png"}, - inventory_image = "mcl_itemframes_item_frame.png", - wield_image = "mcl_itemframes_item_frame.png", - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 }, - sounds = mcl_sounds.node_sound_defaults(), - node_placement_prediction = "", - on_timer = function(pos) - local inv = minetest.get_meta(pos):get_inventory() - local stack = inv:get_stack("main", 1) - local itemname = stack:get_name() - if minetest.get_item_group(itemname, "clock") > 0 then - local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) - if itemname ~= new_name then - stack:set_name(new_name) - inv:set_stack("main", 1, stack) - local node = minetest.get_node(pos) - update_item_entity(pos, node, node.param2) - end - minetest.get_node_timer(pos):start(1.0) - end - end, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end - - -- Use pointed node's on_rightclick function first, if present - local node = minetest.get_node(pointed_thing.under) - if placer and not placer:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack - end - end - - return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) - end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("main", 1) - end, - on_rightclick = function(pos, node, clicker, itemstack) - if not itemstack then - return - end - local pname = clicker:get_player_name() - if minetest.is_protected(pos, pname) then - minetest.record_protection_violation(pos, pname) - return - end - local meta = minetest.get_meta(pos) - drop_item(pos, node, meta, clicker) - local inv = meta:get_inventory() - if itemstack:is_empty() then - remove_item_entity(pos, node) - meta:set_string("infotext", "") - inv:set_stack("main", 1, "") - return itemstack - end - local put_itemstack = ItemStack(itemstack) - 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.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) - end - inv:set_stack("main", 1, put_itemstack) - update_item_entity(pos, node) - -- Add node infotext when item has been named - local imeta = itemstack:get_meta() - local iname = imeta:get_string("name") - if iname then - meta:set_string("infotext", iname) - end - - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end - return itemstack - end, - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return count - end - end, - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, - on_destruct = function(pos) - local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) - drop_item(pos, node, meta) - end, - on_rotate = function(pos, node, user, mode, param2) - if mode == screwdriver.ROTATE_FACE then - -- Rotate face - --local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) - - local objs = nil - if node.name == "mcl_itemframes:item_frame" then - objs = minetest.get_objects_inside_radius(pos, 0.5) - end - if objs then - for _, obj in ipairs(objs) do - if obj and obj:get_luaentity() and obj:get_luaentity().name == "mcl_itemframes:item" then - update_item_entity(pos, node, (node.param2+1) % 4) - break - end - end - end - return - elseif mode == screwdriver.ROTATE_AXIS then - return false - end - end, +-- Register the base item_frame's recipes. +-- was going to make it a specialized function, but minetest refuses to play nice. +minetest.register_craft({ + output = "mcl_itemframes:item_frame", + recipe = { + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + { "mcl_core:stick", "mcl_mobitems:leather", "mcl_core:stick" }, + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + } }) minetest.register_craft({ - output = "mcl_itemframes:item_frame", - recipe = { - {"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"}, - {"mcl_core:stick", "mcl_mobitems:leather", "mcl_core:stick"}, - {"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"}, - } + type = "shapeless", + output = 'mcl_itemframes:glow_item_frame', + recipe = { 'mcl_mobitems:glow_ink_sac', 'mcl_itemframes:item_frame' }, }) +-- for compatibility: minetest.register_lbm({ - label = "Update legacy item frames", - name = "mcl_itemframes:update_legacy_item_frames", - nodenames = {"itemframes:frame"}, - action = function(pos, node) - -- Swap legacy node, then respawn entity - node.name = "mcl_itemframes:item_frame" - local meta = minetest.get_meta(pos) - local item = meta:get_string("item") - minetest.swap_node(pos, node) - if item ~= "" then - local itemstack = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) - local inv = meta:get_inventory() - inv:set_size("main", 1) - if not itemstack:is_empty() then - inv:set_stack("main", 1, itemstack) - end - end - update_item_entity(pos, node) - end, + label = "Update legacy item frames", + name = "mcl_itemframes:update_legacy_item_frames", + nodenames = { "itemframes:frame" }, + action = function(pos, node) + -- Swap legacy node, then respawn entity + node.name = "mcl_itemframes:item_frame" + local meta = minetest.get_meta(pos) + local item = meta:get_string("item") + minetest.swap_node(pos, node) + if item ~= "" then + local itemstack = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) + local inv = meta:get_inventory() + inv:set_size("main", 1) + if not itemstack:is_empty() then + inv:set_stack("main", 1, itemstack) + end + end + mcl_itemframes.update_item_entity(pos, node) + end, }) - --- FIXME: Item entities can get destroyed by /clearobjects -minetest.register_lbm({ - label = "Respawn item frame item entities", - name = "mcl_itemframes:respawn_entities", - nodenames = {"mcl_itemframes:item_frame"}, - run_at_every_load = true, - action = function(pos, node) - update_item_entity(pos, node) - end, -}) - minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame") diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua new file mode 100644 index 000000000..1f740219b --- /dev/null +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -0,0 +1,570 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by michieal. +--- DateTime: 10/26/22 1:16 AM +--- + +mcl_itemframes = {} +mcl_itemframes.item_frame_base = {} +mcl_itemframes.glow_frame_base = {} +mcl_itemframes.frames_registered = {} +mcl_itemframes.frames_registered.glowing = {} +mcl_itemframes.frames_registered.standard = {} + +local S = minetest.get_translator(minetest.get_current_modname()) +local table = table +local DEBUG = false + +if 1 == 1 then + minetest.log("action", "[mcl_itemframes] API initialized.") +end + +local VISUAL_SIZE = 0.3 +local facedir = {} +facedir[0] = { x = 0, y = 0, z = 1 } +facedir[1] = { x = 1, y = 0, z = 0 } +facedir[2] = { x = 0, y = 0, z = -1 } +facedir[3] = { x = -1, y = 0, z = 0 } +local pi = math.pi + +local glow_amount = 6 -- LIGHT_MAX is 15, but the items aren't supposed to be a light source. + +local remove_item_entity = function(pos, node) + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do + local entity = obj:get_luaentity() + + if 1 == 1 then + if entity then + minetest.log("action", "[mcl_itemframes] Remove_Entity: Attempting to remove Entity Named: " .. entity.name) + else + minetest.log("action", "[mcl_itemframes] Remove_Entity: Attempting to remove Entity Named: entity not found.\n can be a false positive.") + end + end + + if entity then + if entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:map" or + entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:glow_map" then + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Remove_Entity: Removing Entity Named: " .. entity.name) + end + obj:remove() + end + end + end + end +end + +mcl_itemframes.update_item_glow_entity = function(pos, node, param2) + + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Glow_Item:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) + end + + remove_item_entity(pos, node) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + if not param2 then + param2 = node.param2 + end + if node.name == "mcl_itemframes:glow_item_frame" then + local posad = facedir[param2] + pos.x = pos.x + posad.x * 6.5 / 16 + pos.y = pos.y + posad.y * 6.5 / 16 + pos.z = pos.z + posad.z * 6.5 / 16 + end + local yaw = pi * 2 - param2 * pi / 2 + local map_id = item:get_meta():get_string("mcl_maps:id") + local map_id_entity = {} + local map_id_lua = {} + + if map_id == "" then + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_item") + map_id_lua = map_id_entity:get_luaentity() + map_id_lua._nodename = node.name + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Glow_Item: Adding entity: " .. map_id_lua.name) + end + + local itemname = item:get_name() + if itemname == "" or itemname == nil then + map_id_lua._texture = "blank.png" + map_id_lua._scale = 1 + map_id_lua.glow = glow_amount + else + map_id_lua._texture = itemname + local def = minetest.registered_items[itemname] + map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 + end + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Glow_Item: item's name: " .. itemname) + end + map_id_lua:_update_texture() + if node.name == "mcl_itemframes:glow_item_frame" then + map_id_entity:set_yaw(yaw) + end + else + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_map", map_id) + map_id_entity:set_yaw(yaw) + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Placing map in a glow frame.") + end + end + end +end + +mcl_itemframes.update_item_entity = function(pos, node, param2) + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Item_Entity:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) + end + remove_item_entity(pos, node) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + if not param2 then + param2 = node.param2 + end + if node.name == "mcl_itemframes:item_frame" then + local posad = facedir[param2] + pos.x = pos.x + posad.x * 6.5 / 16 + pos.y = pos.y + posad.y * 6.5 / 16 + pos.z = pos.z + posad.z * 6.5 / 16 + end + local yaw = pi * 2 - param2 * pi / 2 + local map_id = item:get_meta():get_string("mcl_maps:id") + local map_id_entity = {} + local map_id_lua = {} + + if map_id == "" then + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:item") + + map_id_lua = map_id_entity:get_luaentity() + + if DEBUG then + minetest.log("[mcl_itemframes] Map_ID_Entity: \n" .. dump(map_id_entity)) + minetest.log("[mcl_itemframes] Map_ID_LUA: \n" .. dump(map_id_lua)) + end + + map_id_lua._nodename = node.name + local itemname = item:get_name() + if itemname == "" or itemname == nil then + map_id_lua._texture = "blank.png" + map_id_lua._scale = 1 + else + map_id_lua._texture = itemname + local def = minetest.registered_items[itemname] + map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 + end + map_id_lua:_update_texture() + if node.name == "mcl_itemframes:item_frame" then + map_id_entity:set_yaw(yaw) + end + else + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:map", map_id) + map_id_entity:set_yaw(yaw) + end + end +end + +local drop_item = function(pos, node, meta, clicker) + local cname = "" + if clicker and clicker:is_player() then + cname = clicker:get_player_name() + end + if not minetest.is_creative_enabled(cname) then + if (node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame") then + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + minetest.add_item(pos, item) + end + end + end + + meta:set_string("infotext", "") + remove_item_entity(pos, node) +end +mcl_itemframes.item_frame_base = { + description = S("Item Frame"), + _tt_help = S("Can hold an item"), + _doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."), + _doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."), + drawtype = "mesh", + is_ground_content = false, + mesh = "mcl_itemframes_itemframe1facedir.obj", + selection_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, + collision_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, + tiles = { "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "default_wood.png", "mcl_itemframes_item_frame_back.png" }, + inventory_image = "mcl_itemframes_item_frame.png", + wield_image = "mcl_itemframes_item_frame.png", + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + groups = { dig_immediate = 3, deco_block = 1, dig_by_piston = 1, container = 7, attached_node_facedir = 1 }, + sounds = mcl_sounds.node_sound_defaults(), + node_placement_prediction = "", + on_timer = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + local stack = inv:get_stack("main", 1) + local itemname = stack:get_name() + if minetest.get_item_group(itemname, "clock") > 0 then + local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) + if itemname ~= new_name then + stack:set_name(new_name) + inv:set_stack("main", 1, stack) + local node = minetest.get_node(pos) + mcl_itemframes.update_item_entity(pos, node, node.param2) + end + minetest.get_node_timer(pos):start(1.0) + end + end, + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + + return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) + end, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 1) + end, + on_rightclick = function(pos, node, clicker, itemstack) + if not itemstack then + return + end + local pname = clicker:get_player_name() + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) + return + end + local meta = minetest.get_meta(pos) + drop_item(pos, node, meta, clicker) + local inv = meta:get_inventory() + if itemstack:is_empty() then + remove_item_entity(pos, node) + meta:set_string("infotext", "") + inv:set_stack("main", 1, "") + return itemstack + end + local put_itemstack = ItemStack(itemstack) + 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.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) + end + inv:set_stack("main", 1, put_itemstack) + if node.name == "mcl_itemframes:item_frame" then + mcl_itemframes.update_item_entity(pos, node) + elseif node.name == "mcl_itemframes:glow_item_frame" then + mcl_itemframes.update_item_glow_entity(pos, node) + end + + -- Add node infotext when item has been named + local imeta = itemstack:get_meta() + local iname = imeta:get_string("name") + if iname then + meta:set_string("infotext", iname) + end + + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end + return itemstack + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return count + end + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return stack:get_count() + end + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return stack:get_count() + end + end, + on_destruct = function(pos) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + drop_item(pos, node, meta) + end, + on_rotate = function(pos, node, user, mode, param2) + if mode == screwdriver.ROTATE_FACE then + -- Rotate face + --local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + + local objs = nil + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + objs = minetest.get_objects_inside_radius(pos, 0.5) + end + if objs then + for _, obj in ipairs(objs) do + if obj and obj:get_luaentity() then + if obj:get_luaentity().name == "mcl_itemframes:item" then + mcl_itemframes.update_item_entity(pos, node, (node.param2 + 1) % 4) + break + end + if obj:get_luaentity().name == "mcl_itemframes:glow_item_frame" then + mcl_itemframes.update_item_glow_entity(pos, node, (node.param2 + 1) % 4) + break + end + end + end + end + return + elseif mode == screwdriver.ROTATE_AXIS then + return false + end + end, +} + +function mcl_itemframes.create_item_entity() + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] create_item_entity.") + end + + --"mcl_itemframes:item", + local frame_item = { + hp_max = 1, + visual = "wielditem", + visual_size = { x = VISUAL_SIZE, y = VISUAL_SIZE }, + physical = false, + pointable = false, + textures = { "blank.png" }, + _texture = "blank.png", + _scale = 1, + + on_activate = function(self, staticdata) + if staticdata and staticdata ~= "" then + local data = staticdata:split(";") + if data and data[1] and data[2] then + self._nodename = data[1] + self._texture = data[2] + if data[3] then + self._scale = data[3] + else + self._scale = 1 + end + end + end + if self._texture then + self.object:set_properties({ + textures = { self._texture }, + visual_size = { x = VISUAL_SIZE / self._scale, y = VISUAL_SIZE / self._scale }, + }) + end + end, + get_staticdata = function(self) + if self._nodename and self._texture then + local ret = self._nodename .. ";" .. self._texture + if self._scale then + ret = ret .. ";" .. self._scale + end + return ret + end + return "" + end, + + _update_texture = function(self) + if self._texture then + self.object:set_properties({ + textures = { self._texture }, + visual_size = { x = VISUAL_SIZE / self._scale, y = VISUAL_SIZE / self._scale }, + }) + end + end, + } + -- "mcl_itemframes:map", + local map_item = { + initial_properties = { + visual = "upright_sprite", + visual_size = { x = 1, y = 1 }, + pointable = false, + physical = false, + collide_with_objects = false, + textures = { "blank.png" }, + }, + on_activate = function(self, staticdata) + self.id = staticdata + mcl_maps.load_map(self.id, function(texture) + -- will not crash even if self.object is invalid by now + self.object:set_properties({ textures = { texture } }) + end) + end, + get_staticdata = function(self) + return self.id + end, + } + + local glow_frame_item = table.copy(frame_item) + glow_frame_item.glow = glow_amount + glow_frame_item.name = "mcl_itemframes:glow_item" + local glow_frame_map_item = table.copy(map_item) + glow_frame_map_item.glow = glow_amount + glow_frame_map_item.name = "mcl_itemframes:glow_map" + + minetest.register_entity("mcl_itemframes:glow_item", glow_frame_item) + minetest.register_entity("mcl_itemframes:glow_map", glow_frame_map_item) + minetest.register_entity("mcl_itemframes:item", frame_item) + minetest.register_entity("mcl_itemframes:map", map_item) + +end +mcl_itemframes.create_item_entity() + +function mcl_itemframes.update_frame_registry(modname, name, has_glow) + local mod_name_pass = false + if modname ~= "" and modname ~= "false" then + if minetest.get_modpath(modname) then + mod_name_pass = true + end + if mod_name_pass == false then + return + end + end + + mcl_itemframes.frames_registered.glowing = {} + mcl_itemframes.frames_registered.standard = {} + + local frame = "mcl_itemframes:" .. name + if has_glow == true then + table.insert(mcl_itemframes.frames_registered.glowing, frame) + else + table.insert(mcl_itemframes.frames_registered.standard, frame) + end + +end + +function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, color, ttframe, description) + local mod_name_pass = false + if modname ~= "" and modname ~= "false" then + if minetest.get_modpath(modname) then + mod_name_pass = true + end + if mod_name_pass == false then + return + end + end + if name == nil then + name = "" + end + + if has_glow == nil or has_glow == "" then + has_glow = false + end + + if tiles == nil or tiles == "" then + minetest.log("error", "No textures passed to Create_Custom_Frame!! Exiting frame creation.") + return + end + + local custom_itemframe_definition = {} + + if has_glow == false then + custom_itemframe_definition = table.copy(mcl_itemframes.item_frame_base) + else + custom_itemframe_definition = table.copy(mcl_itemframes.glow_frame_base) + end + + custom_itemframe_definition.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" } + custom_itemframe_definition._tt_help = ttframe + custom_itemframe_definition.description=description + mcl_itemframes.update_frame_registry(modname, name, has_glow) + mcl_itemframes.create_register_lbm(name, has_glow) + +end + +function mcl_itemframes.create_base_frames() + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] create_frames.") + end + + minetest.register_node("mcl_itemframes:item_frame", mcl_itemframes.item_frame_base) + + -- make glow frame from the base item_frame. + mcl_itemframes.glow_frame_base = table.copy(mcl_itemframes.item_frame_base) + mcl_itemframes.glow_frame_base.description = S("Glow Item Frame") + mcl_itemframes.glow_frame_base._tt_help = S("Can hold an item and glows") + mcl_itemframes.glow_frame_base.longdesc = S("Glow item frames are decorative blocks in which items can be placed.") + mcl_itemframes.glow_frame_base.tiles = { "mcl_itemframes_glow_item_frame.png" } + mcl_itemframes.glow_frame_base.inventory_image = "mcl_itemframes_glow_item_frame_item.png" + mcl_itemframes.glow_frame_base.wield_image = "mcl_itemframes_glow_item_frame.png" + mcl_itemframes.glow_frame_base.mesh = "mcl_itemframes_glow_item_frame.obj" + + --mcl_itemframes.glow_frame_base.light_source = minetest.LIGHT_MAX -- add in glow (a hack at best, but it's a node) TODO: make actual glow. + mcl_itemframes.glow_frame_base.on_timer = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + local stack = inv:get_stack("main", 1) + local itemname = stack:get_name() + if minetest.get_item_group(itemname, "clock") > 0 then + local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) + if itemname ~= new_name then + stack:set_name(new_name) + inv:set_stack("main", 1, stack) + local node = minetest.get_node(pos) + mcl_itemframes.update_item_glow_entity(pos, node, node.param2) + end + minetest.get_node_timer(pos):start(1.0) + end + end + + minetest.register_node("mcl_itemframes:glow_item_frame", mcl_itemframes.glow_frame_base) + + mcl_itemframes.update_frame_registry("false", "item_frame", false) + mcl_itemframes.update_frame_registry("false", "glow_item_frame", true) + mcl_itemframes.create_register_lbm("item_frame", false) + mcl_itemframes.create_register_lbm("glow_item_frame", true) +end + +function mcl_itemframes.create_register_lbm(name, has_glow) + + -- FIXME: Item entities can get destroyed by /clearobjects + -- glow frame + minetest.register_lbm({ + label = "Respawn item frame item entities", + name = "mcl_itemframes:respawn_entities", + nodenames = { "mcl_itemframes:" .. name }, + run_at_every_load = true, + action = function(pos, node) + if has_glow == true then + mcl_itemframes.update_item_glow_entity(pos, node) + else + mcl_itemframes.update_item_entity(pos, node) + end + end, + }) + +end + From 09d452667b98d0b9079a0de344b0aab971c5effb Mon Sep 17 00:00:00 2001 From: Michieal Date: Wed, 26 Oct 2022 11:45:49 +0000 Subject: [PATCH 02/14] glowframe textures commit --- .../textures/mcl_itemframes_glow_item_frame.png | Bin 0 -> 6285 bytes .../mcl_itemframes_glow_item_frame_border.png | Bin 0 -> 7216 bytes .../mcl_itemframes_glow_item_frame_item.png | Bin 0 -> 6285 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame.png create mode 100644 mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame_border.png create mode 100644 mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame_item.png diff --git a/mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame.png b/mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame.png new file mode 100644 index 0000000000000000000000000000000000000000..e83b4e0608b452b5b3033bbb4c1bd0a7c594b753 GIT binary patch literal 6285 zcmeHLdpK0<9$u7`OQ}%F)->p{Gv;Du%uFU*#%0{Exy#I&HDkqGTC+4mD5B6N(Y90U zluAk}N+LTuMHi$CrFO)w9lGhTQ%ap@hNN>k`<(tb|Mi<^JT7Ke^H94wU{rDb`G#BB@yA)yOg9is zAj^jhn|mta&dj?zyFKAjfye2+mD&O22I2D^BLWz#t|zmQpcgSEthS@|#{Ve&-TrxJ zMpsQAaU11eK$(F%*rXcP;Cf||?o@Z5ot|msn_r@{ zRn5wag%)*h;se~@pBiXIUqbw#=G+B+(i^d>o7WD7+Wpnh)|aIzf$wZ(ejH+pC(=Oswp1hxbHjvO$v|CNng@K>lezUEuWqUp=2pyCkJB}&62Lvab zVb*4mu_b?C$0Xnz-_qlcCw+7->6huFzpNh%k zCFxcoj*%@hmM3h^I^7ZdVv_*BVpum)^4k_2+K&%^zEcKXOUO+&UVNhag0qgk=PXmZ z*|@C2Z3~edb3vz_Klyu6T30R#X`(Xk=ZjgKfo$ z-BD*~L0v8FzZ}*zYmY`ce%a(wOg`+fE5C(MeaLyw+qd_3Ue$5tP@%$Lb&G+*<+pLc z{E(i0~0Q+s4EsPJdb!uL*WR+6cXQwM?|ON0 zm<@x@k;UsJ9J`=%ufwC*N1oi6H1{sm%FQTV`?4dqd_U$|Rmnjww~IMv54XJXY0a{` zdoSBJbs5P=1{HKB+;})?c-wn?84(A@oq?<}7bShF&&UDx=T=kS!_(m>y)J~(~-k*8Hv1$8yO>PHO1u1+^P z^w`>`X2eG`KHk~lZsukTl-JpelP|q!_2OQ%XXv2!?biLJ!o?57e~7#pq$DI=hH-v} zM#>rSd541ooN8#B-`%0#8Uc?Lxk|3C8cY^ZUdKD!7I*YnPLep@_tG#>}zhvxu6 zP)O*toGbuPNrr80J=nIkAJ1$6kmtp1XFAq-=q9^++ig!voX0XG`GlCIq|u!8wubFJ zsTUYUi0)lLh8?|v4b^TZZnEC$t3F2%@?Ef+O~3kurY81vJEybwr6*Hfp8q2*Pj;=V z<}I){l)tN$s1jZ!Tm*V9%?|mgDs<+?l=vSPnpj*-Dbl~$fArY;zJpa;`^`T5YJJ47 zDL`wg;{|CWLD;R`o$GqPZ z+*4ZmY|Lw|;9lH@1JfJhvqB@_F5?36{K`rZe8os|W|G#5d1Xthy)tt$uT6R(7<3H? zd!XMFFz{!aRYUKj%!2{APC$K2ZFoZ2?YNHn_g9?WuzuITTb1w{q;OmQIS2q|lGSSa)w+e5ke>jBNs-BqzpL|tJGzPqzuI{9*a>z&=nz}d;+btLQx4U84S<1@Ti_G1zVkI%%0qo{;|$IE0gbD4#?7!lx!bUGbR zAmK?Q9Kz${q|qXjBgcuP#tMm14HhH?5mEBlP$m|ufx%$L#9;{v+R4%J z1d4m5ycFf(*%A~a%Y_mrp&W zS};*wE|iSxe}?|(mlCY>mBA8&QHrE&789$OFM}rrVID*ImBXdbAr1uMEJ!>ej!dBQ za9k=#!GU}-#JA*<`5=ijL5eMsq8t$jDWv2=i8&1O7*s0AwcuJ%aWpQMizCx4NI04W zkA$PpEogiaNTXX4zzGuW2rPg_oXCl@Qb_S&9)nDy@pxRC1&%}~S>VVN3IWHZfn=No zpUNTecyv0|Vsti&ePGylu$fqrIYB9|9Px}m4BSH?!#KJ<30K!W|0wqPUF^c6t zB9x=(4knhU9G43v3|j=^pkl;FERJMi6?4NVB$Z8tu^MX^hKm?f5|vRI4+_`HY5dC|dFM-FEydVKAMUiOs ze_7PO;H*Xq))AJXVkCM(es5^)=-ud%6bUP>!eErg0D}XL+Arm-gLuj<7=HwYb3_7& z$Hb0x&qoUUg+iuLsXRKJ!@-e2GKeG7349!vOeW%}Ac04r(`c5KH1g-_QZXNuaS+Hx z0Etj0)&Ukul>3ZXGFE>}KgY|$Aw_W!NJJcgh$9hvh;#INnk9G4Oa1;1rHTvJ^6JeulTd^b>fd%2HyG-=A z>AwIRRd9hpNF){iUG9mHQClXwh!pQPrBz-m`xP2i`0*F!Se5*rW32lAzws@}SH(BG zzAC=i^;PlBuCI!3c70WRv+Jwk@9fg}^phJB@t9Z{)_TS4#qON|08HUJJFtKcicdjJ zQ8oYo($?{ty&ww6F1`njCvZ> zwj*VCB;9mz*e@3p;6+IX zj7)*pjDS{%(O79`=#U}Qp9HWp)G8uT%22@YV`;6*1Vpj57zC;^4A{B*!@hlaAwMX_ z&Ai>c_nz~e?>pz-lbKynTy$Fs8ipiEO3Ba5y;G8;LE<+cNs^?@GhgeHln^PMJh`|u z6q2NznqSn6FG!p;qKesJ&_Q&^`Z{HHAQywb%U*P!Z zrW;rNbjvH}`Zs=7oiw+!e$}#H9WD8A+BEs%jcXT9f4=g)jg=R+x3?bn&Cj%?>3_d& z)eUtg(W>NKch4yJysrGkn*6Nl)ao~z(~G~l{oj9SZC!cjC);moo_%capyHeVbT;+y zl1(+67qo0^nej^5j-0i(eUSC^-&%_bPOg4;#pK`Rq_GM#x_0OKS#xKS^Y8JJ(}gb& z&zO91=mY;emRFk=DS4-=qA*{XGIjT}M&U;n$4}jro^krs$A%Z5IsS0ugW|1;JLk2Y zA9wn-V{*UDqr+!?zA>+;K672KnRRyt&L#Wjk?bxIEMtnX^%GbYG{&+!?;1K!S;sO~yZ}fI*+_EGzn}>g z7-OP30bC#vOvDq62*%j)N1F3OMP!1p>=^2fJkV4gEiLHSU%G^yiZK#5jXTp0i`X&a zOk-gM6HEy)s7x_2D6#%9B~+$5#mIUPDvV^Ri7CpdP8k)EgdAD7^X5u(pU#CY)Q{dG zNz%P>%UfDr5t5L&+vN=qKneyGOwPdM)Or)KDKV@9sf-BHn7N|t3+*~k`o1I${UUCZ zMf1ufv}j(r6@#d%jA)3OT;&*Kpb!LwGlGGD0vt3jXqXVg3Fdn96ldKv5{ynV~SCT!$b~ssST}n$*BL4RMv~T!k>l5Ej8eCRmIi1O}&K z4T%UK0|Qg=pt`+q$=qV%!Egpai<4>>kWnxN4T2G6#ISytgzb~Uff7Ol6M|`o6JP*T zR|sPaVtCkVf{KbbWLT+M7+fS`4@XK`sRRoFUHUJn`7k1?a9cm zLN#%6VoFgzwzZpT`;EUcLfwJCYn#5{4e4s*m2ak7{6_oKz{SiN8ct;cg6VG zeVdH@k-9sw81+t!KSW=V=4t6GjJ!Pcn2{&O0}*dM2J*XmqpJzjnHZ1F_efgz#C%Vr z^+rrzmF8->nmgN{i_S*9VC0JNLv{m5d{T(>sakxtvOb1#F1|7&YM{s4kB*b1gg}1o zr0MFO#%YBEcN7oGC`|tK3xy-Hk6zPU)He3BwgF9T1M8ZhDR6gL)-Tu0FP@lk-QEXI zJjXY;WS!i*xP9N3AD_5+X=e6g+YkKy%e*Gue@H?9^}9#ad^LCQq$TRx@AfNdSa9mc zP4`Yn4~@9t!Iu4BTo|5v$GXM8jr?catM5EG^YwPTazy&N0&}fCtNo3j#*_2boP6Qn z{Khgfts(m*^N|@(PFnh-$}zhJ?B&<2Z~wIMuiH)~<=1T<+4jVQ{f)}g4NnGY$~I*e ztlsf{gEIE;)-xNPFIkKx>{IXibYJ+;u)4Cdx2znQc5#$Ep!_f!``>Y?PrO-sBym}w zZN^UR(4Vu;ZOHiK`csw1QtF4*UjL6sR?cgw!E66@77yKXw*HZ+g-=Bu{cuUmsH7v+ Wjpx^FZI>iT%AZn{+jQ&wRsRQy<9%2F literal 0 HcmV?d00001 diff --git a/mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame_item.png b/mods/ITEMS/mcl_itemframes/textures/mcl_itemframes_glow_item_frame_item.png new file mode 100644 index 0000000000000000000000000000000000000000..e83b4e0608b452b5b3033bbb4c1bd0a7c594b753 GIT binary patch literal 6285 zcmeHLdpK0<9$u7`OQ}%F)->p{Gv;Du%uFU*#%0{Exy#I&HDkqGTC+4mD5B6N(Y90U zluAk}N+LTuMHi$CrFO)w9lGhTQ%ap@hNN>k`<(tb|Mi<^JT7Ke^H94wU{rDb`G#BB@yA)yOg9is zAj^jhn|mta&dj?zyFKAjfye2+mD&O22I2D^BLWz#t|zmQpcgSEthS@|#{Ve&-TrxJ zMpsQAaU11eK$(F%*rXcP;Cf||?o@Z5ot|msn_r@{ zRn5wag%)*h;se~@pBiXIUqbw#=G+B+(i^d>o7WD7+Wpnh)|aIzf$wZ(ejH+pC(=Oswp1hxbHjvO$v|CNng@K>lezUEuWqUp=2pyCkJB}&62Lvab zVb*4mu_b?C$0Xnz-_qlcCw+7->6huFzpNh%k zCFxcoj*%@hmM3h^I^7ZdVv_*BVpum)^4k_2+K&%^zEcKXOUO+&UVNhag0qgk=PXmZ z*|@C2Z3~edb3vz_Klyu6T30R#X`(Xk=ZjgKfo$ z-BD*~L0v8FzZ}*zYmY`ce%a(wOg`+fE5C(MeaLyw+qd_3Ue$5tP@%$Lb&G+*<+pLc z{E(i0~0Q+s4EsPJdb!uL*WR+6cXQwM?|ON0 zm<@x@k;UsJ9J`=%ufwC*N1oi6H1{sm%FQTV`?4dqd_U$|Rmnjww~IMv54XJXY0a{` zdoSBJbs5P=1{HKB+;})?c-wn?84(A@oq?<}7bShF&&UDx=T=kS!_(m>y)J~(~-k*8Hv1$8yO>PHO1u1+^P z^w`>`X2eG`KHk~lZsukTl-JpelP|q!_2OQ%XXv2!?biLJ!o?57e~7#pq$DI=hH-v} zM#>rSd541ooN8#B-`%0#8Uc?Lxk|3C8cY^ZUdKD!7I*YnPLep@_tG#>}zhvxu6 zP)O*toGbuPNrr80J=nIkAJ1$6kmtp1XFAq-=q9^++ig!voX0XG`GlCIq|u!8wubFJ zsTUYUi0)lLh8?|v4b^TZZnEC$t3F2%@?Ef+O~3kurY81vJEybwr6*Hfp8q2*Pj;=V z<}I){l)tN$s1jZ!Tm*V9%?|mgDs<+?l=vSPnpj*-Dbl~$fArY;zJpa;`^`T5YJJ47 zDL`wg;{|CWLD;R`o$GqPZ z+*4ZmY|Lw|;9lH@1JfJhvqB@_F5?36{K`rZe8os|W|G#5d1Xthy)tt$uT6R(7<3H? zd!XMFFz{!aRYUKj%!2{APC$K2ZFoZ2?YNHn_g9?WuzuITTb1w{q;OmQIS2q|lGSSa)w+e5ke>jBNs-BqzpL|tJGzPqzuI{9*a>z&=nz}d;+btLQx4U84S<1@Ti_G1zVkI%%0qo{;|$IE0gbD4#?7!lx!bUGbR zAmK?Q9Kz${q|qXjBgcuP#tMm14HhH?5mEBlP$m|ufx%$L#9;{v+R4%J z1d4m5ycFf(*%A~a%Y_mrp&W zS};*wE|iSxe}?|(mlCY>mBA8&QHrE&789$OFM}rrVID*ImBXdbAr1uMEJ!>ej!dBQ za9k=#!GU}-#JA*<`5=ijL5eMsq8t$jDWv2=i8&1O7*s0AwcuJ%aWpQMizCx4NI04W zkA$PpEogiaNTXX4zzGuW2rPg_oXCl@Qb_S&9)nDy@pxRC1&%}~S>VVN3IWHZfn=No zpUNTecyv0|Vsti&ePGylu$fqrIYB9|9Px}m4BSH?!#KJ<30K!W|0wqPUF^c6t zB9x=(4knhU9G43v3|j=^pkl;FERJMi6?4NVB$Z8tu^MX^hKm?f5|vRI4+_`HY5dC|dFM-FEydVKAMUiOs ze_7PO;H*Xq))AJXVkCM(es5^)=-ud%6bUP>!eErg0D}XL+Arm-gLuj<7=HwYb3_7& z$Hb0x&qoUUg+iuLsXRKJ!@-e2GKeG7349!vOeW%}Ac04r(`c5KH1g-_QZXNuaS+Hx z0Etj0)&Ukul>3ZXGFE>}KgY|$Aw_W!NJJcgh$9hvh;#INnk9G4Oa1;1rHTvJ^6JeulTd^b>fd%2HyG-=A z>AwIRRd9hpNF){iUG9mHQClXwh!pQPrBz-m`xP2i`0*F!Se5*rW32lAzws@}SH(BG zzAC=i^;PlBuCI!3c70WRv+Jwk@9fg}^phJB@t9Z{)_TS4#qON|08HUJJFtKcicdjJ zQ8oYo($?{ty&ww6F1`njCvZ> zwj*VCB;9mz*e@3p Date: Wed, 26 Oct 2022 11:46:45 +0000 Subject: [PATCH 03/14] glowframe model commit --- .../models/mcl_itemframes_glow_item_frame.obj | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 mods/ITEMS/mcl_itemframes/models/mcl_itemframes_glow_item_frame.obj diff --git a/mods/ITEMS/mcl_itemframes/models/mcl_itemframes_glow_item_frame.obj b/mods/ITEMS/mcl_itemframes/models/mcl_itemframes_glow_item_frame.obj new file mode 100644 index 000000000..d0a5b0c5f --- /dev/null +++ b/mods/ITEMS/mcl_itemframes/models/mcl_itemframes_glow_item_frame.obj @@ -0,0 +1,156 @@ +# Blender v2.76 (sub 0) OBJ File: 'itemframe1facedir.blend' +# www.blender.org +mtllib itemframe1facedir.mtl +o right.frame_Cube.005 +v -0.313413 -0.313413 0.435326 +v -0.313413 0.313413 0.435326 +v -0.313413 -0.313413 0.498008 +v -0.313413 0.313413 0.498008 +v -0.376095 -0.313413 0.435326 +v -0.376095 0.313413 0.435326 +v -0.376095 -0.313413 0.498008 +v -0.376095 0.313413 0.498008 +vt 0.875000 0.812500 +vt 0.812500 0.812500 +vt 0.812500 0.187500 +vt 0.875000 0.187500 +vt 1.000000 0.812500 +vt 0.937500 0.812500 +vt 0.937500 0.187500 +vt 1.000000 0.187500 +vt -0.000000 0.937500 +vt 0.062500 0.937500 +vt 0.062500 1.000000 +vt -0.000000 1.000000 +vn 1.000000 0.000000 -0.000000 +vn 0.000000 0.000000 1.000000 +vn -1.000000 0.000000 0.000000 +vn -0.000000 0.000000 -1.000000 +vn 0.000000 -1.000000 -0.000000 +vn 0.000000 1.000000 0.000000 +usemtl None +s off +f 2/1/1 4/2/1 3/3/1 1/4/1 +f 4/1/2 8/2/2 7/3/2 3/4/2 +f 8/5/3 6/6/3 5/7/3 7/8/3 +f 6/1/4 2/2/4 1/3/4 5/4/4 +f 1/9/5 3/10/5 7/11/5 5/12/5 +f 6/9/6 8/10/6 4/11/6 2/12/6 +o left.frame_Cube.004 +v 0.376095 -0.313413 0.435326 +v 0.376095 0.313413 0.435326 +v 0.376095 -0.313413 0.498008 +v 0.376095 0.313413 0.498008 +v 0.313413 -0.313413 0.435326 +v 0.313413 0.313413 0.435326 +v 0.313413 -0.313413 0.498008 +v 0.313413 0.313413 0.498008 +vt 0.875000 0.812500 +vt 0.812500 0.812500 +vt 0.812500 0.187500 +vt 0.875000 0.187500 +vt 1.000000 0.812500 +vt 0.937500 0.812500 +vt 0.937500 0.187500 +vt 1.000000 0.187500 +vt -0.000000 0.937500 +vt 0.062500 0.937500 +vt 0.062500 1.000000 +vt -0.000000 1.000000 +vn 1.000000 0.000000 -0.000000 +vn 0.000000 0.000000 1.000000 +vn -1.000000 0.000000 0.000000 +vn 0.000000 0.000000 -1.000000 +vn 0.000000 -1.000000 -0.000000 +vn 0.000000 1.000000 0.000000 +usemtl None +s off +f 10/13/7 12/14/7 11/15/7 9/16/7 +f 12/13/8 16/14/8 15/15/8 11/16/8 +f 16/17/9 14/18/9 13/19/9 15/20/9 +f 14/13/10 10/14/10 9/15/10 13/16/10 +f 9/21/11 11/22/11 15/23/11 13/24/11 +f 14/21/12 16/22/12 12/23/12 10/24/12 +o lower.frame_Cube.003 +v 0.376095 -0.376095 0.435326 +v 0.376095 -0.313413 0.435326 +v 0.376095 -0.376095 0.498008 +v 0.376095 -0.313413 0.498008 +v -0.376095 -0.376095 0.435326 +v -0.376095 -0.313413 0.435326 +v -0.376095 -0.376095 0.498008 +v -0.376095 -0.313413 0.498008 +vt 0.187500 0.187500 +vt 0.125000 0.187500 +vt 0.125000 0.125000 +vt 0.187500 0.125000 +vt 0.875000 0.187500 +vt 0.875000 0.125000 +vt 0.812500 0.187500 +vt 0.812500 0.125000 +vt 0.875000 0.937500 +vt 0.875000 1.000000 +vt 0.125000 1.000000 +vt 0.125000 0.937500 +vn 1.000000 0.000000 0.000000 +vn 0.000000 0.000000 1.000000 +vn -1.000000 0.000000 0.000000 +vn -0.000000 0.000000 -1.000000 +vn 0.000000 -1.000000 0.000000 +vn 0.000000 1.000000 0.000000 +usemtl None +s off +f 18/25/13 20/26/13 19/27/13 17/28/13 +f 20/29/14 24/26/14 23/27/14 19/30/14 +f 24/29/15 22/31/15 21/32/15 23/30/15 +f 22/29/16 18/26/16 17/27/16 21/30/16 +f 17/33/17 19/34/17 23/35/17 21/36/17 +f 22/30/18 24/29/18 20/26/18 18/27/18 +o upper.frame_Cube.002 +v 0.376095 0.313413 0.435326 +v 0.376095 0.376095 0.435326 +v 0.376095 0.313413 0.498008 +v 0.376095 0.376095 0.498008 +v -0.376095 0.313413 0.435326 +v -0.376095 0.376095 0.435326 +v -0.376095 0.313413 0.498008 +v -0.376095 0.376095 0.498008 +vt 0.187500 0.875000 +vt 0.125000 0.875000 +vt 0.125000 0.812500 +vt 0.187500 0.812500 +vt 0.875000 0.875000 +vt 0.875000 0.812500 +vt 0.812500 0.875000 +vt 0.812500 0.812500 +vt 0.875000 0.937500 +vt 0.875000 1.000000 +vt 0.125000 1.000000 +vt 0.125000 0.937500 +vn 1.000000 0.000000 0.000000 +vn 0.000000 0.000000 1.000000 +vn -1.000000 0.000000 0.000000 +vn -0.000000 0.000000 -1.000000 +vn 0.000000 -1.000000 0.000000 +vn 0.000000 1.000000 0.000000 +usemtl None +s off +f 26/37/19 28/38/19 27/39/19 25/40/19 +f 28/41/20 32/38/20 31/39/20 27/42/20 +f 32/41/21 30/43/21 29/44/21 31/42/21 +f 30/41/22 26/38/22 25/39/22 29/42/22 +f 25/45/23 27/46/23 31/47/23 29/48/23 +f 30/48/24 32/38/24 28/41/24 26/45/24 +o background_Plane +v 0.313413 -0.313413 0.466667 +v -0.313413 -0.313413 0.466667 +v 0.313413 0.313413 0.466667 +v -0.313413 0.313413 0.466667 +vt 0.187500 0.187500 +vt 0.812500 0.187500 +vt 0.812500 0.812500 +vt 0.187500 0.812500 +vn -0.000000 0.000000 -1.000000 +usemtl None +s off +f 33/49/25 34/50/25 36/51/25 35/52/25 From 4d74e4d9c1749104cec146870876800d08e4fbba Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 28 Oct 2022 10:44:07 +0000 Subject: [PATCH 04/14] update the translation template --- mods/ITEMS/mcl_itemframes/locale/template.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/ITEMS/mcl_itemframes/locale/template.txt b/mods/ITEMS/mcl_itemframes/locale/template.txt index bacbfaa69..87cd55c65 100644 --- a/mods/ITEMS/mcl_itemframes/locale/template.txt +++ b/mods/ITEMS/mcl_itemframes/locale/template.txt @@ -3,3 +3,6 @@ Item Frame= Item frames are decorative blocks in which items can be placed.= Just place any item on the item frame. Use the item frame again to retrieve the item.= Can hold an item= +Glow Item Frame= +Glow item frames are decorative blocks in which items can be placed.= +Can hold an item and glows= From 1f5b92f7bf19498cc4f536be6250983c45d44fc7 Mon Sep 17 00:00:00 2001 From: Michieal Date: Tue, 1 Nov 2022 00:54:19 +0000 Subject: [PATCH 05/14] code clean up. testing & debugging custom frames. cleaned up a LOT of duplicate code. Added in the custom frames, and a couple of calls in init.lua to begin testing custom frames out. to do: fix the freaking maps. (It looks like it's client side that is failing, to be honest.) --- mods/ITEMS/mcl_itemframes/init.lua | 26 + mods/ITEMS/mcl_itemframes/item_frames_API.lua | 455 +++++++++++++----- 2 files changed, 352 insertions(+), 129 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index f3dd3c214..1ad51e156 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -29,6 +29,32 @@ minetest.register_craft({ recipe = { 'mcl_mobitems:glow_ink_sac', 'mcl_itemframes:item_frame' }, }) + +-- test for the create custom frame +mcl_itemframes.create_custom_frame("false", "my_regular_frame", false, "mcl_itemframes_item_frame.png", mcl_colors.DARK_GREEN, "A Green frame", "My Green Frame") +mcl_itemframes.create_custom_frame("false", "my_glowing_frame", true, "mcl_itemframes_glow_item_frame.png", mcl_colors.DARK_GREEN, "A Green glowing frame", "My Green glowing Frame") + +if 1 == 1 then + minetest.log("action", "registering custom frame recipes [start].") +end +minetest.register_craft({ + output = "mcl_itemframes:my_regular_frame", + recipe = { + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + } +}) + +minetest.register_craft({ + type = "shapeless", + output = "mcl_itemframes:my_glowing_frame", + recipe = { "mcl_mobitems:glow_ink_sac", "mcl_itemframes:my_regular_frame" }, +}) +if 1 == 1 then + minetest.log("action", "registering custom frame recipes [finished].") +end + -- for compatibility: minetest.register_lbm({ label = "Update legacy item frames", diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua index 1f740219b..b3ba16384 100644 --- a/mods/ITEMS/mcl_itemframes/item_frames_API.lua +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -28,6 +28,8 @@ facedir[3] = { x = -1, y = 0, z = 0 } local pi = math.pi local glow_amount = 6 -- LIGHT_MAX is 15, but the items aren't supposed to be a light source. +local frame_item_base = {} +local map_item_base = {} local remove_item_entity = function(pos, node) if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then @@ -55,66 +57,6 @@ local remove_item_entity = function(pos, node) end end -mcl_itemframes.update_item_glow_entity = function(pos, node, param2) - - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Update_Glow_Item:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) - end - - remove_item_entity(pos, node) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - if not param2 then - param2 = node.param2 - end - if node.name == "mcl_itemframes:glow_item_frame" then - local posad = facedir[param2] - pos.x = pos.x + posad.x * 6.5 / 16 - pos.y = pos.y + posad.y * 6.5 / 16 - pos.z = pos.z + posad.z * 6.5 / 16 - end - local yaw = pi * 2 - param2 * pi / 2 - local map_id = item:get_meta():get_string("mcl_maps:id") - local map_id_entity = {} - local map_id_lua = {} - - if map_id == "" then - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_item") - map_id_lua = map_id_entity:get_luaentity() - map_id_lua._nodename = node.name - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Update_Glow_Item: Adding entity: " .. map_id_lua.name) - end - - local itemname = item:get_name() - if itemname == "" or itemname == nil then - map_id_lua._texture = "blank.png" - map_id_lua._scale = 1 - map_id_lua.glow = glow_amount - else - map_id_lua._texture = itemname - local def = minetest.registered_items[itemname] - map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 - end - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Update_Glow_Item: item's name: " .. itemname) - end - map_id_lua:_update_texture() - if node.name == "mcl_itemframes:glow_item_frame" then - map_id_entity:set_yaw(yaw) - end - else - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_map", map_id) - map_id_entity:set_yaw(yaw) - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Placing map in a glow frame.") - end - end - end -end - mcl_itemframes.update_item_entity = function(pos, node, param2) if 1 == 1 then minetest.log("action", "[mcl_itemframes] Update_Item_Entity:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) @@ -127,27 +69,26 @@ mcl_itemframes.update_item_entity = function(pos, node, param2) if not param2 then param2 = node.param2 end - if node.name == "mcl_itemframes:item_frame" then + + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then local posad = facedir[param2] pos.x = pos.x + posad.x * 6.5 / 16 pos.y = pos.y + posad.y * 6.5 / 16 pos.z = pos.z + posad.z * 6.5 / 16 end + local yaw = pi * 2 - param2 * pi / 2 local map_id = item:get_meta():get_string("mcl_maps:id") local map_id_entity = {} local map_id_lua = {} if map_id == "" then - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:item") - - map_id_lua = map_id_entity:get_luaentity() - - if DEBUG then - minetest.log("[mcl_itemframes] Map_ID_Entity: \n" .. dump(map_id_entity)) - minetest.log("[mcl_itemframes] Map_ID_LUA: \n" .. dump(map_id_lua)) + if node.name == "mcl_itemframes:item_frame" then + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:item") + elseif node.name == "mcl_itemframes:glow_item_frame" then + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_item") end - + map_id_lua = map_id_entity:get_luaentity() map_id_lua._nodename = node.name local itemname = item:get_name() if itemname == "" or itemname == nil then @@ -159,16 +100,113 @@ mcl_itemframes.update_item_entity = function(pos, node, param2) map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 end map_id_lua:_update_texture() - if node.name == "mcl_itemframes:item_frame" then + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then map_id_entity:set_yaw(yaw) end else - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:map", map_id) + if node.name == "mcl_itemframes:item_frame" then + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:map", map_id) + elseif node.name == "mcl_itemframes:glow_item_frame" then + map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_map", map_id) + end map_id_entity:set_yaw(yaw) end end end +mcl_itemframes.update_generic_item_entity = function(pos, node, param2) + + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) + end + + remove_item_entity(pos, node) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + -- update existing items placed. + if not param2 then + param2 = node.param2 + end + + local name_found = false + local found_name_to_use = "" + local has_glow = false + + for gl = 1, #mcl_itemframes.frames_registered.glowing do + if node.name == mcl_itemframes.frames_registered.glowing[gl] then + name_found = true + has_glow = true + found_name_to_use = mcl_itemframes.frames_registered.glowing[gl] + break + end + end + + -- try to cut down on excess looping, if possible. + if name_found == false then + for ngl = 1, #mcl_itemframes.frames_registered.standard do + if node.name == mcl_itemframes.frames_registered.glowing[ngl] then + name_found = true + has_glow = false + found_name_to_use = mcl_itemframes.frames_registered.glowing[ngl] + break + end + end + end + + if node.name == found_name_to_use then + local pos_adj = facedir[param2] + pos.x = pos.x + pos_adj.x * 6.5 / 16 + pos.y = pos.y + pos_adj.y * 6.5 / 16 + pos.z = pos.z + pos_adj.z * 6.5 / 16 + end + local yaw = pi * 2 - param2 * pi / 2 + local map_id = item:get_meta():get_string("mcl_maps:id") + local map_id_entity = {} + local map_id_lua = {} + + if map_id == "" then + -- handle regular items placed into custom frame. + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nAdding entity: " .. node.name .. "_item") + end + map_id_entity = minetest.add_entity(pos, node.name .. "_item") + map_id_lua = map_id_entity:get_luaentity() + + map_id_lua._nodename = node.name + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item: Adding entity: " .. map_id_lua.name) + end + + local itemname = item:get_name() + if itemname == "" or itemname == nil then + map_id_lua._texture = "blank.png" + map_id_lua._scale = 1 + if has_glow then + map_id_lua.glow = glow_amount + end + else + map_id_lua._texture = itemname + local def = minetest.registered_items[itemname] + map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 + end + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item: item's name: " .. itemname) + end + map_id_lua:_update_texture() + map_id_entity:set_yaw(yaw) + else + -- handle map items placed into custom frame. + map_id_entity = minetest.add_entity(pos, found_name_to_use .. "_map", map_id) + map_id_entity:set_yaw(yaw) + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] Placing map in a " .. found_name_to_use .. " frame.") + end + end + end +end + local drop_item = function(pos, node, meta, clicker) local cname = "" if clicker and clicker:is_player() then @@ -187,6 +225,49 @@ local drop_item = function(pos, node, meta, clicker) meta:set_string("infotext", "") remove_item_entity(pos, node) end + +function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) + local name_found = false + local found_name_to_use = "" + + for gl = 1, #mcl_itemframes.frames_registered.glowing do + if node.name == mcl_itemframes.frames_registered.glowing[gl] then + name_found = true + found_name_to_use = mcl_itemframes.frames_registered.glowing[gl] + break + end + end + + -- try to cut down on excess looping, if possible. + if name_found == false then + for ngl = 1, #mcl_itemframes.frames_registered.standard do + if node.name == mcl_itemframes.frames_registered.glowing[ngl] then + name_found = true + found_name_to_use = mcl_itemframes.frames_registered.glowing[ngl] + break + end + end + end + + local cname = "" + if clicker and clicker:is_player() then + cname = clicker:get_player_name() + end + if not minetest.is_creative_enabled(cname) then + if (node.name == found_name_to_use) then + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + minetest.add_item(pos, item) + end + end + end + + meta:set_string("infotext", "") + remove_item_entity(pos, node) + +end + mcl_itemframes.item_frame_base = { description = S("Item Frame"), _tt_help = S("Can hold an item"), @@ -207,6 +288,7 @@ mcl_itemframes.item_frame_base = { groups = { dig_immediate = 3, deco_block = 1, dig_by_piston = 1, container = 7, attached_node_facedir = 1 }, sounds = mcl_sounds.node_sound_defaults(), node_placement_prediction = "", + on_timer = function(pos) local inv = minetest.get_meta(pos):get_inventory() local stack = inv:get_stack("main", 1) @@ -217,11 +299,17 @@ mcl_itemframes.item_frame_base = { stack:set_name(new_name) inv:set_stack("main", 1, stack) local node = minetest.get_node(pos) - mcl_itemframes.update_item_entity(pos, node, node.param2) + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + mcl_itemframes.update_item_entity(pos, node, node.param2) + else + mcl_itemframes.update_generic_item_entity(pos, node, node.param2) + end + end minetest.get_node_timer(pos):start(1.0) end end, + on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return itemstack @@ -237,11 +325,13 @@ mcl_itemframes.item_frame_base = { return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) end, + on_construct = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() inv:set_size("main", 1) end, + on_rightclick = function(pos, node, clicker, itemstack) if not itemstack then return @@ -252,7 +342,13 @@ mcl_itemframes.item_frame_base = { return end local meta = minetest.get_meta(pos) - drop_item(pos, node, meta, clicker) + + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + drop_item(pos, node, meta, clicker) + else + mcl_itemframes.drop_generic_item(pos, node, meta, clicker) + end + local inv = meta:get_inventory() if itemstack:is_empty() then remove_item_entity(pos, node) @@ -269,11 +365,12 @@ mcl_itemframes.item_frame_base = { if minetest.get_item_group(itemname, "clock") > 0 then minetest.get_node_timer(pos):start(1.0) end + inv:set_stack("main", 1, put_itemstack) - if node.name == "mcl_itemframes:item_frame" then + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then mcl_itemframes.update_item_entity(pos, node) - elseif node.name == "mcl_itemframes:glow_item_frame" then - mcl_itemframes.update_item_glow_entity(pos, node) + else + mcl_itemframes.update_generic_item_entity(pos, node) end -- Add node infotext when item has been named @@ -288,6 +385,7 @@ mcl_itemframes.item_frame_base = { end return itemstack end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) local name = player:get_player_name() if minetest.is_protected(pos, name) then @@ -297,6 +395,7 @@ mcl_itemframes.item_frame_base = { return count end end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) local name = player:get_player_name() if minetest.is_protected(pos, name) then @@ -306,6 +405,7 @@ mcl_itemframes.item_frame_base = { return stack:get_count() end end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) local name = player:get_player_name() if minetest.is_protected(pos, name) then @@ -315,11 +415,18 @@ mcl_itemframes.item_frame_base = { return stack:get_count() end end, + on_destruct = function(pos) local meta = minetest.get_meta(pos) local node = minetest.get_node(pos) - drop_item(pos, node, meta) + + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + drop_item(pos, node, meta) -- originally had ", clicker" too. Except, clicker doesn't exist in the context. + else + mcl_itemframes.drop_generic_item(pos, node, meta) + end end, + on_rotate = function(pos, node, user, mode, param2) if mode == screwdriver.ROTATE_FACE then -- Rotate face @@ -327,18 +434,40 @@ mcl_itemframes.item_frame_base = { local node = minetest.get_node(pos) local objs = nil - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + + local name_found = false + local found_name_to_use = "" + + for gl = 1, #mcl_itemframes.frames_registered.glowing do + if node.name == mcl_itemframes.frames_registered.glowing[gl] then + name_found = true + found_name_to_use = mcl_itemframes.frames_registered.glowing[gl] + break + end + end + + -- try to cut down on excess looping, if possible. + if name_found == false then + for ngl = 1, #mcl_itemframes.frames_registered.standard do + if node.name == mcl_itemframes.frames_registered.glowing[ngl] then + name_found = true + found_name_to_use = mcl_itemframes.frames_registered.glowing[ngl] + break + end + end + end + if node.name == found_name_to_use then objs = minetest.get_objects_inside_radius(pos, 0.5) end if objs then for _, obj in ipairs(objs) do if obj and obj:get_luaentity() then - if obj:get_luaentity().name == "mcl_itemframes:item" then + local obj_name = obj:get_luaentity().name + if obj_name == "mcl_itemframes:item" or obj_name == "mcl_itemframes:glow_item" then mcl_itemframes.update_item_entity(pos, node, (node.param2 + 1) % 4) break - end - if obj:get_luaentity().name == "mcl_itemframes:glow_item_frame" then - mcl_itemframes.update_item_glow_entity(pos, node, (node.param2 + 1) % 4) + elseif obj_name == found_name_to_use .. "_item" then + mcl_itemframes.update_generic_item_entity(pos, node, (node.param2 + 1) % 4) break end end @@ -351,13 +480,32 @@ mcl_itemframes.item_frame_base = { end, } -function mcl_itemframes.create_item_entity() +local function update_map_texture (self, staticdata) + self.id = staticdata + local result = true + result = mcl_maps.load_map(self.id, function(texture) + -- will not crash even if self.object is invalid by now + -- update... quite possibly will screw up with each version of Minetest. >.< + if not texture then + minetest.log("error", "Failed to load the map texture using mcl_maps.") + end + + self.object:set_properties({ textures = { texture } }) + end) + if result ~= nil and result == false then + mintest.log("error", "[mcl_itemframes] Error setting up Map Item.") + end + +end + +--- reworked to set up the base item definitions, and to register them for item and glow_item. +function mcl_itemframes.create_base_item_entity() if 1 == 1 then minetest.log("action", "[mcl_itemframes] create_item_entity.") end --"mcl_itemframes:item", - local frame_item = { + frame_item_base = { hp_max = 1, visual = "wielditem", visual_size = { x = VISUAL_SIZE, y = VISUAL_SIZE }, @@ -408,7 +556,7 @@ function mcl_itemframes.create_item_entity() end, } -- "mcl_itemframes:map", - local map_item = { + map_item_base = { initial_properties = { visual = "upright_sprite", visual_size = { x = 1, y = 1 }, @@ -418,31 +566,53 @@ function mcl_itemframes.create_item_entity() textures = { "blank.png" }, }, on_activate = function(self, staticdata) - self.id = staticdata - mcl_maps.load_map(self.id, function(texture) - -- will not crash even if self.object is invalid by now - self.object:set_properties({ textures = { texture } }) - end) + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] map_item:on_activate.") + + end + update_map_texture(self, staticdata) end, + get_staticdata = function(self) return self.id end, } - local glow_frame_item = table.copy(frame_item) + local glow_frame_item = table.copy(frame_item_base) glow_frame_item.glow = glow_amount - glow_frame_item.name = "mcl_itemframes:glow_item" - local glow_frame_map_item = table.copy(map_item) - glow_frame_map_item.glow = glow_amount + local glow_frame_map_item = table.copy(map_item_base) glow_frame_map_item.name = "mcl_itemframes:glow_map" minetest.register_entity("mcl_itemframes:glow_item", glow_frame_item) minetest.register_entity("mcl_itemframes:glow_map", glow_frame_map_item) - minetest.register_entity("mcl_itemframes:item", frame_item) - minetest.register_entity("mcl_itemframes:map", map_item) + minetest.register_entity("mcl_itemframes:item", frame_item_base) + minetest.register_entity("mcl_itemframes:map", map_item_base) end -mcl_itemframes.create_item_entity() + +function mcl_itemframes.create_custom_items(name, has_glow) + + if has_glow then + local glow_frame_item = table.copy(frame_item_base) + local glow_frame_map_item = table.copy(map_item_base) + glow_frame_map_item.glow = glow_amount + glow_frame_item.glow = glow_amount + + minetest.register_entity(name .. "_item", glow_frame_item) + minetest.register_entity(name .. "_map", glow_frame_map_item) + if 1 == 1 then + minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_item") + minetest.log("action", "[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_map\n") + end + else + minetest.register_entity(name .. "_item", frame_item_base) + minetest.register_entity(name .. "_map", map_item_base) + if 1 == 1 then + minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: name: " .. name .. "_item") + minetest.log("action", "[mcl_itemframes] create_custom_item_entity: name: " .. name .. "_map\n") + end + end +end function mcl_itemframes.update_frame_registry(modname, name, has_glow) local mod_name_pass = false @@ -455,10 +625,7 @@ function mcl_itemframes.update_frame_registry(modname, name, has_glow) end end - mcl_itemframes.frames_registered.glowing = {} - mcl_itemframes.frames_registered.standard = {} - - local frame = "mcl_itemframes:" .. name + local frame = name -- should only be called within the create_frames functions. if has_glow == true then table.insert(mcl_itemframes.frames_registered.glowing, frame) else @@ -467,6 +634,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) local mod_name_pass = false if modname ~= "" and modname ~= "false" then @@ -490,6 +659,16 @@ function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, colo return end + local working_name = "mcl_itemframes:" .. name + + if 1 == 1 then + minetest.log("action", "[mcl_itemframes] create_custom_frame: " .. working_name) + minetest.log("action", "[mcl_itemframes] create_custom_frame - calling create_custom_items " .. working_name) + end + + -- make any special frame items. + mcl_itemframes.create_custom_items(working_name, has_glow) + local custom_itemframe_definition = {} if has_glow == false then @@ -500,9 +679,44 @@ function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, colo custom_itemframe_definition.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" } custom_itemframe_definition._tt_help = ttframe - custom_itemframe_definition.description=description - mcl_itemframes.update_frame_registry(modname, name, has_glow) - mcl_itemframes.create_register_lbm(name, has_glow) + custom_itemframe_definition.description = description + + 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) + +end + +-- the local version is for the base glow & base frame. +local function create_register_lbm(name) + + -- FIXME: Item entities can get destroyed by /clearobjects + -- glow frame + minetest.register_lbm({ + label = "Respawn item frame item entities", + name = "mcl_itemframes:respawn_entities", + nodenames = { name }, + run_at_every_load = true, + action = function(pos, node) + mcl_itemframes.update_item_entity(pos, node) + end, + }) + +end +function mcl_itemframes.custom_register_lbm(name) + + -- FIXME: Item entities can get destroyed by /clearobjects + -- glow frame + minetest.register_lbm({ + label = "Respawn item frame item entities", + name = "mcl_itemframes:respawn_entities", + nodenames = { name }, + run_at_every_load = true, + action = function(pos, node) + mcl_itemframes.update_generic_item_entity(pos, node) + end, + }) end @@ -511,6 +725,9 @@ function mcl_itemframes.create_base_frames() minetest.log("action", "[mcl_itemframes] create_frames.") end + -- make the base items for the base frames. + mcl_itemframes.create_base_item_entity() + minetest.register_node("mcl_itemframes:item_frame", mcl_itemframes.item_frame_base) -- make glow frame from the base item_frame. @@ -534,7 +751,7 @@ function mcl_itemframes.create_base_frames() stack:set_name(new_name) inv:set_stack("main", 1, stack) local node = minetest.get_node(pos) - mcl_itemframes.update_item_glow_entity(pos, node, node.param2) + mcl_itemframes.update_item_entity(pos, node, node.param2) end minetest.get_node_timer(pos):start(1.0) end @@ -542,29 +759,9 @@ function mcl_itemframes.create_base_frames() minetest.register_node("mcl_itemframes:glow_item_frame", mcl_itemframes.glow_frame_base) - mcl_itemframes.update_frame_registry("false", "item_frame", false) - mcl_itemframes.update_frame_registry("false", "glow_item_frame", true) - mcl_itemframes.create_register_lbm("item_frame", false) - mcl_itemframes.create_register_lbm("glow_item_frame", true) -end - -function mcl_itemframes.create_register_lbm(name, has_glow) - - -- FIXME: Item entities can get destroyed by /clearobjects - -- glow frame - minetest.register_lbm({ - label = "Respawn item frame item entities", - name = "mcl_itemframes:respawn_entities", - nodenames = { "mcl_itemframes:" .. name }, - run_at_every_load = true, - action = function(pos, node) - if has_glow == true then - mcl_itemframes.update_item_glow_entity(pos, node) - else - mcl_itemframes.update_item_entity(pos, node) - end - end, - }) - + mcl_itemframes.update_frame_registry("false", "mcl_itemframes:item_frame", false) + mcl_itemframes.update_frame_registry("false", "mcl_itemframes:glow_item_frame", true) + create_register_lbm("mcl_itemframes:item_frame") + create_register_lbm("mcl_itemframes:glow_item_frame") end From 6d1b1b3c742b6036d09d40a2a89ce667d793292a Mon Sep 17 00:00:00 2001 From: Michieal Date: Tue, 1 Nov 2022 00:57:04 +0000 Subject: [PATCH 06/14] Added a return code to load_maps Added a return code to load_maps to check for if dynamic_add_media registers a fail. Used by mcl_itemframes when reloading a map placed into an itemframe. --- mods/ITEMS/mcl_maps/init.lua | 550 ++++++++++++++++++----------------- 1 file changed, 283 insertions(+), 267 deletions(-) diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index 09dcd4f95..87d7dc452 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -22,11 +22,14 @@ local map_textures_path = worldpath .. "/mcl_maps/" minetest.mkdir(map_textures_path) +-- overwrite the builtin tga_encoder +dofile(modpath .. "/tga_encoder_init.lua") + local function load_json_file(name) - local file = assert(io.open(modpath .. "/" .. name .. ".json", "r")) - local data = minetest.parse_json(file:read()) - file:close() - return data + local file = assert(io.open(modpath .. "/" .. name .. ".json", "r")) + local data = minetest.parse_json(file:read()) + file:close() + return data end local texture_colors = load_json_file("colors") @@ -40,180 +43,193 @@ local loaded_maps = {} local c_air = minetest.get_content_id("air") function mcl_maps.create_map(pos) - local minp = vector.multiply(vector.floor(vector.divide(pos, 128)), 128) - local maxp = vector.add(minp, vector.new(127, 127, 127)) + local minp = vector.multiply(vector.floor(vector.divide(pos, 128)), 128) + local maxp = vector.add(minp, vector.new(127, 127, 127)) - local itemstack = ItemStack("mcl_maps:filled_map") - local meta = itemstack:get_meta() - local next_id = storage:get_int("next_id") - storage:set_int("next_id", next_id + 1) - local id = tostring(next_id) - meta:set_string("mcl_maps:id", id) - meta:set_string("mcl_maps:minp", pos_to_string(minp)) - meta:set_string("mcl_maps:maxp", pos_to_string(maxp)) - tt.reload_itemstack_description(itemstack) + local itemstack = ItemStack("mcl_maps:filled_map") + local meta = itemstack:get_meta() + local next_id = storage:get_int("next_id") + storage:set_int("next_id", next_id + 1) + local id = tostring(next_id) + meta:set_string("mcl_maps:id", id) + meta:set_string("mcl_maps:minp", pos_to_string(minp)) + meta:set_string("mcl_maps:maxp", pos_to_string(maxp)) + tt.reload_itemstack_description(itemstack) - creating_maps[id] = true - minetest.emerge_area(minp, maxp, function(blockpos, action, calls_remaining) - if calls_remaining > 0 then - return - end - local vm = minetest.get_voxel_manip() - local emin, emax = vm:read_from_map(minp, maxp) - local data = vm:get_data() - local param2data = vm:get_param2_data() - local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) - local pixels = {} - local last_heightmap - for x = 1, 128 do - local map_x = minp.x - 1 + x - local heightmap = {} - for z = 1, 128 do - local map_z = minp.z - 1 + z - local color, height - for map_y = maxp.y, minp.y, -1 do - local index = area:index(map_x, map_y, map_z) - local c_id = data[index] - if c_id ~= c_air then - color = color_cache[c_id] - if color == nil then - local nodename = minetest.get_name_from_content_id(c_id) - local def = minetest.registered_nodes[nodename] - if def then - local texture - if def.palette then - texture = def.palette - elseif def.tiles then - texture = def.tiles[1] - if type(texture) == "table" then - texture = texture.name - end - end - if texture then - texture = texture:match("([^=^%^]-([^.]+))$"):split("^")[1] - end - if def.palette then - local palette = palettes[texture] - color = palette and {palette = palette} - else - color = texture_colors[texture] - end - end - end + creating_maps[id] = true + minetest.emerge_area(minp, maxp, function(blockpos, action, calls_remaining) + if calls_remaining > 0 then + return + end + local vm = minetest.get_voxel_manip() + local emin, emax = vm:read_from_map(minp, maxp) + local data = vm:get_data() + local param2data = vm:get_param2_data() + local area = VoxelArea:new({ MinEdge = emin, MaxEdge = emax }) + local pixels = {} + local last_heightmap + for x = 1, 128 do + local map_x = minp.x - 1 + x + local heightmap = {} + for z = 1, 128 do + local map_z = minp.z - 1 + z + local color, height + for map_y = maxp.y, minp.y, -1 do + local index = area:index(map_x, map_y, map_z) + local c_id = data[index] + if c_id ~= c_air then + color = color_cache[c_id] + if color == nil then + local nodename = minetest.get_name_from_content_id(c_id) + local def = minetest.registered_nodes[nodename] + if def then + local texture + if def.palette then + texture = def.palette + elseif def.tiles then + texture = def.tiles[1] + if type(texture) == "table" then + texture = texture.name + end + end + if texture then + texture = texture:match("([^=^%^]-([^.]+))$"):split("^")[1] + end + if def.palette then + local palette = palettes[texture] + color = palette and { palette = palette } + else + color = texture_colors[texture] + end + end + end - if color and color.palette then - color = color.palette[param2data[index] + 1] - else - color_cache[c_id] = color or false - end + if color and color.palette then + color = color.palette[param2data[index] + 1] + else + color_cache[c_id] = color or false + end - if color and last_heightmap then - local last_height = last_heightmap[z] - if last_height < map_y then - color = { - math.min(255, color[1] + 16), - math.min(255, color[2] + 16), - math.min(255, color[3] + 16), - } - elseif last_height > map_y then - color = { - math.max(0, color[1] - 16), - math.max(0, color[2] - 16), - math.max(0, color[3] - 16), - } - end - end - height = map_y - break - end - end - heightmap[z] = height or minp.y - pixels[z] = pixels[z] or {} - pixels[z][x] = color or {0, 0, 0} - end - last_heightmap = heightmap - end - tga_encoder.image(pixels):save(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".tga") - creating_maps[id] = nil - end) - return itemstack + if color and last_heightmap then + local last_height = last_heightmap[z] + if last_height < map_y then + color = { + math.min(255, color[1] + 16), + math.min(255, color[2] + 16), + math.min(255, color[3] + 16), + } + elseif last_height > map_y then + color = { + math.max(0, color[1] - 16), + math.max(0, color[2] - 16), + math.max(0, color[3] - 16), + } + end + end + height = map_y + break + end + end + heightmap[z] = height or minp.y + pixels[z] = pixels[z] or {} + pixels[z][x] = color or { 0, 0, 0 } + end + last_heightmap = heightmap + end + tga_encoder.image(pixels):save(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".tga") + creating_maps[id] = nil + end) + return itemstack end function mcl_maps.load_map(id, callback) - if id == "" or creating_maps[id] then - return - end + if id == "" or creating_maps[id] then + return false + end - local texture = "mcl_maps_map_texture_" .. id .. ".tga" + local texture = "mcl_maps_map_texture_" .. id .. ".tga" - if not loaded_maps[id] then - if not minetest.features.dynamic_add_media_table then - -- minetest.dynamic_add_media() blocks in - -- Minetest 5.3 and 5.4 until media loads - loaded_maps[id] = true - dynamic_add_media(map_textures_path .. texture, function() end) - if callback then callback(texture) end - else - -- minetest.dynamic_add_media() never blocks - -- in Minetest 5.5, callback runs after load - dynamic_add_media(map_textures_path .. texture, function() - loaded_maps[id] = true - if callback then callback(texture) end - end) - end - end + local result = true - if loaded_maps[id] then - if callback then callback(texture) end - return texture - end + if not loaded_maps[id] then + if not minetest.features.dynamic_add_media_table then + -- minetest.dynamic_add_media() blocks in + -- Minetest 5.3 and 5.4 until media loads + loaded_maps[id] = true + result = dynamic_add_media(map_textures_path .. texture, function() + end) + if callback then + callback(texture) + end + else + -- minetest.dynamic_add_media() never blocks + -- in Minetest 5.5, callback runs after load + result = dynamic_add_media(map_textures_path .. texture, function() + loaded_maps[id] = true + if callback then + callback(texture) + end + end) + end + end + + if result == false then + return false + end + + if loaded_maps[id] then + if callback then + callback(texture) + end + return texture + end end function mcl_maps.load_map_item(itemstack) - return mcl_maps.load_map(itemstack:get_meta():get_string("mcl_maps:id")) + return mcl_maps.load_map(itemstack:get_meta():get_string("mcl_maps:id")) end local function fill_map(itemstack, placer, pointed_thing) - local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing) - if new_stack then - return new_stack - end + local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing) + if new_stack then + return new_stack + end - if minetest.settings:get_bool("enable_real_maps", true) then - local new_map = mcl_maps.create_map(placer:get_pos()) - itemstack:take_item() - if itemstack:is_empty() then - return new_map - else - local inv = placer:get_inventory() - if inv:room_for_item("main", new_map) then - inv:add_item("main", new_map) - else - minetest.add_item(placer:get_pos(), new_map) - end - return itemstack - end - end + if minetest.settings:get_bool("enable_real_maps", true) then + local new_map = mcl_maps.create_map(placer:get_pos()) + itemstack:take_item() + if itemstack:is_empty() then + return new_map + else + local inv = placer:get_inventory() + if inv:room_for_item("main", new_map) then + inv:add_item("main", new_map) + else + minetest.add_item(placer:get_pos(), new_map) + end + return itemstack + end + end end minetest.register_craftitem("mcl_maps:empty_map", { - description = S("Empty Map"), - _doc_items_longdesc = S("Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used."), - _doc_items_usagehelp = S("Rightclick to create a filled map (which can't be stacked anymore)."), - inventory_image = "mcl_maps_map_empty.png", - on_place = fill_map, - on_secondary_use = fill_map, - stack_max = 64, + description = S("Empty Map"), + _doc_items_longdesc = S("Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used."), + _doc_items_usagehelp = S("Rightclick to create a filled map (which can't be stacked anymore)."), + inventory_image = "mcl_maps_map_empty.png", + on_place = fill_map, + on_secondary_use = fill_map, + stack_max = 64, }) local filled_def = { - description = S("Map"), - _tt_help = S("Shows a map image."), - _doc_items_longdesc = S("When created, the map saves the nearby area as an image that can be viewed any time by holding the map."), - _doc_items_usagehelp = S("Hold the map in your hand. This will display a map on your screen."), - inventory_image = "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)", - stack_max = 64, - groups = {not_in_creative_inventory = 1, filled_map = 1, tool = 1}, + description = S("Map"), + _tt_help = S("Shows a map image."), + _doc_items_longdesc = S("When created, the map saves the nearby area as an image that can be viewed any time by holding the map."), + _doc_items_usagehelp = S("Hold the map in your hand. This will display a map on your screen."), + inventory_image = "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)", + stack_max = 64, + groups = { not_in_creative_inventory = 1, filled_map = 1, tool = 1 }, } minetest.register_craftitem("mcl_maps:filled_map", filled_def) @@ -221,7 +237,7 @@ minetest.register_craftitem("mcl_maps:filled_map", filled_def) local filled_wield_def = table.copy(filled_def) filled_wield_def.use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false filled_wield_def.visual_scale = 1 -filled_wield_def.wield_scale = {x = 1, y = 1, z = 1} +filled_wield_def.wield_scale = { x = 1, y = 1, z = 1 } filled_wield_def.paramtype = "light" filled_wield_def.drawtype = "mesh" filled_wield_def.node_placement_prediction = "" @@ -232,72 +248,72 @@ filled_wield_def._mcl_wieldview_item = "mcl_maps:filled_map" local mcl_skins_enabled = minetest.global_exists("mcl_skins") if mcl_skins_enabled then - -- Generate a node for every skin - local list = mcl_skins.get_skin_list() - for _, skin in pairs(list) do - if skin.slim_arms then - local female = table.copy(filled_wield_def) - female._mcl_hand_id = skin.id - female.mesh = "mcl_meshhand_female.b3d" - female.tiles = {skin.texture} - minetest.register_node("mcl_maps:filled_map_" .. skin.id, female) - else - local male = table.copy(filled_wield_def) - male._mcl_hand_id = skin.id - male.mesh = "mcl_meshhand.b3d" - male.tiles = {skin.texture} - minetest.register_node("mcl_maps:filled_map_" .. skin.id, male) - end - end + -- Generate a node for every skin + local list = mcl_skins.get_skin_list() + for _, skin in pairs(list) do + if skin.slim_arms then + local female = table.copy(filled_wield_def) + female._mcl_hand_id = skin.id + female.mesh = "mcl_meshhand_female.b3d" + female.tiles = { skin.texture } + minetest.register_node("mcl_maps:filled_map_" .. skin.id, female) + else + local male = table.copy(filled_wield_def) + male._mcl_hand_id = skin.id + male.mesh = "mcl_meshhand.b3d" + male.tiles = { skin.texture } + minetest.register_node("mcl_maps:filled_map_" .. skin.id, male) + end + end else - filled_wield_def._mcl_hand_id = "hand" - filled_wield_def.mesh = "mcl_meshhand.b3d" - filled_wield_def.tiles = {"character.png"} - minetest.register_node("mcl_maps:filled_map_hand", filled_wield_def) + filled_wield_def._mcl_hand_id = "hand" + filled_wield_def.mesh = "mcl_meshhand.b3d" + filled_wield_def.tiles = { "character.png" } + minetest.register_node("mcl_maps:filled_map_hand", filled_wield_def) end local old_add_item = minetest.add_item function minetest.add_item(pos, stack) - stack = ItemStack(stack) - if get_item_group(stack:get_name(), "filled_map") > 0 then - stack:set_name("mcl_maps:filled_map") - end - return old_add_item(pos, stack) + stack = ItemStack(stack) + if get_item_group(stack:get_name(), "filled_map") > 0 then + stack:set_name("mcl_maps:filled_map") + end + return old_add_item(pos, stack) end tt.register_priority_snippet(function(itemstring, _, itemstack) - if itemstack and get_item_group(itemstring, "filled_map") > 0 then - local id = itemstack:get_meta():get_string("mcl_maps:id") - if id ~= "" then - return "#" .. id, mcl_colors.GRAY - end - end + if itemstack and get_item_group(itemstring, "filled_map") > 0 then + local id = itemstack:get_meta():get_string("mcl_maps:id") + if id ~= "" then + return "#" .. id, mcl_colors.GRAY + end + end end) minetest.register_craft({ - output = "mcl_maps:empty_map", - recipe = { - { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, - { "mcl_core:paper", "group:compass", "mcl_core:paper" }, - { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, - } + output = "mcl_maps:empty_map", + recipe = { + { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, + { "mcl_core:paper", "group:compass", "mcl_core:paper" }, + { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, + } }) minetest.register_craft({ - type = "shapeless", - output = "mcl_maps:filled_map 2", - recipe = {"group:filled_map", "mcl_maps:empty_map"}, + type = "shapeless", + output = "mcl_maps:filled_map 2", + recipe = { "group:filled_map", "mcl_maps:empty_map" }, }) local function on_craft(itemstack, player, old_craft_grid, craft_inv) - if itemstack:get_name() == "mcl_maps:filled_map" then - for _, stack in pairs(old_craft_grid) do - if get_item_group(stack:get_name(), "filled_map") > 0 then - itemstack:get_meta():from_table(stack:get_meta():to_table()) - return itemstack - end - end - end + if itemstack:get_name() == "mcl_maps:filled_map" then + for _, stack in pairs(old_craft_grid) do + if get_item_group(stack:get_name(), "filled_map") > 0 then + itemstack:get_meta():from_table(stack:get_meta():to_table()) + return itemstack + end + end + end end minetest.register_on_craft(on_craft) @@ -307,80 +323,80 @@ local maps = {} local huds = {} minetest.register_on_joinplayer(function(player) - local map_def = { - hud_elem_type = "image", - text = "blank.png", - position = {x = 0.75, y = 0.8}, - alignment = {x = 0, y = -1}, - offset = {x = 0, y = 0}, - scale = {x = 2, y = 2}, - } - local marker_def = table.copy(map_def) - marker_def.alignment = {x = 0, y = 0} - huds[player] = { - map = player:hud_add(map_def), - marker = player:hud_add(marker_def), - } + local map_def = { + hud_elem_type = "image", + text = "blank.png", + position = { x = 0.75, y = 0.8 }, + alignment = { x = 0, y = -1 }, + offset = { x = 0, y = 0 }, + scale = { x = 2, y = 2 }, + } + local marker_def = table.copy(map_def) + marker_def.alignment = { x = 0, y = 0 } + huds[player] = { + map = player:hud_add(map_def), + marker = player:hud_add(marker_def), + } end) minetest.register_on_leaveplayer(function(player) - maps[player] = nil - huds[player] = nil + maps[player] = nil + huds[player] = nil end) minetest.register_globalstep(function(dtime) - for _, player in pairs(get_connected_players()) do - local wield = player:get_wielded_item() - local texture = mcl_maps.load_map_item(wield) - local hud = huds[player] - if texture then - local wield_def = wield:get_definition() - local hand_def = player:get_inventory():get_stack("hand", 1):get_definition() + for _, player in pairs(get_connected_players()) do + local wield = player:get_wielded_item() + local texture = mcl_maps.load_map_item(wield) + local hud = huds[player] + if texture then + local wield_def = wield:get_definition() + local hand_def = player:get_inventory():get_stack("hand", 1):get_definition() - if hand_def and wield_def and hand_def._mcl_hand_id ~= wield_def._mcl_hand_id then - wield:set_name("mcl_maps:filled_map_" .. hand_def._mcl_hand_id) - player:set_wielded_item(wield) - end + if hand_def and wield_def and hand_def._mcl_hand_id ~= wield_def._mcl_hand_id then + wield:set_name("mcl_maps:filled_map_" .. hand_def._mcl_hand_id) + player:set_wielded_item(wield) + end - if texture ~= maps[player] then - player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture) - maps[player] = texture - end + if texture ~= maps[player] then + player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture) + maps[player] = texture + end - local pos = vector.round(player:get_pos()) - local meta = wield:get_meta() - local minp = string_to_pos(meta:get_string("mcl_maps:minp")) - local maxp = string_to_pos(meta:get_string("mcl_maps:maxp")) + local pos = vector.round(player:get_pos()) + local meta = wield:get_meta() + local minp = string_to_pos(meta:get_string("mcl_maps:minp")) + local maxp = string_to_pos(meta:get_string("mcl_maps:maxp")) - local marker = "mcl_maps_player_arrow.png" + local marker = "mcl_maps_player_arrow.png" - if pos.x < minp.x then - marker = "mcl_maps_player_dot.png" - pos.x = minp.x - elseif pos.x > maxp.x then - marker = "mcl_maps_player_dot.png" - pos.x = maxp.x - end + if pos.x < minp.x then + marker = "mcl_maps_player_dot.png" + pos.x = minp.x + elseif pos.x > maxp.x then + marker = "mcl_maps_player_dot.png" + pos.x = maxp.x + end - if pos.z < minp.z then - marker = "mcl_maps_player_dot.png" - pos.z = minp.z - elseif pos.z > maxp.z then - marker = "mcl_maps_player_dot.png" - pos.z = maxp.z - end + if pos.z < minp.z then + marker = "mcl_maps_player_dot.png" + pos.z = minp.z + elseif pos.z > maxp.z then + marker = "mcl_maps_player_dot.png" + pos.z = maxp.z + end - if marker == "mcl_maps_player_arrow.png" then - local yaw = (math.floor(player:get_look_horizontal() * 180 / math.pi / 90 + 0.5) % 4) * 90 - marker = marker .. "^[transformR" .. yaw - end + if marker == "mcl_maps_player_arrow.png" then + local yaw = (math.floor(player:get_look_horizontal() * 180 / math.pi / 90 + 0.5) % 4) * 90 + marker = marker .. "^[transformR" .. yaw + end - player:hud_change(hud.marker, "text", marker) - player:hud_change(hud.marker, "offset", {x = (6 - 140 / 2 + pos.x - minp.x) * 2, y = (6 - 140 + maxp.z - pos.z) * 2}) - elseif maps[player] then - player:hud_change(hud.map, "text", "blank.png") - player:hud_change(hud.marker, "text", "blank.png") - maps[player] = nil - end - end + player:hud_change(hud.marker, "text", marker) + player:hud_change(hud.marker, "offset", { x = (6 - 140 / 2 + pos.x - minp.x) * 2, y = (6 - 140 + maxp.z - pos.z) * 2 }) + elseif maps[player] then + player:hud_change(hud.map, "text", "blank.png") + player:hud_change(hud.marker, "text", "blank.png") + maps[player] = nil + end + end end) From 8a21b9e99ccac7c8fa7835bed46c9949cb1aa747 Mon Sep 17 00:00:00 2001 From: Michieal Date: Tue, 1 Nov 2022 02:59:07 +0000 Subject: [PATCH 07/14] Changed detection code custom frames. todo: figure out why the standard item frame is using the wrong item entities. todo: fix screwdriver rotating the item displayed. --- mods/ITEMS/mcl_itemframes/item_frames_API.lua | 165 +++++++++++------- 1 file changed, 106 insertions(+), 59 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua index b3ba16384..334d29a63 100644 --- a/mods/ITEMS/mcl_itemframes/item_frames_API.lua +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -15,6 +15,8 @@ local S = minetest.get_translator(minetest.get_current_modname()) local table = table local DEBUG = false +local pairs = pairs + if 1 == 1 then minetest.log("action", "[mcl_itemframes] API initialized.") end @@ -32,23 +34,43 @@ local frame_item_base = {} local map_item_base = {} local remove_item_entity = function(pos, node) - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then + + local name_found = false + local found_name_to_use = "" + + for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + + -- try to cut down on excess looping, if possible. + if name_found == false then + for k,v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + end + + if 1==1 then + minetest.log("action","mcl_itemframes] remove_item_entity: " .. found_name_to_use .. "'s displayed item." ) + end + + if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" or node.name == found_name_to_use then for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do local entity = obj:get_luaentity() - - if 1 == 1 then - if entity then - minetest.log("action", "[mcl_itemframes] Remove_Entity: Attempting to remove Entity Named: " .. entity.name) - else - minetest.log("action", "[mcl_itemframes] Remove_Entity: Attempting to remove Entity Named: entity not found.\n can be a false positive.") - end - end - if entity then if entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:map" or entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:glow_map" then - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Remove_Entity: Removing Entity Named: " .. entity.name) + obj:remove() + elseif entity.name == found_name_to_use .. "_item" or entity.name == found_name_to_use .. "_map" then + if 1==1 then + minetest.log("action","mcl_itemframes] remove_item_entity: " .. entity.name .. "-- the item." ) end obj:remove() end @@ -124,42 +146,53 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local item = inv:get_stack("main", 1) + + local name_found = false + local found_name_to_use = "" + local has_glow = false + + for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + has_glow = true + found_name_to_use = v + break + end + end + + -- try to cut down on excess looping, if possible. + if name_found == false then + for k,v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + has_glow = false + found_name_to_use = v + break + end + end + end + + if name_found == false then + minetest.log("error","[mcl_itemframes] Update_Generic_Item:\nFailed to find registered node:\nNode name - " .. node.name) + minetest.log("error","[mcl_itemframes] Update_Generic_Item:\nRegistry definition:" .. dump(mcl_itemframes.frames_registered)) + return + end + if not item:is_empty() then -- update existing items placed. if not param2 then param2 = node.param2 end - - local name_found = false - local found_name_to_use = "" - local has_glow = false - - for gl = 1, #mcl_itemframes.frames_registered.glowing do - if node.name == mcl_itemframes.frames_registered.glowing[gl] then - name_found = true - has_glow = true - found_name_to_use = mcl_itemframes.frames_registered.glowing[gl] - break - end - end - - -- try to cut down on excess looping, if possible. - if name_found == false then - for ngl = 1, #mcl_itemframes.frames_registered.standard do - if node.name == mcl_itemframes.frames_registered.glowing[ngl] then - name_found = true - has_glow = false - found_name_to_use = mcl_itemframes.frames_registered.glowing[ngl] - break - end - end - end + local pos_adj = facedir[param2] if node.name == found_name_to_use then - local pos_adj = facedir[param2] pos.x = pos.x + pos_adj.x * 6.5 / 16 pos.y = pos.y + pos_adj.y * 6.5 / 16 pos.z = pos.z + pos_adj.z * 6.5 / 16 + + if 1 == 1 then + minetest.log("[mcl_itemframes] Update_Generic_Item:\nFound Name in Registry: " .. found_name_to_use) + end end local yaw = pi * 2 - param2 * pi / 2 local map_id = item:get_meta():get_string("mcl_maps:id") @@ -171,14 +204,18 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) if 1 == 1 then minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nAdding entity: " .. node.name .. "_item") end - map_id_entity = minetest.add_entity(pos, node.name .. "_item") - map_id_lua = map_id_entity:get_luaentity() + if node.name == found_name_to_use then + map_id_entity = minetest.add_entity(pos, node.name .. "_item") + else + local debugs_string = "[mcl_itemframes] Update_Generic_Item:\nCouldn't find node name in registry: " + minetest.log("error", debugs_string .. found_name_to_use "\nregistry: " .. dump(mcl_itemframes.frames_registered)) - map_id_lua._nodename = node.name - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Update_Generic_Item: Adding entity: " .. map_id_lua.name) + return end + map_id_lua = map_id_entity:get_luaentity() + map_id_lua._nodename = node.name + local itemname = item:get_name() if itemname == "" or itemname == nil then map_id_lua._texture = "blank.png" @@ -195,13 +232,22 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) minetest.log("action", "[mcl_itemframes] Update_Generic_Item: item's name: " .. itemname) end map_id_lua:_update_texture() - map_id_entity:set_yaw(yaw) + if node.name == found_name_to_use then + map_id_entity:set_yaw(yaw) + else + minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Display Item's yaw. " .. node.name) + end else -- handle map items placed into custom frame. - map_id_entity = minetest.add_entity(pos, found_name_to_use .. "_map", map_id) - map_id_entity:set_yaw(yaw) if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Placing map in a " .. found_name_to_use .. " frame.") + minetest.log("action", "[mcl_itemframes] Update_Generic_Item: Placing map in a " .. found_name_to_use .. " frame.") + end + + if node.name == found_name_to_use then + map_id_entity = minetest.add_entity(pos, found_name_to_use .. "_map", map_id) + map_id_entity:set_yaw(yaw) + else + minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Map Item in " .. found_name_to_use .. "'s frame.") end end end @@ -230,20 +276,20 @@ function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) local name_found = false local found_name_to_use = "" - for gl = 1, #mcl_itemframes.frames_registered.glowing do - if node.name == mcl_itemframes.frames_registered.glowing[gl] then + for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then name_found = true - found_name_to_use = mcl_itemframes.frames_registered.glowing[gl] + found_name_to_use = v break end end -- try to cut down on excess looping, if possible. if name_found == false then - for ngl = 1, #mcl_itemframes.frames_registered.standard do - if node.name == mcl_itemframes.frames_registered.glowing[ngl] then + for k,v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then name_found = true - found_name_to_use = mcl_itemframes.frames_registered.glowing[ngl] + found_name_to_use = v break end end @@ -438,24 +484,25 @@ mcl_itemframes.item_frame_base = { local name_found = false local found_name_to_use = "" - for gl = 1, #mcl_itemframes.frames_registered.glowing do - if node.name == mcl_itemframes.frames_registered.glowing[gl] then + for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then name_found = true - found_name_to_use = mcl_itemframes.frames_registered.glowing[gl] + found_name_to_use = v break end end -- try to cut down on excess looping, if possible. if name_found == false then - for ngl = 1, #mcl_itemframes.frames_registered.standard do - if node.name == mcl_itemframes.frames_registered.glowing[ngl] then + for k,v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then name_found = true - found_name_to_use = mcl_itemframes.frames_registered.glowing[ngl] + found_name_to_use = v break end end end + if node.name == found_name_to_use then objs = minetest.get_objects_inside_radius(pos, 0.5) end From 18e83e576351c312b50459c99c6f015b870cf501 Mon Sep 17 00:00:00 2001 From: Michieal Date: Wed, 2 Nov 2022 06:14:09 +0000 Subject: [PATCH 08/14] Added in display item rotation Updated the Readme. Added in the ability to rotate the displayed item with a screwdriver. Made the Screwdriver mod required, due to rotating the item being fundamental behavoir. Finalized a few bug fixes... still have to remove the all of the forced debug code, and move the item frames and glow frames over to the new api, and do a final test. --- mods/ITEMS/mcl_itemframes/README.txt | 11 +- mods/ITEMS/mcl_itemframes/item_frames_API.lua | 223 ++++++++++++------ mods/ITEMS/mcl_itemframes/mod.conf | 3 +- 3 files changed, 158 insertions(+), 79 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/README.txt b/mods/ITEMS/mcl_itemframes/README.txt index d9514a03b..c2756a1c9 100644 --- a/mods/ITEMS/mcl_itemframes/README.txt +++ b/mods/ITEMS/mcl_itemframes/README.txt @@ -1,4 +1,13 @@ -This mod is originally by Zeg9, but heavily modified for MineClone 2. +This mod has been rewritten and revamped by Michieal / Faerraven. Based on the code originally done by Zeg9, and then +heavily modified by the Mineclone 2 dev team. + +This mod now supports all the base item frame functions, like rotating the displayed item, which it didn't do before it +was rewritten. Additionally, Glow Frames have been added in, and item frames now has an API to allow new item frames to +be created in other modules. +Now requires the Screwdriver to have full functionality. + +The code is licenced under the standard MineClone 2 license for usage, with the requirement that this readme is +included in the code / module. Model created by 22i, licensed under the GNU GPLv3 . diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua index 334d29a63..43b4fd518 100644 --- a/mods/ITEMS/mcl_itemframes/item_frames_API.lua +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -33,12 +33,105 @@ local glow_amount = 6 -- LIGHT_MAX is 15, but the items aren't supposed to be a local frame_item_base = {} local map_item_base = {} +-- Time to Fleckenstein! (it just sounds cool lol) + +--- self: the object to roll. +local function update_roll(self, pos) + + -- get the entity's metadata. + local meta = minetest.get_meta(pos) + + -- using an integer, as it's the number of 45 degree turns. ie, 0 to 7 + local current_roll = meta:get_int("roll", 0) + local new_roll = current_roll + 1 + + if new_roll == 8 then + new_roll = 0 + end + meta:set_int("roll", new_roll) + + local new_roll_deg = new_roll * 45 + + -- * `get_rotation()`: returns the rotation, a vector (radians) + local rot = self:get_rotation() + local Radians = 0 + + -- Radians = Degrees * (pi / 180) degrees to radian formula + -- Radian quick chart + -- One full revolution is equal to 2π rad (or) 360°. + -- 1° = 0.017453 radians and 1 rad = 57.2958°. + -- To convert an angle from degrees to radians, we multiply it by π/180°. + -- To convert an angle from radians to degrees, we multiply it by 180°/π. + + Radians = new_roll_deg * (pi / 180) + rot.z = Radians + + self:set_rotation(rot) + +end + +--- self: the object to roll. +--- faceDeg: 0-7, inclusive. +local function set_roll(self, faceDeg) + -- get the entity's metadata. + local meta = minetest.get_meta(self:get_pos()) + + -- using an integer, as it's the number of 45 degree turns. ie, 0 to 7 + local new_roll = faceDeg + + if new_roll >= 8 then + new_roll = 7 + end + if new_roll <= 0 then + new_roll = 0 + end + + meta:set_int("roll", new_roll) + + local new_roll_deg = new_roll * 45 + + -- * `get_rotation()`: returns the rotation, a vector (radians) + local rot = self:get_rotation() + local Radians = 0 + + -- Radians = Degrees * (pi / 180) degrees to radian formula + -- Radian quick chart + -- One full revolution is equal to 2π rad (or) 360°. + -- 1° = 0.017453 radians and 1 rad = 57.2958°. + -- To convert an angle from degrees to radians, we multiply it by π/180°. + -- To convert an angle from radians to degrees, we multiply it by 180°/π. + + Radians = new_roll_deg * (pi / 180) + + rot.z = Radians + + self:set_rotation(rot) +end + +local function update_map_texture (self, staticdata) + self.id = staticdata + local result = true + result = mcl_maps.load_map(self.id, function(texture) + -- will not crash even if self.object is invalid by now + -- update... quite possibly will screw up with each version of Minetest. >.< + if not texture then + minetest.log("error", "Failed to load the map texture using mcl_maps.") + end + + self.object:set_properties({ textures = { texture } }) + end) + if result ~= nil and result == false then + mintest.log("error", "[mcl_itemframes] Error setting up Map Item.") + end + +end + local remove_item_entity = function(pos, node) local name_found = false local found_name_to_use = "" - for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do if node.name == v then name_found = true found_name_to_use = v @@ -48,7 +141,7 @@ local remove_item_entity = function(pos, node) -- try to cut down on excess looping, if possible. if name_found == false then - for k,v in pairs(mcl_itemframes.frames_registered.standard) do + for k, v in pairs(mcl_itemframes.frames_registered.standard) do if node.name == v then name_found = true found_name_to_use = v @@ -57,8 +150,8 @@ local remove_item_entity = function(pos, node) end end - if 1==1 then - minetest.log("action","mcl_itemframes] remove_item_entity: " .. found_name_to_use .. "'s displayed item." ) + if 1 == 1 then + minetest.log("action", "mcl_itemframes] remove_item_entity: " .. found_name_to_use .. "'s displayed item.") end if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" or node.name == found_name_to_use then @@ -69,8 +162,8 @@ local remove_item_entity = function(pos, node) entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:glow_map" then obj:remove() elseif entity.name == found_name_to_use .. "_item" or entity.name == found_name_to_use .. "_map" then - if 1==1 then - minetest.log("action","mcl_itemframes] remove_item_entity: " .. entity.name .. "-- the item." ) + if 1 == 1 then + minetest.log("action", "mcl_itemframes] remove_item_entity: " .. entity.name .. "-- the item.") end obj:remove() end @@ -133,6 +226,11 @@ mcl_itemframes.update_item_entity = function(pos, node, param2) end map_id_entity:set_yaw(yaw) end + + -- finally, set the rotation (roll) of the displayed object. + local roll = meta:get_int("roll", 0) + set_roll(map_id_entity, roll) + end end @@ -151,7 +249,7 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) local found_name_to_use = "" local has_glow = false - for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do if node.name == v then name_found = true has_glow = true @@ -162,7 +260,7 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) -- try to cut down on excess looping, if possible. if name_found == false then - for k,v in pairs(mcl_itemframes.frames_registered.standard) do + for k, v in pairs(mcl_itemframes.frames_registered.standard) do if node.name == v then name_found = true has_glow = false @@ -173,8 +271,8 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) end if name_found == false then - minetest.log("error","[mcl_itemframes] Update_Generic_Item:\nFailed to find registered node:\nNode name - " .. node.name) - minetest.log("error","[mcl_itemframes] Update_Generic_Item:\nRegistry definition:" .. dump(mcl_itemframes.frames_registered)) + minetest.log("error", "[mcl_itemframes] Update_Generic_Item:\nFailed to find registered node:\nNode name - " .. node.name) + minetest.log("error", "[mcl_itemframes] Update_Generic_Item:\nRegistry definition:" .. dump(mcl_itemframes.frames_registered)) return end @@ -250,6 +348,10 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Map Item in " .. found_name_to_use .. "'s frame.") end end + + -- finally, set the rotation (roll) of the displayed object. + local roll = meta:get_int("roll", 0) + set_roll(map_id_entity, roll) end end @@ -269,6 +371,7 @@ local drop_item = function(pos, node, meta, clicker) end meta:set_string("infotext", "") + meta:set_int("roll", 0) remove_item_entity(pos, node) end @@ -276,7 +379,7 @@ function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) local name_found = false local found_name_to_use = "" - for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do if node.name == v then name_found = true found_name_to_use = v @@ -286,7 +389,7 @@ function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) -- try to cut down on excess looping, if possible. if name_found == false then - for k,v in pairs(mcl_itemframes.frames_registered.standard) do + for k, v in pairs(mcl_itemframes.frames_registered.standard) do if node.name == v then name_found = true found_name_to_use = v @@ -474,77 +577,64 @@ mcl_itemframes.item_frame_base = { end, on_rotate = function(pos, node, user, mode, param2) - if mode == screwdriver.ROTATE_FACE then - -- Rotate face - --local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) + --local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) - local objs = nil + local objs = nil + local name_found = false + local found_name_to_use = "" + name_found = false + found_name_to_use = "" - local name_found = false - local found_name_to_use = "" + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end - for k,v in pairs(mcl_itemframes.frames_registered.glowing) do + -- try to cut down on excess looping, if possible. + if name_found == false then + for k, v in pairs(mcl_itemframes.frames_registered.standard) do if node.name == v then name_found = true found_name_to_use = v break end end + end - -- try to cut down on excess looping, if possible. - if name_found == false then - for k,v in pairs(mcl_itemframes.frames_registered.standard) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end - end + if node.name == found_name_to_use then + objs = minetest.get_objects_inside_radius(pos, 0.5) + else + return -- short circuit if it's somehow not the right thing. + end - if node.name == found_name_to_use then - objs = minetest.get_objects_inside_radius(pos, 0.5) - end - if objs then + if objs then + if mode == screwdriver.ROTATE_FACE or mode == screwdriver.ROTATE_AXIS then for _, obj in ipairs(objs) do if obj and obj:get_luaentity() then local obj_name = obj:get_luaentity().name if obj_name == "mcl_itemframes:item" or obj_name == "mcl_itemframes:glow_item" then - mcl_itemframes.update_item_entity(pos, node, (node.param2 + 1) % 4) + if mode == screwdriver.ROTATE_AXIS then + update_roll(obj, pos) + end break elseif obj_name == found_name_to_use .. "_item" then - mcl_itemframes.update_generic_item_entity(pos, node, (node.param2 + 1) % 4) + if mode == screwdriver.ROTATE_AXIS then + update_roll(obj, pos) + end break end end end + return false end - return - elseif mode == screwdriver.ROTATE_AXIS then - return false end end, } -local function update_map_texture (self, staticdata) - self.id = staticdata - local result = true - result = mcl_maps.load_map(self.id, function(texture) - -- will not crash even if self.object is invalid by now - -- update... quite possibly will screw up with each version of Minetest. >.< - if not texture then - minetest.log("error", "Failed to load the map texture using mcl_maps.") - end - - self.object:set_properties({ textures = { texture } }) - end) - if result ~= nil and result == false then - mintest.log("error", "[mcl_itemframes] Error setting up Map Item.") - end - -end - --- reworked to set up the base item definitions, and to register them for item and glow_item. function mcl_itemframes.create_base_item_entity() if 1 == 1 then @@ -615,7 +705,6 @@ function mcl_itemframes.create_base_item_entity() on_activate = function(self, staticdata) if 1 == 1 then minetest.log("action", "[mcl_itemframes] map_item:on_activate.") - end update_map_texture(self, staticdata) end, @@ -787,23 +876,6 @@ function mcl_itemframes.create_base_frames() mcl_itemframes.glow_frame_base.wield_image = "mcl_itemframes_glow_item_frame.png" mcl_itemframes.glow_frame_base.mesh = "mcl_itemframes_glow_item_frame.obj" - --mcl_itemframes.glow_frame_base.light_source = minetest.LIGHT_MAX -- add in glow (a hack at best, but it's a node) TODO: make actual glow. - mcl_itemframes.glow_frame_base.on_timer = function(pos) - local inv = minetest.get_meta(pos):get_inventory() - local stack = inv:get_stack("main", 1) - local itemname = stack:get_name() - if minetest.get_item_group(itemname, "clock") > 0 then - local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) - if itemname ~= new_name then - stack:set_name(new_name) - inv:set_stack("main", 1, stack) - local node = minetest.get_node(pos) - mcl_itemframes.update_item_entity(pos, node, node.param2) - end - minetest.get_node_timer(pos):start(1.0) - end - end - minetest.register_node("mcl_itemframes:glow_item_frame", mcl_itemframes.glow_frame_base) mcl_itemframes.update_frame_registry("false", "mcl_itemframes:item_frame", false) @@ -811,4 +883,3 @@ function mcl_itemframes.create_base_frames() create_register_lbm("mcl_itemframes:item_frame") create_register_lbm("mcl_itemframes:glow_item_frame") end - diff --git a/mods/ITEMS/mcl_itemframes/mod.conf b/mods/ITEMS/mcl_itemframes/mod.conf index ff09c3bcc..f9421e657 100644 --- a/mods/ITEMS/mcl_itemframes/mod.conf +++ b/mods/ITEMS/mcl_itemframes/mod.conf @@ -1,3 +1,2 @@ name = mcl_itemframes -depends = mcl_core, mcl_sounds, mcl_compass, mcl_maps -optional_depends = screwdriver +depends = mcl_core, mcl_sounds, mcl_compass, mcl_maps, screwdriver From 61df48e46e28418a60bf379135849a2372938242 Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 4 Nov 2022 09:15:29 +0000 Subject: [PATCH 09/14] Translations for the Item Frames. --- mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.de.tr | 11 +++++++---- mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.es.tr | 9 ++++++--- mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.fr.tr | 11 +++++++---- mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.pl.tr | 7 +++++++ mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.ru.tr | 7 +++++++ 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.de.tr b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.de.tr index 07d7812f6..b9bf40e1a 100644 --- a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.de.tr +++ b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.de.tr @@ -1,5 +1,8 @@ # textdomain: mcl_itemframes -Item Frame=Rahmen -Item frames are decorative blocks in which items can be placed.=Rahmen sind dekorative Blöcke, in denen man Gegenstände platzieren kann. -Just place any item on the item frame. Use the item frame again to retrieve the item.=Platzieren Sie einfach einen beliebigen Gegenstand in den Rahmen. Benutzen Sie den Rahmen erneut, um den Gegenstand zurück zu erhalten. -Can hold an item=Kann einen Gegenstand halten +Item Frame=Artikel Rahmen +Item frames are decorative blocks in which items can be placed.=Artikelrahmen sind dekorative Blöcke, in denen Artikel platziert werden können. +Just place any item on the item frame. Use the item frame again to retrieve the item.=Platzieren Sie einfach einen beliebigen Gegenstand auf dem Gegenstandsrahmen. Verwenden Sie den Artikelrahmen erneut, um den Artikel abzurufen. +Can hold an item.=Kann einen Gegenstand halten. +Glowing Item Frame=Leuchtender Gegenstandsrahmen +Glowing item frames are decorative blocks in which items can be placed and made to glow.=Leuchtende Gegenstandsrahmen sind dekorative Blöcke, in denen Gegenstände platziert und zum Leuchten gebracht werden können. +Can hold an item and glows.=Kann einen Gegenstand halten und leuchtet. diff --git a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.es.tr b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.es.tr index 0803234b0..d5c3aed71 100644 --- a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.es.tr +++ b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.es.tr @@ -1,5 +1,8 @@ # textdomain: mcl_itemframes -Item Frame=Marco +Item Frame=Cuadro de artículo Item frames are decorative blocks in which items can be placed.=Los marcos de elementos son bloques decorativos en los que se pueden colocar elementos. -Just place any item on the item frame. Use the item frame again to retrieve the item.=Simplemente coloque cualquier artículo en el marco del artículo. Use el marco del artículo nuevamente para recuperar el artículo. - +Just place any item on the item frame. Use the item frame again to retrieve the item.=Simplemente coloque cualquier elemento en el marco del elemento. Use el marco del elemento nuevamente para recuperar el elemento. +Can hold an item.=Puede contener un artículo. +Glowing Item Frame=Marco de artículo brillante +Glowing item frames are decorative blocks in which items can be placed and made to glow.=Los marcos de elementos brillantes son bloques decorativos en los que se pueden colocar elementos y hacer que brillen. +Can hold an item and glows.=Puede sostener un artículo y brilla. diff --git a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.fr.tr b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.fr.tr index 180c5555f..e847779f2 100644 --- a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.fr.tr +++ b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.fr.tr @@ -1,5 +1,8 @@ # textdomain: mcl_itemframes -Item Frame=Cadre -Item frames are decorative blocks in which items can be placed.=Les cadres sont des blocs décoratifs dans lesquels les objets peuvent être placés. -Just place any item on the item frame. Use the item frame again to retrieve the item.=Placez simplement n'importe quel objet sur le cadre. Utilisez à nouveau le cadre décoré pour récupérer l'élément. -Can hold an item=Peut contenir un objet +Item Frame=Cadre de l'article +Item frames are decorative blocks in which items can be placed.=Les cadres d'objets sont des blocs décoratifs dans lesquels des objets peuvent être placés. +Just place any item on the item frame. Use the item frame again to retrieve the item.=Placez simplement n'importe quel élément sur le cadre de l'élément. Utilisez à nouveau le cadre de l'objet pour récupérer l'objet. +Can hold an item.=Peut contenir un objet. +Glowing Item Frame=Cadre d'objet lumineux +Glowing item frames are decorative blocks in which items can be placed and made to glow.=Les cadres d'objets lumineux sont des blocs décoratifs dans lesquels des objets peuvent être placés et rendus brillants. +Can hold an item and glows.=Peut contenir un objet et brille. diff --git a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.pl.tr b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.pl.tr index 8de889471..87b83c27d 100644 --- a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.pl.tr +++ b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.pl.tr @@ -3,3 +3,10 @@ Item Frame=Ramka na przedmiot Item frames are decorative blocks in which items can be placed.=Ramki na przedmiot to dekoracyjne bloki w których można umieszczać przedmioty. Just place any item on the item frame. Use the item frame again to retrieve the item.=Umieść dowolny przedmiot w ramce. Użyj ramki ponownie aby odzyskać przedmiot. Can hold an item=Może przetrzymywać przedmiot +Item Frame=Rama przedmiotu +Item frames are decorative blocks in which items can be placed.=Ramki na przedmioty to klocki ozdobne, w których można umieszczać przedmioty. +Just place any item on the item frame. Use the item frame again to retrieve the item.=Wystarczy umieścić dowolny przedmiot na ramie przedmiotu. Użyj ponownie ramki elementu, aby pobrać element. +Can hold an item.=Może pomieścić przedmiot. +Glowing Item Frame=Świecąca ramka na przedmiot +Glowing item frames are decorative blocks in which items can be placed and made to glow.=Świecące ramki na przedmioty to ozdobne bloki, w których można umieścić przedmioty i sprawić, by świeciły. +Can hold an item and glows.=Może trzymać przedmiot i świeci. diff --git a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.ru.tr b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.ru.tr index 7d3d90cc4..bf9076815 100644 --- a/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.ru.tr +++ b/mods/ITEMS/mcl_itemframes/locale/mcl_itemframes.ru.tr @@ -3,3 +3,10 @@ Item Frame=Рамка Item frames are decorative blocks in which items can be placed.=Рамки это декоративные блоки, в которые можно помещать предметы. Just place any item on the item frame. Use the item frame again to retrieve the item.=Просто поместите в рамку любой предмет. Используйте рамку вновь, чтобы заполучить из неё предмет обратно. Can hold an item=Может хранить предмет +Item Frame=Рамка предмета +Item frames are decorative blocks in which items can be placed.=Рамки предметов — это декоративные блоки, в которые можно помещать предметы. +Just place any item on the item frame. Use the item frame again to retrieve the item.=Просто поместите любой предмет на рамку предмета. Используйте рамку предмета снова, чтобы получить предмет. +Can hold an item.=Может держать предмет. +Glowing Item Frame=Светящаяся рамка предмета +Glowing item frames are decorative blocks in which items can be placed and made to glow.=Светящиеся рамки предметов — это декоративные блоки, в которые можно помещать предметы и заставлять их светиться. +Can hold an item and glows.=Может держать предмет и светится. From 76991fcba9d54d71acd5ec60ca212897b2e1dfb9 Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 4 Nov 2022 09:23:40 +0000 Subject: [PATCH 10/14] Pre-review Item frames code * Cleaned up all of the code, checked to make sure that there were no erraneous debug logging. * To enable debugging, turn it on in the api by changing the following line in item_frames_api.lua: mcl_itemframes.DEBUG = false -- set to true to see debug output. * Made the standard Item Frame and the new Glow Frame use the frames API. Added in backwards compatibility mode. * Made frames pop out items into the world on the old frames' entities when they are a hidden / broken entity. (Part of the backwards compatibility.) * Tested locally. Should be fully functional and ready for review. --- mods/ITEMS/mcl_itemframes/init.lua | 68 +- mods/ITEMS/mcl_itemframes/item_frames_API.lua | 671 ++++++++---------- 2 files changed, 326 insertions(+), 413 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 1ad51e156..47cd95348 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -3,16 +3,24 @@ local modpath = minetest.get_modpath(modname) local S = minetest.get_translator(minetest.get_current_modname()) -if 1 == 1 then - minetest.log("action", "[mcl_itemframes] initialized.") -end - -- mcl_itemframes API dofile(modpath .. "/item_frames_API.lua") -mcl_itemframes.create_base_frames() +-- actual api initialization. +mcl_itemframes.create_base_definitions() --- Register the base item_frame's recipes. +-- necessary to maintain compatibility amongst older versions. +mcl_itemframes.backwards_compatibility () + +-- test for the create custom frame +mcl_itemframes.create_custom_frame("false", "item_frame", false, + "mcl_itemframes_item_frame.png", mcl_colors.WHITE, "Item Frame", + "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.") + +-- Register the base frame's recipes. -- was going to make it a specialized function, but minetest refuses to play nice. minetest.register_craft({ output = "mcl_itemframes:item_frame", @@ -29,20 +37,20 @@ minetest.register_craft({ recipe = { 'mcl_mobitems:glow_ink_sac', 'mcl_itemframes:item_frame' }, }) +--[[ green frames just for testing +mcl_itemframes.create_custom_frame("false", "my_regular_frame", false, + "mcl_itemframes_item_frame.png", mcl_colors.DARK_GREEN, "A Green frame", + "My Green Frame") +mcl_itemframes.create_custom_frame("false", "my_glowing_frame", true, + "mcl_itemframes_glow_item_frame.png", mcl_colors.DARK_GREEN, "A Green glowing frame", + "My Green glowing Frame") --- test for the create custom frame -mcl_itemframes.create_custom_frame("false", "my_regular_frame", false, "mcl_itemframes_item_frame.png", mcl_colors.DARK_GREEN, "A Green frame", "My Green Frame") -mcl_itemframes.create_custom_frame("false", "my_glowing_frame", true, "mcl_itemframes_glow_item_frame.png", mcl_colors.DARK_GREEN, "A Green glowing frame", "My Green glowing Frame") - -if 1 == 1 then - minetest.log("action", "registering custom frame recipes [start].") -end minetest.register_craft({ output = "mcl_itemframes:my_regular_frame", recipe = { - { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, - { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, - { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + { "", "mcl_core:stick", "" }, + { "mcl_core:stick", "", "mcl_core:stick" }, + { "", "mcl_core:stick", "" }, } }) @@ -51,30 +59,4 @@ minetest.register_craft({ output = "mcl_itemframes:my_glowing_frame", recipe = { "mcl_mobitems:glow_ink_sac", "mcl_itemframes:my_regular_frame" }, }) -if 1 == 1 then - minetest.log("action", "registering custom frame recipes [finished].") -end - --- for compatibility: -minetest.register_lbm({ - label = "Update legacy item frames", - name = "mcl_itemframes:update_legacy_item_frames", - nodenames = { "itemframes:frame" }, - action = function(pos, node) - -- Swap legacy node, then respawn entity - node.name = "mcl_itemframes:item_frame" - local meta = minetest.get_meta(pos) - local item = meta:get_string("item") - minetest.swap_node(pos, node) - if item ~= "" then - local itemstack = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) - local inv = meta:get_inventory() - inv:set_size("main", 1) - if not itemstack:is_empty() then - inv:set_stack("main", 1, itemstack) - end - end - mcl_itemframes.update_item_entity(pos, node) - end, -}) -minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame") +--]] diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua index 43b4fd518..fe9b62149 100644 --- a/mods/ITEMS/mcl_itemframes/item_frames_API.lua +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -11,22 +11,23 @@ mcl_itemframes.frames_registered = {} mcl_itemframes.frames_registered.glowing = {} mcl_itemframes.frames_registered.standard = {} +-- Set to true to get all of the DEBUG messages. +mcl_itemframes.DEBUG = false + +if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] initialized.") +end + local S = minetest.get_translator(minetest.get_current_modname()) local table = table -local DEBUG = false - local pairs = pairs -if 1 == 1 then +if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] API initialized.") end local VISUAL_SIZE = 0.3 local facedir = {} -facedir[0] = { x = 0, y = 0, z = 1 } -facedir[1] = { x = 1, y = 0, z = 0 } -facedir[2] = { x = 0, y = 0, z = -1 } -facedir[3] = { x = -1, y = 0, z = 0 } local pi = math.pi local glow_amount = 6 -- LIGHT_MAX is 15, but the items aren't supposed to be a light source. @@ -150,19 +151,30 @@ local remove_item_entity = function(pos, node) end end - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "mcl_itemframes] remove_item_entity: " .. found_name_to_use .. "'s displayed item.") end - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" or node.name == found_name_to_use then + -- node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" or + if node.name == found_name_to_use then for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do local entity = obj:get_luaentity() if entity then - if entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:map" or - entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:glow_map" then + -- remove old entities + if entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:map" or entity.name == "mcl_itemframes:glow_map" then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + if (node.name == found_name_to_use) then + minetest.add_item(pos, item) + end + meta:set_string("infotext", "") + end obj:remove() - elseif entity.name == found_name_to_use .. "_item" or entity.name == found_name_to_use .. "_map" then - if 1 == 1 then + end + if entity.name == found_name_to_use .. "_item" or entity.name == found_name_to_use .. "_map" then + if mcl_itemframes.DEBUG then minetest.log("action", "mcl_itemframes] remove_item_entity: " .. entity.name .. "-- the item.") end obj:remove() @@ -173,70 +185,8 @@ local remove_item_entity = function(pos, node) end mcl_itemframes.update_item_entity = function(pos, node, param2) - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] Update_Item_Entity:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) - end - remove_item_entity(pos, node) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - if not param2 then - param2 = node.param2 - end - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then - local posad = facedir[param2] - pos.x = pos.x + posad.x * 6.5 / 16 - pos.y = pos.y + posad.y * 6.5 / 16 - pos.z = pos.z + posad.z * 6.5 / 16 - end - - local yaw = pi * 2 - param2 * pi / 2 - local map_id = item:get_meta():get_string("mcl_maps:id") - local map_id_entity = {} - local map_id_lua = {} - - if map_id == "" then - if node.name == "mcl_itemframes:item_frame" then - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:item") - elseif node.name == "mcl_itemframes:glow_item_frame" then - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_item") - end - map_id_lua = map_id_entity:get_luaentity() - map_id_lua._nodename = node.name - local itemname = item:get_name() - if itemname == "" or itemname == nil then - map_id_lua._texture = "blank.png" - map_id_lua._scale = 1 - else - map_id_lua._texture = itemname - local def = minetest.registered_items[itemname] - map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 - end - map_id_lua:_update_texture() - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then - map_id_entity:set_yaw(yaw) - end - else - if node.name == "mcl_itemframes:item_frame" then - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:map", map_id) - elseif node.name == "mcl_itemframes:glow_item_frame" then - map_id_entity = minetest.add_entity(pos, "mcl_itemframes:glow_map", map_id) - end - map_id_entity:set_yaw(yaw) - end - - -- finally, set the rotation (roll) of the displayed object. - local roll = meta:get_int("roll", 0) - set_roll(map_id_entity, roll) - - end -end - -mcl_itemframes.update_generic_item_entity = function(pos, node, param2) - - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) end @@ -288,7 +238,7 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) pos.y = pos.y + pos_adj.y * 6.5 / 16 pos.z = pos.z + pos_adj.z * 6.5 / 16 - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("[mcl_itemframes] Update_Generic_Item:\nFound Name in Registry: " .. found_name_to_use) end end @@ -299,15 +249,15 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) if map_id == "" then -- handle regular items placed into custom frame. - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nAdding entity: " .. node.name .. "_item") end + if node.name == found_name_to_use then map_id_entity = minetest.add_entity(pos, node.name .. "_item") else - local debugs_string = "[mcl_itemframes] Update_Generic_Item:\nCouldn't find node name in registry: " - minetest.log("error", debugs_string .. found_name_to_use "\nregistry: " .. dump(mcl_itemframes.frames_registered)) - + local debug_string = "[mcl_itemframes] Update_Generic_Item:\nCouldn't find node name in registry: " + minetest.log("error", debug_string .. found_name_to_use "\nregistry: " .. dump(mcl_itemframes.frames_registered)) return end @@ -326,7 +276,7 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) local def = minetest.registered_items[itemname] map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 end - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] Update_Generic_Item: item's name: " .. itemname) end map_id_lua:_update_texture() @@ -337,7 +287,7 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) end else -- handle map items placed into custom frame. - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] Update_Generic_Item: Placing map in a " .. found_name_to_use .. " frame.") end @@ -353,26 +303,7 @@ mcl_itemframes.update_generic_item_entity = function(pos, node, param2) local roll = meta:get_int("roll", 0) set_roll(map_id_entity, roll) end -end -local drop_item = function(pos, node, meta, clicker) - local cname = "" - if clicker and clicker:is_player() then - cname = clicker:get_player_name() - end - if not minetest.is_creative_enabled(cname) then - if (node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame") then - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - minetest.add_item(pos, item) - end - end - end - - meta:set_string("infotext", "") - meta:set_int("roll", 0) - remove_item_entity(pos, node) end function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) @@ -417,227 +348,9 @@ function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) end -mcl_itemframes.item_frame_base = { - description = S("Item Frame"), - _tt_help = S("Can hold an item"), - _doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."), - _doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."), - drawtype = "mesh", - is_ground_content = false, - mesh = "mcl_itemframes_itemframe1facedir.obj", - selection_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, - collision_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, - tiles = { "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "default_wood.png", "mcl_itemframes_item_frame_back.png" }, - inventory_image = "mcl_itemframes_item_frame.png", - wield_image = "mcl_itemframes_item_frame.png", - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - groups = { dig_immediate = 3, deco_block = 1, dig_by_piston = 1, container = 7, attached_node_facedir = 1 }, - sounds = mcl_sounds.node_sound_defaults(), - node_placement_prediction = "", - - on_timer = function(pos) - local inv = minetest.get_meta(pos):get_inventory() - local stack = inv:get_stack("main", 1) - local itemname = stack:get_name() - if minetest.get_item_group(itemname, "clock") > 0 then - local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) - if itemname ~= new_name then - stack:set_name(new_name) - inv:set_stack("main", 1, stack) - local node = minetest.get_node(pos) - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then - mcl_itemframes.update_item_entity(pos, node, node.param2) - else - mcl_itemframes.update_generic_item_entity(pos, node, node.param2) - end - - end - minetest.get_node_timer(pos):start(1.0) - end - end, - - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end - - -- Use pointed node's on_rightclick function first, if present - local node = minetest.get_node(pointed_thing.under) - if placer and not placer:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack - end - end - - return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) - end, - - on_construct = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("main", 1) - end, - - on_rightclick = function(pos, node, clicker, itemstack) - if not itemstack then - return - end - local pname = clicker:get_player_name() - if minetest.is_protected(pos, pname) then - minetest.record_protection_violation(pos, pname) - return - end - local meta = minetest.get_meta(pos) - - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then - drop_item(pos, node, meta, clicker) - else - mcl_itemframes.drop_generic_item(pos, node, meta, clicker) - end - - local inv = meta:get_inventory() - if itemstack:is_empty() then - remove_item_entity(pos, node) - meta:set_string("infotext", "") - inv:set_stack("main", 1, "") - return itemstack - end - local put_itemstack = ItemStack(itemstack) - 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.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) - end - - inv:set_stack("main", 1, put_itemstack) - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then - mcl_itemframes.update_item_entity(pos, node) - else - mcl_itemframes.update_generic_item_entity(pos, node) - end - - -- Add node infotext when item has been named - local imeta = itemstack:get_meta() - local iname = imeta:get_string("name") - if iname then - meta:set_string("infotext", iname) - end - - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end - return itemstack - end, - - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return count - end - end, - - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, - - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, - - on_destruct = function(pos) - local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) - - if node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" then - drop_item(pos, node, meta) -- originally had ", clicker" too. Except, clicker doesn't exist in the context. - else - mcl_itemframes.drop_generic_item(pos, node, meta) - end - end, - - on_rotate = function(pos, node, user, mode, param2) - --local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) - - local objs = nil - local name_found = false - local found_name_to_use = "" - name_found = false - found_name_to_use = "" - - for k, v in pairs(mcl_itemframes.frames_registered.glowing) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end - - -- try to cut down on excess looping, if possible. - if name_found == false then - for k, v in pairs(mcl_itemframes.frames_registered.standard) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end - end - - if node.name == found_name_to_use then - objs = minetest.get_objects_inside_radius(pos, 0.5) - else - return -- short circuit if it's somehow not the right thing. - end - - if objs then - if mode == screwdriver.ROTATE_FACE or mode == screwdriver.ROTATE_AXIS then - for _, obj in ipairs(objs) do - if obj and obj:get_luaentity() then - local obj_name = obj:get_luaentity().name - if obj_name == "mcl_itemframes:item" or obj_name == "mcl_itemframes:glow_item" then - if mode == screwdriver.ROTATE_AXIS then - update_roll(obj, pos) - end - break - elseif obj_name == found_name_to_use .. "_item" then - if mode == screwdriver.ROTATE_AXIS then - update_roll(obj, pos) - end - break - end - end - end - return false - end - end - end, -} - ---- reworked to set up the base item definitions, and to register them for item and glow_item. +--- reworked to set up the base item definitions. function mcl_itemframes.create_base_item_entity() - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] create_item_entity.") end @@ -703,7 +416,7 @@ function mcl_itemframes.create_base_item_entity() textures = { "blank.png" }, }, on_activate = function(self, staticdata) - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] map_item:on_activate.") end update_map_texture(self, staticdata) @@ -714,40 +427,26 @@ function mcl_itemframes.create_base_item_entity() end, } - local glow_frame_item = table.copy(frame_item_base) - glow_frame_item.glow = glow_amount - local glow_frame_map_item = table.copy(map_item_base) - glow_frame_map_item.name = "mcl_itemframes:glow_map" - - minetest.register_entity("mcl_itemframes:glow_item", glow_frame_item) - minetest.register_entity("mcl_itemframes:glow_map", glow_frame_map_item) - minetest.register_entity("mcl_itemframes:item", frame_item_base) - minetest.register_entity("mcl_itemframes:map", map_item_base) - end function mcl_itemframes.create_custom_items(name, has_glow) - + local custom_frame_item = table.copy(frame_item_base) + local custom_frame_map_item = table.copy(map_item_base) if has_glow then - local glow_frame_item = table.copy(frame_item_base) - local glow_frame_map_item = table.copy(map_item_base) - glow_frame_map_item.glow = glow_amount - glow_frame_item.glow = glow_amount - - minetest.register_entity(name .. "_item", glow_frame_item) - minetest.register_entity(name .. "_map", glow_frame_map_item) - if 1 == 1 then + custom_frame_map_item.glow = glow_amount + custom_frame_item.glow = glow_amount + if mcl_itemframes.DEBUG then minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_item") minetest.log("action", "[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_map\n") end else - minetest.register_entity(name .. "_item", frame_item_base) - minetest.register_entity(name .. "_map", map_item_base) - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: name: " .. name .. "_item") 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) end function mcl_itemframes.update_frame_registry(modname, name, has_glow) @@ -786,6 +485,11 @@ function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, colo name = "" end + if name == "" then + minetest.log("error", "attempted to create an item frame WITHOUT a name!") + return + end + if has_glow == nil or has_glow == "" then has_glow = false end @@ -797,7 +501,7 @@ function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, colo local working_name = "mcl_itemframes:" .. name - if 1 == 1 then + if mcl_itemframes.DEBUG then minetest.log("action", "[mcl_itemframes] create_custom_frame: " .. working_name) minetest.log("action", "[mcl_itemframes] create_custom_frame - calling create_custom_items " .. working_name) end @@ -824,8 +528,7 @@ function mcl_itemframes.create_custom_frame(modname, name, has_glow, tiles, colo end --- the local version is for the base glow & base frame. -local function create_register_lbm(name) +function mcl_itemframes.custom_register_lbm(name) -- FIXME: Item entities can get destroyed by /clearobjects -- glow frame @@ -840,46 +543,274 @@ local function create_register_lbm(name) }) end -function mcl_itemframes.custom_register_lbm(name) - -- FIXME: Item entities can get destroyed by /clearobjects - -- glow frame - minetest.register_lbm({ - label = "Respawn item frame item entities", - name = "mcl_itemframes:respawn_entities", - nodenames = { name }, - run_at_every_load = true, - action = function(pos, node) - mcl_itemframes.update_generic_item_entity(pos, node) - end, - }) - -end - -function mcl_itemframes.create_base_frames() - if 1 == 1 then - minetest.log("action", "[mcl_itemframes] create_frames.") +function mcl_itemframes.create_base_definitions() + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] create_base_definitions.") end + -- set up the facedir information. + facedir[0] = { x = 0, y = 0, z = 1 } + facedir[1] = { x = 1, y = 0, z = 0 } + facedir[2] = { x = 0, y = 0, z = -1 } + facedir[3] = { x = -1, y = 0, z = 0 } + + mcl_itemframes.item_frame_base = { + description = S("Item Frame"), + _tt_help = S("Can hold an item"), + _doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."), + _doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."), + drawtype = "mesh", + is_ground_content = false, + mesh = "mcl_itemframes_itemframe1facedir.obj", + selection_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, + collision_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, + tiles = { "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "default_wood.png", "mcl_itemframes_item_frame_back.png" }, + inventory_image = "mcl_itemframes_item_frame.png", + wield_image = "mcl_itemframes_item_frame.png", + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + groups = { dig_immediate = 3, deco_block = 1, dig_by_piston = 1, container = 7, attached_node_facedir = 1 }, + sounds = mcl_sounds.node_sound_defaults(), + node_placement_prediction = "", + + on_timer = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + local stack = inv:get_stack("main", 1) + local itemname = stack:get_name() + if minetest.get_item_group(itemname, "clock") > 0 then + local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) + if itemname ~= new_name then + stack:set_name(new_name) + inv:set_stack("main", 1, stack) + local node = minetest.get_node(pos) + mcl_itemframes.update_item_entity(pos, node, node.param2) + + end + minetest.get_node_timer(pos):start(1.0) + end + end, + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + + return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) + end, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 1) + end, + + on_rightclick = function(pos, node, clicker, itemstack) + if not itemstack then + return + end + local pname = clicker:get_player_name() + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) + return + end + local meta = minetest.get_meta(pos) + mcl_itemframes.drop_generic_item(pos, node, meta, clicker) + + local inv = meta:get_inventory() + if itemstack:is_empty() then + remove_item_entity(pos, node) + meta:set_string("infotext", "") + inv:set_stack("main", 1, "") + return itemstack + end + local put_itemstack = ItemStack(itemstack) + 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.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) + end + + inv:set_stack("main", 1, put_itemstack) + mcl_itemframes.update_item_entity(pos, node) + + -- Add node infotext when item has been named + local imeta = itemstack:get_meta() + local iname = imeta:get_string("name") + if iname then + meta:set_string("infotext", iname) + end + + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end + return itemstack + end, + + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return count + end + end, + + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return stack:get_count() + end + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return stack:get_count() + end + end, + + on_destruct = function(pos) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + + mcl_itemframes.drop_generic_item(pos, node, meta) + + end, + + on_rotate = function(pos, node, user, mode, param2) + --local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + + local objs = nil + local name_found = false + local found_name_to_use = "" + name_found = false + found_name_to_use = "" + + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + + -- try to cut down on excess looping, if possible. + if name_found == false then + for k, v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + end + + if node.name == found_name_to_use then + objs = minetest.get_objects_inside_radius(pos, 0.5) + else + return -- short circuit if it's somehow not the right thing. + end + + if objs then + if mode == screwdriver.ROTATE_FACE or mode == screwdriver.ROTATE_AXIS then + for _, obj in ipairs(objs) do + if obj and obj:get_luaentity() then + local obj_name = obj:get_luaentity().name + if obj_name == found_name_to_use .. "_item" then + if mode == screwdriver.ROTATE_AXIS then + update_roll(obj, pos) + end + break + end + end + end + return false + end + end + end, + } + -- make the base items for the base frames. mcl_itemframes.create_base_item_entity() - minetest.register_node("mcl_itemframes:item_frame", mcl_itemframes.item_frame_base) + -- minetest.register_node("mcl_itemframes:item_frame", mcl_itemframes.item_frame_base) -- make glow frame from the base item_frame. mcl_itemframes.glow_frame_base = table.copy(mcl_itemframes.item_frame_base) - mcl_itemframes.glow_frame_base.description = S("Glow Item Frame") - mcl_itemframes.glow_frame_base._tt_help = S("Can hold an item and glows") - mcl_itemframes.glow_frame_base.longdesc = S("Glow item frames are decorative blocks in which items can be placed.") + mcl_itemframes.glow_frame_base.description = S("Glowing Item Frame") + mcl_itemframes.glow_frame_base._tt_help = S("Can hold an item and glows.") + mcl_itemframes.glow_frame_base.longdesc = S("Glowing item frames are decorative blocks in which items can be placed and made to glow.") mcl_itemframes.glow_frame_base.tiles = { "mcl_itemframes_glow_item_frame.png" } mcl_itemframes.glow_frame_base.inventory_image = "mcl_itemframes_glow_item_frame_item.png" mcl_itemframes.glow_frame_base.wield_image = "mcl_itemframes_glow_item_frame.png" mcl_itemframes.glow_frame_base.mesh = "mcl_itemframes_glow_item_frame.obj" + --[[ minetest.register_node("mcl_itemframes:glow_item_frame", mcl_itemframes.glow_frame_base) mcl_itemframes.update_frame_registry("false", "mcl_itemframes:item_frame", false) mcl_itemframes.update_frame_registry("false", "mcl_itemframes:glow_item_frame", true) create_register_lbm("mcl_itemframes:item_frame") create_register_lbm("mcl_itemframes:glow_item_frame") + --]] +end + +-- for compatibility: +function mcl_itemframes.backwards_compatibility () + minetest.register_lbm({ + label = "Update legacy item frames", + name = "mcl_itemframes:update_legacy_item_frames", + nodenames = { "itemframes:frame" }, + action = function(pos, node) + -- Swap legacy node, then respawn entity + node.name = "mcl_itemframes:item_frame" + local meta = minetest.get_meta(pos) + local item = meta:get_string("item") + minetest.swap_node(pos, node) + if item ~= "" then + local itemstack = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) + local inv = meta:get_inventory() + inv:set_size("main", 1) + if not itemstack:is_empty() then + inv:set_stack("main", 1, itemstack) + end + end + mcl_itemframes.update_item_entity(pos, node) + end, + }) + minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame") + + -- To be installed when complete; 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") + minetest.register_alias("mcl_itemframes:glow_map", "mcl_itemframes:glow_item_frame_map") + + minetest.register_entity("mcl_itemframes:item", frame_item_base) + minetest.register_entity("mcl_itemframes:map", map_item_base) + minetest.register_entity("mcl_itemframes:glow_item", frame_item_base) + minetest.register_entity("mcl_itemframes:glow_map", map_item_base) + end From 3409c5a2202f3dceb2861365a2842ed0cc00c1e9 Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 4 Nov 2022 10:00:52 +0000 Subject: [PATCH 11/14] Prereview code, but with the spaces converted to tabs. * Cleaned up all of the code, checked to make sure that there were no erraneous debug logging. * To enable debugging, turn it on in the api by changing the following line in item_frames_api.lua: mcl_itemframes.DEBUG = false -- set to true to see debug output. * Made the standard Item Frame and the new Glow Frame use the frames API. Added in backwards compatibility mode. * Made frames pop out items into the world on the old frames' entities when they are a hidden / broken entity. (Part of the backwards compatibility.) * Tested locally. * *Converted the spaces to tabs!* Should be fully functional and ready for review. --- mods/ITEMS/mcl_itemframes/init.lua | 54 +- mods/ITEMS/mcl_itemframes/item_frames_API.lua | 1270 ++++++++--------- 2 files changed, 662 insertions(+), 662 deletions(-) diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 47cd95348..a7c949b8c 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -10,53 +10,53 @@ dofile(modpath .. "/item_frames_API.lua") mcl_itemframes.create_base_definitions() -- necessary to maintain compatibility amongst older versions. -mcl_itemframes.backwards_compatibility () +mcl_itemframes.backwards_compatibility() -- test for the create custom frame mcl_itemframes.create_custom_frame("false", "item_frame", false, - "mcl_itemframes_item_frame.png", mcl_colors.WHITE, "Item Frame", - "Can hold an item.") + "mcl_itemframes_item_frame.png", mcl_colors.WHITE, "Item Frame", + "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.") + "mcl_itemframes_glow_item_frame.png", mcl_colors.WHITE, "Glowing Item Frame", + "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. minetest.register_craft({ - output = "mcl_itemframes:item_frame", - recipe = { - { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, - { "mcl_core:stick", "mcl_mobitems:leather", "mcl_core:stick" }, - { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, - } + output = "mcl_itemframes:item_frame", + recipe = { + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + { "mcl_core:stick", "mcl_mobitems:leather", "mcl_core:stick" }, + { "mcl_core:stick", "mcl_core:stick", "mcl_core:stick" }, + } }) minetest.register_craft({ - type = "shapeless", - output = 'mcl_itemframes:glow_item_frame', - recipe = { 'mcl_mobitems:glow_ink_sac', 'mcl_itemframes:item_frame' }, + type = "shapeless", + output = 'mcl_itemframes:glow_item_frame', + recipe = { 'mcl_mobitems:glow_ink_sac', 'mcl_itemframes:item_frame' }, }) --[[ green frames just for testing mcl_itemframes.create_custom_frame("false", "my_regular_frame", false, - "mcl_itemframes_item_frame.png", mcl_colors.DARK_GREEN, "A Green frame", - "My Green Frame") + "mcl_itemframes_item_frame.png", mcl_colors.DARK_GREEN, "A Green frame", + "My Green Frame") mcl_itemframes.create_custom_frame("false", "my_glowing_frame", true, - "mcl_itemframes_glow_item_frame.png", mcl_colors.DARK_GREEN, "A Green glowing frame", - "My Green glowing Frame") + "mcl_itemframes_glow_item_frame.png", mcl_colors.DARK_GREEN, "A Green glowing frame", + "My Green glowing Frame") minetest.register_craft({ - output = "mcl_itemframes:my_regular_frame", - recipe = { - { "", "mcl_core:stick", "" }, - { "mcl_core:stick", "", "mcl_core:stick" }, - { "", "mcl_core:stick", "" }, - } + output = "mcl_itemframes:my_regular_frame", + recipe = { + { "", "mcl_core:stick", "" }, + { "mcl_core:stick", "", "mcl_core:stick" }, + { "", "mcl_core:stick", "" }, + } }) minetest.register_craft({ - type = "shapeless", - output = "mcl_itemframes:my_glowing_frame", - recipe = { "mcl_mobitems:glow_ink_sac", "mcl_itemframes:my_regular_frame" }, + type = "shapeless", + output = "mcl_itemframes:my_glowing_frame", + recipe = { "mcl_mobitems:glow_ink_sac", "mcl_itemframes:my_regular_frame" }, }) --]] diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua index fe9b62149..9173192bb 100644 --- a/mods/ITEMS/mcl_itemframes/item_frames_API.lua +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -15,7 +15,7 @@ mcl_itemframes.frames_registered.standard = {} mcl_itemframes.DEBUG = false if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] initialized.") + minetest.log("action", "[mcl_itemframes] initialized.") end local S = minetest.get_translator(minetest.get_current_modname()) @@ -23,7 +23,7 @@ local table = table local pairs = pairs if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] API initialized.") + minetest.log("action", "[mcl_itemframes] API initialized.") end local VISUAL_SIZE = 0.3 @@ -39,778 +39,778 @@ local map_item_base = {} --- self: the object to roll. local function update_roll(self, pos) - -- get the entity's metadata. - local meta = minetest.get_meta(pos) + -- get the entity's metadata. + local meta = minetest.get_meta(pos) - -- using an integer, as it's the number of 45 degree turns. ie, 0 to 7 - local current_roll = meta:get_int("roll", 0) - local new_roll = current_roll + 1 + -- using an integer, as it's the number of 45 degree turns. ie, 0 to 7 + local current_roll = meta:get_int("roll", 0) + local new_roll = current_roll + 1 - if new_roll == 8 then - new_roll = 0 - end - meta:set_int("roll", new_roll) + if new_roll == 8 then + new_roll = 0 + end + meta:set_int("roll", new_roll) - local new_roll_deg = new_roll * 45 + local new_roll_deg = new_roll * 45 - -- * `get_rotation()`: returns the rotation, a vector (radians) - local rot = self:get_rotation() - local Radians = 0 + -- * `get_rotation()`: returns the rotation, a vector (radians) + local rot = self:get_rotation() + local Radians = 0 - -- Radians = Degrees * (pi / 180) degrees to radian formula - -- Radian quick chart - -- One full revolution is equal to 2π rad (or) 360°. - -- 1° = 0.017453 radians and 1 rad = 57.2958°. - -- To convert an angle from degrees to radians, we multiply it by π/180°. - -- To convert an angle from radians to degrees, we multiply it by 180°/π. + -- Radians = Degrees * (pi / 180) degrees to radian formula + -- Radian quick chart + -- One full revolution is equal to 2π rad (or) 360°. + -- 1° = 0.017453 radians and 1 rad = 57.2958°. + -- To convert an angle from degrees to radians, we multiply it by π/180°. + -- To convert an angle from radians to degrees, we multiply it by 180°/π. - Radians = new_roll_deg * (pi / 180) - rot.z = Radians + Radians = new_roll_deg * (pi / 180) + rot.z = Radians - self:set_rotation(rot) + self:set_rotation(rot) end --- self: the object to roll. --- faceDeg: 0-7, inclusive. local function set_roll(self, faceDeg) - -- get the entity's metadata. - local meta = minetest.get_meta(self:get_pos()) + -- get the entity's metadata. + local meta = minetest.get_meta(self:get_pos()) - -- using an integer, as it's the number of 45 degree turns. ie, 0 to 7 - local new_roll = faceDeg + -- using an integer, as it's the number of 45 degree turns. ie, 0 to 7 + local new_roll = faceDeg - if new_roll >= 8 then - new_roll = 7 - end - if new_roll <= 0 then - new_roll = 0 - end + if new_roll >= 8 then + new_roll = 7 + end + if new_roll <= 0 then + new_roll = 0 + end - meta:set_int("roll", new_roll) + meta:set_int("roll", new_roll) - local new_roll_deg = new_roll * 45 + local new_roll_deg = new_roll * 45 - -- * `get_rotation()`: returns the rotation, a vector (radians) - local rot = self:get_rotation() - local Radians = 0 + -- * `get_rotation()`: returns the rotation, a vector (radians) + local rot = self:get_rotation() + local Radians = 0 - -- Radians = Degrees * (pi / 180) degrees to radian formula - -- Radian quick chart - -- One full revolution is equal to 2π rad (or) 360°. - -- 1° = 0.017453 radians and 1 rad = 57.2958°. - -- To convert an angle from degrees to radians, we multiply it by π/180°. - -- To convert an angle from radians to degrees, we multiply it by 180°/π. + -- Radians = Degrees * (pi / 180) degrees to radian formula + -- Radian quick chart + -- One full revolution is equal to 2π rad (or) 360°. + -- 1° = 0.017453 radians and 1 rad = 57.2958°. + -- To convert an angle from degrees to radians, we multiply it by π/180°. + -- To convert an angle from radians to degrees, we multiply it by 180°/π. - Radians = new_roll_deg * (pi / 180) + Radians = new_roll_deg * (pi / 180) - rot.z = Radians + rot.z = Radians - self:set_rotation(rot) + self:set_rotation(rot) end local function update_map_texture (self, staticdata) - self.id = staticdata - local result = true - result = mcl_maps.load_map(self.id, function(texture) - -- will not crash even if self.object is invalid by now - -- update... quite possibly will screw up with each version of Minetest. >.< - if not texture then - minetest.log("error", "Failed to load the map texture using mcl_maps.") - end + self.id = staticdata + local result = true + result = mcl_maps.load_map(self.id, function(texture) + -- will not crash even if self.object is invalid by now + -- update... quite possibly will screw up with each version of Minetest. >.< + if not texture then + minetest.log("error", "Failed to load the map texture using mcl_maps.") + end - self.object:set_properties({ textures = { texture } }) - end) - if result ~= nil and result == false then - mintest.log("error", "[mcl_itemframes] Error setting up Map Item.") - end + self.object:set_properties({ textures = { texture } }) + end) + if result ~= nil and result == false then + mintest.log("error", "[mcl_itemframes] Error setting up Map Item.") + end end local remove_item_entity = function(pos, node) - local name_found = false - local found_name_to_use = "" + local name_found = false + local found_name_to_use = "" - for k, v in pairs(mcl_itemframes.frames_registered.glowing) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end - -- try to cut down on excess looping, if possible. - if name_found == false then - for k, v in pairs(mcl_itemframes.frames_registered.standard) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end - end + -- try to cut down on excess looping, if possible. + if name_found == false then + for k, v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + end - if mcl_itemframes.DEBUG then - minetest.log("action", "mcl_itemframes] remove_item_entity: " .. found_name_to_use .. "'s displayed item.") - end + if mcl_itemframes.DEBUG then + minetest.log("action", "mcl_itemframes] remove_item_entity: " .. found_name_to_use .. "'s displayed item.") + end - -- node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" or - if node.name == found_name_to_use then - for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do - local entity = obj:get_luaentity() - if entity then - -- remove old entities - if entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:map" or entity.name == "mcl_itemframes:glow_map" then - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - if (node.name == found_name_to_use) then - minetest.add_item(pos, item) - end - meta:set_string("infotext", "") - end - obj:remove() - end - if entity.name == found_name_to_use .. "_item" or entity.name == found_name_to_use .. "_map" then - if mcl_itemframes.DEBUG then - minetest.log("action", "mcl_itemframes] remove_item_entity: " .. entity.name .. "-- the item.") - end - obj:remove() - end - end - end - end + -- node.name == "mcl_itemframes:item_frame" or node.name == "mcl_itemframes:glow_item_frame" or + if node.name == found_name_to_use then + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do + local entity = obj:get_luaentity() + if entity then + -- remove old entities + if entity.name == "mcl_itemframes:item" or entity.name == "mcl_itemframes:glow_item" or entity.name == "mcl_itemframes:map" or entity.name == "mcl_itemframes:glow_map" then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + if (node.name == found_name_to_use) then + minetest.add_item(pos, item) + end + meta:set_string("infotext", "") + end + obj:remove() + end + if entity.name == found_name_to_use .. "_item" or entity.name == found_name_to_use .. "_map" then + if mcl_itemframes.DEBUG then + minetest.log("action", "mcl_itemframes] remove_item_entity: " .. entity.name .. "-- the item.") + end + obj:remove() + end + end + end + end end mcl_itemframes.update_item_entity = function(pos, node, param2) - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) - end + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nPosition: " .. dump(pos) .. "\nNode: " .. dump(node)) + end - remove_item_entity(pos, node) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) + remove_item_entity(pos, node) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) - local name_found = false - local found_name_to_use = "" - local has_glow = false + local name_found = false + local found_name_to_use = "" + local has_glow = false - for k, v in pairs(mcl_itemframes.frames_registered.glowing) do - if node.name == v then - name_found = true - has_glow = true - found_name_to_use = v - break - end - end + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + has_glow = true + found_name_to_use = v + break + end + end - -- try to cut down on excess looping, if possible. - if name_found == false then - for k, v in pairs(mcl_itemframes.frames_registered.standard) do - if node.name == v then - name_found = true - has_glow = false - found_name_to_use = v - break - end - end - end + -- try to cut down on excess looping, if possible. + if name_found == false then + for k, v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + has_glow = false + found_name_to_use = v + break + end + end + end - if name_found == false then - minetest.log("error", "[mcl_itemframes] Update_Generic_Item:\nFailed to find registered node:\nNode name - " .. node.name) - minetest.log("error", "[mcl_itemframes] Update_Generic_Item:\nRegistry definition:" .. dump(mcl_itemframes.frames_registered)) - return - end + if name_found == false then + minetest.log("error", "[mcl_itemframes] Update_Generic_Item:\nFailed to find registered node:\nNode name - " .. node.name) + minetest.log("error", "[mcl_itemframes] Update_Generic_Item:\nRegistry definition:" .. dump(mcl_itemframes.frames_registered)) + return + end - if not item:is_empty() then - -- update existing items placed. - if not param2 then - param2 = node.param2 - end - local pos_adj = facedir[param2] + if not item:is_empty() then + -- update existing items placed. + if not param2 then + param2 = node.param2 + end + local pos_adj = facedir[param2] - if node.name == found_name_to_use then - pos.x = pos.x + pos_adj.x * 6.5 / 16 - pos.y = pos.y + pos_adj.y * 6.5 / 16 - pos.z = pos.z + pos_adj.z * 6.5 / 16 + if node.name == found_name_to_use then + pos.x = pos.x + pos_adj.x * 6.5 / 16 + pos.y = pos.y + pos_adj.y * 6.5 / 16 + pos.z = pos.z + pos_adj.z * 6.5 / 16 - if mcl_itemframes.DEBUG then - minetest.log("[mcl_itemframes] Update_Generic_Item:\nFound Name in Registry: " .. found_name_to_use) - end - end - local yaw = pi * 2 - param2 * pi / 2 - local map_id = item:get_meta():get_string("mcl_maps:id") - local map_id_entity = {} - local map_id_lua = {} + if mcl_itemframes.DEBUG then + minetest.log("[mcl_itemframes] Update_Generic_Item:\nFound Name in Registry: " .. found_name_to_use) + end + end + local yaw = pi * 2 - param2 * pi / 2 + local map_id = item:get_meta():get_string("mcl_maps:id") + local map_id_entity = {} + local map_id_lua = {} - if map_id == "" then - -- handle regular items placed into custom frame. - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nAdding entity: " .. node.name .. "_item") - end + if map_id == "" then + -- handle regular items placed into custom frame. + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item:\nAdding entity: " .. node.name .. "_item") + end - if node.name == found_name_to_use then - map_id_entity = minetest.add_entity(pos, node.name .. "_item") - else - local debug_string = "[mcl_itemframes] Update_Generic_Item:\nCouldn't find node name in registry: " - minetest.log("error", debug_string .. found_name_to_use "\nregistry: " .. dump(mcl_itemframes.frames_registered)) - return - end + if node.name == found_name_to_use then + map_id_entity = minetest.add_entity(pos, node.name .. "_item") + else + local debug_string = "[mcl_itemframes] Update_Generic_Item:\nCouldn't find node name in registry: " + minetest.log("error", debug_string .. found_name_to_use "\nregistry: " .. dump(mcl_itemframes.frames_registered)) + return + end - map_id_lua = map_id_entity:get_luaentity() - map_id_lua._nodename = node.name + map_id_lua = map_id_entity:get_luaentity() + map_id_lua._nodename = node.name - local itemname = item:get_name() - if itemname == "" or itemname == nil then - map_id_lua._texture = "blank.png" - map_id_lua._scale = 1 - if has_glow then - map_id_lua.glow = glow_amount - end - else - map_id_lua._texture = itemname - local def = minetest.registered_items[itemname] - map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 - end - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] Update_Generic_Item: item's name: " .. itemname) - end - map_id_lua:_update_texture() - if node.name == found_name_to_use then - map_id_entity:set_yaw(yaw) - else - minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Display Item's yaw. " .. node.name) - end - else - -- handle map items placed into custom frame. - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] Update_Generic_Item: Placing map in a " .. found_name_to_use .. " frame.") - end + local itemname = item:get_name() + if itemname == "" or itemname == nil then + map_id_lua._texture = "blank.png" + map_id_lua._scale = 1 + if has_glow then + map_id_lua.glow = glow_amount + end + else + map_id_lua._texture = itemname + local def = minetest.registered_items[itemname] + map_id_lua._scale = def and def.wield_scale and def.wield_scale.x or 1 + end + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item: item's name: " .. itemname) + end + map_id_lua:_update_texture() + if node.name == found_name_to_use then + map_id_entity:set_yaw(yaw) + else + minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Display Item's yaw. " .. node.name) + end + else + -- handle map items placed into custom frame. + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] Update_Generic_Item: Placing map in a " .. found_name_to_use .. " frame.") + end - if node.name == found_name_to_use then - map_id_entity = minetest.add_entity(pos, found_name_to_use .. "_map", map_id) - map_id_entity:set_yaw(yaw) - else - minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Map Item in " .. found_name_to_use .. "'s frame.") - end - end + if node.name == found_name_to_use then + map_id_entity = minetest.add_entity(pos, found_name_to_use .. "_map", map_id) + map_id_entity:set_yaw(yaw) + else + minetest.log("error", "[mcl_itemframes] Update_Generic_Item: Failed to set Map Item in " .. found_name_to_use .. "'s frame.") + end + end - -- finally, set the rotation (roll) of the displayed object. - local roll = meta:get_int("roll", 0) - set_roll(map_id_entity, roll) - end + -- finally, set the rotation (roll) of the displayed object. + local roll = meta:get_int("roll", 0) + set_roll(map_id_entity, roll) + end end function mcl_itemframes.drop_generic_item(pos, node, meta, clicker) - local name_found = false - local found_name_to_use = "" + local name_found = false + local found_name_to_use = "" - for k, v in pairs(mcl_itemframes.frames_registered.glowing) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end - -- try to cut down on excess looping, if possible. - if name_found == false then - for k, v in pairs(mcl_itemframes.frames_registered.standard) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end - end + -- try to cut down on excess looping, if possible. + if name_found == false then + for k, v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + end - local cname = "" - if clicker and clicker:is_player() then - cname = clicker:get_player_name() - end - if not minetest.is_creative_enabled(cname) then - if (node.name == found_name_to_use) then - local inv = meta:get_inventory() - local item = inv:get_stack("main", 1) - if not item:is_empty() then - minetest.add_item(pos, item) - end - end - end + local cname = "" + if clicker and clicker:is_player() then + cname = clicker:get_player_name() + end + if not minetest.is_creative_enabled(cname) then + if (node.name == found_name_to_use) then + local inv = meta:get_inventory() + local item = inv:get_stack("main", 1) + if not item:is_empty() then + minetest.add_item(pos, item) + end + end + end - meta:set_string("infotext", "") - remove_item_entity(pos, node) + meta:set_string("infotext", "") + remove_item_entity(pos, node) end --- reworked to set up the base item definitions. function mcl_itemframes.create_base_item_entity() - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] create_item_entity.") - end + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] create_item_entity.") + end - --"mcl_itemframes:item", - frame_item_base = { - hp_max = 1, - visual = "wielditem", - visual_size = { x = VISUAL_SIZE, y = VISUAL_SIZE }, - physical = false, - pointable = false, - textures = { "blank.png" }, - _texture = "blank.png", - _scale = 1, + --"mcl_itemframes:item", + frame_item_base = { + hp_max = 1, + visual = "wielditem", + visual_size = { x = VISUAL_SIZE, y = VISUAL_SIZE }, + physical = false, + pointable = false, + textures = { "blank.png" }, + _texture = "blank.png", + _scale = 1, - on_activate = function(self, staticdata) - if staticdata and staticdata ~= "" then - local data = staticdata:split(";") - if data and data[1] and data[2] then - self._nodename = data[1] - self._texture = data[2] - if data[3] then - self._scale = data[3] - else - self._scale = 1 - end - end - end - if self._texture then - self.object:set_properties({ - textures = { self._texture }, - visual_size = { x = VISUAL_SIZE / self._scale, y = VISUAL_SIZE / self._scale }, - }) - end - end, - get_staticdata = function(self) - if self._nodename and self._texture then - local ret = self._nodename .. ";" .. self._texture - if self._scale then - ret = ret .. ";" .. self._scale - end - return ret - end - return "" - end, + on_activate = function(self, staticdata) + if staticdata and staticdata ~= "" then + local data = staticdata:split(";") + if data and data[1] and data[2] then + self._nodename = data[1] + self._texture = data[2] + if data[3] then + self._scale = data[3] + else + self._scale = 1 + end + end + end + if self._texture then + self.object:set_properties({ + textures = { self._texture }, + visual_size = { x = VISUAL_SIZE / self._scale, y = VISUAL_SIZE / self._scale }, + }) + end + end, + get_staticdata = function(self) + if self._nodename and self._texture then + local ret = self._nodename .. ";" .. self._texture + if self._scale then + ret = ret .. ";" .. self._scale + end + return ret + end + return "" + end, - _update_texture = function(self) - if self._texture then - self.object:set_properties({ - textures = { self._texture }, - visual_size = { x = VISUAL_SIZE / self._scale, y = VISUAL_SIZE / self._scale }, - }) - end - end, - } - -- "mcl_itemframes:map", - map_item_base = { - initial_properties = { - visual = "upright_sprite", - visual_size = { x = 1, y = 1 }, - pointable = false, - physical = false, - collide_with_objects = false, - textures = { "blank.png" }, - }, - on_activate = function(self, staticdata) - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] map_item:on_activate.") - end - update_map_texture(self, staticdata) - end, + _update_texture = function(self) + if self._texture then + self.object:set_properties({ + textures = { self._texture }, + visual_size = { x = VISUAL_SIZE / self._scale, y = VISUAL_SIZE / self._scale }, + }) + end + end, + } + -- "mcl_itemframes:map", + map_item_base = { + initial_properties = { + visual = "upright_sprite", + visual_size = { x = 1, y = 1 }, + pointable = false, + physical = false, + collide_with_objects = false, + textures = { "blank.png" }, + }, + on_activate = function(self, staticdata) + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] map_item:on_activate.") + end + update_map_texture(self, staticdata) + end, - get_staticdata = function(self) - return self.id - end, - } + get_staticdata = function(self) + return self.id + end, + } end function mcl_itemframes.create_custom_items(name, has_glow) - local custom_frame_item = table.copy(frame_item_base) - local custom_frame_map_item = table.copy(map_item_base) - if has_glow then - custom_frame_map_item.glow = glow_amount - custom_frame_item.glow = glow_amount - if mcl_itemframes.DEBUG then - minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_item") - minetest.log("action", "[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_map\n") - end - else - if mcl_itemframes.DEBUG then - minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: name: " .. name .. "_item") - 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) + local custom_frame_item = table.copy(frame_item_base) + local custom_frame_map_item = table.copy(map_item_base) + if has_glow then + custom_frame_map_item.glow = glow_amount + custom_frame_item.glow = glow_amount + if mcl_itemframes.DEBUG then + minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_item") + minetest.log("action", "[mcl_itemframes] create_custom_item_entity: glow name: " .. name .. "_map\n") + end + else + if mcl_itemframes.DEBUG then + minetest.log("action", "\n[mcl_itemframes] create_custom_item_entity: name: " .. name .. "_item") + 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) end function mcl_itemframes.update_frame_registry(modname, name, has_glow) - local mod_name_pass = false - if modname ~= "" and modname ~= "false" then - if minetest.get_modpath(modname) then - mod_name_pass = true - end - if mod_name_pass == false then - return - end - end + local mod_name_pass = false + if modname ~= "" and modname ~= "false" then + if minetest.get_modpath(modname) then + mod_name_pass = true + end + if mod_name_pass == false then + return + end + end - local frame = name -- should only be called within the create_frames functions. - if has_glow == true then - table.insert(mcl_itemframes.frames_registered.glowing, frame) - else - table.insert(mcl_itemframes.frames_registered.standard, frame) - end + local frame = name -- should only be called within the create_frames functions. + if has_glow == true then + table.insert(mcl_itemframes.frames_registered.glowing, frame) + else + table.insert(mcl_itemframes.frames_registered.standard, frame) + end 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) - local mod_name_pass = false - if modname ~= "" and modname ~= "false" then - if minetest.get_modpath(modname) then - mod_name_pass = true - end - if mod_name_pass == false then - return - end - end - if name == nil then - name = "" - end + local mod_name_pass = false + if modname ~= "" and modname ~= "false" then + if minetest.get_modpath(modname) then + mod_name_pass = true + end + if mod_name_pass == false then + return + end + end + if name == nil then + name = "" + end - if name == "" then - minetest.log("error", "attempted to create an item frame WITHOUT a name!") - return - end + if name == "" then + minetest.log("error", "attempted to create an item frame WITHOUT a name!") + return + end - if has_glow == nil or has_glow == "" then - has_glow = false - end + if has_glow == nil or has_glow == "" then + has_glow = false + end - if tiles == nil or tiles == "" then - minetest.log("error", "No textures passed to Create_Custom_Frame!! Exiting frame creation.") - return - end + if tiles == nil or tiles == "" then + minetest.log("error", "No textures passed to Create_Custom_Frame!! Exiting frame creation.") + return + end - local working_name = "mcl_itemframes:" .. name + local working_name = "mcl_itemframes:" .. name - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] create_custom_frame: " .. working_name) - minetest.log("action", "[mcl_itemframes] create_custom_frame - calling create_custom_items " .. working_name) - end + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] create_custom_frame: " .. working_name) + minetest.log("action", "[mcl_itemframes] create_custom_frame - calling create_custom_items " .. working_name) + end - -- make any special frame items. - mcl_itemframes.create_custom_items(working_name, has_glow) + -- make any special frame items. + mcl_itemframes.create_custom_items(working_name, has_glow) - local custom_itemframe_definition = {} + local custom_itemframe_definition = {} - if has_glow == false then - custom_itemframe_definition = table.copy(mcl_itemframes.item_frame_base) - else - custom_itemframe_definition = table.copy(mcl_itemframes.glow_frame_base) - end + if has_glow == false then + custom_itemframe_definition = table.copy(mcl_itemframes.item_frame_base) + else + custom_itemframe_definition = table.copy(mcl_itemframes.glow_frame_base) + end - custom_itemframe_definition.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" } - custom_itemframe_definition._tt_help = ttframe - custom_itemframe_definition.description = description + 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) + mcl_itemframes.update_frame_registry(modname, working_name, has_glow) + mcl_itemframes.custom_register_lbm(working_name) end function mcl_itemframes.custom_register_lbm(name) - -- FIXME: Item entities can get destroyed by /clearobjects - -- glow frame - minetest.register_lbm({ - label = "Respawn item frame item entities", - name = "mcl_itemframes:respawn_entities", - nodenames = { name }, - run_at_every_load = true, - action = function(pos, node) - mcl_itemframes.update_item_entity(pos, node) - end, - }) + -- FIXME: Item entities can get destroyed by /clearobjects + -- glow frame + minetest.register_lbm({ + label = "Respawn item frame item entities", + name = "mcl_itemframes:respawn_entities", + nodenames = { name }, + run_at_every_load = true, + action = function(pos, node) + mcl_itemframes.update_item_entity(pos, node) + end, + }) end function mcl_itemframes.create_base_definitions() - if mcl_itemframes.DEBUG then - minetest.log("action", "[mcl_itemframes] create_base_definitions.") - end + if mcl_itemframes.DEBUG then + minetest.log("action", "[mcl_itemframes] create_base_definitions.") + end - -- set up the facedir information. - facedir[0] = { x = 0, y = 0, z = 1 } - facedir[1] = { x = 1, y = 0, z = 0 } - facedir[2] = { x = 0, y = 0, z = -1 } - facedir[3] = { x = -1, y = 0, z = 0 } + -- set up the facedir information. + facedir[0] = { x = 0, y = 0, z = 1 } + facedir[1] = { x = 1, y = 0, z = 0 } + facedir[2] = { x = 0, y = 0, z = -1 } + facedir[3] = { x = -1, y = 0, z = 0 } - mcl_itemframes.item_frame_base = { - description = S("Item Frame"), - _tt_help = S("Can hold an item"), - _doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."), - _doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."), - drawtype = "mesh", - is_ground_content = false, - mesh = "mcl_itemframes_itemframe1facedir.obj", - selection_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, - collision_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, - tiles = { "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "default_wood.png", "mcl_itemframes_item_frame_back.png" }, - inventory_image = "mcl_itemframes_item_frame.png", - wield_image = "mcl_itemframes_item_frame.png", - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - groups = { dig_immediate = 3, deco_block = 1, dig_by_piston = 1, container = 7, attached_node_facedir = 1 }, - sounds = mcl_sounds.node_sound_defaults(), - node_placement_prediction = "", + mcl_itemframes.item_frame_base = { + description = S("Item Frame"), + _tt_help = S("Can hold an item"), + _doc_items_longdesc = S("Item frames are decorative blocks in which items can be placed."), + _doc_items_usagehelp = S("Just place any item on the item frame. Use the item frame again to retrieve the item."), + drawtype = "mesh", + is_ground_content = false, + mesh = "mcl_itemframes_itemframe1facedir.obj", + selection_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, + collision_box = { type = "fixed", fixed = { -6 / 16, -6 / 16, 7 / 16, 6 / 16, 6 / 16, 0.5 } }, + tiles = { "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "mcl_itemframes_item_frame_back.png", "default_wood.png", "mcl_itemframes_item_frame_back.png" }, + inventory_image = "mcl_itemframes_item_frame.png", + wield_image = "mcl_itemframes_item_frame.png", + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + groups = { dig_immediate = 3, deco_block = 1, dig_by_piston = 1, container = 7, attached_node_facedir = 1 }, + sounds = mcl_sounds.node_sound_defaults(), + node_placement_prediction = "", - on_timer = function(pos) - local inv = minetest.get_meta(pos):get_inventory() - local stack = inv:get_stack("main", 1) - local itemname = stack:get_name() - if minetest.get_item_group(itemname, "clock") > 0 then - local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) - if itemname ~= new_name then - stack:set_name(new_name) - inv:set_stack("main", 1, stack) - local node = minetest.get_node(pos) - mcl_itemframes.update_item_entity(pos, node, node.param2) + on_timer = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + local stack = inv:get_stack("main", 1) + local itemname = stack:get_name() + if minetest.get_item_group(itemname, "clock") > 0 then + local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) + if itemname ~= new_name then + stack:set_name(new_name) + inv:set_stack("main", 1, stack) + local node = minetest.get_node(pos) + mcl_itemframes.update_item_entity(pos, node, node.param2) - end - minetest.get_node_timer(pos):start(1.0) - end - end, + end + minetest.get_node_timer(pos):start(1.0) + end + end, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end - -- Use pointed node's on_rightclick function first, if present - local node = minetest.get_node(pointed_thing.under) - if placer and not placer:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack - end - end + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end - return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) - end, + return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) + end, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("main", 1) - end, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 1) + end, - on_rightclick = function(pos, node, clicker, itemstack) - if not itemstack then - return - end - local pname = clicker:get_player_name() - if minetest.is_protected(pos, pname) then - minetest.record_protection_violation(pos, pname) - return - end - local meta = minetest.get_meta(pos) - mcl_itemframes.drop_generic_item(pos, node, meta, clicker) + on_rightclick = function(pos, node, clicker, itemstack) + if not itemstack then + return + end + local pname = clicker:get_player_name() + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) + return + end + local meta = minetest.get_meta(pos) + mcl_itemframes.drop_generic_item(pos, node, meta, clicker) - local inv = meta:get_inventory() - if itemstack:is_empty() then - remove_item_entity(pos, node) - meta:set_string("infotext", "") - inv:set_stack("main", 1, "") - return itemstack - end - local put_itemstack = ItemStack(itemstack) - 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.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) - end + local inv = meta:get_inventory() + if itemstack:is_empty() then + remove_item_entity(pos, node) + meta:set_string("infotext", "") + inv:set_stack("main", 1, "") + return itemstack + end + local put_itemstack = ItemStack(itemstack) + 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.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) + end - inv:set_stack("main", 1, put_itemstack) - mcl_itemframes.update_item_entity(pos, node) + inv:set_stack("main", 1, put_itemstack) + mcl_itemframes.update_item_entity(pos, node) - -- Add node infotext when item has been named - local imeta = itemstack:get_meta() - local iname = imeta:get_string("name") - if iname then - meta:set_string("infotext", iname) - end + -- Add node infotext when item has been named + local imeta = itemstack:get_meta() + local iname = imeta:get_string("name") + if iname then + meta:set_string("infotext", iname) + end - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end - return itemstack - end, + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end + return itemstack + end, - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return count - end - end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return count + end + end, - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return stack:get_count() + end + end, - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local name = player:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return 0 + else + return stack:get_count() + end + end, - on_destruct = function(pos) - local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) + on_destruct = function(pos) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) - mcl_itemframes.drop_generic_item(pos, node, meta) + mcl_itemframes.drop_generic_item(pos, node, meta) - end, + end, - on_rotate = function(pos, node, user, mode, param2) - --local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) + on_rotate = function(pos, node, user, mode, param2) + --local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) - local objs = nil - local name_found = false - local found_name_to_use = "" - name_found = false - found_name_to_use = "" + local objs = nil + local name_found = false + local found_name_to_use = "" + name_found = false + found_name_to_use = "" - for k, v in pairs(mcl_itemframes.frames_registered.glowing) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end + for k, v in pairs(mcl_itemframes.frames_registered.glowing) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end - -- try to cut down on excess looping, if possible. - if name_found == false then - for k, v in pairs(mcl_itemframes.frames_registered.standard) do - if node.name == v then - name_found = true - found_name_to_use = v - break - end - end - end + -- try to cut down on excess looping, if possible. + if name_found == false then + for k, v in pairs(mcl_itemframes.frames_registered.standard) do + if node.name == v then + name_found = true + found_name_to_use = v + break + end + end + end - if node.name == found_name_to_use then - objs = minetest.get_objects_inside_radius(pos, 0.5) - else - return -- short circuit if it's somehow not the right thing. - end + if node.name == found_name_to_use then + objs = minetest.get_objects_inside_radius(pos, 0.5) + else + return -- short circuit if it's somehow not the right thing. + end - if objs then - if mode == screwdriver.ROTATE_FACE or mode == screwdriver.ROTATE_AXIS then - for _, obj in ipairs(objs) do - if obj and obj:get_luaentity() then - local obj_name = obj:get_luaentity().name - if obj_name == found_name_to_use .. "_item" then - if mode == screwdriver.ROTATE_AXIS then - update_roll(obj, pos) - end - break - end - end - end - return false - end - end - end, - } + if objs then + if mode == screwdriver.ROTATE_FACE or mode == screwdriver.ROTATE_AXIS then + for _, obj in ipairs(objs) do + if obj and obj:get_luaentity() then + local obj_name = obj:get_luaentity().name + if obj_name == found_name_to_use .. "_item" then + if mode == screwdriver.ROTATE_AXIS then + update_roll(obj, pos) + end + break + end + end + end + return false + end + end + end, + } - -- make the base items for the base frames. - mcl_itemframes.create_base_item_entity() + -- make the base items for the base frames. + mcl_itemframes.create_base_item_entity() - -- minetest.register_node("mcl_itemframes:item_frame", mcl_itemframes.item_frame_base) + -- minetest.register_node("mcl_itemframes:item_frame", mcl_itemframes.item_frame_base) - -- make glow frame from the base item_frame. - mcl_itemframes.glow_frame_base = table.copy(mcl_itemframes.item_frame_base) - mcl_itemframes.glow_frame_base.description = S("Glowing Item Frame") - mcl_itemframes.glow_frame_base._tt_help = S("Can hold an item and glows.") - mcl_itemframes.glow_frame_base.longdesc = S("Glowing item frames are decorative blocks in which items can be placed and made to glow.") - mcl_itemframes.glow_frame_base.tiles = { "mcl_itemframes_glow_item_frame.png" } - mcl_itemframes.glow_frame_base.inventory_image = "mcl_itemframes_glow_item_frame_item.png" - mcl_itemframes.glow_frame_base.wield_image = "mcl_itemframes_glow_item_frame.png" - mcl_itemframes.glow_frame_base.mesh = "mcl_itemframes_glow_item_frame.obj" + -- make glow frame from the base item_frame. + mcl_itemframes.glow_frame_base = table.copy(mcl_itemframes.item_frame_base) + mcl_itemframes.glow_frame_base.description = S("Glowing Item Frame") + mcl_itemframes.glow_frame_base._tt_help = S("Can hold an item and glows.") + mcl_itemframes.glow_frame_base.longdesc = S("Glowing item frames are decorative blocks in which items can be placed and made to glow.") + mcl_itemframes.glow_frame_base.tiles = { "mcl_itemframes_glow_item_frame.png" } + mcl_itemframes.glow_frame_base.inventory_image = "mcl_itemframes_glow_item_frame_item.png" + mcl_itemframes.glow_frame_base.wield_image = "mcl_itemframes_glow_item_frame.png" + mcl_itemframes.glow_frame_base.mesh = "mcl_itemframes_glow_item_frame.obj" - --[[ - minetest.register_node("mcl_itemframes:glow_item_frame", mcl_itemframes.glow_frame_base) + --[[ + minetest.register_node("mcl_itemframes:glow_item_frame", mcl_itemframes.glow_frame_base) - mcl_itemframes.update_frame_registry("false", "mcl_itemframes:item_frame", false) - mcl_itemframes.update_frame_registry("false", "mcl_itemframes:glow_item_frame", true) - create_register_lbm("mcl_itemframes:item_frame") - create_register_lbm("mcl_itemframes:glow_item_frame") - --]] + mcl_itemframes.update_frame_registry("false", "mcl_itemframes:item_frame", false) + mcl_itemframes.update_frame_registry("false", "mcl_itemframes:glow_item_frame", true) + create_register_lbm("mcl_itemframes:item_frame") + create_register_lbm("mcl_itemframes:glow_item_frame") + --]] end -- for compatibility: function mcl_itemframes.backwards_compatibility () - minetest.register_lbm({ - label = "Update legacy item frames", - name = "mcl_itemframes:update_legacy_item_frames", - nodenames = { "itemframes:frame" }, - action = function(pos, node) - -- Swap legacy node, then respawn entity - node.name = "mcl_itemframes:item_frame" - local meta = minetest.get_meta(pos) - local item = meta:get_string("item") - minetest.swap_node(pos, node) - if item ~= "" then - local itemstack = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) - local inv = meta:get_inventory() - inv:set_size("main", 1) - if not itemstack:is_empty() then - inv:set_stack("main", 1, itemstack) - end - end - mcl_itemframes.update_item_entity(pos, node) - end, - }) - minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame") + minetest.register_lbm({ + label = "Update legacy item frames", + name = "mcl_itemframes:update_legacy_item_frames", + nodenames = { "itemframes:frame" }, + action = function(pos, node) + -- Swap legacy node, then respawn entity + node.name = "mcl_itemframes:item_frame" + local meta = minetest.get_meta(pos) + local item = meta:get_string("item") + minetest.swap_node(pos, node) + if item ~= "" then + local itemstack = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) + local inv = meta:get_inventory() + inv:set_size("main", 1) + if not itemstack:is_empty() then + inv:set_stack("main", 1, itemstack) + end + end + mcl_itemframes.update_item_entity(pos, node) + end, + }) + minetest.register_alias("itemframes:frame", "mcl_itemframes:item_frame") - -- To be installed when complete; 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") - minetest.register_alias("mcl_itemframes:glow_map", "mcl_itemframes:glow_item_frame_map") + -- To be installed when complete; 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") + minetest.register_alias("mcl_itemframes:glow_map", "mcl_itemframes:glow_item_frame_map") - minetest.register_entity("mcl_itemframes:item", frame_item_base) - minetest.register_entity("mcl_itemframes:map", map_item_base) - minetest.register_entity("mcl_itemframes:glow_item", frame_item_base) - minetest.register_entity("mcl_itemframes:glow_map", map_item_base) + minetest.register_entity("mcl_itemframes:item", frame_item_base) + minetest.register_entity("mcl_itemframes:map", map_item_base) + minetest.register_entity("mcl_itemframes:glow_item", frame_item_base) + minetest.register_entity("mcl_itemframes:glow_map", map_item_base) end From 93913ed780b7bd3dff50276fdc5b359cc0d952cd Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 4 Nov 2022 10:36:26 +0000 Subject: [PATCH 12/14] Fix accidental conversion of tabs to spaces. --- mods/ITEMS/mcl_maps/init.lua | 554 +++++++++++++++++------------------ 1 file changed, 277 insertions(+), 277 deletions(-) diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index 87d7dc452..b447953f3 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -26,10 +26,10 @@ minetest.mkdir(map_textures_path) dofile(modpath .. "/tga_encoder_init.lua") local function load_json_file(name) - local file = assert(io.open(modpath .. "/" .. name .. ".json", "r")) - local data = minetest.parse_json(file:read()) - file:close() - return data + local file = assert(io.open(modpath .. "/" .. name .. ".json", "r")) + local data = minetest.parse_json(file:read()) + file:close() + return data end local texture_colors = load_json_file("colors") @@ -43,193 +43,193 @@ local loaded_maps = {} local c_air = minetest.get_content_id("air") function mcl_maps.create_map(pos) - local minp = vector.multiply(vector.floor(vector.divide(pos, 128)), 128) - local maxp = vector.add(minp, vector.new(127, 127, 127)) + local minp = vector.multiply(vector.floor(vector.divide(pos, 128)), 128) + local maxp = vector.add(minp, vector.new(127, 127, 127)) - local itemstack = ItemStack("mcl_maps:filled_map") - local meta = itemstack:get_meta() - local next_id = storage:get_int("next_id") - storage:set_int("next_id", next_id + 1) - local id = tostring(next_id) - meta:set_string("mcl_maps:id", id) - meta:set_string("mcl_maps:minp", pos_to_string(minp)) - meta:set_string("mcl_maps:maxp", pos_to_string(maxp)) - tt.reload_itemstack_description(itemstack) + local itemstack = ItemStack("mcl_maps:filled_map") + local meta = itemstack:get_meta() + local next_id = storage:get_int("next_id") + storage:set_int("next_id", next_id + 1) + local id = tostring(next_id) + meta:set_string("mcl_maps:id", id) + meta:set_string("mcl_maps:minp", pos_to_string(minp)) + meta:set_string("mcl_maps:maxp", pos_to_string(maxp)) + tt.reload_itemstack_description(itemstack) - creating_maps[id] = true - minetest.emerge_area(minp, maxp, function(blockpos, action, calls_remaining) - if calls_remaining > 0 then - return - end - local vm = minetest.get_voxel_manip() - local emin, emax = vm:read_from_map(minp, maxp) - local data = vm:get_data() - local param2data = vm:get_param2_data() - local area = VoxelArea:new({ MinEdge = emin, MaxEdge = emax }) - local pixels = {} - local last_heightmap - for x = 1, 128 do - local map_x = minp.x - 1 + x - local heightmap = {} - for z = 1, 128 do - local map_z = minp.z - 1 + z - local color, height - for map_y = maxp.y, minp.y, -1 do - local index = area:index(map_x, map_y, map_z) - local c_id = data[index] - if c_id ~= c_air then - color = color_cache[c_id] - if color == nil then - local nodename = minetest.get_name_from_content_id(c_id) - local def = minetest.registered_nodes[nodename] - if def then - local texture - if def.palette then - texture = def.palette - elseif def.tiles then - texture = def.tiles[1] - if type(texture) == "table" then - texture = texture.name - end - end - if texture then - texture = texture:match("([^=^%^]-([^.]+))$"):split("^")[1] - end - if def.palette then - local palette = palettes[texture] - color = palette and { palette = palette } - else - color = texture_colors[texture] - end - end - end + creating_maps[id] = true + minetest.emerge_area(minp, maxp, function(blockpos, action, calls_remaining) + if calls_remaining > 0 then + return + end + local vm = minetest.get_voxel_manip() + local emin, emax = vm:read_from_map(minp, maxp) + local data = vm:get_data() + local param2data = vm:get_param2_data() + local area = VoxelArea:new({ MinEdge = emin, MaxEdge = emax }) + local pixels = {} + local last_heightmap + for x = 1, 128 do + local map_x = minp.x - 1 + x + local heightmap = {} + for z = 1, 128 do + local map_z = minp.z - 1 + z + local color, height + for map_y = maxp.y, minp.y, -1 do + local index = area:index(map_x, map_y, map_z) + local c_id = data[index] + if c_id ~= c_air then + color = color_cache[c_id] + if color == nil then + local nodename = minetest.get_name_from_content_id(c_id) + local def = minetest.registered_nodes[nodename] + if def then + local texture + if def.palette then + texture = def.palette + elseif def.tiles then + texture = def.tiles[1] + if type(texture) == "table" then + texture = texture.name + end + end + if texture then + texture = texture:match("([^=^%^]-([^.]+))$"):split("^")[1] + end + if def.palette then + local palette = palettes[texture] + color = palette and { palette = palette } + else + color = texture_colors[texture] + end + end + end - if color and color.palette then - color = color.palette[param2data[index] + 1] - else - color_cache[c_id] = color or false - end + if color and color.palette then + color = color.palette[param2data[index] + 1] + else + color_cache[c_id] = color or false + end - if color and last_heightmap then - local last_height = last_heightmap[z] - if last_height < map_y then - color = { - math.min(255, color[1] + 16), - math.min(255, color[2] + 16), - math.min(255, color[3] + 16), - } - elseif last_height > map_y then - color = { - math.max(0, color[1] - 16), - math.max(0, color[2] - 16), - math.max(0, color[3] - 16), - } - end - end - height = map_y - break - end - end - heightmap[z] = height or minp.y - pixels[z] = pixels[z] or {} - pixels[z][x] = color or { 0, 0, 0 } - end - last_heightmap = heightmap - end - tga_encoder.image(pixels):save(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".tga") - creating_maps[id] = nil - end) - return itemstack + if color and last_heightmap then + local last_height = last_heightmap[z] + if last_height < map_y then + color = { + math.min(255, color[1] + 16), + math.min(255, color[2] + 16), + math.min(255, color[3] + 16), + } + elseif last_height > map_y then + color = { + math.max(0, color[1] - 16), + math.max(0, color[2] - 16), + math.max(0, color[3] - 16), + } + end + end + height = map_y + break + end + end + heightmap[z] = height or minp.y + pixels[z] = pixels[z] or {} + pixels[z][x] = color or { 0, 0, 0 } + end + last_heightmap = heightmap + end + tga_encoder.image(pixels):save(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".tga") + creating_maps[id] = nil + end) + return itemstack end function mcl_maps.load_map(id, callback) - if id == "" or creating_maps[id] then - return false - end + if id == "" or creating_maps[id] then + return false + end - local texture = "mcl_maps_map_texture_" .. id .. ".tga" + local texture = "mcl_maps_map_texture_" .. id .. ".tga" - local result = true + local result = true - if not loaded_maps[id] then - if not minetest.features.dynamic_add_media_table then - -- minetest.dynamic_add_media() blocks in - -- Minetest 5.3 and 5.4 until media loads - loaded_maps[id] = true - result = dynamic_add_media(map_textures_path .. texture, function() - end) - if callback then - callback(texture) - end - else - -- minetest.dynamic_add_media() never blocks - -- in Minetest 5.5, callback runs after load - result = dynamic_add_media(map_textures_path .. texture, function() - loaded_maps[id] = true - if callback then - callback(texture) - end - end) - end - end + if not loaded_maps[id] then + if not minetest.features.dynamic_add_media_table then + -- minetest.dynamic_add_media() blocks in + -- Minetest 5.3 and 5.4 until media loads + loaded_maps[id] = true + result = dynamic_add_media(map_textures_path .. texture, function() + end) + if callback then + callback(texture) + end + else + -- minetest.dynamic_add_media() never blocks + -- in Minetest 5.5, callback runs after load + result = dynamic_add_media(map_textures_path .. texture, function() + loaded_maps[id] = true + if callback then + callback(texture) + end + end) + end + end - if result == false then - return false - end + if result == false then + return false + end - if loaded_maps[id] then - if callback then - callback(texture) - end - return texture - end + if loaded_maps[id] then + if callback then + callback(texture) + end + return texture + end end function mcl_maps.load_map_item(itemstack) - return mcl_maps.load_map(itemstack:get_meta():get_string("mcl_maps:id")) + return mcl_maps.load_map(itemstack:get_meta():get_string("mcl_maps:id")) end local function fill_map(itemstack, placer, pointed_thing) - local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing) - if new_stack then - return new_stack - end + local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing) + if new_stack then + return new_stack + end - if minetest.settings:get_bool("enable_real_maps", true) then - local new_map = mcl_maps.create_map(placer:get_pos()) - itemstack:take_item() - if itemstack:is_empty() then - return new_map - else - local inv = placer:get_inventory() - if inv:room_for_item("main", new_map) then - inv:add_item("main", new_map) - else - minetest.add_item(placer:get_pos(), new_map) - end - return itemstack - end - end + if minetest.settings:get_bool("enable_real_maps", true) then + local new_map = mcl_maps.create_map(placer:get_pos()) + itemstack:take_item() + if itemstack:is_empty() then + return new_map + else + local inv = placer:get_inventory() + if inv:room_for_item("main", new_map) then + inv:add_item("main", new_map) + else + minetest.add_item(placer:get_pos(), new_map) + end + return itemstack + end + end end minetest.register_craftitem("mcl_maps:empty_map", { - description = S("Empty Map"), - _doc_items_longdesc = S("Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used."), - _doc_items_usagehelp = S("Rightclick to create a filled map (which can't be stacked anymore)."), - inventory_image = "mcl_maps_map_empty.png", - on_place = fill_map, - on_secondary_use = fill_map, - stack_max = 64, + description = S("Empty Map"), + _doc_items_longdesc = S("Empty maps are not useful as maps, but they can be stacked and turned to maps which can be used."), + _doc_items_usagehelp = S("Rightclick to create a filled map (which can't be stacked anymore)."), + inventory_image = "mcl_maps_map_empty.png", + on_place = fill_map, + on_secondary_use = fill_map, + stack_max = 64, }) local filled_def = { - description = S("Map"), - _tt_help = S("Shows a map image."), - _doc_items_longdesc = S("When created, the map saves the nearby area as an image that can be viewed any time by holding the map."), - _doc_items_usagehelp = S("Hold the map in your hand. This will display a map on your screen."), - inventory_image = "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)", - stack_max = 64, - groups = { not_in_creative_inventory = 1, filled_map = 1, tool = 1 }, + description = S("Map"), + _tt_help = S("Shows a map image."), + _doc_items_longdesc = S("When created, the map saves the nearby area as an image that can be viewed any time by holding the map."), + _doc_items_usagehelp = S("Hold the map in your hand. This will display a map on your screen."), + inventory_image = "mcl_maps_map_filled.png^(mcl_maps_map_filled_markings.png^[colorize:#000000)", + stack_max = 64, + groups = { not_in_creative_inventory = 1, filled_map = 1, tool = 1 }, } minetest.register_craftitem("mcl_maps:filled_map", filled_def) @@ -248,72 +248,72 @@ filled_wield_def._mcl_wieldview_item = "mcl_maps:filled_map" local mcl_skins_enabled = minetest.global_exists("mcl_skins") if mcl_skins_enabled then - -- Generate a node for every skin - local list = mcl_skins.get_skin_list() - for _, skin in pairs(list) do - if skin.slim_arms then - local female = table.copy(filled_wield_def) - female._mcl_hand_id = skin.id - female.mesh = "mcl_meshhand_female.b3d" - female.tiles = { skin.texture } - minetest.register_node("mcl_maps:filled_map_" .. skin.id, female) - else - local male = table.copy(filled_wield_def) - male._mcl_hand_id = skin.id - male.mesh = "mcl_meshhand.b3d" - male.tiles = { skin.texture } - minetest.register_node("mcl_maps:filled_map_" .. skin.id, male) - end - end + -- Generate a node for every skin + local list = mcl_skins.get_skin_list() + for _, skin in pairs(list) do + if skin.slim_arms then + local female = table.copy(filled_wield_def) + female._mcl_hand_id = skin.id + female.mesh = "mcl_meshhand_female.b3d" + female.tiles = { skin.texture } + minetest.register_node("mcl_maps:filled_map_" .. skin.id, female) + else + local male = table.copy(filled_wield_def) + male._mcl_hand_id = skin.id + male.mesh = "mcl_meshhand.b3d" + male.tiles = { skin.texture } + minetest.register_node("mcl_maps:filled_map_" .. skin.id, male) + end + end else - filled_wield_def._mcl_hand_id = "hand" - filled_wield_def.mesh = "mcl_meshhand.b3d" - filled_wield_def.tiles = { "character.png" } - minetest.register_node("mcl_maps:filled_map_hand", filled_wield_def) + filled_wield_def._mcl_hand_id = "hand" + filled_wield_def.mesh = "mcl_meshhand.b3d" + filled_wield_def.tiles = { "character.png" } + minetest.register_node("mcl_maps:filled_map_hand", filled_wield_def) end local old_add_item = minetest.add_item function minetest.add_item(pos, stack) - stack = ItemStack(stack) - if get_item_group(stack:get_name(), "filled_map") > 0 then - stack:set_name("mcl_maps:filled_map") - end - return old_add_item(pos, stack) + stack = ItemStack(stack) + if get_item_group(stack:get_name(), "filled_map") > 0 then + stack:set_name("mcl_maps:filled_map") + end + return old_add_item(pos, stack) end tt.register_priority_snippet(function(itemstring, _, itemstack) - if itemstack and get_item_group(itemstring, "filled_map") > 0 then - local id = itemstack:get_meta():get_string("mcl_maps:id") - if id ~= "" then - return "#" .. id, mcl_colors.GRAY - end - end + if itemstack and get_item_group(itemstring, "filled_map") > 0 then + local id = itemstack:get_meta():get_string("mcl_maps:id") + if id ~= "" then + return "#" .. id, mcl_colors.GRAY + end + end end) minetest.register_craft({ - output = "mcl_maps:empty_map", - recipe = { - { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, - { "mcl_core:paper", "group:compass", "mcl_core:paper" }, - { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, - } + output = "mcl_maps:empty_map", + recipe = { + { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, + { "mcl_core:paper", "group:compass", "mcl_core:paper" }, + { "mcl_core:paper", "mcl_core:paper", "mcl_core:paper" }, + } }) minetest.register_craft({ - type = "shapeless", - output = "mcl_maps:filled_map 2", - recipe = { "group:filled_map", "mcl_maps:empty_map" }, + type = "shapeless", + output = "mcl_maps:filled_map 2", + recipe = { "group:filled_map", "mcl_maps:empty_map" }, }) local function on_craft(itemstack, player, old_craft_grid, craft_inv) - if itemstack:get_name() == "mcl_maps:filled_map" then - for _, stack in pairs(old_craft_grid) do - if get_item_group(stack:get_name(), "filled_map") > 0 then - itemstack:get_meta():from_table(stack:get_meta():to_table()) - return itemstack - end - end - end + if itemstack:get_name() == "mcl_maps:filled_map" then + for _, stack in pairs(old_craft_grid) do + if get_item_group(stack:get_name(), "filled_map") > 0 then + itemstack:get_meta():from_table(stack:get_meta():to_table()) + return itemstack + end + end + end end minetest.register_on_craft(on_craft) @@ -323,80 +323,80 @@ local maps = {} local huds = {} minetest.register_on_joinplayer(function(player) - local map_def = { - hud_elem_type = "image", - text = "blank.png", - position = { x = 0.75, y = 0.8 }, - alignment = { x = 0, y = -1 }, - offset = { x = 0, y = 0 }, - scale = { x = 2, y = 2 }, - } - local marker_def = table.copy(map_def) - marker_def.alignment = { x = 0, y = 0 } - huds[player] = { - map = player:hud_add(map_def), - marker = player:hud_add(marker_def), - } + local map_def = { + hud_elem_type = "image", + text = "blank.png", + position = { x = 0.75, y = 0.8 }, + alignment = { x = 0, y = -1 }, + offset = { x = 0, y = 0 }, + scale = { x = 2, y = 2 }, + } + local marker_def = table.copy(map_def) + marker_def.alignment = { x = 0, y = 0 } + huds[player] = { + map = player:hud_add(map_def), + marker = player:hud_add(marker_def), + } end) minetest.register_on_leaveplayer(function(player) - maps[player] = nil - huds[player] = nil + maps[player] = nil + huds[player] = nil end) minetest.register_globalstep(function(dtime) - for _, player in pairs(get_connected_players()) do - local wield = player:get_wielded_item() - local texture = mcl_maps.load_map_item(wield) - local hud = huds[player] - if texture then - local wield_def = wield:get_definition() - local hand_def = player:get_inventory():get_stack("hand", 1):get_definition() + for _, player in pairs(get_connected_players()) do + local wield = player:get_wielded_item() + local texture = mcl_maps.load_map_item(wield) + local hud = huds[player] + if texture then + local wield_def = wield:get_definition() + local hand_def = player:get_inventory():get_stack("hand", 1):get_definition() - if hand_def and wield_def and hand_def._mcl_hand_id ~= wield_def._mcl_hand_id then - wield:set_name("mcl_maps:filled_map_" .. hand_def._mcl_hand_id) - player:set_wielded_item(wield) - end + if hand_def and wield_def and hand_def._mcl_hand_id ~= wield_def._mcl_hand_id then + wield:set_name("mcl_maps:filled_map_" .. hand_def._mcl_hand_id) + player:set_wielded_item(wield) + end - if texture ~= maps[player] then - player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture) - maps[player] = texture - end + if texture ~= maps[player] then + player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture) + maps[player] = texture + end - local pos = vector.round(player:get_pos()) - local meta = wield:get_meta() - local minp = string_to_pos(meta:get_string("mcl_maps:minp")) - local maxp = string_to_pos(meta:get_string("mcl_maps:maxp")) + local pos = vector.round(player:get_pos()) + local meta = wield:get_meta() + local minp = string_to_pos(meta:get_string("mcl_maps:minp")) + local maxp = string_to_pos(meta:get_string("mcl_maps:maxp")) - local marker = "mcl_maps_player_arrow.png" + local marker = "mcl_maps_player_arrow.png" - if pos.x < minp.x then - marker = "mcl_maps_player_dot.png" - pos.x = minp.x - elseif pos.x > maxp.x then - marker = "mcl_maps_player_dot.png" - pos.x = maxp.x - end + if pos.x < minp.x then + marker = "mcl_maps_player_dot.png" + pos.x = minp.x + elseif pos.x > maxp.x then + marker = "mcl_maps_player_dot.png" + pos.x = maxp.x + end - if pos.z < minp.z then - marker = "mcl_maps_player_dot.png" - pos.z = minp.z - elseif pos.z > maxp.z then - marker = "mcl_maps_player_dot.png" - pos.z = maxp.z - end + if pos.z < minp.z then + marker = "mcl_maps_player_dot.png" + pos.z = minp.z + elseif pos.z > maxp.z then + marker = "mcl_maps_player_dot.png" + pos.z = maxp.z + end - if marker == "mcl_maps_player_arrow.png" then - local yaw = (math.floor(player:get_look_horizontal() * 180 / math.pi / 90 + 0.5) % 4) * 90 - marker = marker .. "^[transformR" .. yaw - end + if marker == "mcl_maps_player_arrow.png" then + local yaw = (math.floor(player:get_look_horizontal() * 180 / math.pi / 90 + 0.5) % 4) * 90 + marker = marker .. "^[transformR" .. yaw + end - player:hud_change(hud.marker, "text", marker) - player:hud_change(hud.marker, "offset", { x = (6 - 140 / 2 + pos.x - minp.x) * 2, y = (6 - 140 + maxp.z - pos.z) * 2 }) - elseif maps[player] then - player:hud_change(hud.map, "text", "blank.png") - player:hud_change(hud.marker, "text", "blank.png") - maps[player] = nil - end - end + player:hud_change(hud.marker, "text", marker) + player:hud_change(hud.marker, "offset", { x = (6 - 140 / 2 + pos.x - minp.x) * 2, y = (6 - 140 + maxp.z - pos.z) * 2 }) + elseif maps[player] then + player:hud_change(hud.map, "text", "blank.png") + player:hud_change(hud.marker, "text", "blank.png") + maps[player] = nil + end + end end) From c4981d894c2a80f5245e1f20aed1c70957fccb2c Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 4 Nov 2022 22:18:46 +0000 Subject: [PATCH 13/14] Removed the local cached copy of the built in TGA encoder. --- mods/ITEMS/mcl_maps/init.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index b447953f3..84f4019ea 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -22,9 +22,6 @@ local map_textures_path = worldpath .. "/mcl_maps/" minetest.mkdir(map_textures_path) --- overwrite the builtin tga_encoder -dofile(modpath .. "/tga_encoder_init.lua") - local function load_json_file(name) local file = assert(io.open(modpath .. "/" .. name .. ".json", "r")) local data = minetest.parse_json(file:read()) From b62f61db1079b7da1e06e1a3662f8fb028fa6005 Mon Sep 17 00:00:00 2001 From: Michieal Date: Fri, 4 Nov 2022 22:54:06 +0000 Subject: [PATCH 14/14] 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. --- mods/ITEMS/mcl_itemframes/init.lua | 6 ++-- mods/ITEMS/mcl_itemframes/item_frames_API.lua | 17 +++++---- .../mcl_itemframes/item_frames_api_doc.txt | 36 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 mods/ITEMS/mcl_itemframes/item_frames_api_doc.txt diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index a7c949b8c..e0c41c1f4 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -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. diff --git a/mods/ITEMS/mcl_itemframes/item_frames_API.lua b/mods/ITEMS/mcl_itemframes/item_frames_API.lua index 9173192bb..bd78f33e1 100644 --- a/mods/ITEMS/mcl_itemframes/item_frames_API.lua +++ b/mods/ITEMS/mcl_itemframes/item_frames_API.lua @@ -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") diff --git a/mods/ITEMS/mcl_itemframes/item_frames_api_doc.txt b/mods/ITEMS/mcl_itemframes/item_frames_api_doc.txt new file mode 100644 index 000000000..7510b15b5 --- /dev/null +++ b/mods/ITEMS/mcl_itemframes/item_frames_api_doc.txt @@ -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' }, +})