2021-01-27 10:56:53 +02:00
|
|
|
settlements = {}
|
2021-05-29 17:12:33 +03:00
|
|
|
settlements.modpath = minetest.get_modpath(minetest.get_current_modname())
|
2021-01-27 10:56:53 +02:00
|
|
|
|
|
|
|
dofile(settlements.modpath.."/const.lua")
|
|
|
|
dofile(settlements.modpath.."/utils.lua")
|
|
|
|
dofile(settlements.modpath.."/foundation.lua")
|
|
|
|
dofile(settlements.modpath.."/buildings.lua")
|
|
|
|
dofile(settlements.modpath.."/paths.lua")
|
2021-01-29 20:49:33 +02:00
|
|
|
--dofile(settlements.modpath.."/convert_lua_mts.lua")
|
2021-01-27 10:56:53 +02:00
|
|
|
--
|
|
|
|
-- load settlements on server
|
|
|
|
--
|
|
|
|
settlements.grundstellungen()
|
|
|
|
|
2021-02-09 14:06:19 +02:00
|
|
|
|
2021-10-14 04:03:08 +03:00
|
|
|
local villagegen={}
|
2021-01-27 10:56:53 +02:00
|
|
|
--
|
|
|
|
-- register block for npc spawn
|
|
|
|
--
|
2021-02-09 14:06:19 +02:00
|
|
|
minetest.register_node("mcl_villages:stonebrickcarved", {
|
|
|
|
description = ("Chiseled Stone Village Bricks"),
|
|
|
|
_doc_items_longdesc = doc.sub.items.temp.build,
|
|
|
|
tiles = {"mcl_core_stonebrick_carved.png"},
|
|
|
|
stack_max = 64,
|
|
|
|
drop = "mcl_core:stonebrickcarved",
|
|
|
|
groups = {pickaxey=1, stone=1, stonebrick=1, building_block=1, material_stone=1},
|
|
|
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
|
|
|
is_ground_content = false,
|
|
|
|
_mcl_blast_resistance = 6,
|
|
|
|
_mcl_hardness = 1.5,
|
|
|
|
})
|
|
|
|
|
2021-10-14 04:03:08 +03:00
|
|
|
minetest.register_node("mcl_villages:structblock", {drawtype="airlike",groups = {not_in_creative_inventory=1},})
|
2021-01-27 10:56:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--[[ Enable for testing, but use MineClone2's own spawn code if/when merging.
|
|
|
|
--
|
|
|
|
-- register inhabitants
|
|
|
|
--
|
2021-05-29 17:12:33 +03:00
|
|
|
if minetest.get_modpath("mobs_mc") then
|
2021-01-27 10:56:53 +02:00
|
|
|
mobs:register_spawn("mobs_mc:villager", --name
|
|
|
|
{"mcl_core:stonebrickcarved"}, --nodes
|
|
|
|
15, --max_light
|
|
|
|
0, --min_light
|
|
|
|
20, --chance
|
|
|
|
7, --active_object_count
|
|
|
|
31000, --max_height
|
|
|
|
nil) --day_toggle
|
2021-04-16 14:35:03 +03:00
|
|
|
end
|
2021-01-27 10:56:53 +02:00
|
|
|
--]]
|
|
|
|
|
2022-05-09 00:19:37 +03:00
|
|
|
local function spawn_villagers(minp,maxp)
|
|
|
|
local beds=minetest.find_nodes_in_area(minp,maxp,{"mcl_beds:bed_red_bottom"})
|
|
|
|
for _,bed in pairs(beds) do
|
2022-05-19 22:36:11 +03:00
|
|
|
local m = minetest.get_meta(bed)
|
|
|
|
if m:get_string("villager") == "" then
|
|
|
|
local v=minetest.add_entity(bed,"mobs_mc:villager")
|
|
|
|
if v then
|
|
|
|
local l=v:get_luaentity()
|
|
|
|
l._bed = bed
|
|
|
|
m:set_string("villager",l._id)
|
|
|
|
end
|
2022-05-09 00:19:37 +03:00
|
|
|
end
|
2022-05-19 22:36:11 +03:00
|
|
|
|
2022-05-09 00:19:37 +03:00
|
|
|
end
|
2022-05-19 19:36:54 +03:00
|
|
|
local p = minetest.find_node_near(minp,50,"mcl_core:grass_path")
|
2022-05-19 22:36:11 +03:00
|
|
|
if p then
|
|
|
|
minetest.add_entity(p,"mobs_mc:iron_golem")
|
|
|
|
end
|
2022-05-09 00:19:37 +03:00
|
|
|
end
|
|
|
|
|
2021-01-27 10:56:53 +02:00
|
|
|
--
|
|
|
|
-- on map generation, try to build a settlement
|
|
|
|
--
|
2021-02-22 01:15:32 +02:00
|
|
|
local function build_a_settlement(minp, maxp, blockseed)
|
2021-01-27 10:56:53 +02:00
|
|
|
local pr = PseudoRandom(blockseed)
|
2021-01-29 20:49:33 +02:00
|
|
|
|
2021-01-27 10:56:53 +02:00
|
|
|
-- fill settlement_info with buildings and their data
|
2021-01-29 20:49:33 +02:00
|
|
|
local settlement_info = settlements.create_site_plan(maxp, minp, pr)
|
2021-01-27 10:56:53 +02:00
|
|
|
if not settlement_info then return end
|
|
|
|
|
|
|
|
-- evaluate settlement_info and prepair terrain
|
2021-01-29 20:49:33 +02:00
|
|
|
settlements.terraform(settlement_info, pr)
|
2021-01-27 10:56:53 +02:00
|
|
|
|
|
|
|
-- evaluate settlement_info and build paths between buildings
|
2021-01-29 20:49:33 +02:00
|
|
|
settlements.paths(settlement_info)
|
2021-01-27 10:56:53 +02:00
|
|
|
|
|
|
|
-- evaluate settlement_info and place schematics
|
2021-01-29 20:49:33 +02:00
|
|
|
settlements.place_schematics(settlement_info, pr)
|
2022-05-09 00:19:37 +03:00
|
|
|
|
2022-05-09 12:12:52 +03:00
|
|
|
minetest.after(60,function()
|
2022-05-09 00:19:37 +03:00
|
|
|
spawn_villagers(minp,maxp)
|
|
|
|
end) --give the village some time to fully generate
|
2021-01-27 10:56:53 +02:00
|
|
|
end
|
|
|
|
|
2021-02-22 01:15:32 +02:00
|
|
|
local function ecb_village(blockpos, action, calls_remaining, param)
|
|
|
|
if calls_remaining >= 1 then return end
|
|
|
|
local minp, maxp, blockseed = param.minp, param.maxp, param.blockseed
|
|
|
|
build_a_settlement(minp, maxp, blockseed)
|
2021-01-27 10:56:53 +02:00
|
|
|
end
|
|
|
|
|
2021-02-01 23:45:22 +02:00
|
|
|
-- Disable natural generation in singlenode.
|
|
|
|
local mg_name = minetest.get_mapgen_setting("mg_name")
|
|
|
|
if mg_name ~= "singlenode" then
|
2021-02-22 01:15:32 +02:00
|
|
|
mcl_mapgen_core.register_generator("villages", nil, function(minp, maxp, blockseed)
|
2021-02-01 23:45:22 +02:00
|
|
|
-- don't build settlement underground
|
|
|
|
if maxp.y < 0 then return end
|
2021-02-22 01:15:32 +02:00
|
|
|
-- randomly try to build settlements
|
|
|
|
if blockseed % 77 ~= 17 then return end
|
|
|
|
-- needed for manual and automated settlement building
|
2021-02-01 23:45:22 +02:00
|
|
|
-- don't build settlements on (too) uneven terrain
|
2021-10-14 04:03:08 +03:00
|
|
|
local n=minetest.get_node_or_nil(minp)
|
|
|
|
if n and n.name == "mcl_villages:structblock" then return end
|
|
|
|
if villagegen[minetest.pos_to_string(minp)] ~= nil then return end
|
|
|
|
minetest.set_node(minp,{name="mcl_villages:structblock"})
|
|
|
|
|
2021-02-22 01:15:32 +02:00
|
|
|
local height_difference = settlements.evaluate_heightmap()
|
2021-02-01 23:45:22 +02:00
|
|
|
if height_difference > max_height_difference then return end
|
2021-02-22 01:15:32 +02:00
|
|
|
|
2021-10-14 04:03:08 +03:00
|
|
|
villagegen[minetest.pos_to_string(minp)]={minp=vector.new(minp), maxp=vector.new(maxp), blockseed=blockseed}
|
2021-02-01 23:45:22 +02:00
|
|
|
end)
|
|
|
|
end
|
2021-10-14 04:03:08 +03:00
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
name = "mcl_villages:structblock",
|
|
|
|
run_at_every_load = true,
|
|
|
|
nodenames = {"mcl_villages:structblock"},
|
|
|
|
action = function(pos, node)
|
|
|
|
minetest.set_node(pos, {name = "air"})
|
|
|
|
if not villagegen[minetest.pos_to_string(pos)] then return end
|
|
|
|
local minp=villagegen[minetest.pos_to_string(pos)].minp
|
|
|
|
local maxp=villagegen[minetest.pos_to_string(pos)].maxp
|
|
|
|
minetest.emerge_area(minp, maxp, ecb_village, villagegen[minetest.pos_to_string(minp)])
|
|
|
|
villagegen[minetest.pos_to_string(minp)]=nil
|
|
|
|
end
|
|
|
|
})
|
2021-01-29 20:49:33 +02:00
|
|
|
-- manually place villages
|
|
|
|
if minetest.is_creative_enabled("") then
|
|
|
|
minetest.register_craftitem("mcl_villages:tool", {
|
|
|
|
description = "mcl_villages build tool",
|
|
|
|
inventory_image = "default_tool_woodshovel.png",
|
|
|
|
-- build ssettlement
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
if not pointed_thing.under then return end
|
|
|
|
local minp = vector.subtract( pointed_thing.under, half_map_chunk_size)
|
|
|
|
local maxp = vector.add( pointed_thing.under, half_map_chunk_size)
|
2021-02-22 01:15:32 +02:00
|
|
|
build_a_settlement(minp, maxp, math.random(0,32767))
|
2021-01-29 20:49:33 +02:00
|
|
|
end
|
|
|
|
})
|
2021-03-07 18:07:55 +02:00
|
|
|
mcl_wip.register_experimental_item("mcl_villages:tool")
|
2021-01-29 20:49:33 +02:00
|
|
|
end
|