Add cobwebs if Mobs Redo is found
parent
c8cf9710de
commit
0656b67e9a
|
@ -5,6 +5,7 @@
|
|||
Minetest mod for adding underground corridors with rails and wood constructions with
|
||||
a few treasure chests now and then. Optional Treasurer support is available for adding
|
||||
treasures from various mods.
|
||||
Cobwebs are added if the Mobs Redo [mobs] mod is found.
|
||||
|
||||
Use the advanced settings to finetune the railway corridors.
|
||||
|
||||
|
|
|
@ -2,3 +2,4 @@ default
|
|||
tnt
|
||||
farming
|
||||
treasurer?
|
||||
mobs?
|
||||
|
|
|
@ -21,6 +21,10 @@ tsm_railcorridors.nodes = {
|
|||
},
|
||||
}
|
||||
|
||||
if minetest.get_modpath("mobs") then
|
||||
tsm_railcorridors.nodes.cobweb = "mobs:cobweb"
|
||||
end
|
||||
|
||||
-- Fallback function. Returns a random treasure. This function is called for chests
|
||||
-- only if the Treasurer mod is not found.
|
||||
-- pr: A PseudoRandom object
|
||||
|
|
86
init.lua
86
init.lua
|
@ -89,12 +89,16 @@ local chaos_mode = minetest.settings:get_bool("tsm_railcorridors_chaos") or fals
|
|||
|
||||
-- Parameter Ende
|
||||
|
||||
-- random generator
|
||||
local pr
|
||||
-- Random generators
|
||||
local pr, webperlin_major, webperlin_minor
|
||||
local pr_initialized = false
|
||||
|
||||
local function InitRandomizer(seed)
|
||||
-- Mostly used for corridor gen.
|
||||
pr = PseudoRandom(seed)
|
||||
-- Used for cobweb generation, both noises have to reach a high value for cobwebs to appear
|
||||
webperlin_major = PerlinNoise(934, 3, 0.6, 500)
|
||||
webperlin_minor = PerlinNoise(834, 3, 0.6, 50)
|
||||
pr_initialized = true
|
||||
end
|
||||
|
||||
|
@ -107,13 +111,17 @@ local function SetNodeIfCanBuild(pos, node, check_above)
|
|||
if check_above then
|
||||
local abovename = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
|
||||
local abovedef = minetest.registered_nodes[abovename]
|
||||
if abovename == "unknown" or abovename == "ignore" or (abovedef.groups and abovedef.groups.attached_node) or abovedef.liquidtype ~= "none" then
|
||||
if abovename == "unknown" or abovename == "ignore" or
|
||||
(abovedef.groups and abovedef.groups.attached_node) or
|
||||
-- This is done because cobwebs are often fake liquids
|
||||
(abovedef.liquidtype ~= "none" and abovename ~= tsm_railcorridors.nodes.cobweb) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
local name = minetest.get_node(pos).name
|
||||
local def = minetest.registered_nodes[name]
|
||||
if name ~= "unknown" and name ~= "ignore" and def.is_ground_content and def.liquidtype == "none" then
|
||||
if name ~= "unknown" and name ~= "ignore" and def.is_ground_content and
|
||||
(def.liquidtype == "none" or name == tsm_railcorridors.nodes.cobweb) then
|
||||
minetest.set_node(pos, node)
|
||||
return true
|
||||
else
|
||||
|
@ -242,7 +250,7 @@ local function rci()
|
|||
end
|
||||
end
|
||||
-- chests
|
||||
local function Place_Chest(pos, param2)
|
||||
local function PlaceChest(pos, param2)
|
||||
if SetNodeIfCanBuild(pos, {name=tsm_railcorridors.nodes.chest, param2=param2}) then
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
@ -251,6 +259,43 @@ local function Place_Chest(pos, param2)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Try to place a cobweb.
|
||||
-- pos: Position of cobweb
|
||||
-- needs_check: If true, checks if any of the nodes above, below or to the side of the cobweb.
|
||||
-- side_vector: Required if needs_check is true. Unit vector which points towards the side of the cobweb to place.
|
||||
local function TryPlaceCobweb(pos, needs_check, side_vector)
|
||||
local check_passed = false
|
||||
if needs_check then
|
||||
-- Check for walkable nodes above, below or at the side of the cobweb.
|
||||
-- If any of those nodes is walkable, we are fine.
|
||||
local check_vectors = {
|
||||
side_vector,
|
||||
{x=0, y=1, z=0},
|
||||
{x=0, y=-1, z=0},
|
||||
}
|
||||
|
||||
for c=1, #check_vectors do
|
||||
|
||||
local cpos = vector.add(pos, check_vectors[c])
|
||||
local cname = minetest.get_node(cpos).name
|
||||
local cdef = minetest.registered_nodes[cname]
|
||||
if cname ~= "ignore" and cdef.walkable then
|
||||
check_passed = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
check_passed = true
|
||||
end
|
||||
|
||||
if check_passed then
|
||||
return SetNodeIfCanBuild(pos, {name=tsm_railcorridors.nodes.cobweb})
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function WoodBulk(pos, wood)
|
||||
SetNodeIfCanBuild({x=pos.x+1, y=pos.y, z=pos.z+1}, {name=wood})
|
||||
|
@ -468,9 +513,38 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
|
|||
if minetest.get_node({x=p.x+vek.z,y=p.y-1,z=p.z-vek.x}).name == post then
|
||||
chestplace = chestplace + 1
|
||||
else
|
||||
Place_Chest({x=p.x+vek.z,y=p.y,z=p.z-vek.x}, minetest.dir_to_facedir(vek))
|
||||
PlaceChest({x=p.x+vek.z,y=p.y,z=p.z-vek.x}, minetest.dir_to_facedir(vek))
|
||||
end
|
||||
end
|
||||
-- Place cobwebs left and right in the corridor
|
||||
if tsm_railcorridors.nodes.cobweb then
|
||||
-- Helper function to place a cobweb at the side (based on chance an Perlin noise)
|
||||
local cobweb_at_side = function(basepos, vek)
|
||||
if pr:next(1,5) == 1 then
|
||||
local h = pr:next(0, 2) -- 3 possible cobweb heights
|
||||
local cpos = {x=basepos.x+vek.x, y=basepos.y+h, z=basepos.z+vek.z}
|
||||
if webperlin_major:get3d(cpos) > 0.05 and webperlin_minor:get3d(cpos) > 0.1 then
|
||||
if h == 0 then
|
||||
-- No check neccessary at height offset 0 since the cobweb is on the floor
|
||||
return TryPlaceCobweb(cpos)
|
||||
else
|
||||
-- Check nessessary
|
||||
return TryPlaceCobweb(cpos, true, vek)
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Right cobweb
|
||||
local rvek = {x=-vek.z, y=0, z=vek.x}
|
||||
cobweb_at_side(p, rvek)
|
||||
|
||||
-- Left cobweb
|
||||
local lvek = {x=vek.z, y=0, z=-vek.x}
|
||||
cobweb_at_side(p, lvek)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
local offset = table.copy(corridor_vek)
|
||||
|
|
Loading…
Reference in New Issue