1 local MINE_DEEP_MIN
= tonumber(minetest
.setting_get("mines_deep_min"))
2 local MINE_DEEP_MAX
= tonumber(minetest
.setting_get("mines_deep_max"))
3 local MINE_FACTOR
= tonumber(minetest
.setting_get("mines_spawnfactor"))
5 if not MINE_DEEP_MIN
then
8 if not MINE_DEEP_MAX
then
11 if not MINE_FACTOR
then
15 minetest
.register_node("tsm_mines:dummy", {
16 description
= "Air (you hacker you!)",
17 inventory_image
= "unknown_node.png",
18 wield_image
= "unknown_node.png",
21 sunlight_propagates
= true,
26 air_equivalent
= true,
28 groups
= {not_in_creative_inventory
=1},
33 air
= minetest
.get_content_id("air"),
34 fence
= minetest
.get_content_id("default:fence_wood"),
35 wood
= minetest
.get_content_id("default:wood"),
36 dummy
= minetest
.get_content_id("tsm_mines:dummy")
40 if(minetest
.get_modpath("farming")~=nil) then
42 {name
="default:apple", max = 3},
43 {name
="farming:bread", max = 3},
44 {name
="default:steel_ingot", max = 2},
45 {name
="default:gold_ingot", max = 2},
46 {name
="default:diamond", max = 1},
47 {name
="default:pick_steel", max = 1},
48 {name
="default:pick_diamond", max = 1}
52 {name
="default:apple", max = 3},
53 {name
="default:steel_ingot", max = 2},
54 {name
="default:gold_ingot", max = 2},
55 {name
="default:diamond", max = 1},
56 {name
="default:pick_steel", max = 1},
57 {name
="default:pick_diamond", max = 1}
61 local function rotate_torch(pos
)
62 minetest
.after(8, function()
63 local n
= minetest
.get_node(pos
)
65 if n
.name
== "tsm_mines:dummy" then
66 minetest
.set_node(pos
, {name
="default:torch",param2
=1})
72 local function fill_chest(pos
)
73 minetest
.after(5, function()
74 local n
= minetest
.get_node(pos
)
76 if n
.name
== "tsm_mines:dummy" then
77 minetest
.set_node(pos
, {name
="default:chest"})
78 local meta
= minetest
.get_meta(pos
)
79 local inv
= meta
:get_inventory()
80 inv
:set_size("main", 8*4)
82 if(minetest
.get_modpath("treasurer") ~= nil) then
83 stacks
= treasurer
.select_random_treasures(3,4,6,{"minetool", "food", "crafting_component"})
86 local stuff
= chest_stuff
[math
.random(1,#chest_stuff
)]
87 table.insert(stacks
,{name
=stuff
.name
, count
= math
.random(1,stuff
.max)})
91 if not inv
:contains_item("main", stacks
[s
]) then
92 inv
:set_stack("main", math
.random(1,32), stacks
[s
])
100 local function check_dir(dir
,old_dir
)
101 if old_dir
== 1 and dir
== 3 then
103 elseif old_dir
== 3 and dir
== 1 then
105 elseif old_dir
== 2 and dir
== 4 then
107 elseif old_dir
== 4 and dir
== 2 then
112 local function make_mine(mpos
,p2
,p3
, vm_data
, vx_area
,cnt
)
113 local pos
= {x
=mpos
.x
,y
=mpos
.y
,z
=mpos
.z
}
116 local n_switch
= math
.random(1,4)
117 while check_dir(n_switch
,switch
) == true do
118 n_switch
= math
.random(1,4)
123 local pillar
= ids
.air
124 local pillar_top
= ids
.air
125 if i
==0 or i
== 5 or i
== 10 or i
== 15 or i
== 20 then
127 pillar_top
= ids
.wood
129 local x1
, x2
, x3
, x4
, x5
130 local z1
, z2
, z3
, z4
, z5
143 elseif switch
== 2 then
155 elseif switch
== 3 then
180 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
-1, z
=z1
})] = pillar
181 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
-1, z
=z2
})] = ids
.air
182 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
-1, z
=z3
})] = pillar
184 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
, z
=z1
})] = pillar
185 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
, z
=z2
})] = ids
.air
186 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
, z
=z3
})] = pillar
188 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
+1, z
=z1
})] = pillar_top
189 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
+1, z
=z2
})] = pillar_top
190 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
+1, z
=z3
})] = pillar_top
192 if math
.random(0,6) == 3 then
193 vm_data
[vx_area
:indexp({x
=x4
, y
=pos
.y
-1, z
=z4
})] = ids
.dummy
194 rotate_torch({x
=x4
, y
=pos
.y
-1, z
=z4
})
196 if math
.random(0,60) == 13 then
197 local p
= {x
=x5
, y
=pos
.y
-1, z
=z5
}
198 if vm_data
[vx_area
:indexp(p
)] ~= ids
.fence
then
199 vm_data
[vx_area
:indexp(p
)] = ids
.dummy
206 elseif switch
== 2 then
208 elseif switch
== 3 then
210 elseif switch
== 4 then
215 minetest
.log("action", "Created mine at ("..mpos
.x
..","..mpos
.y
..","..mpos
.z
..")")
216 local out2
= make_mine(p2
,p3
,mpos
,vm_data
,vx_area
,1)
217 local out3
= make_mine(p3
,p2
,mpos
,out2
,vx_area
,2)
224 local function find_cave(min,max,vm_data
, vx_area
)
226 for i
in vx_area
:iterp(min, max) do
227 if vm_data
[i
] == ids
.air
then
228 local p
= vx_area
:position(i
)
229 if p
.y
<= MINE_DEEP_MIN
then out
= p
end
236 minetest
.register_on_generated(function(minp
, maxp
, seed
)
237 if minp
.y
> MINE_DEEP_MIN
or minp
.y
< MINE_DEEP_MAX
then
241 if cnt
< 8/MINE_FACTOR
then return end
244 local vm
, emin
, emax
= minetest
.get_mapgen_object("voxelmanip")
245 local data
= vm
:get_data()
246 local va
= VoxelArea
:new
{ MinEdge
= emin
, MaxEdge
= emax
}
247 local mpos
= find_cave(emin
,emax
,data
,va
)
248 if mpos
== nil then return end
249 local mpos2
= {x
=mpos
.x
+math
.random(0,3),y
=mpos
.y
-1,z
=mpos
.z
}
250 local mpos3
= {x
=mpos
.x
,y
=mpos
.y
-2,z
=mpos
.z
+math
.random(0,3)}
251 data
= make_mine(mpos
,mpos2
,mpos3
, data
, va
, 0)
253 vm
:calc_lighting(emin
,emax
)