Restore Witch Hut

This commit is contained in:
kay27 2022-01-19 01:49:28 +04:00
parent 34c6bf3446
commit 75a7f5a3ae
4 changed files with 137 additions and 97 deletions

View File

@ -1,6 +1,4 @@
local END_EXIT_PORTAL_POS = vector.new(-3, -27003, -3) -- End exit portal position
local WITCH_HUT_HEIGHT = 3 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor
local OVERWORLD_STRUCT_MIN, OVERWORLD_STRUCT_MAX = mcl_mapgen.overworld.min, mcl_mapgen.overworld.max
local END_STRUCT_MIN, END_STRUCT_MAX = mcl_mapgen.end_.min, mcl_mapgen.end_.max
local DIVLEN = 5
@ -80,93 +78,6 @@ end
max_noise = max_noise * octaves
max_noise = offset + scale * max_noise
local witch_hut_offsets = {
["0"] = {
{x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5},
},
["180"] = {
{x=2, y=0, z=1}, {x=2, y=0, z=5}, {x=7, y=0, z=1}, {x=7, y=0, z=5},
},
["270"] = {
{x=1, y=0, z=1}, {x=5, y=0, z=1}, {x=1, y=0, z=6}, {x=5, y=0, z=6},
},
["90"] = {
{x=1, y=0, z=2}, {x=5, y=0, z=2}, {x=1, y=0, z=7}, {x=5, y=0, z=7},
},
}
local function spawn_witch_hut(p, nn, pr, vm_context)
minetest.log("warning", "p="..minetest.pos_to_string(p)..", nn="..nn)
-- if p.y > 1 or minetest_get_item_group(nn, "dirt") == 0 then return end
local minp, maxp = vm_context.minp, vm_context.maxp
local prob = minecraft_chunk_probability(48, minp, maxp)
minetest.log("warning", "prob="..tostring(prob))
-- if pr:next(1, prob) ~= 1 then return end
-- Where do witches live?
if V6 then
-- v6: In Normal biome
if biomeinfo.get_v6_biome(p) ~= "Normal" then return end
else
-- Other mapgens: In swampland biome
local biomemap = vm_context.biomemap
if not biomemap then
vm_context.biomemap = minetest_get_mapgen_object('biomemap')
biomemap = vm_context.biomemap
end
local swampland = minetest.get_biome_id("Swampland")
local swampland_shore = minetest.get_biome_id("Swampland_shore")
local bi = xz_to_biomemap_index(p.x, p.z, vm_context.minp, vm_context.maxp)
-- if biomemap[bi] ~= swampland and biomemap[bi] ~= swampland_shore then return end
end
local r = tostring(pr:next(0, 3) * 90) -- "0", "90", "180" or 270"
local p1 = {x=p.x-1, y=WITCH_HUT_HEIGHT+2, z=p.z-1}
local size
if r == "0" or r == "180" then
size = {x=10, y=4, z=8}
else
size = {x=8, y=4, z=10}
end
local p2 = vector.add(p1, size)
-- This checks free space at the “body” of the hut and a bit around.
-- ALL nodes must be free for the placement to succeed.
local free_nodes = minetest_find_nodes_in_area(p1, p2, {"air", "mcl_core:water_source", "mcl_flowers:waterlily"})
if #free_nodes < ((size.x+1)*(size.y+1)*(size.z+1)) then return end
local place = {x=p.x, y=WITCH_HUT_HEIGHT-1, z=p.z}
-- FIXME: For some mysterious reason (black magic?) this
-- function does sometimes NOT spawn the witch hut. One can only see the
-- oak wood nodes in the water, but no hut. :-/
mcl_structures.call_struct(place, "witch_hut", r, pr)
-- TODO: Spawn witch in or around hut when the mob sucks less.
local function place_tree_if_free(pos, prev_result)
local nn = minetest.get_node(pos).name
if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" then
minetest.set_node(pos, {name="mcl_core:tree", param2=0})
return prev_result
else
return false
end
end
local offsets = witch_hut_offsets[r]
for o=1, #offsets do
local ok = true
for y=place.y-1, place.y-64, -1 do
local tpos = vector.add(place, offsets[o])
tpos.y = y
ok = place_tree_if_free(tpos, ok)
if not ok then
break
end
end
end
end
-- TODO: Check spikes sizes, it looks like we have to swap them:
@ -235,10 +146,6 @@ local function generate_structures(vm_context)
local nn0 = minetest.get_node(p).name
-- Check if the node can be replaced
if minetest.registered_nodes[nn0] and minetest.registered_nodes[nn0].buildable_to then
--spawn_desert_temple(p, nn, pr, vm_context)
--spawn_desert_well(p, nn, pr, vm_context)
--spawn_fossil(p, nn, pr, vm_context)
--spawn_witch_hut(p, nn, pr, vm_context)
if V6 then
spawn_spikes_in_v6(p, nn, pr, vm_context)
end

View File

@ -2,10 +2,10 @@ local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
-- local chance_per_chunk = mcl_structures.from_16x16_to_chunk_inverted_chance(4400)
local chance_per_chunk = 1
local noise_multiplier = 0 --1.3
local random_offset = 132
local struct_threshold = 0 --chance_per_chunk - 1
local chance_per_chunk = 100
local noise_multiplier = 1.4
local random_offset = 555
local struct_threshold = chance_per_chunk - 1
local scanning_ratio = 0.0003
local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level

View File

@ -10,4 +10,5 @@ if not mcl_mapgen.singlenode then
dofile(modpath .. "/nice_jungle_temple.lua")
dofile(modpath .. "/noise_indicator.lua")
dofile(modpath .. "/stronghold.lua")
dofile(modpath .. "/witch_hut.lua")
end

View File

@ -0,0 +1,132 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local chance_per_chunk = 3
local noise_multiplier = -0.9
local random_offset = 8
local scanning_ratio = 0.0001
local struct_threshold = chance_per_chunk - 1
local mcl_structures_get_perlin_noise_level = mcl_structures.get_perlin_noise_level
local schematic_file = modpath .. "/schematics/mcl_structures_witch_hut.mts"
local witch_hut_schematic_lua = minetest.serialize_schematic(schematic_file, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic"
local witch_hut_schematic = loadstring(witch_hut_schematic_lua)()
local node_list = {"mcl_core:dirt_with_grass", "mcl_core:dirt"}
local WITCH_HUT_HEIGHT = 2 -- Exact Y level to spawn witch huts at. This height refers to the height of the floor
local witch_hut_offsets = {
["0"] = {
{x=1, y=0, z=1}, {x=1, y=0, z=5}, {x=6, y=0, z=1}, {x=6, y=0, z=5},
},
["180"] = {
{x=2, y=0, z=1}, {x=2, y=0, z=5}, {x=7, y=0, z=1}, {x=7, y=0, z=5},
},
["270"] = {
{x=1, y=0, z=1}, {x=5, y=0, z=1}, {x=1, y=0, z=6}, {x=5, y=0, z=6},
},
["90"] = {
{x=1, y=0, z=2}, {x=5, y=0, z=2}, {x=1, y=0, z=7}, {x=5, y=0, z=7},
},
}
local function on_placed(place, rotation, pr, size)
local offsets = witch_hut_offsets[rotation]
if not offsets then return end
for _, offset in pairs(offsets) do
local tpos = vector.add(place, offset)
for y = place.y - 1, mcl_mapgen.get_chunk_beginning(place.y - 1), -1 do
tpos.y = y
local nn = minetest.get_node(tpos).name
if not nn then break end
local node = minetest.registered_nodes[nn]
local groups = node.groups
if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" or groups.deco_block then
minetest.swap_node(tpos, {name="mcl_core:tree"})
else
break
end
end
end
end
local function place(pos, rotation, pr)
mcl_structures.place_schematic({pos = pos, rotaton = rotation, schematic = witch_hut_schematic, pr = pr, on_placed = on_placed})
end
local function get_place_rank(pos)
local x, y, z = pos.x, pos.y, pos.z
local p1 = {x = x + 1, y = y + 1, z = z + 1}
local p2 = {x = x + 4, y = y + 4, z = z + 4}
local counter = #minetest.find_nodes_in_area(p1, p2, {"air", "group:buildable_to", "group:deco_block"}, false)
return counter
end
local function tune_pos(pos)
local y = pos.y - 1
if y >= WITCH_HUT_HEIGHT - 5 and y <= WITCH_HUT_HEIGHT + 5 then
pos.y = WITCH_HUT_HEIGHT
return pos
end
local water_list = minetest.find_nodes_in_area(p1, p2, {"group:water"}, false)
if not water_list or #water_list < 1 then
pos.y = pos.y - 1
return pos
end
local top = -1
for _, pos in pairs(water_list) do
if pos.y > top then
top = pos.y
end
end
pos.y = top - 1
return pos
end
mcl_structures.register_structure({
name = "witch_hut",
decoration = {
deco_type = "simple",
place_on = node_list,
spawn_by = {"mcl_core:water_source", "group:frosted_ice"},
num_spawn_by = 1,
flags = "all_floors",
fill_ratio = scanning_ratio,
y_min = mcl_mapgen.overworld.min,
y_max = mcl_mapgen.overworld.max,
height = 1,
biomes = mcl_mapgen.v6 and {
"Normal",
} or {
"Swampland",
"Swampland_shore",
"Swampland_ocean",
"Swampland_deep_ocean",
},
},
on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list)
local pr = PseudoRandom(seed + random_offset)
local random_number = pr:next(1, chance_per_chunk)
local noise = mcl_structures_get_perlin_noise_level(minp) * noise_multiplier
if (random_number + noise) < struct_threshold then return end
local pos = tune_pos(pos_list[1])
if #pos_list > 1 then
local count = get_place_rank(pos)
for i = 2, #pos_list do
local pos_i = pos_list[i]
local count_i = get_place_rank(pos_i)
if count_i > count then
count = count_i
pos = pos_i
end
end
end
local pr = PseudoRandom(vm_context.chunkseed)
place(pos, nil, pr)
end,
place_function = place,
})