1
0
Fork 0
MineClone2/mods/MAPGEN/mcl_structures/witch_hut.lua

58 lines
2.1 KiB
Lua
Raw Normal View History

2022-06-24 21:47:44 +02:00
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
local function spawn_witch(p1, p2)
local c = minetest.find_node_near(p1, 15, { "mcl_cauldrons:cauldron" })
2022-06-24 21:47:44 +02:00
if c then
local nn = minetest.find_nodes_in_area_under_air(vector.new(p1.x, c.y - 1, p1.z), vector.new(p2.x, c.y - 1, p2.z),
{ "mcl_core:sprucewood" })
local witch
if not peaceful then
witch = minetest.add_entity(vector.offset(nn[math.random(#nn)], 0, 1, 0), "mobs_mc:witch"):get_luaentity()
witch._home = c
witch.can_despawn = false
end
local cat = minetest.add_entity(vector.offset(nn[math.random(#nn)], 0, 1, 0), "mobs_mc:cat"):get_luaentity()
cat.object:set_properties({ textures = { "mobs_mc_cat_black.png" } })
2022-06-24 21:47:44 +02:00
cat.owner = "!witch!" --so it's not claimable by player
cat._home = c
cat.can_despawn = false
return
end
end
---@param pos Vector
---@param def table
---@param pr PseudoRandom
local function hut_placement_callback(pos, def, pr)
2022-06-24 21:47:44 +02:00
local hl = def.sidelen / 2
local p1 = vector.offset(pos, -hl, -hl, -hl)
local p2 = vector.offset(pos, hl, hl, hl)
local legs = minetest.find_nodes_in_area(vector.offset(pos, -hl, 0, -hl), vector.offset(pos, hl, 0, hl), "mcl_core:tree")
2022-06-24 21:47:44 +02:00
local tree = {}
for _, leg in pairs(legs) do
while minetest.get_item_group(mcl_vars.get_node(vector.offset(leg, 0, -1, 0), true, 333333).name, "water") ~= 0 do
leg = vector.offset(leg, 0, -1, 0)
table.insert(tree, leg)
2022-06-24 21:47:44 +02:00
end
end
minetest.bulk_set_node(tree, { name = "mcl_core:tree", param2 = 2 })
spawn_witch(p1, p2)
2022-06-24 21:47:44 +02:00
end
mcl_structures.register_structure("witch_hut", {
place_on = { "group:sand", "group:grass_block", "mcl_core:water_source", "group:dirt" },
2022-06-24 21:47:44 +02:00
fill_ratio = 0.01,
flags = "place_center_x, place_center_z, liquid_surface, force_placement",
2022-06-25 02:53:58 +02:00
sidelen = 8,
2022-06-25 06:16:43 +02:00
chunk_probability = 300,
2022-06-24 21:47:44 +02:00
y_max = mcl_vars.mg_overworld_max,
y_min = -4,
y_offset = 0,
biomes = { "Swampland", "Swampland_ocean", "Swampland_shore" },
filenames = { modpath .. "/schematics/mcl_structures_witch_hut.mts" },
2022-06-24 21:47:44 +02:00
after_place = hut_placement_callback,
})