From 2c5eca399928567e6423ff733b472721393ed99f Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 4 May 2021 08:49:21 +0200 Subject: [PATCH] Make clocks work in itemframes --- mods/ITEMS/mcl_clock/init.lua | 3 +++ mods/ITEMS/mcl_itemframes/init.lua | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_clock/init.lua b/mods/ITEMS/mcl_clock/init.lua index 30753f43..0f697844 100644 --- a/mods/ITEMS/mcl_clock/init.lua +++ b/mods/ITEMS/mcl_clock/init.lua @@ -92,10 +92,12 @@ minetest.register_globalstep(function(dtime) force_clock_update_timer = 0 mcl_clock.old_time = now + mcl_clock.random_frame = random_frame for p, player in pairs(minetest.get_connected_players()) do for s, stack in pairs(player:get_inventory():get_list("main")) do local dim = mcl_worlds.pos_to_dimension(player:get_pos()) + local frame -- Clocks do not work in certain zones if not mcl_worlds.clock_works(player:get_pos()) then @@ -103,6 +105,7 @@ minetest.register_globalstep(function(dtime) else frame = now end + local count = stack:get_count() if stack:get_name() == mcl_clock.stereotype then player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count) diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 4afb1d04..07779e54 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -148,6 +148,21 @@ minetest.register_node("mcl_itemframes:item_frame",{ 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 @@ -188,9 +203,13 @@ minetest.register_node("mcl_itemframes:item_frame",{ end local put_itemstack = ItemStack(itemstack) put_itemstack:set_count(1) - if minetest.get_item_group(put_itemstack:get_name(), "compass") > 0 then + local itemname = put_itemstack:get_name() + if minetest.get_item_group(itemname, "compass") > 0 then put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2)))) 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