From 221ee0fcf1da898fffbfaeda1fddb1c22491a3da Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 00:13:03 +0800 Subject: [PATCH 1/9] [5.6] mark places with unsafe set_hp entity handling There might be other places i might be missing, but these are the obvious ones. leftover entity handling i did not mark: * everything that involves a apply()-like algorithm (e.g. callbacks) over the same list of objects. * in mcl_damage, it's not known whether mcl_damage.from_mt() would involve entity handling or just player handling. --- mods/CORE/mcl_explosions/init.lua | 3 ++- mods/ENTITIES/mcl_boats/init.lua | 1 + mods/ENTITIES/mcl_mobs/api.lua | 1 + mods/ENVIRONMENT/lightning/init.lua | 3 +++ mods/ITEMS/mcl_armor/damage.lua | 1 + mods/ITEMS/mcl_bows/arrow.lua | 1 + mods/ITEMS/mcl_bows/rocket.lua | 1 + 7 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index 0132d1669..92453a9d5 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -337,12 +337,13 @@ local function trace_explode(pos, strength, raydirs, radius, info, direct, sourc if not obj:is_player() then return end - + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(obj, damage, {type = "explosion", direct = direct, source = source}) obj:add_velocity(vector.multiply(punch_dir, impact * 20)) end) else + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(obj, damage, {type = "explosion", direct = direct, source = source}) if obj:is_player() or ent.tnt_knockback then diff --git a/mods/ENTITIES/mcl_boats/init.lua b/mods/ENTITIES/mcl_boats/init.lua index 087cd7eae..cd8002b22 100644 --- a/mods/ENTITIES/mcl_boats/init.lua +++ b/mods/ENTITIES/mcl_boats/init.lua @@ -201,6 +201,7 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d end function boat.on_step(self, dtime, moveresult) + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) self._v = get_v(self.object:get_velocity()) * get_sign(self._v) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 8945c6e20..d183d55c7 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3617,6 +3617,7 @@ local mob_step = function(self, dtime) check_item_pickup(self) check_aggro(self,dtime) if not self.fire_resistant then + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) end diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index 14d8f5176..48eefce4e 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -120,6 +120,8 @@ function lightning.strike(pos) if not pos then return false end + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS + -- mcl_util.deal_damage inside one of on_strike_functions local objects = get_objects_inside_radius(pos2, 3.5) if lightning.on_strike_functions then for _, func in pairs(lightning.on_strike_functions) do @@ -174,6 +176,7 @@ lightning.register_on_strike(function(pos, pos2, objects) elseif lua and lua.name == "mobs_mc:creeper" then mcl_util.replace_mob(obj, "mobs_mc:creeper_charged") else + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end end diff --git a/mods/ITEMS/mcl_armor/damage.lua b/mods/ITEMS/mcl_armor/damage.lua index ed616397d..e76f8034b 100644 --- a/mods/ITEMS/mcl_armor/damage.lua +++ b/mods/ITEMS/mcl_armor/damage.lua @@ -89,6 +89,7 @@ mcl_damage.register_modifier(function(obj, damage, reason) local thorns_damage = thorns_damage_regular + thorns_damage_irregular if thorns_damage > 0 and reason.type ~= "thorns" and reason.source ~= obj then + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(reason.source, thorns_damage, {type = "thorns", direct = obj}) local thorns_item = thorns_pieces[math.random(#thorns_pieces)] diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index a03b875cb..10b7f6421 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -114,6 +114,7 @@ local function damage_particles(pos, is_critical) end function ARROW_ENTITY.on_step(self, dtime) + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) self._time_in_air = self._time_in_air + .001 diff --git a/mods/ITEMS/mcl_bows/rocket.lua b/mods/ITEMS/mcl_bows/rocket.lua index d25c52647..e08db5323 100644 --- a/mods/ITEMS/mcl_bows/rocket.lua +++ b/mods/ITEMS/mcl_bows/rocket.lua @@ -312,6 +312,7 @@ local function damage_particles(pos, is_critical) end function ARROW_ENTITY.on_step(self, dtime) + -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) self._time_in_air = self._time_in_air + .001 From bce4d29737c46d5ef37a217a0ddf271e0edd1e95 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 10:44:13 +0800 Subject: [PATCH 2/9] [5.6][lightning] fix unsafe entitiy handling this does not excuse all on_strike callbacks to allow oversights. it must also track entity removal. --- mods/ENVIRONMENT/lightning/init.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index 48eefce4e..bd8bc265b 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -120,11 +120,10 @@ function lightning.strike(pos) if not pos then return false end - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS - -- mcl_util.deal_damage inside one of on_strike_functions - local objects = get_objects_inside_radius(pos2, 3.5) if lightning.on_strike_functions then for _, func in pairs(lightning.on_strike_functions) do + -- allow on_strike callbacks to destroy entities by re-obtaining objects for each callback + local objects = get_objects_inside_radius(pos2, 3.5) func(pos, pos2, objects) end end @@ -176,7 +175,7 @@ lightning.register_on_strike(function(pos, pos2, objects) elseif lua and lua.name == "mobs_mc:creeper" then mcl_util.replace_mob(obj, "mobs_mc:creeper_charged") else - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS + -- WARNING: unsafe entity handling. object may be removed immediately mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end end From 4b316923194506b4e897029900a259463f5cf0fa Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 12:09:12 +0800 Subject: [PATCH 3/9] [5.6][boats] fix unsafe entity handling this probably does not affect normal gameplay, unless you can set boats on fire somehow --- mods/ENTITIES/mcl_boats/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_boats/init.lua b/mods/ENTITIES/mcl_boats/init.lua index cd8002b22..9775b8597 100644 --- a/mods/ENTITIES/mcl_boats/init.lua +++ b/mods/ENTITIES/mcl_boats/init.lua @@ -201,8 +201,9 @@ function boat.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d end function boat.on_step(self, dtime, moveresult) - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) + -- mcl_burning.tick may remove object immediately + if not self.object:get_pos() then return end self._v = get_v(self.object:get_velocity()) * get_sign(self._v) local v_factor = 1 From bf80074d98d5399663ffa1034c301f0adf36f583 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 12:36:53 +0800 Subject: [PATCH 4/9] [5.6][mobs] fix unsafe entity handling (unsure) i'm not sure about this one, can't find a suitable test for it. --- mods/ENTITIES/mcl_mobs/api.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index d183d55c7..8cbe9b8ca 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3617,8 +3617,9 @@ local mob_step = function(self, dtime) check_item_pickup(self) check_aggro(self,dtime) if not self.fire_resistant then - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) + -- mcl_burning.tick may remove object immediately + if not self.object:get_pos() then return end end local pos = self.object:get_pos() From 4f2789c498e35067633a5f12e41dcaef303615f8 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 12:43:24 +0800 Subject: [PATCH 5/9] [5.6][armor] fix unsafe entity handling (unsure) i'm not sure about this one, can't fnd a suitable test for it. --- mods/ITEMS/mcl_armor/damage.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_armor/damage.lua b/mods/ITEMS/mcl_armor/damage.lua index e76f8034b..012c32307 100644 --- a/mods/ITEMS/mcl_armor/damage.lua +++ b/mods/ITEMS/mcl_armor/damage.lua @@ -89,8 +89,9 @@ mcl_damage.register_modifier(function(obj, damage, reason) local thorns_damage = thorns_damage_regular + thorns_damage_irregular if thorns_damage > 0 and reason.type ~= "thorns" and reason.source ~= obj then - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(reason.source, thorns_damage, {type = "thorns", direct = obj}) + -- mcl_util.deal_damage may remove object immediately + if not reason.source:get_pos() then return end local thorns_item = thorns_pieces[math.random(#thorns_pieces)] From 156aff21a1aa4ade6ec2164f3a2b1e88c7f86377 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 12:48:09 +0800 Subject: [PATCH 6/9] [5.6][bows] fix unsafe entity handling for arrows --- mods/ITEMS/mcl_bows/arrow.lua | 3 ++- mods/ITEMS/mcl_bows/rocket.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 10b7f6421..ad4a3f30e 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -114,8 +114,9 @@ local function damage_particles(pos, is_critical) end function ARROW_ENTITY.on_step(self, dtime) - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) + -- mcl_burning.tick may remove object immediately + if not self.object:get_pos() then return end self._time_in_air = self._time_in_air + .001 diff --git a/mods/ITEMS/mcl_bows/rocket.lua b/mods/ITEMS/mcl_bows/rocket.lua index e08db5323..e846937d0 100644 --- a/mods/ITEMS/mcl_bows/rocket.lua +++ b/mods/ITEMS/mcl_bows/rocket.lua @@ -312,8 +312,9 @@ local function damage_particles(pos, is_critical) end function ARROW_ENTITY.on_step(self, dtime) - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_burning.tick(self.object, dtime, self) + -- mcl_burning.tick may remove object immediately + if not self.object:get_pos() then return end self._time_in_air = self._time_in_air + .001 From 0e999d8bb9d0c8f12f4761739b67f9ddd0df7223 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Sun, 7 Aug 2022 13:00:43 +0800 Subject: [PATCH 7/9] [5.6] remove incorrect marks. wrong, bad. these are fine. --- mods/CORE/mcl_explosions/init.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index 92453a9d5..cb9af5c79 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -337,13 +337,11 @@ local function trace_explode(pos, strength, raydirs, radius, info, direct, sourc if not obj:is_player() then return end - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(obj, damage, {type = "explosion", direct = direct, source = source}) obj:add_velocity(vector.multiply(punch_dir, impact * 20)) end) else - -- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS mcl_util.deal_damage(obj, damage, {type = "explosion", direct = direct, source = source}) if obj:is_player() or ent.tnt_knockback then From f6148068c54b0b51343f55b728b79abe0ba83b81 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 7 Aug 2022 19:55:01 +1000 Subject: [PATCH 8/9] snow layers and blocks drop nothing by hand --- mods/ITEMS/mcl_core/nodes_base.lua | 4 ++-- mods/ITEMS/mcl_tools/init.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 773aa92a9..2f464a2fc 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -1053,7 +1053,7 @@ for i=1,8 do mcl_core.clear_snow_dirt(npos, node) end, node_box = node_box, - groups = {shovely=1, attached_node=1,deco_block=1, dig_by_piston=1, snow_cover=1, top_snow=i}, + groups = {shovely=2, attached_node=1,deco_block=1, dig_by_piston=1, snow_cover=1, top_snow=i}, sounds = mcl_sounds.node_sound_snow_defaults(), on_construct = mcl_core.on_snow_construct, on_place = on_place, @@ -1072,7 +1072,7 @@ minetest.register_node("mcl_core:snowblock", { tiles = {"default_snow.png"}, is_ground_content = true, stack_max = 64, - groups = {shovely=1, building_block=1, snow_cover=1}, + groups = {shovely=2, building_block=1, snow_cover=1}, sounds = mcl_sounds.node_sound_snow_defaults(), on_construct = mcl_core.on_snow_construct, after_destruct = mcl_core.after_snow_destruct, diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 6111d7b91..118020f0b 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -288,7 +288,7 @@ minetest.register_tool("mcl_tools:shovel_wood", { _repair_material = "group:wood", _mcl_toollike_wield = true, _mcl_diggroups = { - shovely = { speed = 2, level = 1, uses = 60 } + shovely = { speed = 2, level = 2, uses = 60 } }, }) minetest.register_tool("mcl_tools:shovel_stone", { From a34c9172c4f9ee3234e4de8d36e22a3e37ac878c Mon Sep 17 00:00:00 2001 From: PrairieAstronomer Date: Sat, 6 Aug 2022 20:38:15 -0600 Subject: [PATCH 9/9] Fixed light levelwarnings and texture alpha warnings in stonecutter, campfires, and beacon --- mods/ITEMS/mcl_beacons/init.lua | 5 +++-- mods/ITEMS/mcl_campfires/init.lua | 4 +++- mods/ITEMS/mcl_stonecutter/init.lua | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_beacons/init.lua b/mods/ITEMS/mcl_beacons/init.lua index 08586bcef..c484c949d 100644 --- a/mods/ITEMS/mcl_beacons/init.lua +++ b/mods/ITEMS/mcl_beacons/init.lua @@ -98,7 +98,7 @@ minetest.register_node("mcl_beacons:beacon_beam", { } }, pointable= false, - light_source = 15, + light_source = 14, walkable = false, groups = {not_in_creative_inventory=1}, _mcl_blast_resistance = 1200, @@ -226,6 +226,7 @@ minetest.register_node("mcl_beacons:beacon", { collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, mesh = "mcl_beacon.b3d", tiles = {"beacon_UV.png"}, + use_texture_alpha = "clip", on_construct = function(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() @@ -333,7 +334,7 @@ minetest.register_node("mcl_beacons:beacon", { end end end, - light_source = 15, + light_source = 14, groups = {handy=1}, drop = "mcl_beacons:beacon", sounds = mcl_sounds.node_sound_glass_defaults(), diff --git a/mods/ITEMS/mcl_campfires/init.lua b/mods/ITEMS/mcl_campfires/init.lua index e51ec9f54..195612533 100644 --- a/mods/ITEMS/mcl_campfires/init.lua +++ b/mods/ITEMS/mcl_campfires/init.lua @@ -11,7 +11,7 @@ local S = minetest.get_translator(minetest.get_current_modname()) local campfires = { - { name = "Campfire", lightlevel = 15, techname = "campfire", damage = 1, drops = "mcl_core:charcoal_lump 2" }, + { name = "Campfire", lightlevel = 14, techname = "campfire", damage = 1, drops = "mcl_core:charcoal_lump 2" }, { name = "Soul Campfire", lightlevel = 10, techname = "soul_campfire", damage = 2, drops = "mcl_blackstone:soul_soil" }, } @@ -25,6 +25,7 @@ for _, campfire in pairs(campfires) do drawtype = "mesh", mesh = "mcl_campfires_campfire.obj", tiles = {{name="mcl_campfires_log.png"},}, + use_texture_alpha = "clip", groups = { handy=1, axey=1, material_wood=1, not_in_creative_inventory=1, campfire=1, }, paramtype = "light", paramtype2 = "facedir", @@ -73,6 +74,7 @@ for _, campfire in pairs(campfires) do length=2.0 }} }, + use_texture_alpha = "clip", groups = { handy=1, axey=1, material_wood=1, campfire=1, lit_campfire=1 }, paramtype = "light", paramtype2 = "facedir", diff --git a/mods/ITEMS/mcl_stonecutter/init.lua b/mods/ITEMS/mcl_stonecutter/init.lua index 145bc7703..e75884990 100644 --- a/mods/ITEMS/mcl_stonecutter/init.lua +++ b/mods/ITEMS/mcl_stonecutter/init.lua @@ -31,6 +31,7 @@ minetest.register_node("mcl_stonecutter:stonecutter", { length=1 }} }, + use_texture_alpha = "clip", drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir",