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
= "tsm_mines dummy node",
17 x_doc_items_create_entry
= false,
18 inventory_image
= "unknown_node.png",
19 wield_image
= "unknown_node.png",
22 sunlight_propagates
= true,
27 air_equivalent
= true,
29 groups
= {not_in_creative_inventory
=1},
34 air
= minetest
.get_content_id("air"),
35 fence
= minetest
.get_content_id("default:fence_wood"),
36 wood
= minetest
.get_content_id("default:wood"),
37 dummy
= minetest
.get_content_id("tsm_mines:dummy")
41 if(minetest
.get_modpath("farming")~=nil) then
43 {name
="default:apple", max = 3},
44 {name
="farming:bread", max = 3},
45 {name
="default:steel_ingot", max = 2},
46 {name
="default:gold_ingot", max = 2},
47 {name
="default:diamond", max = 1},
48 {name
="default:pick_steel", max = 1},
49 {name
="default:pick_diamond", max = 1}
53 {name
="default:apple", max = 3},
54 {name
="default:steel_ingot", max = 2},
55 {name
="default:gold_ingot", max = 2},
56 {name
="default:diamond", max = 1},
57 {name
="default:pick_steel", max = 1},
58 {name
="default:pick_diamond", max = 1}
62 local function rotate_torch(pos
)
63 minetest
.after(8, function()
64 local n
= minetest
.get_node(pos
)
66 if n
.name
== "tsm_mines:dummy" then
67 minetest
.set_node(pos
, {name
="default:torch",param2
=1})
73 local function fill_chest(pos
)
74 minetest
.after(5, function()
75 local n
= minetest
.get_node(pos
)
77 if n
.name
== "tsm_mines:dummy" then
78 minetest
.set_node(pos
, {name
="default:chest"})
79 local meta
= minetest
.get_meta(pos
)
80 local inv
= meta
:get_inventory()
81 inv
:set_size("main", 8*4)
83 if(minetest
.get_modpath("treasurer") ~= nil) then
84 stacks
= treasurer
.select_random_treasures(3,4,6,{"minetool", "food", "crafting_component"})
87 local stuff
= chest_stuff
[math
.random(1,#chest_stuff
)]
88 table.insert(stacks
,{name
=stuff
.name
, count
= math
.random(1,stuff
.max)})
92 if not inv
:contains_item("main", stacks
[s
]) then
93 inv
:set_stack("main", math
.random(1,32), stacks
[s
])
101 local function check_dir(dir
,old_dir
)
102 if old_dir
== 1 and dir
== 3 then
104 elseif old_dir
== 3 and dir
== 1 then
106 elseif old_dir
== 2 and dir
== 4 then
108 elseif old_dir
== 4 and dir
== 2 then
113 local function make_mine(mpos
,p2
,p3
, vm_data
, vx_area
,cnt
)
114 local pos
= {x
=mpos
.x
,y
=mpos
.y
,z
=mpos
.z
}
117 local n_switch
= math
.random(1,4)
118 while check_dir(n_switch
,switch
) == true do
119 n_switch
= math
.random(1,4)
124 local pillar
= ids
.air
125 local pillar_top
= ids
.air
126 if i
==0 or i
== 5 or i
== 10 or i
== 15 or i
== 20 then
128 pillar_top
= ids
.wood
130 local x1
, x2
, x3
, x4
, x5
131 local z1
, z2
, z3
, z4
, z5
144 elseif switch
== 2 then
156 elseif switch
== 3 then
181 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
-1, z
=z1
})] = pillar
182 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
-1, z
=z2
})] = ids
.air
183 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
-1, z
=z3
})] = pillar
185 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
, z
=z1
})] = pillar
186 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
, z
=z2
})] = ids
.air
187 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
, z
=z3
})] = pillar
189 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
+1, z
=z1
})] = pillar_top
190 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
+1, z
=z2
})] = pillar_top
191 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
+1, z
=z3
})] = pillar_top
193 if math
.random(0,6) == 3 then
194 vm_data
[vx_area
:indexp({x
=x4
, y
=pos
.y
-1, z
=z4
})] = ids
.dummy
195 rotate_torch({x
=x4
, y
=pos
.y
-1, z
=z4
})
197 if math
.random(0,60) == 13 then
198 local p
= {x
=x5
, y
=pos
.y
-1, z
=z5
}
199 if vm_data
[vx_area
:indexp(p
)] ~= ids
.fence
then
200 vm_data
[vx_area
:indexp(p
)] = ids
.dummy
207 elseif switch
== 2 then
209 elseif switch
== 3 then
211 elseif switch
== 4 then
216 minetest
.log("action", "Created mine at ("..mpos
.x
..","..mpos
.y
..","..mpos
.z
..")")
217 local out2
= make_mine(p2
,p3
,mpos
,vm_data
,vx_area
,1)
218 local out3
= make_mine(p3
,p2
,mpos
,out2
,vx_area
,2)
225 local function find_cave(min,max,vm_data
, vx_area
)
227 for i
in vx_area
:iterp(min, max) do
228 if vm_data
[i
] == ids
.air
then
229 local p
= vx_area
:position(i
)
230 if p
.y
<= MINE_DEEP_MIN
then out
= p
end
237 minetest
.register_on_generated(function(minp
, maxp
, seed
)
238 if minp
.y
> MINE_DEEP_MIN
or minp
.y
< MINE_DEEP_MAX
then
242 if cnt
< 8/MINE_FACTOR
then return end
245 local vm
, emin
, emax
= minetest
.get_mapgen_object("voxelmanip")
246 local data
= vm
:get_data()
247 local va
= VoxelArea
:new
{ MinEdge
= emin
, MaxEdge
= emax
}
248 local mpos
= find_cave(emin
,emax
,data
,va
)
249 if mpos
== nil then return end
250 local mpos2
= {x
=mpos
.x
+math
.random(0,3),y
=mpos
.y
-1,z
=mpos
.z
}
251 local mpos3
= {x
=mpos
.x
,y
=mpos
.y
-2,z
=mpos
.z
+math
.random(0,3)}
252 data
= make_mine(mpos
,mpos2
,mpos3
, data
, va
, 0)
254 vm
:calc_lighting(emin
,emax
)