put village goodies into seperate mod

This commit is contained in:
kaadmy 2015-09-02 10:57:24 -07:00
parent 3e9d0e9b65
commit d9906a1433
6 changed files with 97 additions and 87 deletions

7
mods/goodies/README.txt Normal file
View File

@ -0,0 +1,7 @@
Goodies mod
===========
By Kaadmy
Adds goodies so you can auto-fill chests with cool stuff
Source license: WTFPL

85
mods/goodies/init.lua Normal file
View File

@ -0,0 +1,85 @@
--
-- Goodies mod
-- By Kaadmy
--
goodies = {}
goodies.max_stack = 6
goodies.max_items = 20
goodies.types = {}
-- custom types
goodies.types["FURNACE_SRC"] = {
["default:lump_iron"] = 3,
["default:dust_carbonsteel"] = 8,
["farming:flour"] = 5,
}
goodies.types["FURNACE_FUEL"] = {
["default:lump_coal"] = 2,
["default:planks_oak"] = 4,
["default:planks_birch"] = 5,
}
goodies.types["FURNACE_DST"] = {
["default:ingot_steel"] = 5,
["default:ingot_carbonsteel"] = 12,
["farming:bread"] = 8,
}
-- chunk types for villages
if minetest.get_modpath("village") ~= nil then
goodies.types["forge"] = {
["default:ingot_steel"] = 10,
["default:lump_coal"] = 4,
["default:lump_iron"] = 6,
["default:dust_carbonsteel"] = 18,
["default:pick_stone"] = 9,
["default:tree_oak"] = 2,
}
goodies.types["tavern"] = {
["bed:bed"] = 8,
["default:bucket"] = 20,
["mobs:meat"] = 5,
["mobs:pork"] = 9,
["default:ladder"] = 9,
}
goodies.types["house"] = {
["default:stick"] = 2,
["farming:bread"] = 6,
["farming:cotton_1"] = 9,
["farming:wheat_1"] = 6,
["default:axe_stone"] = 13,
["default:apple"] = 3,
["default:bucket"] = 8,
["default:bucket_water"] = 12,
}
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 pr:next(1, keepchance) ~= 1 then
minetest.remove_node(pos)
return
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local size = inv:get_size(listname)
if size < 1 then return end
local item_amt = pr:next(1, size)
for i = 1, item_amt do
local chance = goodies.types[ctype][util.choice(goodies.types[ctype], pr)]
local item = util.choice(goodies.types[ctype], pr)
if pr:next(1, chance) <= 1 then
local itemstr = item.." "..pr:next(1, goodies.max_stack)
inv:set_stack(listname, pr:next(1, size), ItemStack(itemstr))
end
end
end

View File

@ -1,3 +1,4 @@
default
util
mobs
goodies

View File

@ -124,7 +124,7 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
{x = pos.x+12, y = pos.y+16, z = pos.z+12},
"default:chest",
function(pos)
village.goodies.fill(pos, chunktype, pr, "main", 3)
goodies.fill(pos, chunktype, pr, "main", 3)
end)
util.nodefunc(
pos,
@ -181,9 +181,9 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill)
{x = pos.x+12, y = pos.y+16, z = pos.z+12},
"default:furnace",
function(pos)
village.goodies.fill(pos, "FURNACE_SRC", pr, "src", 1)
village.goodies.fill(pos, "FURNACE_DST", pr, "dst", 1)
village.goodies.fill(pos, "FURNACE_FUEL", pr, "fuel", 1)
goodies.fill(pos, "FURNACE_SRC", pr, "src", 1)
goodies.fill(pos, "FURNACE_DST", pr, "dst", 1)
goodies.fill(pos, "FURNACE_FUEL", pr, "fuel", 1)
end)
end
end

View File

@ -1,82 +0,0 @@
--
-- Goodies for filling inventories with!
-- Should work with any node with inventory metadata given the correct parameters
--
village.goodies = {}
village.goodies.max_stack = 8
village.goodies.max_items = 20
village.goodies.types = {}
-- custom types
village.goodies.types["FURNACE_SRC"] = {
["default:lump_iron"] = 3,
["default:dust_carbonsteel"] = 8,
["farming:flour"] = 5,
}
village.goodies.types["FURNACE_FUEL"] = {
["default:lump_coal"] = 2,
["default:planks_oak"] = 4,
["default:planks_birch"] = 5,
}
village.goodies.types["FURNACE_DST"] = {
["default:ingot_steel"] = 5,
["default:ingot_carbonsteel"] = 12,
["farming:bread"] = 8,
}
-- chunk types
village.goodies.types["forge"] = {
["default:ingot_steel"] = 10,
["default:lump_coal"] = 4,
["default:lump_iron"] = 6,
["default:dust_carbonsteel"] = 18,
["default:pick_stone"] = 9,
["default:tree_oak"] = 2,
}
village.goodies.types["tavern"] = {
["bed:bed"] = 8,
["default:bucket"] = 20,
["mobs:meat"] = 5,
["mobs:pork"] = 9,
["default:ladder"] = 9,
}
village.goodies.types["house"] = {
["default:stick"] = 2,
["farming:bread"] = 6,
["farming:cotton_1"] = 9,
["farming:wheat_1"] = 6,
["default:axe_stone"] = 13,
["default:apple"] = 3,
["default:bucket"] = 8,
["default:bucket_water"] = 12,
}
function village.goodies.fill(pos, ctype, pr, listname, keepchance)
-- fill an inventory with a specified type's goodies
if village.goodies.types[ctype] == nil then return end
if pr:next(1, keepchance) ~= 1 then
minetest.remove_node(pos)
return
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local size = inv:get_size(listname)
if size < 1 then return end
local item_amt = pr:next(1, size)
for i = 1, item_amt do
local chance = village.goodies.types[ctype][util.choice(village.goodies.types[ctype], pr)]
local item = util.choice(village.goodies.types[ctype], pr)
if pr:next(1, chance) <= 1 then
local itemstr = item.." "..pr:next(1, village.goodies.max_stack)
inv:set_stack(listname, pr:next(1, size), ItemStack(itemstr))
end
end
end

View File

@ -10,7 +10,6 @@ village.max_size = 6 -- max chunk gen iterations
village.pr = PseudoRandom(minetest.get_mapgen_params().seed)
dofile(minetest.get_modpath("village").."/goodies.lua")
dofile(minetest.get_modpath("village").."/names.lua")
dofile(minetest.get_modpath("village").."/generate.lua")
dofile(minetest.get_modpath("village").."/mapgen.lua")