mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-24 20:03:45 +01:00
Make clocks work in itemframes
This commit is contained in:
parent
74e3c6555d
commit
2c5eca3999
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user