From d9906a1433fea258f3637dd718d9b3fb9fb8a7cd Mon Sep 17 00:00:00 2001 From: kaadmy Date: Wed, 2 Sep 2015 10:57:24 -0700 Subject: [PATCH] put village goodies into seperate mod --- mods/goodies/README.txt | 7 ++++ mods/goodies/init.lua | 85 +++++++++++++++++++++++++++++++++++++++ mods/village/depends.txt | 1 + mods/village/generate.lua | 8 ++-- mods/village/goodies.lua | 82 ------------------------------------- mods/village/init.lua | 1 - 6 files changed, 97 insertions(+), 87 deletions(-) create mode 100644 mods/goodies/README.txt create mode 100644 mods/goodies/init.lua delete mode 100644 mods/village/goodies.lua diff --git a/mods/goodies/README.txt b/mods/goodies/README.txt new file mode 100644 index 0000000..0923ca3 --- /dev/null +++ b/mods/goodies/README.txt @@ -0,0 +1,7 @@ +Goodies mod +=========== +By Kaadmy + +Adds goodies so you can auto-fill chests with cool stuff + +Source license: WTFPL diff --git a/mods/goodies/init.lua b/mods/goodies/init.lua new file mode 100644 index 0000000..dca1721 --- /dev/null +++ b/mods/goodies/init.lua @@ -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 diff --git a/mods/village/depends.txt b/mods/village/depends.txt index 2652f55..82e2adc 100644 --- a/mods/village/depends.txt +++ b/mods/village/depends.txt @@ -1,3 +1,4 @@ default util mobs +goodies diff --git a/mods/village/generate.lua b/mods/village/generate.lua index d9b9f3f..5a12df9 100644 --- a/mods/village/generate.lua +++ b/mods/village/generate.lua @@ -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 diff --git a/mods/village/goodies.lua b/mods/village/goodies.lua deleted file mode 100644 index c492cbf..0000000 --- a/mods/village/goodies.lua +++ /dev/null @@ -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 diff --git a/mods/village/init.lua b/mods/village/init.lua index 5455dfe..5989832 100644 --- a/mods/village/init.lua +++ b/mods/village/init.lua @@ -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")