mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-09-12 00:56:53 +02:00
Add loot generation to api
This commit is contained in:
parent
065767cc77
commit
fcb8160a60
@ -25,6 +25,9 @@ If nospawn is truthy the structure will not be placed by mapgen and the decorati
|
||||
sidelen = int, --length of one side of the structure. used for foundations.
|
||||
solid_ground = bool, -- structure requires solid ground
|
||||
make_foundation = bool, -- a foundation is automatically built for the structure. needs the sidelen param
|
||||
loot = ,
|
||||
--a table of loot tables for mcl_loot indexed by node names
|
||||
-- e.g. { ["mcl_chests:chest_small"] = {loot},... }
|
||||
}
|
||||
## mcl_structures.registered_structures
|
||||
Table of the registered structure defintions indexed by name.
|
||||
|
@ -1,5 +1,21 @@
|
||||
mcl_structures.registered_structures = {}
|
||||
|
||||
local function generate_loot(pos, def, pr)
|
||||
local hl = def.sidelen / 2
|
||||
local p1 = vector.offset(pos,-hl,-hl,-hl)
|
||||
local p2 = vector.offset(pos,hl,hl,hl)
|
||||
for it,lt in pairs(def.loot) do
|
||||
local nodes = minetest.find_nodes_in_area(p1, p2, it)
|
||||
for _,p in pairs(nodes) do
|
||||
local lootitems = mcl_loot.get_multi_loot( lt, pr)
|
||||
mcl_structures.init_node_construct(p)
|
||||
local meta = minetest.get_meta(p)
|
||||
local inv = meta:get_inventory()
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems, pr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mcl_structures.place_structure(pos, def, pr)
|
||||
if not def then return end
|
||||
local logging = not def.terrain_feature
|
||||
@ -42,7 +58,10 @@ function mcl_structures.place_structure(pos, def, pr)
|
||||
local ap = function(pos,def,pr) end
|
||||
if def.after_place then ap = def.after_place end
|
||||
|
||||
mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",function(p) return ap(pos,def,pr) end,pr)
|
||||
mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",function(p)
|
||||
if def.loot then generate_loot(pos,def,pr) end
|
||||
return ap(pos,def,pr)
|
||||
end,pr)
|
||||
if logging then
|
||||
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pos))
|
||||
end
|
||||
@ -88,13 +107,13 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it
|
||||
y_max = def.y_max,
|
||||
y_min = def.y_min
|
||||
})
|
||||
minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups})
|
||||
def.structblock = structblock
|
||||
def.deco_id = minetest.get_decoration_id("mcl_structures:deco_"..name)
|
||||
minetest.set_gen_notify({decoration=true}, { def.deco_id })
|
||||
--catching of gennotify happens in mcl_mapgen_core
|
||||
end)
|
||||
end
|
||||
minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups})
|
||||
def.structblock = structblock
|
||||
mcl_structures.registered_structures[name] = def
|
||||
end
|
||||
|
||||
|
@ -17,54 +17,6 @@ local function temple_placement_callback(pos,def, pr)
|
||||
end
|
||||
end
|
||||
|
||||
-- Find chests.
|
||||
-- FIXME: Searching this large area just for the chets is not efficient. Need a better way to find the chests;
|
||||
-- probably let's just infer it from newpos because the schematic always the same.
|
||||
local chests = minetest.find_nodes_in_area(p1, p2, "mcl_chests:chest")
|
||||
|
||||
-- Add desert temple loot into chests
|
||||
for c=1, #chests do
|
||||
local lootitems = mcl_loot.get_multi_loot({
|
||||
{
|
||||
stacks_min = 2,
|
||||
stacks_max = 4,
|
||||
items = {
|
||||
{ itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 },
|
||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 },
|
||||
{ itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 },
|
||||
{ itemstring = "mcl_books:book", weight = 20, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_mobitems:saddle", weight = 20, },
|
||||
{ itemstring = "mcl_core:apple_gold", weight = 20, },
|
||||
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
|
||||
{ itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 },
|
||||
{ itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "", weight = 15, },
|
||||
{ itemstring = "mcl_mobitems:iron_horse_armor", weight = 15, },
|
||||
{ itemstring = "mcl_mobitems:gold_horse_armor", weight = 10, },
|
||||
{ itemstring = "mcl_mobitems:diamond_horse_armor", weight = 5, },
|
||||
{ itemstring = "mcl_core:diamond", weight = 5, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },
|
||||
}
|
||||
},
|
||||
{
|
||||
stacks_min = 4,
|
||||
stacks_max = 4,
|
||||
items = {
|
||||
{ itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
}
|
||||
}}, pr)
|
||||
mcl_structures.init_node_construct(chests[c])
|
||||
local meta = minetest.get_meta(chests[c])
|
||||
local inv = meta:get_inventory()
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems, pr)
|
||||
end
|
||||
|
||||
-- Initialize pressure plates and randomly remove up to 5 plates
|
||||
local pplates = minetest.find_nodes_in_area(p1, p2, "mesecons_pressureplates:pressure_plate_stone_off")
|
||||
local pplates_remove = 5
|
||||
@ -101,5 +53,42 @@ mcl_structures.register_structure("desert_temple",{
|
||||
y_min = 1,
|
||||
biomes = { "Desert" },
|
||||
filenames = { modpath.."/schematics/mcl_structures_desert_temple.mts" },
|
||||
after_place = temple_placement_callback
|
||||
after_place = temple_placement_callback,
|
||||
loot = {
|
||||
["mcl_chests:chest_small" ] ={
|
||||
{
|
||||
stacks_min = 2,
|
||||
stacks_max = 4,
|
||||
items = {
|
||||
{ itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 },
|
||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 },
|
||||
{ itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 },
|
||||
{ itemstring = "mcl_books:book", weight = 20, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_mobitems:saddle", weight = 20, },
|
||||
{ itemstring = "mcl_core:apple_gold", weight = 20, },
|
||||
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
|
||||
{ itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 },
|
||||
{ itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "", weight = 15, },
|
||||
{ itemstring = "mcl_mobitems:iron_horse_armor", weight = 15, },
|
||||
{ itemstring = "mcl_mobitems:gold_horse_armor", weight = 10, },
|
||||
{ itemstring = "mcl_mobitems:diamond_horse_armor", weight = 5, },
|
||||
{ itemstring = "mcl_core:diamond", weight = 5, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },
|
||||
}
|
||||
},
|
||||
{
|
||||
stacks_min = 4,
|
||||
stacks_max = 4,
|
||||
items = {
|
||||
{ itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
|
||||
}
|
||||
}}
|
||||
}
|
||||
})
|
||||
|
@ -2,44 +2,6 @@ local modname = minetest.get_current_modname()
|
||||
local S = minetest.get_translator(modname)
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
|
||||
local function temple_placement_callback(pos,def, pr)
|
||||
local hl = def.sidelen / 2
|
||||
local p1 = vector.offset(pos,-hl,-hl,-hl)
|
||||
local p2 = vector.offset(pos,hl,hl,hl)
|
||||
--dont remove foliage - looks kind of nice for a jt
|
||||
local chests = minetest.find_nodes_in_area(p1, p2, "mcl_chests:trapped_chest_small")
|
||||
-- Add jungle temple loot into chests
|
||||
for c=1, #chests do
|
||||
local lootitems = mcl_loot.get_multi_loot({
|
||||
{
|
||||
stacks_min = 2,
|
||||
stacks_max = 6,
|
||||
items = {
|
||||
{ itemstring = "mcl_mobitems:bone", weight = 20, amount_min = 4, amount_max=6 },
|
||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 16, amount_min = 3, amount_max=7 },
|
||||
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
|
||||
--{ itemstring = "mcl_bamboo:bamboo", weight = 15, amount_min = 1, amount_max=3 }, --FIXME BAMBOO
|
||||
{ itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 },
|
||||
{ itemstring = "mcl_core:diamond", weight = 3, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "mcl_mobitems:saddle", weight = 3, },
|
||||
{ itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "mcl_books:book", weight = 1, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_mobitems:iron_horse_armor", weight = 1, },
|
||||
{ itemstring = "mcl_mobitems:gold_horse_armor", weight = 1, },
|
||||
{ itemstring = "mcl_mobitems:diamond_horse_armor", weight = 1, },
|
||||
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },
|
||||
}
|
||||
}}, pr)
|
||||
mcl_structures.init_node_construct(chests[c])
|
||||
local meta = minetest.get_meta(chests[c])
|
||||
local inv = meta:get_inventory()
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems, pr)
|
||||
end
|
||||
-- TODO: initialize traps
|
||||
end
|
||||
|
||||
mcl_structures.register_structure("jungle_temple",{
|
||||
place_on = {"group:grass_block","group:dirt","mcl_core:dirt_with_grass"},
|
||||
noise_params = {
|
||||
@ -64,5 +26,27 @@ mcl_structures.register_structure("jungle_temple",{
|
||||
modpath.."/schematics/mcl_structures_jungle_temple.mts",
|
||||
modpath.."/schematics/mcl_structures_jungle_temple_nice.mts",
|
||||
},
|
||||
after_place = temple_placement_callback
|
||||
loot = {
|
||||
["mcl_chests:chest_small" ] ={{
|
||||
stacks_min = 2,
|
||||
stacks_max = 6,
|
||||
items = {
|
||||
{ itemstring = "mcl_mobitems:bone", weight = 20, amount_min = 4, amount_max=6 },
|
||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 16, amount_min = 3, amount_max=7 },
|
||||
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
|
||||
--{ itemstring = "mcl_bamboo:bamboo", weight = 15, amount_min = 1, amount_max=3 }, --FIXME BAMBOO
|
||||
{ itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 },
|
||||
{ itemstring = "mcl_core:diamond", weight = 3, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "mcl_mobitems:saddle", weight = 3, },
|
||||
{ itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 },
|
||||
{ itemstring = "mcl_books:book", weight = 1, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_mobitems:iron_horse_armor", weight = 1, },
|
||||
{ itemstring = "mcl_mobitems:gold_horse_armor", weight = 1, },
|
||||
{ itemstring = "mcl_mobitems:diamond_horse_armor", weight = 1, },
|
||||
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },
|
||||
}
|
||||
}}
|
||||
}
|
||||
})
|
||||
|
@ -35,43 +35,6 @@ local cold_oceans = {
|
||||
"BirchForestM_deep_ocean",
|
||||
"Taiga_deep_ocean",
|
||||
}
|
||||
local function ruins_placement_callback(pos, def, pr)
|
||||
local hl = def.sidelen / 2
|
||||
local p1 = vector.offset(pos,-hl,-hl,-hl)
|
||||
local p2 = vector.offset(pos,hl,hl,hl)
|
||||
local chests = minetest.find_nodes_in_area(p1, p2, "mcl_chests:chest_small")
|
||||
for c=1, #chests do
|
||||
local lootitems = mcl_loot.get_multi_loot({
|
||||
{
|
||||
stacks_min = 2,
|
||||
stacks_max = 4,
|
||||
items = {
|
||||
{ itemstring = "mcl_core:coal_lump", weight = 25, amount_min = 1, amount_max=4 },
|
||||
{ itemstring = "mcl_farming:wheat_item", weight = 25, amount_min = 2, amount_max=3 },
|
||||
{ itemstring = "mcl_core:gold_nugget", weight = 25, amount_min = 1, amount_max=3 },
|
||||
--{ itemstring = "mcl_maps:treasure_map", weight = 20, }, --FIXME Treasure map
|
||||
|
||||
{ itemstring = "mcl_books:book", weight = 10, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_fishing:fishing_rod_enchanted", weight = 20, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 1 },
|
||||
{ itemstring = "mcl_armor:chestplate_leather", weight = 15, amount_min = 1, amount_max = 1 },
|
||||
{ itemstring = "mcl_core:apple_gold", weight = 20, },
|
||||
{ itemstring = "mcl_armor:helmet_gold", weight = 15, amount_min = 1, amount_max = 1 },
|
||||
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
|
||||
{ itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 },
|
||||
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },
|
||||
}
|
||||
}}, pr)
|
||||
mcl_structures.init_node_construct(chests[c])
|
||||
local meta = minetest.get_meta(chests[c])
|
||||
local inv = meta:get_inventory()
|
||||
mcl_loot.fill_inventory(inv, "main", lootitems, pr)
|
||||
end
|
||||
end
|
||||
|
||||
mcl_structures.register_structure("cold_ocean_ruins",{
|
||||
place_on = {"group:sand","mcl_core:gravel","mcl_core:dirt","mcl_core:clay","group:material_stone"},
|
||||
@ -100,5 +63,32 @@ mcl_structures.register_structure("cold_ocean_ruins",{
|
||||
modpath.."/schematics/mcl_structures_ocean_ruins_cold_2.mts",
|
||||
modpath.."/schematics/mcl_structures_ocean_ruins_cold_3.mts",
|
||||
},
|
||||
after_place = ruins_placement_callback
|
||||
loot = {
|
||||
["mcl_chests:chest_small" ] = {
|
||||
{
|
||||
stacks_min = 2,
|
||||
stacks_max = 4,
|
||||
items = {
|
||||
{ itemstring = "mcl_core:coal_lump", weight = 25, amount_min = 1, amount_max=4 },
|
||||
{ itemstring = "mcl_farming:wheat_item", weight = 25, amount_min = 2, amount_max=3 },
|
||||
{ itemstring = "mcl_core:gold_nugget", weight = 25, amount_min = 1, amount_max=3 },
|
||||
--{ itemstring = "mcl_maps:treasure_map", weight = 20, }, --FIXME Treasure map
|
||||
|
||||
{ itemstring = "mcl_books:book", weight = 10, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_fishing:fishing_rod_enchanted", weight = 20, func = function(stack, pr)
|
||||
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
|
||||
end },
|
||||
{ itemstring = "mcl_core:emerald", weight = 15, amount_min = 1, amount_max = 1 },
|
||||
{ itemstring = "mcl_armor:chestplate_leather", weight = 15, amount_min = 1, amount_max = 1 },
|
||||
{ itemstring = "mcl_core:apple_gold", weight = 20, },
|
||||
{ itemstring = "mcl_armor:helmet_gold", weight = 15, amount_min = 1, amount_max = 1 },
|
||||
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
|
||||
{ itemstring = "mcl_core:iron_ingot", weight = 15, amount_min = 1, amount_max = 5 },
|
||||
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user