Make clocks work in itemframes

This commit is contained in:
Elias Fleckenstein 2021-05-04 08:49:21 +02:00
parent 74e3c6555d
commit 2c5eca3999
2 changed files with 23 additions and 1 deletions

View File

@ -92,10 +92,12 @@ minetest.register_globalstep(function(dtime)
force_clock_update_timer = 0 force_clock_update_timer = 0
mcl_clock.old_time = now mcl_clock.old_time = now
mcl_clock.random_frame = random_frame
for p, player in pairs(minetest.get_connected_players()) do for p, player in pairs(minetest.get_connected_players()) do
for s, stack in pairs(player:get_inventory():get_list("main")) do for s, stack in pairs(player:get_inventory():get_list("main")) do
local dim = mcl_worlds.pos_to_dimension(player:get_pos()) local dim = mcl_worlds.pos_to_dimension(player:get_pos())
local frame local frame
-- Clocks do not work in certain zones -- Clocks do not work in certain zones
if not mcl_worlds.clock_works(player:get_pos()) then if not mcl_worlds.clock_works(player:get_pos()) then
@ -103,6 +105,7 @@ minetest.register_globalstep(function(dtime)
else else
frame = now frame = now
end end
local count = stack:get_count() local count = stack:get_count()
if stack:get_name() == mcl_clock.stereotype then if stack:get_name() == mcl_clock.stereotype then
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count) player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)

View File

@ -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 }, groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 },
sounds = mcl_sounds.node_sound_defaults(), sounds = mcl_sounds.node_sound_defaults(),
node_placement_prediction = "", 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) on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return itemstack return itemstack
@ -188,9 +203,13 @@ minetest.register_node("mcl_itemframes:item_frame",{
end end
local put_itemstack = ItemStack(itemstack) local put_itemstack = ItemStack(itemstack)
put_itemstack:set_count(1) 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)))) put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2))))
end 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) inv:set_stack("main", 1, put_itemstack)
update_item_entity(pos, node) update_item_entity(pos, node)
-- Add node infotext when item has been named -- Add node infotext when item has been named