From 76bd636df2587d36eb4e7ab7f4e35f627a3c84f0 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 24 Aug 2019 18:58:20 +0200 Subject: [PATCH] Drop a minetest.after --- init.lua | 57 ++++++++++++++++++++++++++----------------------------- mummy.lua | 2 +- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/init.lua b/init.lua index a5e6ed0..52df87a 100644 --- a/init.lua +++ b/init.lua @@ -40,40 +40,37 @@ else end function tsm_pyramids.fill_chest(pos, stype, flood_sand) - minetest.after(2, function() - local sand = "default:sand" - if stype == "desert_sandstone" or stype == "desert_stone" then - sand = "default:desert_sand" + local sand = "default:sand" + if stype == "desert_sandstone" or stype == "desert_stone" then + sand = "default:desert_sand" + end + 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) + local stacks = {} + -- Fill with sand in sand-flooded pyramids + if flood_sand then + table.insert(stacks, {name=sand, count = math.random(1,32)}) end - 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) - local stacks = {} - -- Fill with sand in sand-flooded pyramids - if flood_sand then - table.insert(stacks, {name=sand, count = math.random(1,32)}) - end - -- Add treasures - if math.random(1,10) >= 7 then - if minetest.get_modpath("treasurer") ~= nil then - stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"}) - else - for i=0,2,1 do - local stuff = chest_stuff[math.random(1,#chest_stuff)] - table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) - end + -- Add treasures + if math.random(1,10) >= 7 then + if minetest.get_modpath("treasurer") ~= nil then + stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"}) + else + for i=0,2,1 do + local stuff = chest_stuff[math.random(1,#chest_stuff)] + table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)}) end end - for s=1,#stacks do - if not inv:contains_item("main", stacks[s]) then - inv:set_stack("main", math.random(1,32), stacks[s]) - end - end - end - end) + for s=1,#stacks do + if not inv:contains_item("main", stacks[s]) then + inv:set_stack("main", math.random(1,32), stacks[s]) + end + end + end end local function add_spawner(pos, mummy_offset) diff --git a/mummy.lua b/mummy.lua index 50516ff..92e61b3 100644 --- a/mummy.lua +++ b/mummy.lua @@ -54,7 +54,7 @@ local function hit(self) self.object:set_properties(prop) minetest.after(0.4, function(self) local prop = {textures = mummy_texture,} - if self.object ~= nil then + if self ~= nil and self.object ~= nil then self.object:set_properties(prop) end end, self)