diff --git a/abms.lua b/abms.lua index 2d634ee..3f8dded 100644 --- a/abms.lua +++ b/abms.lua @@ -302,7 +302,19 @@ minetest.register_abm({ nodenames = {"fun_caves:casket"}, interval = 2, chance = 10, - action = function(pos, node) + catch_up = false, + action = function(pos, node, aoc, active_object_count_wider) + -- do not spawn if too many active entities in area + if active_object_count_wider > 5 then + return + end + + local meta = minetest.get_meta(pos) + local ready = meta:get_string('formspec') + if ready ~= '' then + return + end + local objs = minetest.get_objects_inside_radius(pos, 7) for i = 1, #objs do if objs[i]:is_player() then diff --git a/pyramid.lua b/pyramid.lua index d2b091c..4d96d36 100644 --- a/pyramid.lua +++ b/pyramid.lua @@ -8,11 +8,6 @@ newnode.groups.pyramid = 1 newnode.drop = 'default:sandstone' minetest.register_node("fun_caves:pyramid_1", newnode) -local newnode = fun_caves.clone_node("default:chest") -newnode.description = "Treasure Casket" -newnode.light_source = 1 -newnode.on_construct = nil - local chest_formspec = "size[8,9]" .. default.gui_bg .. @@ -33,16 +28,16 @@ end local gems = {'fun_caves:moonstone', 'fun_caves:coral_gem', 'fun_caves:garnet', 'fun_caves:aquamarine', 'fun_caves:zoisite', 'fun_caves:sky_iron'} +local newnode = fun_caves.clone_node("default:chest") +newnode.description = "Treasure Casket" +newnode.light_source = 1 +newnode.on_construct = nil newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local meta = minetest.get_meta(pos) local ready = meta:get_string('formspec') if ready == '' then - if math.random(15) ~= 1 then - meta:set_string("formspec", 'del') - clicker:set_hp(clicker:get_hp() - 2) - minetest.remove_node(pos) - else + if math.random(10) == 1 then meta:set_string("formspec", chest_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) @@ -50,6 +45,10 @@ newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) inv:add_item('main', filler[math.random(#filler)]) end inv:add_item('main', gems[math.random(#gems)]) + else + meta:set_string("formspec", 'del') + clicker:set_hp(clicker:get_hp() - 2) + minetest.remove_node(pos) end end end