2022-06-24 21:47:44 +02:00
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
local S = minetest.get_translator(modname)
|
|
|
|
local modpath = minetest.get_modpath(modname)
|
|
|
|
|
2022-09-06 12:45:38 +02:00
|
|
|
local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
|
|
|
|
|
2022-06-24 21:47:44 +02:00
|
|
|
local function spawn_witch(p1,p2)
|
2024-11-01 00:28:11 +01:00
|
|
|
local c = minetest.find_node_near(p1,15,{"group:cauldron"})
|
2024-10-31 18:27:21 +01:00
|
|
|
if not c then return end
|
|
|
|
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 witchobj = not peaceful and minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:witch")
|
|
|
|
if witchobj then
|
|
|
|
local witch = witchobj:get_luaentity()
|
|
|
|
witch._home = c
|
|
|
|
witch.can_despawn = false
|
|
|
|
end
|
|
|
|
local catobj = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:cat")
|
|
|
|
if catobj then
|
|
|
|
local cat=catobj:get_luaentity()
|
|
|
|
cat.object:set_properties({textures = {"mobs_mc_cat_black.png"}})
|
|
|
|
cat.owner = "!witch!" --so it's not claimable by player
|
|
|
|
cat._home = c
|
|
|
|
cat.can_despawn = false
|
2022-06-24 21:47:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-23 10:55:30 +02:00
|
|
|
local function hut_placement_callback(pos,def,pr,p1,p2)
|
|
|
|
-- p1.y is the bottom slice only, not a typo, we look for the hut legs
|
|
|
|
local legs = minetest.find_nodes_in_area(p1,vector.new(p2.x,p1.y,p2.z), "mcl_core:tree")
|
2022-06-24 21:47:44 +02:00
|
|
|
local tree = {}
|
2022-06-25 02:53:58 +02:00
|
|
|
for _,leg in pairs(legs) do
|
2024-08-23 10:55:30 +02:00
|
|
|
while true do
|
|
|
|
local name = minetest.get_node(vector.offset(leg,0,-1,0)).name
|
|
|
|
if name == "ignore" then break end
|
|
|
|
if name ~= "air" and minetest.get_item_group(name, "water") == 0 then break end
|
2022-06-25 02:53:58 +02:00
|
|
|
leg = vector.offset(leg,0,-1,0)
|
|
|
|
table.insert(tree,leg)
|
2022-06-24 21:47:44 +02:00
|
|
|
end
|
|
|
|
end
|
2024-09-05 21:28:47 +02:00
|
|
|
minetest.bulk_swap_node(tree, {name = "mcl_core:tree", param2 = 2})
|
2022-06-24 21:47:44 +02:00
|
|
|
spawn_witch(p1,p2)
|
|
|
|
end
|
|
|
|
|
2024-08-23 10:55:30 +02:00
|
|
|
vl_structures.register_structure("witch_hut",{
|
|
|
|
place_on = {"mcl_core:water_source","group:sand","group:grass_block","group:dirt","mclx_core:river_water_source"},
|
|
|
|
spawn_by = {"mcl_core:water_source","mclx_core:river_water_source"},
|
|
|
|
check_offset = -1,
|
|
|
|
num_spawn_by = 3,
|
|
|
|
flags = "place_center_x, place_center_z, all_surfaces",
|
2024-08-06 20:37:44 +02:00
|
|
|
chunk_probability = 8,
|
2024-11-01 00:28:11 +01:00
|
|
|
prepare = { surface = "under_air", tolerance = 3, clear_bottom = 3, padding = 0, corners = 1, foundation = false, mode = "max" },
|
2022-06-24 21:47:44 +02:00
|
|
|
y_max = mcl_vars.mg_overworld_max,
|
2024-08-23 10:55:30 +02:00
|
|
|
y_min = -5,
|
2024-11-01 00:28:11 +01:00
|
|
|
y_offset = -1,
|
2022-06-24 21:47:44 +02:00
|
|
|
biomes = { "Swampland", "Swampland_ocean", "Swampland_shore" },
|
|
|
|
filenames = { modpath.."/schematics/mcl_structures_witch_hut.mts" },
|
|
|
|
after_place = hut_placement_callback,
|
|
|
|
})
|