Merge master from https://github.com/ronoaldo/tsm_pyramids into main: fix crashes

* Fix crash caused by lack of luaentity nil check and minetest 5.6
  from commit d4d89c5cc4
* Add refill to chests 30 minutes after opening; and modify the items
  generated by those of nalc_trm (we must change this later)
  from commit 1eb0bc363e
This commit is contained in:
mckaygerhard 2024-03-21 05:31:37 -04:00
commit dfd03b56c6
4 changed files with 74 additions and 21 deletions

View File

@ -67,13 +67,16 @@ end
function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance)
local sand = "default:sand"
local n = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
if not treasure_chance then
treasure_chance = 100
end
if stype == "desert_sandstone" or stype == "desert_stone" then
if meta:get_string("tsm_pyramids:stype") == "desert_sandstone" or
meta:get_string("tsm_pyramids:stype") == "desert_stone" or
stype == "desert_sandstone" or stype == "desert_stone" then
sand = "default:desert_sand"
end
local n = minetest.get_node(pos)
local treasure_added = false
if n and n.name and n.name == "default:chest" then
local meta = minetest.get_meta(pos)
@ -81,13 +84,13 @@ function tsm_pyramids.fill_chest(pos, stype, flood_sand, treasure_chance)
inv:set_size("main", 8*4)
local stacks = {}
-- Fill with sand in sand-flooded pyramids
if flood_sand then
if meta:get_int("tsm_pyramids:sanded") == 1 or flood_sand then
table.insert(stacks, {name=sand, count = math.random(1,32)})
end
-- Add treasures
if math.random(1,100) <= treasure_chance then
if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
stacks = treasurer.select_random_treasures(3,1,5,{"armes", "armures", "precieux", "nourriture"})
else
for i=0,2,1 do
local stuff = chest_stuff.normal[math.random(1,#chest_stuff.normal)]

View File

@ -320,20 +320,23 @@ MUMMY_DEF.on_step = function(self, dtime)
if self.state == 1 then
self.yawwer = true
self.attacker = ""
for _,object in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 4)) do
if object:is_player() then
self.yawwer = false
local NPC = self.object:get_pos()
local PLAYER = object:get_pos()
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if PLAYER.x > NPC.x then
self.yaw = self.yaw + math.pi
end
self.yaw = self.yaw - 2
self.object:set_yaw(self.yaw)
self.attacker = object
end
local pos_obj = self.object:get_pos()
if pos_obj then
for _,object in ipairs(minetest.get_objects_inside_radius(pos_obj, 4)) do
if object:is_player() then
self.yawwer = false
local NPC = self.object:get_pos()
local PLAYER = object:get_pos()
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if PLAYER.x > NPC.x then
self.yaw = self.yaw + math.pi
end
self.yaw = self.yaw - 2
self.object:set_yaw(self.yaw)
self.attacker = object
end
end
end
if self.attacker == "" and self.turn_timer > math.random(1,4) then
@ -342,7 +345,8 @@ MUMMY_DEF.on_step = function(self, dtime)
self.turn_timer = 0
self.direction = {x = math.sin(self.yaw)*-1, y = -20, z = math.cos(self.yaw)}
end
self.object:set_velocity({x=0,y=self.object:get_velocity().y,z=0})
local old_vel = self.object:get_velocity()
self.object:set_velocity({x=0,y=old_vel and old_vel.y or 0,z=0})
if self.npc_anim ~= ANIM_STAND then
self.anim = get_animations()
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, mummy_animation_speed, mummy_animation_blend)
@ -357,7 +361,12 @@ MUMMY_DEF.on_step = function(self, dtime)
if self.state == 2 then
if self.direction ~= nil then
self.object:set_velocity({x=self.direction.x*mummy_chillaxin_speed,y=self.object:get_velocity().y,z=self.direction.z*mummy_chillaxin_speed})
local old_vel = self.object:get_velocity()
self.object:set_velocity({
x=self.direction.x*mummy_chillaxin_speed,
y=old_vel and old_vel.y or 0,
z=self.direction.z*mummy_chillaxin_speed,
})
end
if self.turn_timer > math.random(1,4) and not self.attacker then
self.yaw = 360 * math.random()

View File

@ -97,3 +97,30 @@ register_trap_stone("desert_trap",
"default_desert_sandstone_brick.png",
{ items = { { items = { "default:desert_sand" }, rarity = 1 }, { items = { "default:desert_sand" }, rarity = 2 }, } })
local chest = minetest.registered_nodes["default:chest"]
local def_on_rightclick = chest.on_rightclick
local def_on_timer = chest.on_timer
minetest.override_item(
"default:chest",
{
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if minetest.get_meta(pos):get_string("tsm_pyramids:stype") ~= "" then
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1800) -- remplissages des coffres toutes les 30 minutes
end
end
return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
end,
on_timer = function(pos, elapsed)
if minetest.get_meta(pos):get_string("tsm_pyramids:stype") ~= "" then
minetest.log("action", "[DEBUG] chest refilling")
tsm_pyramids.fill_chest(pos)
return false
else
if def_on_timer then return def_on_timer(pos, elapsed) else return false end
end
end,
})
minetest.register_alias("tsm_pyramids:chest", "default:chest")

View File

@ -960,6 +960,7 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
end
tries = tries + 1
end
local sanded = room.flood_sand ~= false and stype ~= "desert_stone" and math.random(1,8) == 1
local chests = {}
local column_style
if stype == "desert_stone" then
@ -1002,6 +1003,13 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
local nn = replace(n_str, iy, code_table, deco, column_style)
minetest.set_node(cpos, {name=nn, param2=p2})
if nn == "default:chest" then
local meta = minetest.get_meta(cpos)
meta:set_string("tsm_pyramids:stype", stype)
if sanded then
meta:set_int("tsm_pyramids:sanded", 1)
else
meta:set_int("tsm_pyramids:sanded", 0)
end
table.insert(chests, cpos)
end
end
@ -1045,6 +1053,13 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
local nn = code_table[n_str]
minetest.set_node(cpos, {name=nn, param2=p2})
if nn == "default:chest" then
local meta = minetest.get_meta(cpos)
meta:set_string("tsm_pyramids:stype", stype)
if sanded then
meta:set_int("tsm_pyramids:sanded", 1)
else
meta:set_int("tsm_pyramids:sanded", 0)
end
table.insert(chests, cpos)
end
end
@ -1053,7 +1068,6 @@ function tsm_pyramids.make_room(pos, stype, room_id, rotations)
else
minetest.log("error", "Invalid pyramid room style! room type ID="..r)
end
local sanded = room.flood_sand ~= false and stype ~= "desert_stone" and math.random(1,8) == 1
if #chests > 0 then
-- Make at least 8 attempts to fill chests
local filled = 0