Compare commits

...

7 Commits

Author SHA1 Message Date
Sys Quatre fbb674a01c Réduit le spawn des pyramides 2019-04-04 16:29:07 +02:00
sys4-fr ea6f428e7d Ajoute message de chargement du mod dans le journal "action" 2019-01-19 19:35:58 +01:00
sys4-fr 7b281bec47 Ajout de la régénération des items toutes les 30 minutes
- Les coffres deviennent indestructibles
- Ajout d'un timer de 30 minutes pour le régénération des items
2018-12-23 13:01:43 +01:00
sys4-fr 99349cc616 Rend les pyramides indestructibles 2018-12-23 10:39:17 +01:00
sys4-fr 57adec6576 Modifie la génération des objets dans les coffres 2018-12-22 11:17:04 +01:00
sys4-fr 55f4a1f292 Pyramids spawn only in desert biomes with desert_sand.
There is 3 types of pyramids now:
Sand (default), desert_sand and silver_sand pyramids.
2018-03-28 01:39:54 +02:00
sys4-fr 145a73188c Update falling nodes detection in order to avoid crash 2018-03-26 19:50:35 +02:00
4 changed files with 162 additions and 96 deletions

View File

@ -1,4 +1,5 @@
default
maptools
farming?
sandplus?
treasurer?

198
init.lua
View File

@ -1,4 +1,6 @@
pyramids = {}
pyramids.max_time = 60 * 30
local random = math.random
dofile(minetest.get_modpath("tsm_pyramids").."/mummy.lua")
dofile(minetest.get_modpath("tsm_pyramids").."/nodes.lua")
@ -16,31 +18,29 @@ 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 == "default:chest" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
if math.random(1,10) < 7 then return end
local stacks = {}
if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
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(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 random(1,10) < 7 then return end
local stacks = {}
if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,1,5,{"armes", "armures", "precieux"})
else
for i=0,2,1 do
local stuff = chest_stuff[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 = 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", random(1,32), stacks[s])
end
end
end
end
local function add_spawner(pos)
@ -67,7 +67,7 @@ local function underground(pos, stone, sand)
while can_replace(p2)==true do
cnt = cnt+1
if cnt > 25 then break end
if cnt>math.random(2,4) then mat = stone end
if cnt>random(2,4) then mat = stone end
minetest.set_node(p2, {name=mat})
p2.y = p2.y-1
end
@ -92,7 +92,7 @@ local function make(pos, brick, sandstone, stone, sand)
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}, stone, sand) end
if iy <1 then underground({x=pos.x+ix,y=pos.y,z=pos.z+iz}, stone, sand) end
minetest.set_node({x=pos.x+ix,y=pos.y+iy,z=pos.z+iz}, {name=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})
@ -133,74 +133,86 @@ local function ground(pos, old)
end
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y < 0 then return end
math.randomseed(seed)
local cnt = 0
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
local perlin1 = minetest.env: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.75 or noise1 < -0.76 then
local mpos = {x=random(minp.x,maxp.x), y=random(minp.y,maxp.y), z=random(minp.z,maxp.z)}
local sands = {"default:desert_sand"}
local p2
local sand
for s=1, #sands do
sand = sands[s]
p2 = minetest.find_node_near(mpos, 25, sand)
while p2 == nil and cnt < 5 do
cnt = cnt+1
mpos = {x=random(minp.x,maxp.x), y=random(minp.y,maxp.y), z=random(minp.z,maxp.z)}
p2 = minetest.find_node_near(mpos, 25, sand)
end
if p2 ~= nil then
break
end
end
if p2 == nil then return end
if p2.y < 0 then return end
local perlin1 = minetest.env: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 then
local mpos = {x=math.random(minp.x,maxp.x), y=math.random(minp.y,maxp.y), z=math.random(minp.z,maxp.z)}
local sands = {"default:desert_sand", "default:sand"}
local p2
local sand
for s=1, #sands do
sand = sands[s]
p2 = minetest.find_node_near(mpos, 25, 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, sand)
end
if p2 ~= nil then
break
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, {"default:sandstonebrick"}) ~= nil or
minetest.find_node_near(p2, 52, {"sandplus:desert_sandstonebrick"}) ~= nil then
return
end
if math.random(0,10) > 7 then
return
end
if sand == "default:desert_sand" then
if minetest.get_modpath("sandplus") then
minetest.after(0.8, make, p2, "sandplus:desert_sandstonebrick", "sandplus:desert_sandstone", "default:desert_stone", "default:desert_sand")
else
minetest.after(0.8, make, p2, "default:sandstonebrick", "default:sandstone", "default:desert_stone", "default:desert_sand")
end
else
minetest.after(0.8, make, p2, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand")
end
end
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 or
minetest.find_node_near(p2, 52, {"maptools:desert_sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"maptools:silver_sandstone_brick"}) ~= nil or
minetest.find_node_near(p2, 52, {"sandplus:desert_sandstonebrick"}) ~= nil
then return end
if random(0,10) > 7 then
return
end
local p_type = random(1, 3)
local p_pot = {
[1] = {"maptools:sandstone_brick", "default:sandstone", "default:sandstone", "default:sand"},
[2] = {"maptools:desert_sandstone_brick", "default:desert_sandstone", "default:desert_stone", "default:desert_sand"},
[3] = {"maptools:silver_sandstone_brick", "default:silver_sandstone", "default:silver_sandstone", "default:silver_sand"}
}
if sand == "default:desert_sand" then
if minetest.get_modpath("sandplus") then
minetest.after(0.8, make, p2, "sandplus:desert_sandstonebrick", "sandplus:desert_sandstone", "default:desert_stone", "default:desert_sand")
else
minetest.after(0.8, make, p2, p_pot[p_type][1], p_pot[p_type][2], p_pot[p_type][3], p_pot[p_type][4])
end
else
minetest.after(0.8, make, p2, "default:sandstonebrick", "default:sandstone", "default:sandstone", "default:sand")
end
end
end, minp, maxp, seed)
end)
-- Add backwards-compability for nodes from the original pyramids mod
if minetest.get_modpath("pyramids") == nil then
@ -215,3 +227,5 @@ if minetest.get_modpath("pyramids") == nil then
-- FIXME: Entities are currently NOT backwards-compatible
-- TODO: Update README when full backwards-compability is achieved
end
minetest.log("action", "[tsm_pyramids] loaded.")

View File

@ -20,7 +20,7 @@ for i=1,3 do
_doc_items_longdesc = decodesc,
tiles = {"default_sandstone.png", "default_sandstone.png", "default_sandstone.png^tsm_pyramids_"..img[i]..".png"},
is_ground_content = false,
groups = minetest.registered_nodes["default:sandstone"].groups,
groups = {unbreakable=1},
sounds = default.node_sound_stone_defaults(),
})
end
@ -33,7 +33,7 @@ local trap_on_timer = function (pos, elapsed)
if n and n.name then
if minetest.registered_nodes[n.name]._tsm_pyramids_crack and minetest.registered_nodes[n.name]._tsm_pyramids_crack < 2 then
minetest.set_node(pos, {name="tsm_pyramids:trap_2"})
nodeupdate(pos)
minetest.check_for_falling(pos)
end
end
end
@ -65,3 +65,53 @@ minetest.register_node("tsm_pyramids:trap_2", {
sounds = default.node_sound_stone_defaults(),
drop = "",
})
local function get_chest_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
local formspec =
"size[8,9]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[nodemeta:" .. spos .. ";main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
return formspec
end
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,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not default.can_interact_with_node(clicker, pos) then
return itemstack
end
minetest.after(
0.2,
minetest.show_formspec,
clicker:get_player_name(),
"default:chest", get_chest_formspec(pos))
end,
})

View File

@ -35,6 +35,8 @@ local function replace(str,iy)
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" then out = "tsm_pyramids:" end
if str == "s" then out = "maptools:" end
return out..code[str]
end
@ -42,8 +44,8 @@ local function replace2(str,iy)
local out = "default:"
if iy == 0 and str == "l" then out = "tsm_pyramids:" str = "t"
elseif iy < 3 and str == "l" then str = "a" end
if str == "a" then out = "" end
if str == "b" then out = "maptools:" end
return out..code[str]
end
@ -56,7 +58,6 @@ function pyramids.make_room(pos)
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
minetest.set_node({x=loch.x+ix,y=loch.y-iy,z=loch.z+iz}, {name=replace(n_str,iy), param2=p2})
end