2022-06-24 19:47:44 +00:00
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
local modpath = minetest.get_modpath(modname)
|
|
|
|
|
2022-11-11 09:35:25 +00:00
|
|
|
---@param pos Vector
|
|
|
|
---@param pr PseudoRandom
|
|
|
|
---@return boolean|nil
|
|
|
|
---@return string
|
2022-06-24 19:47:44 +00:00
|
|
|
function mcl_structures.generate_igloo_top(pos, pr)
|
2022-10-14 03:06:58 +00:00
|
|
|
-- Furnace does ot work atm because apparently meta is not set. Need a bit of help with fixing this for furnaces, bookshelves, and brewing stands.
|
2022-11-11 09:35:25 +00:00
|
|
|
local newpos = vector.offset(pos, 0, -2, 0)
|
|
|
|
local path = modpath .. "/schematics/mcl_structures_igloo_top.mts"
|
|
|
|
local rotation = tostring(pr:next(0, 3) * 90)
|
2022-10-15 01:39:45 +00:00
|
|
|
return mcl_structures.place_schematic(newpos, path, rotation, nil, true, nil, function()
|
2022-11-11 09:35:25 +00:00
|
|
|
local p1 = vector.offset(pos, -5, -5, -5)
|
|
|
|
local p2 = vector.offset(pos, 5, 5, 5)
|
|
|
|
mcl_structures.construct_nodes(p1, p2, { "mcl_furnaces:furnace", "mcl_books:bookshelf" })
|
2022-10-15 01:39:45 +00:00
|
|
|
end), rotation
|
2022-06-24 19:47:44 +00:00
|
|
|
end
|
|
|
|
|
2022-11-11 09:35:25 +00:00
|
|
|
local function spawn_mobs(p1, p2, vi, zv)
|
|
|
|
local mc = minetest.find_nodes_in_area_under_air(p1, p2, { "mcl_core:stonebrickmossy" })
|
2022-10-28 23:26:32 +00:00
|
|
|
if #mc == 2 then
|
|
|
|
local vp = mc[1]
|
|
|
|
local zp = mc[2]
|
2022-11-11 09:35:25 +00:00
|
|
|
if not vi and zv and zv:get_pos() and vector.distance(mc[1], zv:get_pos()) < 2 then
|
2022-10-28 23:26:32 +00:00
|
|
|
vp = mc[2]
|
2022-11-11 09:35:25 +00:00
|
|
|
elseif not zv and vi and vi:get_pos() and vector.distance(mc[2], vi:get_pos()) < 2 then
|
2022-10-28 23:26:32 +00:00
|
|
|
zp = mc[1]
|
|
|
|
elseif zv and vi then
|
|
|
|
return
|
|
|
|
end
|
2022-11-11 09:35:25 +00:00
|
|
|
vi = minetest.add_entity(vector.offset(mc[1], 0, 1, 0), "mobs_mc:villager")
|
|
|
|
zv = minetest.add_entity(vector.offset(mc[2], 0, 1, 0), "mobs_mc:villager_zombie")
|
|
|
|
minetest.after(1, spawn_mobs, p1, p2, vi, zv)
|
2022-10-28 23:26:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-11 09:35:25 +00:00
|
|
|
---@param pos Vector
|
|
|
|
---@param orientation any
|
|
|
|
---@param loot any
|
|
|
|
---@param pr PseudoRandom
|
2022-06-24 21:24:51 +00:00
|
|
|
function mcl_structures.generate_igloo_basement(pos, orientation, loot, pr)
|
2022-06-24 19:47:44 +00:00
|
|
|
-- TODO: Add monster eggs
|
2022-11-11 09:35:25 +00:00
|
|
|
local path = modpath .. "/schematics/mcl_structures_igloo_basement.mts"
|
2022-06-24 21:24:51 +00:00
|
|
|
mcl_structures.place_schematic(pos, path, orientation, nil, true, nil, function()
|
2022-11-11 09:35:25 +00:00
|
|
|
local p1 = vector.offset(pos, -5, -5, -5)
|
|
|
|
local p2 = vector.offset(pos, 5, 5, 5)
|
|
|
|
mcl_structures.fill_chests(p1, p2, loot, pr)
|
|
|
|
mcl_structures.construct_nodes(p1, p2, { "mcl_brewing:stand_000", "mcl_books:bookshelf" })
|
|
|
|
spawn_mobs(p1, p2)
|
2022-06-24 21:24:51 +00:00
|
|
|
end, pr)
|
2022-06-24 19:47:44 +00:00
|
|
|
end
|
|
|
|
|
2022-11-11 09:35:25 +00:00
|
|
|
---@param pos Vector
|
|
|
|
---@param def table
|
|
|
|
---@param pr PseudoRandom
|
2022-06-24 19:47:44 +00:00
|
|
|
function mcl_structures.generate_igloo(pos, def, pr)
|
|
|
|
-- Place igloo
|
|
|
|
local success, rotation = mcl_structures.generate_igloo_top(pos, pr)
|
|
|
|
-- Place igloo basement with 50% chance
|
2022-11-11 09:35:25 +00:00
|
|
|
local r = pr:next(1, 2)
|
2022-06-24 19:47:44 +00:00
|
|
|
if r == 1 then
|
|
|
|
-- Select basement depth
|
|
|
|
local dim = mcl_worlds.pos_to_dimension(pos)
|
|
|
|
--local buffer = pos.y - (mcl_vars.mg_lava_overworld_max + 10)
|
|
|
|
local buffer
|
|
|
|
if dim == "nether" then
|
|
|
|
buffer = pos.y - (mcl_vars.mg_lava_nether_max + 10)
|
|
|
|
elseif dim == "end" then
|
|
|
|
buffer = pos.y - (mcl_vars.mg_end_min + 1)
|
|
|
|
elseif dim == "overworld" then
|
|
|
|
buffer = pos.y - (mcl_vars.mg_lava_overworld_max + 10)
|
|
|
|
else
|
|
|
|
return success
|
|
|
|
end
|
|
|
|
if buffer <= 19 then
|
|
|
|
return success
|
|
|
|
end
|
|
|
|
local depth = pr:next(19, buffer)
|
2022-11-11 09:35:25 +00:00
|
|
|
local bpos = vector.offset(pos, 0, -depth, 0)
|
2022-06-24 19:47:44 +00:00
|
|
|
-- trapdoor position
|
|
|
|
local tpos
|
|
|
|
local dir, tdir
|
|
|
|
if rotation == "0" then
|
2022-11-11 09:35:25 +00:00
|
|
|
dir = vector.new(-1, 0, 0)
|
|
|
|
tdir = vector.new(1, 0, 0)
|
|
|
|
tpos = vector.offset(pos, 7, -2, 3)
|
2022-06-24 19:47:44 +00:00
|
|
|
elseif rotation == "90" then
|
2022-11-11 09:35:25 +00:00
|
|
|
dir = vector.new(0, 0, -1)
|
|
|
|
tdir = vector.new(0, 0, -1)
|
|
|
|
tpos = vector.offset(pos, 3, -2, 1)
|
2022-06-24 19:47:44 +00:00
|
|
|
elseif rotation == "180" then
|
2022-11-11 09:35:25 +00:00
|
|
|
dir = vector.new(1, 0, 0)
|
|
|
|
tdir = vector.new(-1, 0, 0)
|
|
|
|
tpos = vector.offset(pos, 1, -2, 3)
|
2022-06-24 19:47:44 +00:00
|
|
|
elseif rotation == "270" then
|
2022-11-11 09:35:25 +00:00
|
|
|
dir = vector.new(0, 0, 1)
|
|
|
|
tdir = vector.new(0, 0, 1)
|
|
|
|
tpos = vector.offset(pos, 3, -2, 7)
|
2022-06-24 19:47:44 +00:00
|
|
|
else
|
|
|
|
return success
|
|
|
|
end
|
|
|
|
local function set_brick(pos)
|
|
|
|
local c = pr:next(1, 3) -- cracked chance
|
|
|
|
local m = pr:next(1, 10) -- chance for monster egg
|
|
|
|
local brick
|
|
|
|
if m == 1 then
|
|
|
|
if c == 1 then
|
|
|
|
brick = "mcl_monster_eggs:monster_egg_stonebrickcracked"
|
|
|
|
else
|
|
|
|
brick = "mcl_monster_eggs:monster_egg_stonebrick"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if c == 1 then
|
|
|
|
brick = "mcl_core:stonebrickcracked"
|
|
|
|
else
|
|
|
|
brick = "mcl_core:stonebrick"
|
|
|
|
end
|
|
|
|
end
|
2022-11-11 09:35:25 +00:00
|
|
|
minetest.set_node(pos, { name = brick })
|
2022-06-24 19:47:44 +00:00
|
|
|
end
|
2022-11-11 09:35:25 +00:00
|
|
|
|
2022-06-24 19:47:44 +00:00
|
|
|
local ladder_param2 = minetest.dir_to_wallmounted(tdir)
|
|
|
|
local real_depth = 0
|
|
|
|
-- Check how deep we can actuall dig
|
2022-11-11 09:35:25 +00:00
|
|
|
for y = 1, depth - 5 do
|
2022-06-24 19:47:44 +00:00
|
|
|
real_depth = real_depth + 1
|
2022-11-11 09:35:25 +00:00
|
|
|
local node = minetest.get_node(vector.offset(tpos, 0, -y, 0))
|
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
if not (ndef and ndef.walkable and ndef.liquidtype == "none" and ndef.is_ground_content) then
|
|
|
|
bpos.y = tpos.y - y + 1
|
2022-06-24 19:47:44 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if real_depth <= 6 then
|
|
|
|
return success
|
|
|
|
end
|
|
|
|
-- Generate ladder to basement
|
2022-11-11 09:35:25 +00:00
|
|
|
for y = 1, real_depth - 1 do
|
|
|
|
set_brick(vector.offset(tpos, -1, -y, 0))
|
|
|
|
set_brick(vector.offset(tpos, 1, -y, 0))
|
|
|
|
set_brick(vector.offset(tpos, 0, -y, -1))
|
|
|
|
set_brick(vector.offset(tpos, 0, -y, 1))
|
|
|
|
minetest.set_node(vector.offset(tpos, 0, -y, 0), { name = "mcl_core:ladder", param2 = ladder_param2 })
|
2022-06-24 19:47:44 +00:00
|
|
|
end
|
|
|
|
-- Place basement
|
2022-06-24 21:24:51 +00:00
|
|
|
mcl_structures.generate_igloo_basement(bpos, rotation, def.loot, pr)
|
2022-06-24 19:47:44 +00:00
|
|
|
-- Place hidden trapdoor
|
2022-11-11 09:35:25 +00:00
|
|
|
minetest.after(5, function(tpos2, dir2)
|
|
|
|
minetest.set_node(tpos2, { name = "mcl_doors:trapdoor", param2 = 20 + minetest.dir_to_facedir(dir2) }) -- TODO: more reliable param2
|
2022-06-24 19:47:44 +00:00
|
|
|
end, tpos, dir)
|
|
|
|
end
|
|
|
|
return success
|
|
|
|
end
|
|
|
|
|
2022-11-11 09:35:25 +00:00
|
|
|
mcl_structures.register_structure("igloo", {
|
|
|
|
place_on = { "mcl_core:snowblock", "mcl_core:snow", "group:grass_block_snow" },
|
2022-06-24 19:47:44 +00:00
|
|
|
fill_ratio = 0.01,
|
|
|
|
sidelen = 16,
|
2022-06-25 00:53:58 +00:00
|
|
|
chunk_probability = 250,
|
2022-06-24 21:24:51 +00:00
|
|
|
solid_ground = true,
|
|
|
|
make_foundation = true,
|
2022-06-24 19:47:44 +00:00
|
|
|
y_max = mcl_vars.mg_overworld_max,
|
|
|
|
y_min = 0,
|
|
|
|
y_offset = 0,
|
2022-11-11 09:35:25 +00:00
|
|
|
biomes = { "ColdTaiga", "IcePlainsSpikes", "IcePlains" },
|
2022-06-24 19:47:44 +00:00
|
|
|
place_func = mcl_structures.generate_igloo,
|
|
|
|
loot = {
|
2022-11-11 09:35:25 +00:00
|
|
|
["mcl_chests:chest_small"] = { {
|
2022-06-24 19:47:44 +00:00
|
|
|
stacks_min = 1,
|
|
|
|
stacks_max = 1,
|
|
|
|
items = {
|
|
|
|
{ itemstring = "mcl_core:apple_gold", weight = 1 },
|
|
|
|
}
|
|
|
|
},
|
2022-11-11 09:35:25 +00:00
|
|
|
{
|
|
|
|
stacks_min = 2,
|
|
|
|
stacks_max = 8,
|
|
|
|
items = {
|
|
|
|
{ itemstring = "mcl_core:coal_lump", weight = 15, amount_min = 1, amount_max = 4 },
|
|
|
|
{ itemstring = "mcl_core:apple", weight = 15, amount_min = 1, amount_max = 3 },
|
|
|
|
{ itemstring = "mcl_farming:wheat_item", weight = 10, amount_min = 2, amount_max = 3 },
|
|
|
|
{ itemstring = "mcl_core:gold_nugget", weight = 10, amount_min = 1, amount_max = 3 },
|
|
|
|
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10 },
|
|
|
|
{ itemstring = "mcl_tools:axe_stone", weight = 2 },
|
|
|
|
{ itemstring = "mcl_core:emerald", weight = 1 },
|
|
|
|
{ itemstring = "mcl_core:apple_gold", weight = 1 },
|
|
|
|
}
|
|
|
|
} },
|
2022-06-24 19:47:44 +00:00
|
|
|
}
|
|
|
|
})
|