chests generate and random colour sheeps

master
juraj 2016-03-17 00:38:48 +01:00
parent 8668259312
commit be4979dba8
5 changed files with 69 additions and 3 deletions

10
API.lua
View File

@ -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)

34
chests_gen.lua Normal file
View File

@ -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)

View File

@ -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.")

View File

@ -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

View File

@ -1,2 +1,3 @@
SPAWN_PYRAMIDS = true
SPAWNERS_GENERATE = true
SPAWNERS_GENERATE = false
CHESTS_GENERATE = false