diff --git a/mods/tsm_pyramids/depends.txt b/mods/tsm_pyramids/depends.txt index 35c3eb6c..81a62cad 100755 --- a/mods/tsm_pyramids/depends.txt +++ b/mods/tsm_pyramids/depends.txt @@ -1,5 +1,6 @@ default mobs +maptools farming? treasurer? watershed? diff --git a/mods/tsm_pyramids/init.lua b/mods/tsm_pyramids/init.lua index ad9327e0..5cbc7b42 100755 --- a/mods/tsm_pyramids/init.lua +++ b/mods/tsm_pyramids/init.lua @@ -1,4 +1,5 @@ pyramids = {} +pyramids.max_time = 30*60 dofile(minetest.get_modpath("tsm_pyramids").."/mummy.lua") dofile(minetest.get_modpath("tsm_pyramids").."/nodes.lua") @@ -16,37 +17,34 @@ local chest_stuff = { } function pyramids.fill_chest(pos) - minetest.after(2, function() - local n = minetest.get_node(pos) - if n and n.name and n.name == "maptools:chest" then - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - inv:set_size("main", 8*4) - inv:set_list("main", - { - [1] = "", - [32] = "" - } - ) - if math.random(1,10) < 7 then return end - local stacks = {} - if minetest.get_modpath("treasurer") ~= nil then - stacks = treasurer.select_random_treasures() - else - for i=0,2,1 do - local stuff = chest_stuff[math.random(1,#chest_stuff)] - if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end - table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) - end + local n = minetest.get_node_or_nil(pos) + if n and n.name and n.name == "tsm_pyramids:chest" then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 8*4) + inv:set_list("main", + { + [1] = "", + [32] = "" + } + ) + if math.random(1,10) < 7 then return end + local stacks = {} + if minetest.get_modpath("treasurer") ~= nil then + stacks = treasurer.select_random_treasures() + else + for i=0,2,1 do + local stuff = chest_stuff[math.random(1,#chest_stuff)] + if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end + table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) end - for s=1,#stacks do - if not inv:contains_item("main", stacks[s]) then - inv:set_stack("main", math.random(1,32), stacks[s]) - end - end - end - end) + for s=1,#stacks do + if not inv:contains_item("main", stacks[s]) then + inv:set_stack("main", math.random(1,32), stacks[s]) + end + end + end end local function add_spawner(pos) @@ -73,45 +71,45 @@ local function underground(pos) while can_replace(p2)==true do cnt = cnt+1 if cnt > 25 then break end - if cnt>math.random(2,4) then mat = "desert_stone"end + if cnt>math.random(2,4) then mat = "desert_stone" end minetest.set_node(p2, {name="default:"..mat}) p2.y = p2.y-1 end end local function make_entrance(pos) - local gang = {x=pos.x+10,y=pos.y, z=pos.z} - for iy=2,3,1 do - for iz=0,6,1 do - minetest.remove_node({x=gang.x+1,y=gang.y+iy,z=gang.z+iz}) - if iz >=3 and iy == 3 then - minetest.set_node({x=gang.x,y=gang.y+iy+1,z=gang.z+iz}, {name="maptools:sandstone_brick"}) - minetest.set_node({x=gang.x+1,y=gang.y+iy+1,z=gang.z+iz}, {name="maptools:sandstone_brick"}) - minetest.set_node({x=gang.x+2,y=gang.y+iy+1,z=gang.z+iz}, {name="maptools:sandstone_brick"}) + local gang = {x=pos.x+10,y=pos.y, z=pos.z} + for iy=2,3,1 do + for iz=0,6,1 do + minetest.remove_node({x=gang.x+1,y=gang.y+iy,z=gang.z+iz}) + if iz >=3 and iy == 3 then + minetest.set_node({x=gang.x,y=gang.y+iy+1,z=gang.z+iz}, {name="maptools:sandstone_brick"}) + minetest.set_node({x=gang.x+1,y=gang.y+iy+1,z=gang.z+iz}, {name="maptools:sandstone_brick"}) + minetest.set_node({x=gang.x+2,y=gang.y+iy+1,z=gang.z+iz}, {name="maptools:sandstone_brick"}) + end end end - end end -local function make(pos) - minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")") - for iy=0,10,1 do - for ix=iy,22-iy,1 do - for iz=iy,22-iy,1 do - if iy <1 then underground({x=pos.x+ix,y=pos.y,z=pos.z+iz}) end - minetest.set_node({x=pos.x+ix,y=pos.y+iy,z=pos.z+iz}, {name="maptools:sandstone_brick"}) - for yy=1,10-iy,1 do - local n = minetest.get_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz}) - if n and n.name and n.name == "default:desert_stone" then minetest.set_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz},{name="default:desert_sand"}) end - end +function pyramids.make(pos) + minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")") + for iy=0,10,1 do + for ix=iy,22-iy,1 do + for iz=iy,22-iy,1 do + if iy <1 then underground({x=pos.x+ix,y=pos.y,z=pos.z+iz}) end + minetest.set_node({x=pos.x+ix,y=pos.y+iy,z=pos.z+iz}, {name="maptools:sandstone_brick"}) + for yy=1,10-iy,1 do + local n = minetest.get_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz}) + if n and n.name and n.name == "default:desert_stone" then minetest.set_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz},{name="default:desert_sand"}) end + end + end end end - end - pyramids.make_room(pos) - minetest.after(2, pyramids.make_traps, pos) - add_spawner({x=pos.x+11,y=pos.y+2, z=pos.z+17}) - make_entrance({x=pos.x,y=pos.y, z=pos.z}) + pyramids.make_room(pos) + minetest.after(2, pyramids.make_traps, pos) + add_spawner({x=pos.x+11,y=pos.y+2, z=pos.z+17}) + make_entrance({x=pos.x,y=pos.y, z=pos.z}) end local perl1 = {SEED1 = 9130, OCTA1 = 3, PERS1 = 0.5, SCAL1 = 250} -- Values should match minetest mapgen V6 desert noise. @@ -124,6 +122,7 @@ local function hlp_fnct(pos, name) return false end end + local function ground(pos, old) local p2 = pos while hlp_fnct(p2, "air") do @@ -140,48 +139,49 @@ end minetest.register_on_generated(function(minp, maxp, seed) minetest.after(3, function(minp, maxp, seed) - if maxp.y < 0 then return end - math.randomseed(seed) - local cnt = 0 + if maxp.y < 0 then return end + math.randomseed(seed) + local cnt = 0 - local perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1) - local noise1 = perlin1:get2d({x=minp.x,y=minp.y})--,z=minp.z}) + local perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1) + local noise1 = perlin1:get2d({x=minp.x,y=minp.y})--,z=minp.z}) - if noise1 > 0.25 or noise1 < -0.26 and math.random(1,100) % 2 == 0 then -- Coward attempt to divide per 2 the spawn rate - local mpos = {x=math.random(minp.x,maxp.x), y=math.random(minp.y,maxp.y), z=math.random(minp.z,maxp.z)} + if noise1 > 0.25 or noise1 < -0.26 and math.random(1,100) % 2 == 0 then -- Coward attempt to divide per 2 the spawn rate + local mpos = {x=math.random(minp.x,maxp.x), y=math.random(minp.y,maxp.y), z=math.random(minp.z,maxp.z)} - local p2 = minetest.find_node_near(mpos, 25, {"default:desert_sand"}) - while p2 == nil and cnt < 5 do - cnt = cnt+1 - mpos = {x=math.random(minp.x,maxp.x), y=math.random(minp.y,maxp.y), z=math.random(minp.z,maxp.z)} - p2 = minetest.find_node_near(mpos, 25, {"default:desert_sand"}) + local p2 = minetest.find_node_near(mpos, 25, {"default:desert_sand"}) + while p2 == nil and cnt < 5 do + cnt = cnt+1 + mpos = {x=math.random(minp.x,maxp.x), y=math.random(minp.y,maxp.y), z=math.random(minp.z,maxp.z)} + p2 = minetest.find_node_near(mpos, 25, {"default:desert_sand"}) + end + if p2 == nil then return end + if p2.y < 0 then return end + + local off = 0 + local opos1 = {x=p2.x+22,y=p2.y-1,z=p2.z+22} + local opos2 = {x=p2.x+22,y=p2.y-1,z=p2.z} + local opos3 = {x=p2.x,y=p2.y-1,z=p2.z+22} + local opos1_n = minetest.get_node_or_nil(opos1) + local opos2_n = minetest.get_node_or_nil(opos2) + local opos3_n = minetest.get_node_or_nil(opos3) + if opos1_n and opos1_n.name and opos1_n.name == "air" then + p2 = ground(opos1, p2) + end + if opos2_n and opos2_n.name and opos2_n.name == "air" then + p2 = ground(opos2, p2) + end + if opos3_n and opos3_n.name and opos3_n.name == "air" then + p2 = ground(opos3, p2) + end + p2.y = p2.y - 3 + if p2.y < 0 then p2.y = 0 end + if minetest.find_node_near(p2, 25, {"default:water_source"}) ~= nil + or minetest.find_node_near(p2, 22, {"default:dirt_with_grass"}) ~= nil + or minetest.find_node_near(p2, 52, {"maptools:sandstone_brick"}) ~= nil then return end + + if math.random(0,10) > 7 then return end + pyramids.make(p2) end - if p2 == nil then return end - if p2.y < 0 then return end - - local off = 0 - local opos1 = {x=p2.x+22,y=p2.y-1,z=p2.z+22} - local opos2 = {x=p2.x+22,y=p2.y-1,z=p2.z} - local opos3 = {x=p2.x,y=p2.y-1,z=p2.z+22} - local opos1_n = minetest.get_node_or_nil(opos1) - local opos2_n = minetest.get_node_or_nil(opos2) - local opos3_n = minetest.get_node_or_nil(opos3) - if opos1_n and opos1_n.name and opos1_n.name == "air" then - p2 = ground(opos1, p2) - end - if opos2_n and opos2_n.name and opos2_n.name == "air" then - p2 = ground(opos2, p2) - end - if opos3_n and opos3_n.name and opos3_n.name == "air" then - p2 = ground(opos3, p2) - end - p2.y = p2.y - 3 - if p2.y < 0 then p2.y = 0 end - if minetest.find_node_near(p2, 25, {"default:water_source"}) ~= nil or minetest.find_node_near(p2, 22, {"default:dirt_with_grass"}) ~= nil or minetest.find_node_near(p2, 52, {"maptools:sandstone_brick"}) ~= nil then return end - - if math.random(0,10) > 7 then return end - make(p2) - end - end, minp, maxp, seed) end) diff --git a/mods/tsm_pyramids/mummy.lua b/mods/tsm_pyramids/mummy.lua index 4107f9e6..d7449047 100755 --- a/mods/tsm_pyramids/mummy.lua +++ b/mods/tsm_pyramids/mummy.lua @@ -52,10 +52,31 @@ mobs:register_mob("tsm_pyramids:mummy", { sit_start = 81, sit_end = 160, lay_start = 162, lay_end = 166, mine_start = 74, mine_end = 105, - walk_mine_start = 74, walk_mine_end = 105, + walk_mine_start = 74, walk_mine_end = 105, }, }) +--MFF ABM to replace old maptools:chest +minetest.register_abm({ + nodenames = {"tsm_pyramids:spawner_mummy"}, + interval = 10.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local chests = minetest.find_nodes_in_area( + {x=pos.x-4, y=pos.y-3, z=pos.z-10}, + {x=pos.x+4, y=pos.y, z=pos.z}, + "maptools:chest" + ) + for _, cpos in ipairs(chests) do + local p2 = 0 + local n = minetest.get_node_or_nil(cpos) + if n and n.param2 then + p2 = n.param2 + end + minetest.set_node(cpos, {name="tsm_pyramids:chest", param2=p2}) + end + end +}) -- spawner (spawn in pyramids, near the spawner) if not minetest.setting_getbool("only_peaceful_mobs") then minetest.register_abm({ @@ -101,10 +122,10 @@ minetest.register_node("tsm_pyramids:spawner_mummy", { drop = "", on_construct = function(pos) pos.y = pos.y - 0.28 - minetest.env:add_entity(pos,"tsm_pyramids:mummy_spawner") + minetest.add_entity(pos,"tsm_pyramids:mummy_spawner") end, on_destruct = function(pos) - for _,obj in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do + for _,obj in ipairs(minetest.get_objects_inside_radius(pos, 1)) do if not obj:is_player() then if obj ~= nil and obj:get_luaentity().m_name == "dummy" then obj:remove() @@ -122,7 +143,7 @@ minetest.register_craftitem("tsm_pyramids:spawn_egg", { stack_max = 99, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type == "node" then - minetest.env:add_entity(pointed_thing.above,"tsm_pyramids:mummy") + minetest.add_entity(pointed_thing.above,"tsm_pyramids:mummy") if not minetest.setting_getbool("creative_mode") then itemstack:take_item() end return itemstack end diff --git a/mods/tsm_pyramids/nodes.lua b/mods/tsm_pyramids/nodes.lua index 14817bce..560f907d 100755 --- a/mods/tsm_pyramids/nodes.lua +++ b/mods/tsm_pyramids/nodes.lua @@ -4,14 +4,14 @@ for i=1,3 do minetest.register_node("tsm_pyramids:deco_stone"..i, { description = "Sandstone with "..img[i], tiles = {"default_sandstone.png^tsm_pyramids_"..img[i]..".png"}, - is_ground_content = true, + is_ground_content = false, groups = {unbreakable=1}, sounds = default.node_sound_stone_defaults(), }) end -trap_on_timer = function (pos, elapsed) - local objs = minetest.env:get_objects_inside_radius(pos, 2) +local trap_on_timer = function (pos, elapsed) + local objs = minetest.get_objects_inside_radius(pos, 2) for i, obj in pairs(objs) do if obj:is_player() then local n = minetest.get_node(pos) @@ -27,11 +27,11 @@ end minetest.register_node("tsm_pyramids:trap", { description = "Cracked sandstone brick", tiles = {"default_sandstone_brick.png^tsm_pyramids_crack.png"}, - is_ground_content = true, + is_ground_content = false, groups = {crumbly=2,cracky=3}, sounds = default.node_sound_stone_defaults(), on_construct = function(pos) - minetest.env:get_node_timer(pos):start(0.1) + minetest.get_node_timer(pos):start(0.1) end, crack = 1, on_timer = trap_on_timer, @@ -41,8 +41,31 @@ minetest.register_node("tsm_pyramids:trap", { minetest.register_node("tsm_pyramids:trap_2", { description = "trapstone", tiles = {"default_sandstone_brick.png^tsm_pyramids_crack.png^[transformR90"}, - is_ground_content = true, + is_ground_content = false, groups = {crumbly=2,cracky=3,falling_node=1,not_in_creative_inventory=1}, sounds = default.node_sound_stone_defaults(), drop = "", }) + +local chestdef = minetest.registered_nodes["default:chest"] +minetest.register_node("tsm_pyramids:chest",{ + description = "tsm_pyramids Chest auto refilled", + tiles = chestdef.tiles, + stack_max = 1000, + paramtype2 = "facedir", + is_ground_content = false, + on_construct = function(pos) + chestdef.on_construct(pos) + minetest.get_node_timer(pos):start(pyramids.max_time) + pyramids.fill_chest(pos) + end, + on_metadata_inventory_move = chestdef.on_metadata_inventory_move, + on_metadata_inventory_put = chestdef.on_metadata_inventory_put, + on_metadata_inventory_take = chestdef.on_metadata_inventory_take, + groups = {unbreakable = 1, not_in_creative_inventory = 1}, + on_timer = function (pos, elapsed) + pyramids.fill_chest(pos) + return true + end, +}) + diff --git a/mods/tsm_pyramids/room.lua b/mods/tsm_pyramids/room.lua index ec2a76e3..1a6306fe 100755 --- a/mods/tsm_pyramids/room.lua +++ b/mods/tsm_pyramids/room.lua @@ -1,6 +1,3 @@ -pyramids.saved_chests = {} -pyramids.max_time = 30*60 - local room = {"a","a","a","a","a","a","a","a","a", "a","c","a","c","a","c","a","c","a", @@ -33,56 +30,14 @@ code["a"] = "air" code["l"] = "lava_source" code["t"] = "trap" -function loadchests() - local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","r") - if file then - local saved_chests = minetest.deserialize(file:read()) - io.close(file) - if saved_chests and type(saved_chests) == "table" then - minetest.log("action","[tsm_pyramids] Chest loaded") - return saved_chests - else - minetest.log("error","[tsm_pyramids] Loading Chest failed") - end - end - return {} -end - - -function savechests() - local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","w") - if not file then return end -- should not happen - file:write(minetest.serialize(pyramids.saved_chests)) - io.close(file) - minetest.log("action","[tsm_pyramids] Chests saved") -end - -pyramids.saved_chests = loadchests() -minetest.register_on_shutdown(function() - savechests() -end) - -local function chests_reload() - -- It might happen that chests are not loaded - if pyramids.saved_chests then - for _,k in ipairs(pyramids.saved_chests) do - pyramids.fill_chest(k) - end - else - pyramids.saved_chests = loadchests() or {} - end - minetest.log("action","[tsm_pyramids] Chests reloaded") - minetest.after(pyramids.max_time, chests_reload) -end -minetest.after(0, chests_reload) - local function replace(str,iy) local out = "default:" if iy < 4 and str == "c" then str = "a" end if iy == 0 and str == "s" then out = "tsm_pyramids:" str = "sun" end if iy == 3 and str == "s" then out = "tsm_pyramids:" str = "men" end if str == "a" then out = "" end - if str == "c" or str == "s" or str == "b" then out = "maptools:" end + if str == "c" then out = "tsm_pyramids:" end --MFF newchest + if str == "s" or str == "b" then out = "maptools:" end return out..code[str] end @@ -96,35 +51,30 @@ local function replace2(str,iy) end function pyramids.make_room(pos) - local loch = {x=pos.x+7,y=pos.y+5, z=pos.z+7} - for iy=0,4,1 do - for ix=0,8,1 do - for iz=0,8,1 do - local n_str = room[tonumber(ix*9+iz+1)] - local p2 = 0 - if n_str == "c" then - if ix < 3 then p2 = 1 else p2 = 3 end - pyramids.fill_chest({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}) - end - local node_name = replace(n_str,iy) - minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=node_name, param2=p2}) - if node_name == "maptools:chest" then - table.insert(pyramids.saved_chests,1,{x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}) + local loch = {x=pos.x+7,y=pos.y+5, z=pos.z+7} + for iy=0,4,1 do + for ix=0,8,1 do + for iz=0,8,1 do + local n_str = room[tonumber(ix*9+iz+1)] + local p2 = 0 + if n_str == "c" then + if ix < 3 then p2 = 1 else p2 = 3 end + end + minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=replace(n_str,iy), param2=p2}) end end end - end end function pyramids.make_traps(pos) - local loch = {x=pos.x+7,y=pos.y, z=pos.z+7} - for iy=0,4,1 do - for ix=0,8,1 do - for iz=0,8,1 do - local n_str = trap[tonumber(ix*9+iz+1)] - local p2 = 0 - minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=replace2(n_str,iy), param2=p2}) + local loch = {x=pos.x+7,y=pos.y, z=pos.z+7} + for iy=0,4,1 do + for ix=0,8,1 do + for iz=0,8,1 do + local n_str = trap[tonumber(ix*9+iz+1)] + local p2 = 0 + minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=replace2(n_str,iy), param2=p2}) + end end end - end end