From 049406162e0050819adab2624718e90df2a693bb Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 24 Mar 2023 23:05:16 +0000 Subject: [PATCH 1/3] Fix crash when skeleton tries to jock when there is no pos, maybe because pos is unloaded. --- mods/ENTITIES/mcl_mobs/api.lua | 5 ++++- mods/ENTITIES/mobs_mc/skeleton+stray.lua | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 50b9ad8ec..39d2f45a9 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -62,8 +62,11 @@ function mob_class:update_tag() --update nametag and/or the debug box end function mob_class:jock_to(mob, reletive_pos, rot) + local pos = self.object:get_pos() + if not pos then return end + self.jockey = mob - local jock = minetest.add_entity(self.object:get_pos(), mob) + local jock = minetest.add_entity(pos, mob) if not jock then return end jock:get_luaentity().docile_by_day = false jock:get_luaentity().riden_by_jock = true diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index 75cfa8bd8..0ee53e8ec 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -91,7 +91,7 @@ local skeleton = { }, on_spawn = function(self) if math.random(100) == 1 then - self:jock_to("mobs_mc:spider", vector.new(0,0,0), vector.new(0,0,0)) + self:jock_to("mobs_mc:spider", vector.zero(), vector.zero()) end return true end, From b72dbf17a60a1dd1ddcdad027c4b764751df1daa Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 24 Mar 2023 23:16:12 +0000 Subject: [PATCH 2/3] Crash for dropper failing as potentially cannot get pos. --- mods/ITEMS/REDSTONE/mcl_droppers/init.lua | 1 + mods/ITEMS/mcl_maps/init.lua | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua index b9c46d6b8..5f8f94d84 100644 --- a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua @@ -99,6 +99,7 @@ local dropperdef = { mesecons = {effector = { -- Drop random item when triggered action_on = function(pos, node) + if not pos then return end local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local droppos diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index 7ed8ab910..d882785c5 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -278,6 +278,10 @@ end local old_add_item = minetest.add_item function minetest.add_item(pos, stack) + if not pos then + minetest.log("warning", "Trying to add item with missing pos: " .. tostring(stack)) + return + end stack = ItemStack(stack) if get_item_group(stack:get_name(), "filled_map") > 0 then stack:set_name("mcl_maps:filled_map") From 6c8113dec890610625dc65884ff077b647f7dc4c Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sat, 25 Mar 2023 00:34:38 +0000 Subject: [PATCH 3/3] Fix crash when cannot get wear for tool --- mods/CORE/_mcl_autogroup/init.lua | 4 ++++ mods/ITEMS/mcl_tools/init.lua | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 4d8ab35b8..c0c5021b5 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -300,6 +300,10 @@ end -- loading order. function mcl_autogroup.get_wear(toolname, diggroup) local tdef = minetest.registered_tools[toolname] + if not tdef then + minetest.log("warning", "Adding wear for tool: " .. tostring(toolname) .. " failed with diggroup: " .. tostring(diggroup)) + return nil + end local uses = tdef._mcl_diggroups[diggroup].uses return math.ceil(65535 / uses) end diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 9f8afdc89..5846f8942 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -183,7 +183,9 @@ local make_grass_path = function(itemstack, placer, pointed_thing) -- Add wear (as if digging a shovely node) local toolname = itemstack:get_name() local wear = mcl_autogroup.get_wear(toolname, "shovely") - itemstack:add_wear(wear) + if wear then + itemstack:add_wear(wear) + end end minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above}, true) minetest.swap_node(pointed_thing.under, {name="mcl_core:grass_path"}) @@ -212,7 +214,10 @@ if minetest.get_modpath("mcl_farming") then -- Add wear (as if digging a shearsy node) local toolname = itemstack:get_name() local wear = mcl_autogroup.get_wear(toolname, "shearsy") - itemstack:add_wear(wear) + if wear then + itemstack:add_wear(wear) + end + end minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = pointed_thing.above}, true) local dir = vector.subtract(pointed_thing.under, pointed_thing.above) @@ -379,7 +384,9 @@ local function make_stripped_trunk(itemstack, placer, pointed_thing) -- Add wear (as if digging a axey node) local toolname = itemstack:get_name() local wear = mcl_autogroup.get_wear(toolname, "axey") - itemstack:add_wear(wear) + if wear then + itemstack:add_wear(wear) + end end end return itemstack