From be4979dba8d167f210a1443d012542eb0b925621 Mon Sep 17 00:00:00 2001 From: juraj Date: Thu, 17 Mar 2016 00:38:48 +0100 Subject: [PATCH] chests generate and random colour sheeps --- API.lua | 10 ++++++++++ chests_gen.lua | 34 ++++++++++++++++++++++++++++++++++ init.lua | 9 ++++++++- pyramids.lua | 16 +++++++++++++++- settings.txt | 3 ++- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 chests_gen.lua diff --git a/API.lua b/API.lua index 96df7e6..cad871d 100644 --- a/API.lua +++ b/API.lua @@ -55,6 +55,16 @@ function spawners.start_spawning(pos, how_many, mob_name, mod_prefix, sound_cust sound_name = mod_prefix.."_"..mob_name end + -- use random colours for sheeps + if mob_name == "sheep_white" then + local mob_name1 = "" + local sheep_colours = {"black", "blue", "brown", "cyan", "dark_green", "dark_grey", "green", "grey", "magenta", "orange", "pink", "red", "violet", "white", "yellow"} + local random_colour = math.random(1, #sheep_colours) + mob_name1 = string.split(mob_name, "_") + mob_name1 = mob_name1[1] + mob_name = mob_name1.."_"..sheep_colours[random_colour] + end + for i=1,how_many do local obj = minetest.add_entity(pos, mod_prefix..":"..mob_name) diff --git a/chests_gen.lua b/chests_gen.lua new file mode 100644 index 0000000..fff5d72 --- /dev/null +++ b/chests_gen.lua @@ -0,0 +1,34 @@ +-- Place chests in dungeons and temples +local function place_chest(param) + local tab = param + + local pos = tab[math.random(1, (#tab or 4))] + pos.y = pos.y - 1 + + local n = minetest.get_node_or_nil(pos) + + if n and n.name ~= "air" then + pos.y = pos.y + 1 + + minetest.log("action", "[Mod][Spawners] Chest placed at: "..minetest.pos_to_string(pos)) + + minetest.set_node(pos, {name = "default:chest"}) + + pyramids.fill_chest(pos) + end +end + +minetest.set_gen_notify("dungeon") +minetest.set_gen_notify("temple") + +minetest.register_on_generated(function(minp, maxp, blockseed) + local ntf = minetest.get_mapgen_object("gennotify") + + if ntf and ntf.dungeon then + minetest.after(3, place_chest, table.copy(ntf.dungeon)) + end + + if ntf and ntf.temple then + minetest.after(3, place_chest, table.copy(ntf.temple)) + end +end) \ No newline at end of file diff --git a/init.lua b/init.lua index f704c70..12a768a 100644 --- a/init.lua +++ b/init.lua @@ -29,7 +29,14 @@ end if SPAWNERS_GENERATE then dofile(minetest.get_modpath("spawners").."/spawners_gen.lua") - print("[Mod][spawners] Environmental enabled") + print("[Mod][spawners] Spawners generate enabled") +end + +-- Add Chests to dungeons, temples.. +if CHESTS_GENERATE then + dofile(minetest.get_modpath("spawners").."/chests_gen.lua") + + print("[Mod][spawners] Chests generate enabled") end print ("[Mod] Spawners 0.6 Loaded.") \ No newline at end of file diff --git a/pyramids.lua b/pyramids.lua index de8eae5..277d875 100644 --- a/pyramids.lua +++ b/pyramids.lua @@ -39,20 +39,34 @@ local chest_stuff = { {name="default:axe_steel", max = 1}, {name="default:axe_stone", max = 1}, {name="default:axe_wood", max = 1}, + {name="diamonds:diamond_apple", max = 1}, } function pyramids.fill_chest(pos) minetest.after(2, function() local n = minetest.get_node(pos) + if n and n.name and n.name == "default:chest" then local meta = minetest.get_meta(pos) local inv = meta:get_inventory() + inv:set_size("main", 8*4) + if math.random(1,10) < 5 then return end + for i=0,2,1 do local stuff = chest_stuff[math.random(1,#chest_stuff)] - if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then stuff = chest_stuff[1] end + + if stuff.name == "farming:bread" and not minetest.get_modpath("farming") then + stuff = chest_stuff[1] + end + + if stuff.name == "diamonds:diamond_apple" and not minetest.get_modpath("diamonds") then + stuff = chest_stuff[1] + end + local stack = {name=stuff.name, count = math.random(1,stuff.max)} + if not inv:contains_item("main", stack) then inv:set_stack("main", math.random(1,32), stack) end diff --git a/settings.txt b/settings.txt index eca1ff2..fc019d3 100644 --- a/settings.txt +++ b/settings.txt @@ -1,2 +1,3 @@ SPAWN_PYRAMIDS = true -SPAWNERS_GENERATE = true +SPAWNERS_GENERATE = false +CHESTS_GENERATE = false