Add support for get_treasures
parent
4c20c6227a
commit
0eb23cd4a6
|
@ -145,3 +145,11 @@ function tsm_railcorridors.get_default_treasure(pr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Alternative treasure fallback function. This function is called
|
||||||
|
-- to return ALL treasures of a single chest at all. It must return
|
||||||
|
-- a table of items. If this function is defined, get_default_treasure
|
||||||
|
-- is ignored.
|
||||||
|
-- Syntax:
|
||||||
|
-- tsm_railcorridors.get_treasures = function(pr)
|
||||||
|
-- Not used by default.
|
||||||
|
tsm_railcorridors.get_treasures = nil
|
||||||
|
|
19
init.lua
19
init.lua
|
@ -3,6 +3,8 @@ tsm_railcorridors = {}
|
||||||
-- Load node names
|
-- Load node names
|
||||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/gameconfig.lua")
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/gameconfig.lua")
|
||||||
|
|
||||||
|
local treasurer_supported = minetest.get_modpath("treasurer") ~= nil
|
||||||
|
|
||||||
-- Settings
|
-- Settings
|
||||||
local setting
|
local setting
|
||||||
|
|
||||||
|
@ -374,10 +376,8 @@ local function Platform(p, radius, node, node2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function RandomChestItem()
|
||||||
-- Random chest items
|
if treasurer_supported then
|
||||||
local function rci()
|
|
||||||
if(minetest.get_modpath("treasurer") ~= nil) then
|
|
||||||
local treasures
|
local treasures
|
||||||
if pr_treasures:next(0,100) < 3 then
|
if pr_treasures:next(0,100) < 3 then
|
||||||
treasures = treasurer.select_random_treasures(1,2,4)
|
treasures = treasurer.select_random_treasures(1,2,4)
|
||||||
|
@ -418,8 +418,15 @@ local function PlaceChest(pos, param2)
|
||||||
if SetNodeIfCanBuild(pos, {name=tsm_railcorridors.nodes.chest, param2=param2}) then
|
if SetNodeIfCanBuild(pos, {name=tsm_railcorridors.nodes.chest, param2=param2}) then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
for i=1, inv:get_size("main") do
|
if not treasurer_supported and tsm_railcorridors.get_treasures then
|
||||||
inv:set_stack("main", i, ItemStack(rci()))
|
local items = tsm_railcorridors.get_treasures(pr)
|
||||||
|
for i=1, math.min(#items, inv:get_size("main")) do
|
||||||
|
inv:set_stack("main", i, ItemStack(items[i]))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i=1, inv:get_size("main") do
|
||||||
|
inv:set_stack("main", i, ItemStack(RandomChestItem()))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue