update tsm_pyramids, add new chest with timer to refill and remove file to save chest pos used to refill

add abm to replace old chest
add maptools in depends.txt
fix indentations
This commit is contained in:
crabman77 2017-04-20 00:46:48 +02:00
parent d1a7ed5ee6
commit c9b5199e97
5 changed files with 169 additions and 174 deletions

View File

@ -1,5 +1,6 @@
default default
mobs mobs
maptools
farming? farming?
treasurer? treasurer?
watershed? watershed?

View File

@ -1,4 +1,5 @@
pyramids = {} pyramids = {}
pyramids.max_time = 30*60
dofile(minetest.get_modpath("tsm_pyramids").."/mummy.lua") dofile(minetest.get_modpath("tsm_pyramids").."/mummy.lua")
dofile(minetest.get_modpath("tsm_pyramids").."/nodes.lua") dofile(minetest.get_modpath("tsm_pyramids").."/nodes.lua")
@ -16,37 +17,34 @@ local chest_stuff = {
} }
function pyramids.fill_chest(pos) function pyramids.fill_chest(pos)
minetest.after(2, function() local n = minetest.get_node_or_nil(pos)
local n = minetest.get_node(pos) if n and n.name and n.name == "tsm_pyramids:chest" then
if n and n.name and n.name == "maptools:chest" then local meta = minetest.get_meta(pos)
local meta = minetest.get_meta(pos) local inv = meta:get_inventory()
local inv = meta:get_inventory() inv:set_size("main", 8*4)
inv:set_size("main", 8*4) inv:set_list("main",
inv:set_list("main", {
{ [1] = "",
[1] = "", [32] = ""
[32] = "" }
} )
) if math.random(1,10) < 7 then return end
if math.random(1,10) < 7 then return end local stacks = {}
local stacks = {} if minetest.get_modpath("treasurer") ~= nil then
if minetest.get_modpath("treasurer") ~= nil then stacks = treasurer.select_random_treasures()
stacks = treasurer.select_random_treasures() else
else for i=0,2,1 do
for i=0,2,1 do local stuff = chest_stuff[math.random(1,#chest_stuff)]
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
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)})
table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)})
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
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 end
local function add_spawner(pos) local function add_spawner(pos)
@ -73,45 +71,45 @@ local function underground(pos)
while can_replace(p2)==true do while can_replace(p2)==true do
cnt = cnt+1 cnt = cnt+1
if cnt > 25 then break end 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}) minetest.set_node(p2, {name="default:"..mat})
p2.y = p2.y-1 p2.y = p2.y-1
end end
end end
local function make_entrance(pos) local function make_entrance(pos)
local gang = {x=pos.x+10,y=pos.y, z=pos.z} local gang = {x=pos.x+10,y=pos.y, z=pos.z}
for iy=2,3,1 do for iy=2,3,1 do
for iz=0,6,1 do for iz=0,6,1 do
minetest.remove_node({x=gang.x+1,y=gang.y+iy,z=gang.z+iz}) minetest.remove_node({x=gang.x+1,y=gang.y+iy,z=gang.z+iz})
if iz >=3 and iy == 3 then 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,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+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"}) 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
end
end end
local function make(pos) function pyramids.make(pos)
minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")") minetest.log("action", "Created pyramid at ("..pos.x..","..pos.y..","..pos.z..")")
for iy=0,10,1 do for iy=0,10,1 do
for ix=iy,22-iy,1 do for ix=iy,22-iy,1 do
for iz=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 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"}) 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 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}) 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 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
end end
end
pyramids.make_room(pos) pyramids.make_room(pos)
minetest.after(2, pyramids.make_traps, pos) minetest.after(2, pyramids.make_traps, pos)
add_spawner({x=pos.x+11,y=pos.y+2, z=pos.z+17}) 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}) make_entrance({x=pos.x,y=pos.y, z=pos.z})
end end
local perl1 = {SEED1 = 9130, OCTA1 = 3, PERS1 = 0.5, SCAL1 = 250} -- Values should match minetest mapgen V6 desert noise. 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 return false
end end
end end
local function ground(pos, old) local function ground(pos, old)
local p2 = pos local p2 = pos
while hlp_fnct(p2, "air") do while hlp_fnct(p2, "air") do
@ -140,48 +139,49 @@ end
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
minetest.after(3, function(minp, maxp, seed) minetest.after(3, function(minp, maxp, seed)
if maxp.y < 0 then return end if maxp.y < 0 then return end
math.randomseed(seed) math.randomseed(seed)
local cnt = 0 local cnt = 0
local perlin1 = minetest.get_perlin(perl1.SEED1, perl1.OCTA1, perl1.PERS1, perl1.SCAL1) 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 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 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 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"}) local p2 = minetest.find_node_near(mpos, 25, {"default:desert_sand"})
while p2 == nil and cnt < 5 do while p2 == nil and cnt < 5 do
cnt = cnt+1 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)} 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"}) 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 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, minp, maxp, seed)
end) end)

View File

@ -52,10 +52,31 @@ mobs:register_mob("tsm_pyramids:mummy", {
sit_start = 81, sit_end = 160, sit_start = 81, sit_end = 160,
lay_start = 162, lay_end = 166, lay_start = 162, lay_end = 166,
mine_start = 74, mine_end = 105, 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) -- spawner (spawn in pyramids, near the spawner)
if not minetest.setting_getbool("only_peaceful_mobs") then if not minetest.setting_getbool("only_peaceful_mobs") then
minetest.register_abm({ minetest.register_abm({
@ -101,10 +122,10 @@ minetest.register_node("tsm_pyramids:spawner_mummy", {
drop = "", drop = "",
on_construct = function(pos) on_construct = function(pos)
pos.y = pos.y - 0.28 pos.y = pos.y - 0.28
minetest.env:add_entity(pos,"tsm_pyramids:mummy_spawner") minetest.add_entity(pos,"tsm_pyramids:mummy_spawner")
end, end,
on_destruct = function(pos) 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 not obj:is_player() then
if obj ~= nil and obj:get_luaentity().m_name == "dummy" then if obj ~= nil and obj:get_luaentity().m_name == "dummy" then
obj:remove() obj:remove()
@ -122,7 +143,7 @@ minetest.register_craftitem("tsm_pyramids:spawn_egg", {
stack_max = 99, stack_max = 99,
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
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 if not minetest.setting_getbool("creative_mode") then itemstack:take_item() end
return itemstack return itemstack
end end

View File

@ -4,14 +4,14 @@ for i=1,3 do
minetest.register_node("tsm_pyramids:deco_stone"..i, { minetest.register_node("tsm_pyramids:deco_stone"..i, {
description = "Sandstone with "..img[i], description = "Sandstone with "..img[i],
tiles = {"default_sandstone.png^tsm_pyramids_"..img[i]..".png"}, tiles = {"default_sandstone.png^tsm_pyramids_"..img[i]..".png"},
is_ground_content = true, is_ground_content = false,
groups = {unbreakable=1}, groups = {unbreakable=1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
}) })
end end
trap_on_timer = function (pos, elapsed) local trap_on_timer = function (pos, elapsed)
local objs = minetest.env:get_objects_inside_radius(pos, 2) local objs = minetest.get_objects_inside_radius(pos, 2)
for i, obj in pairs(objs) do for i, obj in pairs(objs) do
if obj:is_player() then if obj:is_player() then
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
@ -27,11 +27,11 @@ end
minetest.register_node("tsm_pyramids:trap", { minetest.register_node("tsm_pyramids:trap", {
description = "Cracked sandstone brick", description = "Cracked sandstone brick",
tiles = {"default_sandstone_brick.png^tsm_pyramids_crack.png"}, tiles = {"default_sandstone_brick.png^tsm_pyramids_crack.png"},
is_ground_content = true, is_ground_content = false,
groups = {crumbly=2,cracky=3}, groups = {crumbly=2,cracky=3},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) on_construct = function(pos)
minetest.env:get_node_timer(pos):start(0.1) minetest.get_node_timer(pos):start(0.1)
end, end,
crack = 1, crack = 1,
on_timer = trap_on_timer, on_timer = trap_on_timer,
@ -41,8 +41,31 @@ minetest.register_node("tsm_pyramids:trap", {
minetest.register_node("tsm_pyramids:trap_2", { minetest.register_node("tsm_pyramids:trap_2", {
description = "trapstone", description = "trapstone",
tiles = {"default_sandstone_brick.png^tsm_pyramids_crack.png^[transformR90"}, 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}, groups = {crumbly=2,cracky=3,falling_node=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
drop = "", 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,
})

View File

@ -1,6 +1,3 @@
pyramids.saved_chests = {}
pyramids.max_time = 30*60
local room = {"a","a","a","a","a","a","a","a","a", local room = {"a","a","a","a","a","a","a","a","a",
"a","c","a","c","a","c","a","c","a", "a","c","a","c","a","c","a","c","a",
@ -33,56 +30,14 @@ code["a"] = "air"
code["l"] = "lava_source" code["l"] = "lava_source"
code["t"] = "trap" 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 function replace(str,iy)
local out = "default:" local out = "default:"
if iy < 4 and str == "c" then str = "a" end 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 == 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 iy == 3 and str == "s" then out = "tsm_pyramids:" str = "men" end
if str == "a" then out = "" 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] return out..code[str]
end end
@ -96,35 +51,30 @@ local function replace2(str,iy)
end end
function pyramids.make_room(pos) function pyramids.make_room(pos)
local loch = {x=pos.x+7,y=pos.y+5, z=pos.z+7} local loch = {x=pos.x+7,y=pos.y+5, z=pos.z+7}
for iy=0,4,1 do for iy=0,4,1 do
for ix=0,8,1 do for ix=0,8,1 do
for iz=0,8,1 do for iz=0,8,1 do
local n_str = room[tonumber(ix*9+iz+1)] local n_str = room[tonumber(ix*9+iz+1)]
local p2 = 0 local p2 = 0
if n_str == "c" then if n_str == "c" then
if ix < 3 then p2 = 1 else p2 = 3 end 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
end minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=replace(n_str,iy), param2=p2})
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})
end end
end end
end end
end
end end
function pyramids.make_traps(pos) function pyramids.make_traps(pos)
local loch = {x=pos.x+7,y=pos.y, z=pos.z+7} local loch = {x=pos.x+7,y=pos.y, z=pos.z+7}
for iy=0,4,1 do for iy=0,4,1 do
for ix=0,8,1 do for ix=0,8,1 do
for iz=0,8,1 do for iz=0,8,1 do
local n_str = trap[tonumber(ix*9+iz+1)] local n_str = trap[tonumber(ix*9+iz+1)]
local p2 = 0 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}) 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
end
end end