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")
39 if(minetest
.get_modpath("farming")~=nil) then
41 {name
="default:apple", max = 3},
42 {name
="farming:bread", max = 3},
43 {name
="default:steel_ingot", max = 2},
44 {name
="default:gold_ingot", max = 2},
45 {name
="default:diamond", max = 1},
46 {name
="default:pick_steel", max = 1},
47 {name
="default:pick_diamond", max = 1}
51 {name
="default:apple", max = 3},
52 {name
="default:steel_ingot", max = 2},
53 {name
="default:gold_ingot", max = 2},
54 {name
="default:diamond", max = 1},
55 {name
="default:pick_steel", max = 1},
56 {name
="default:pick_diamond", max = 1}
60 local function rotate_torch(pos
)
61 minetest
.after(8, function()
62 local n
= minetest
.get_node(pos
)
64 if n
.name
== "tsm_mines:dummy" then
65 minetest
.set_node(pos
, {name
="default:torch",param2
=1})
71 local function fill_chest(pos
)
72 minetest
.after(5, function()
73 local n
= minetest
.get_node(pos
)
75 if n
.name
== "tsm_mines:dummy" then
76 minetest
.set_node(pos
, {name
="default:chest"})
77 local meta
= minetest
.get_meta(pos
)
78 --meta:set_string("formspec",default.chest_formspec)
79 --meta:set_string("infotext", "Chest")
80 local inv
= meta
:get_inventory()
81 inv
:set_size("main", 8*4)
83 local stuff
= chest_stuff
[math
.random(1,#chest_stuff
)]
84 local stack
= {name
=stuff
.name
, count
= math
.random(1,stuff
.max)}
85 if not inv
:contains_item("main", stack
) then
86 inv
:set_stack("main", math
.random(1,32), stack
)
94 local function check_dir(dir
,old_dir
)
95 if old_dir
== 1 and dir
== 3 then
98 elseif old_dir
== 3 and dir
== 1 then
101 elseif old_dir
== 2 and dir
== 4 then
104 elseif old_dir
== 4 and dir
== 2 then
110 local function make_mine(mpos
,p2
,p3
, vm_data
, vx_area
,cnt
)
111 local pos
= {x
=mpos
.x
,y
=mpos
.y
,z
=mpos
.z
}
114 n_switch
= math
.random(1,4)
115 while check_dir(n_switch
,switch
) == true do
116 n_switch
= math
.random(1,4)
121 local pillar
= ids
.air
122 local pillar_top
= ids
.air
123 if i
==0 or i
== 5 or i
== 10 or i
== 15 or i
== 20 then
125 pillar_top
= ids
.wood
147 elseif switch
== 2 then
159 elseif switch
== 3 then
184 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
-1, z
=z1
})] = pillar
185 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
-1, z
=z2
})] = ids
.air
186 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
-1, z
=z3
})] = pillar
188 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
, z
=z1
})] = pillar
189 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
, z
=z2
})] = ids
.air
190 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
, z
=z3
})] = pillar
192 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
+1, z
=z1
})] = pillar_top
193 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
+1, z
=z2
})] = pillar_top
194 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
+1, z
=z3
})] = pillar_top
196 if math
.random(0,6) == 3 then
197 vm_data
[vx_area
:indexp({x
=x4
, y
=pos
.y
-1, z
=z4
})] = ids
.dummy
198 rotate_torch({x
=x4
, y
=pos
.y
-1, z
=z4
})
200 if math
.random(0,60) == 13 then
201 local p
= {x
=x5
, y
=pos
.y
-1, z
=z5
}
202 if vm_data
[vx_area
:indexp(p
)] ~= ids
.fence
then
203 vm_data
[vx_area
:indexp(p
)] = ids
.dummy
211 elseif switch
== 2 then
214 elseif switch
== 3 then
217 elseif switch
== 4 then
223 minetest
.log("action", "Created mine at ("..mpos
.x
..","..mpos
.y
..","..mpos
.z
..")")
224 local out2
= make_mine(p2
,p3
,mpos
,vm_data
,vx_area
,1)
225 local out3
= make_mine(p3
,p2
,mpos
,out2
,vx_area
,2)
232 local function find_cave(min,max,vm_data
, vx_area
)
234 for i
in vx_area
:iterp(min, max) do
235 if vm_data
[i
] == ids
.air
then
236 local p
= vx_area
:position(i
)
237 if p
.y
<= MINE_DEEP_MIN
then out
= p
end
244 minetest
.register_on_generated(function(minp
, maxp
, seed
)
245 if minp
.y
> MINE_DEEP_MIN
or minp
.y
< MINE_DEEP_MAX
then
249 if cnt
< 8/MINE_FACTOR
then return end
252 --if math.random(0,100) > 85 then return end
253 local vm
, emin
, emax
= minetest
.get_mapgen_object("voxelmanip")
254 local data
= vm
:get_data()
255 local va
= VoxelArea
:new
{ MinEdge
= emin
, MaxEdge
= emax
}
256 local mpos
= find_cave(emin
,emax
,data
,va
)
257 if mpos
== nil then return end
258 local mpos2
= {x
=mpos
.x
+math
.random(0,3),y
=mpos
.y
-1,z
=mpos
.z
}
259 local mpos3
= {x
=mpos
.x
,y
=mpos
.y
-2,z
=mpos
.z
+math
.random(0,3)}
260 data
= make_mine(mpos
,mpos2
,mpos3
, data
, va
, 0)
262 vm
:calc_lighting(emin
,emax
)