1 local MINE_DEEP_MIN
= tonumber(minetest
.settings
:get("mines_deep_min")) or -64
2 local MINE_DEEP_MAX
= tonumber(minetest
.settings
:get("mines_deep_max")) or -380
3 local MINE_FACTOR
= tonumber(minetest
.settings
:get("mines_spawnfactor")) or 1.5
5 minetest
.log("info", "Mod \"tsm_mines\" set MINE_DEEP_MIN to "..MINE_DEEP_MIN
)
6 minetest
.log("info", "Mod \"tsm_mines\" set MINE_DEEP_MAX to "..MINE_DEEP_MAX
)
7 minetest
.log("info", "Mod \"tsm_mines\" set MINE_FACTOR to "..MINE_FACTOR
)
9 minetest
.register_node("tsm_mines:dummy", {
10 description
= "tsm_mines dummy node",
11 _doc_items_create_entry
= false,
12 inventory_image
= "unknown_node.png",
13 wield_image
= "unknown_node.png",
16 sunlight_propagates
= true,
21 air_equivalent
= true,
23 groups
= {not_in_creative_inventory
=1},
28 air
= minetest
.get_content_id("air"),
29 fence
= minetest
.get_content_id("default:fence_wood"),
30 wood
= minetest
.get_content_id("default:wood"),
31 dummy
= minetest
.get_content_id("tsm_mines:dummy")
35 if(minetest
.get_modpath("farming")~=nil) then
37 {name
="default:apple", max = 3},
38 {name
="farming:bread", max = 3},
39 {name
="default:steel_ingot", max = 2},
40 {name
="default:gold_ingot", max = 2},
41 {name
="default:diamond", max = 1},
42 {name
="default:pick_steel", max = 1},
43 {name
="default:pick_diamond", max = 1}
47 {name
="default:apple", max = 3},
48 {name
="default:steel_ingot", max = 2},
49 {name
="default:gold_ingot", max = 2},
50 {name
="default:diamond", max = 1},
51 {name
="default:pick_steel", max = 1},
52 {name
="default:pick_diamond", max = 1}
56 local function rotate_torch(pos
)
57 minetest
.after(8, function()
58 local n
= minetest
.get_node(pos
)
60 if n
.name
== "tsm_mines:dummy" then
61 minetest
.set_node(pos
, {name
="default:torch",param2
=1})
67 local function fill_chest(pos
)
68 minetest
.after(5, function()
69 local n
= minetest
.get_node(pos
)
71 if n
.name
== "tsm_mines:dummy" then
72 minetest
.set_node(pos
, {name
="default:chest"})
73 local meta
= minetest
.get_meta(pos
)
74 local inv
= meta
:get_inventory()
75 inv
:set_size("main", 8*4)
77 if(minetest
.get_modpath("treasurer") ~= nil) then
78 stacks
= treasurer
.select_random_treasures(3,4,6,{"minetool", "food", "crafting_component"})
81 local stuff
= chest_stuff
[math
.random(1,#chest_stuff
)]
82 table.insert(stacks
,{name
=stuff
.name
, count
= math
.random(1,stuff
.max)})
86 if not inv
:contains_item("main", stacks
[s
]) then
87 inv
:set_stack("main", math
.random(1,32), stacks
[s
])
95 local function check_dir(dir
,old_dir
)
96 if old_dir
== 1 and dir
== 3 then
98 elseif old_dir
== 3 and dir
== 1 then
100 elseif old_dir
== 2 and dir
== 4 then
102 elseif old_dir
== 4 and dir
== 2 then
107 local function make_mine(mpos
,p2
,p3
, vm_data
, vx_area
,cnt
)
108 local pos
= {x
=mpos
.x
,y
=mpos
.y
,z
=mpos
.z
}
111 local n_switch
= math
.random(1,4)
112 while check_dir(n_switch
,switch
) == true do
113 n_switch
= math
.random(1,4)
118 local pillar
= ids
.air
119 local pillar_top
= ids
.air
120 if i
==0 or i
== 5 or i
== 10 or i
== 15 or i
== 20 then
122 pillar_top
= ids
.wood
124 local x1
, x2
, x3
, x4
, x5
125 local z1
, z2
, z3
, z4
, z5
138 elseif switch
== 2 then
150 elseif switch
== 3 then
175 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
-1, z
=z1
})] = pillar
176 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
-1, z
=z2
})] = ids
.air
177 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
-1, z
=z3
})] = pillar
179 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
, z
=z1
})] = pillar
180 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
, z
=z2
})] = ids
.air
181 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
, z
=z3
})] = pillar
183 vm_data
[vx_area
:indexp({x
=x1
, y
=pos
.y
+1, z
=z1
})] = pillar_top
184 vm_data
[vx_area
:indexp({x
=x2
, y
=pos
.y
+1, z
=z2
})] = pillar_top
185 vm_data
[vx_area
:indexp({x
=x3
, y
=pos
.y
+1, z
=z3
})] = pillar_top
187 if math
.random(0,6) == 3 then
188 vm_data
[vx_area
:indexp({x
=x4
, y
=pos
.y
-1, z
=z4
})] = ids
.dummy
189 rotate_torch({x
=x4
, y
=pos
.y
-1, z
=z4
})
191 if math
.random(0,60) == 13 then
192 local p
= {x
=x5
, y
=pos
.y
-1, z
=z5
}
193 if vm_data
[vx_area
:indexp(p
)] ~= ids
.fence
then
194 vm_data
[vx_area
:indexp(p
)] = ids
.dummy
201 elseif switch
== 2 then
203 elseif switch
== 3 then
205 elseif switch
== 4 then
210 minetest
.log("action", "Created mine at ("..mpos
.x
..","..mpos
.y
..","..mpos
.z
..")")
211 local out2
= make_mine(p2
,p3
,mpos
,vm_data
,vx_area
,1)
212 local out3
= make_mine(p3
,p2
,mpos
,out2
,vx_area
,2)
219 local function find_cave(min,max,vm_data
, vx_area
)
221 for i
in vx_area
:iterp(min, max) do
222 if vm_data
[i
] == ids
.air
then
223 local p
= vx_area
:position(i
)
224 if p
.y
<= MINE_DEEP_MIN
then out
= p
end
231 minetest
.register_on_generated(function(minp
, maxp
, seed
)
232 if minp
.y
> MINE_DEEP_MIN
or minp
.y
< MINE_DEEP_MAX
then
236 if cnt
< 8/MINE_FACTOR
then return end
239 local vm
, emin
, emax
= minetest
.get_mapgen_object("voxelmanip")
240 local data
= vm
:get_data()
241 local va
= VoxelArea
:new
{ MinEdge
= emin
, MaxEdge
= emax
}
242 local mpos
= find_cave(emin
,emax
,data
,va
)
243 if mpos
== nil then return end
244 local mpos2
= {x
=mpos
.x
+math
.random(0,3),y
=mpos
.y
-1,z
=mpos
.z
}
245 local mpos3
= {x
=mpos
.x
,y
=mpos
.y
-2,z
=mpos
.z
+math
.random(0,3)}
246 data
= make_mine(mpos
,mpos2
,mpos3
, data
, va
, 0)
248 vm
:calc_lighting(emin
,emax
)