Generate locked chests in villages

This commit is contained in:
Wuzzy 2019-09-21 16:36:53 +02:00
parent b38d7373c1
commit 7457a794e3
4 changed files with 77 additions and 35 deletions

View File

@ -9,6 +9,7 @@ goodies.max_stack_default = 6
goodies.max_items = 20
goodies.types = {}
goodies.types_valuable = {}
-- custom types
goodies.types["FURNACE_SRC"] = {
["default:lump_iron"] = 3,
@ -27,20 +28,24 @@ goodies.types["FURNACE_DST"] = {
-- chunk types for villages
if minetest.get_modpath("village") ~= nil then
goodies.types["forge"] = {
["default:ingot_steel"] = 10,
["default:ingot_carbon_steel"] = 12,
["default:lump_coal"] = 4,
["default:lump_iron"] = 6,
["default:pick_stone"] = 9,
["default:tree_oak"] = 2,
}
goodies.types_valuable["forge"] = {
["default:ingot_steel"] = 10,
["default:ingot_carbon_steel"] = 12,
}
goodies.types["tavern"] = {
["bed:bed"] = { chance = 8, max_stack = 1},
["default:bucket"] = 20,
["mobs:meat"] = 5,
["mobs:pork"] = 9,
["default:ladder"] = 9,
}
goodies.types_valuable["tavern"] = {
["mobs:pork"] = 9,
}
goodies.types["house"] = {
["default:stick"] = 2,
["farming:bread"] = 6,
@ -54,22 +59,39 @@ if minetest.get_modpath("village") ~= nil then
-- jewels and gold
if minetest.get_modpath("jewels") ~= nil then
goodies.types["house"]["jewels:bench"] = { chance = 24, max_stack = 1} -- jeweling benches
goodies.types["house"]["jewels:jewel"] = 34
goodies.types["tavern"]["jewels:jewel"] = 32
goodies.types["forge"]["jewels:jewel"] = 30
goodies.types_valuable["house"] = {
["jewels:bench"] = { chance = 24, max_stack = 1},
["jewels:jewel"] = 34,
}
goodies.types_valuable["tavern"] = { ["jewels:jewel"] = 32 }
goodies.types_valuable["forge"] = { ["jewels:jewel"] = 30 }
end
if minetest.get_modpath("gold") ~= nil then
goodies.types["house"]["gold:ingot_gold"] = 12
goodies.types["tavern"]["gold:ingot_gold"] = 10
goodies.types["forge"]["gold:ingot_gold"] = 8
goodies.types_valuable["house"] = { ["gold:ingot_gold"] = 12 }
goodies.types_valuable["tavern"] = { ["gold:ingot_gold"] = 10 }
goodies.types_valuable["forge"] = { ["gold:ingot_gold"] = 8 }
end
end
goodies.types_all = {}
for k,v in pairs(goodies.types) do
goodies.types_all[k] = table.copy(v)
end
for k,v in pairs(goodies.types_valuable) do
if not goodies.types_all[k] then
goodies.types_all[k] = table.copy(v)
else
for q,r in pairs(v) do
goodies.types_all[k][q] = r
end
end
end
function goodies.fill(pos, ctype, pr, listname, keepchance)
-- fill an inventory with a specified type's goodies
if goodies.types[ctype] == nil then return end
if goodies.types_all[ctype] == nil then return end
if pr:next(1, keepchance) ~= 1 then
minetest.remove_node(pos)
@ -83,11 +105,24 @@ function goodies.fill(pos, ctype, pr, listname, keepchance)
if size < 1 then return end
local is_locked = false
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name, "locked") > 0 then
is_locked = true
end
local item_amt = pr:next(1, size)
local types
if is_locked then
types = goodies.types_all
else
types = goodies.types
end
for i = 1, item_amt do
local item = util.choice(goodies.types[ctype], pr)
local goodie = goodies.types[ctype][item]
local item = util.choice(types[ctype], pr)
local goodie = types[ctype][item]
local chance, max_stack
if type(goodie) == "table" then
chance = goodie.chance

View File

@ -119,25 +119,14 @@ function util.reconstruct(pos1, pos2, nomanip)
manip:read_from_map(pos1, pos2)
end
-- fix chests
local nodes = minetest.find_nodes_in_area(pos1, pos2, "default:chest")
local node = minetest.registered_nodes["default:chest"]
for _, pos in ipairs(nodes) do
node.on_construct(pos)
end
-- fix music players
nodes = minetest.find_nodes_in_area(pos1, pos2, "music:player")
node = minetest.registered_nodes["music:player"]
for _, pos in ipairs(nodes) do
node.on_construct(pos)
end
-- fix furnaces
nodes = minetest.find_nodes_in_area(pos1, pos2, "default:furnace")
node = minetest.registered_nodes["default:furnace"]
for _, pos in ipairs(nodes) do
node.on_construct(pos)
-- Fix chests, locked chests, music players, furnaces
local nodetypes = { "default:chest", "locks:chest", "music:player", "default:furnace" }
for n=1, #nodetypes do
local nodes = minetest.find_nodes_in_area(pos1, pos2, nodetypes[n])
local node = minetest.registered_nodes[nodetypes[n]]
for _, pos in ipairs(nodes) do
node.on_construct(pos)
end
end
end

View File

@ -3,3 +3,4 @@ util
mobs
goodies
nav
locks?

View File

@ -10,6 +10,7 @@ village.villages = {}
local village_file = minetest.get_worldpath() .. "/villages.dat"
local modpath = minetest.get_modpath("village")
local mod_locks = minetest.get_modpath("locks") ~= nil
local mapseed = minetest.get_mapgen_setting("seed")
local water_level = tonumber(minetest.get_mapgen_setting("water_level"))
@ -365,15 +366,31 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill, dont_c
true
)
util.reconstruct(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12})
util.fixlight(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12})
-- Replace some chests with locked chests
if mod_locks then
util.nodefunc(
pos,
{x = pos.x+12, y = pos.y+12, z = pos.z+12},
"default:chest",
function(pos)
if math.random(1,4) == 1 then
local node = minetest.get_node(pos)
node.name = "locks:chest"
minetest.swap_node(pos, node)
end
end, true)
end
util.reconstruct(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12})
util.nodefunc(
pos,
{x = pos.x+12, y = pos.y+12, z = pos.z+12},
"default:chest",
{"default:chest", "locks:chest"},
function(pos)
goodies.fill(pos, chunktype, pr, "main", 3)
goodies.fill(pos, chunktype, pr, "main", 3)
end, true)
-- Restrict number of music players