From 70d05a6720911b2f980cc56373f7bd6aa742dbeb Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 3 Jan 2025 16:02:12 -0600 Subject: [PATCH 1/6] Fix bobber colliding with doors,trapdoors, rework vl_projectile collides_with handling to affect all entities physical or not --- mods/ITEMS/mcl_fishing/init.lua | 5 +++-- mods/ITEMS/vl_projectile/init.lua | 36 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 7c95d3c9c..86a48e4b3 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -313,11 +313,12 @@ bobber_ENTITY.on_step = bobber_on_step core.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY) vl_projectile.register("mcl_fishing:flying_bobber_entity", { - physical = false, + physical = true, + collide_with_objects = false, timer=0, textures = {"mcl_fishing_bobber.png"}, --FIXME: Replace with correct texture. visual_size = {x=0.5, y=0.5}, - collisionbox = {0,0,0,0,0,0}, + collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1}, pointable = false, get_staticdata = mcl_throwing.get_staticdata, diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index df57b3777..ca824e1a8 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -359,24 +359,24 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def) local node_def = core.registered_nodes[node.name] local collides_with = projectile_def.collides_with - if entity_def.physical then - -- Projectile has stopped in one axis, so it probably hit something. - -- This detection is a bit clunky, but sadly, MT does not offer a direct collision detection for us. :-( - local vel = self.object:get_velocity() - if not self._last_velocity then - self._last_velocity = vel - return - end + if not collides_with or not mcl_util.match_node_to_filter(node.name, collides_with) then + if entity_def.physical then + -- Projectile has stopped in one axis, so it probably hit something. + -- This detection is a bit clunky, but sadly, MT does not offer a direct collision detection for us. :-( + local vel = self.object:get_velocity() + if not self._last_velocity then + self._last_velocity = vel + return + end - local delta_v = (vel - self._last_velocity) - local vel_length = vector.length(vel) - if vel_length > 1 then delta_v = delta_v / vel_length end - self._last_velocity = vel - if math.abs(delta_v.x) <= 0.1 and math.abs(delta_v.z) <= 0.1 and math.abs(delta_v.y) <= 0.2 then - return - end - else - if node_def and not node_def.walkable and (not collides_with or not mcl_util.match_node_to_filter(node.name, collides_with)) then + local delta_v = (vel - self._last_velocity) + local vel_length = vector.length(vel) + if vel_length > 1 then delta_v = delta_v / vel_length end + self._last_velocity = vel + if math.abs(delta_v.x) <= 0.1 and math.abs(delta_v.z) <= 0.1 and math.abs(delta_v.y) <= 0.2 then + return + end + elseif node_def and not node_def.walkable then return end end @@ -430,7 +430,7 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def) if hook then hook(self, self._stuckin, snode, sdef) end end - -- Call entity collied hook + -- Call entity collided hook local hook = projectile_def.on_collide_with_solid if hook then hook(self, pos, node, node_def) end From bd31808beda5f939bd1112da7665762197098f97 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 3 Jan 2025 16:17:39 -0600 Subject: [PATCH 2/6] Fix ender pearl crash --- mods/ITEMS/mcl_throwing/ender_pearl.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_throwing/ender_pearl.lua b/mods/ITEMS/mcl_throwing/ender_pearl.lua index f270774c3..d6f542ade 100644 --- a/mods/ITEMS/mcl_throwing/ender_pearl.lua +++ b/mods/ITEMS/mcl_throwing/ender_pearl.lua @@ -31,7 +31,7 @@ function on_collide(self, pos, node) end -- Make sure we have a reference to the player - local player = self._thrower and core.get_player_by_name(self._thrower) + local player = self._owner and core.get_player_by_name(self._owner) if not player then return end -- Teleport and hurt player @@ -113,7 +113,6 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{ on_step = vl_projectile.update_projectile, _lastpos={}, - _thrower = nil, -- Player ObjectRef of the player who threw the ender pearl _vl_projectile = { behaviors = { vl_projectile.collides_with_solids, From 6824ce0428c29e072ebe8fde03b1c832f0e10b7f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 4 Jan 2025 12:38:45 -0600 Subject: [PATCH 3/6] Give snowballs, eggs and ender pearls a collision box --- mods/ITEMS/mcl_throwing/egg.lua | 4 ++-- mods/ITEMS/mcl_throwing/ender_pearl.lua | 4 ++-- mods/ITEMS/mcl_throwing/snowball.lua | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_throwing/egg.lua b/mods/ITEMS/mcl_throwing/egg.lua index 344314b6c..6720d6125 100644 --- a/mods/ITEMS/mcl_throwing/egg.lua +++ b/mods/ITEMS/mcl_throwing/egg.lua @@ -32,11 +32,11 @@ local function egg_spawn_chicks(pos) end vl_projectile.register("mcl_throwing:egg_entity",{ - physical = false, + physical = true, timer=0, textures = {"mcl_throwing_egg.png"}, visual_size = {x=0.45, y=0.45}, - collisionbox = {0,0,0,0,0,0}, + collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1}, pointable = false, get_staticdata = mcl_throwing.get_staticdata, diff --git a/mods/ITEMS/mcl_throwing/ender_pearl.lua b/mods/ITEMS/mcl_throwing/ender_pearl.lua index d6f542ade..f20b29df5 100644 --- a/mods/ITEMS/mcl_throwing/ender_pearl.lua +++ b/mods/ITEMS/mcl_throwing/ender_pearl.lua @@ -101,11 +101,11 @@ end -- Ender pearl entity vl_projectile.register("mcl_throwing:ender_pearl_entity",{ - physical = false, + physical = true, timer=0, textures = {"mcl_throwing_ender_pearl.png"}, visual_size = {x=0.9, y=0.9}, - collisionbox = {0,0,0,0,0,0}, + collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1}, pointable = false, get_staticdata = mcl_throwing.get_staticdata, diff --git a/mods/ITEMS/mcl_throwing/snowball.lua b/mods/ITEMS/mcl_throwing/snowball.lua index 6d3fca3ce..37d220dfc 100644 --- a/mods/ITEMS/mcl_throwing/snowball.lua +++ b/mods/ITEMS/mcl_throwing/snowball.lua @@ -40,11 +40,11 @@ local function snowball_particles(pos, vel) }) end vl_projectile.register("mcl_throwing:snowball_entity", { - physical = false, + physical = true, timer=0, textures = {"mcl_throwing_snowball.png"}, visual_size = {x=0.5, y=0.5}, - collisionbox = {0,0,0,0,0,0}, + collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1}, pointable = false, get_staticdata = mcl_throwing.get_staticdata, From 98f115eb3150a03a31a1f1e94ec7d97aedd4c693 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 5 Jan 2025 07:17:29 -0600 Subject: [PATCH 4/6] Update flying bobber detection to work with Projectile API changes --- mods/ITEMS/mcl_fishing/init.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 86a48e4b3..8b632d7a3 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -173,15 +173,12 @@ local fish = function(itemstack, player, pointed_thing) end end --Check for flying bobber. + local player_name = player:get_player_name() for n = 1, #objs do ent = objs[n]:get_luaentity() - if ent then - if ent._thrower and ent.objtype=="fishing" then - if player:get_player_name() == ent._thrower then - noent = false - break - end - end + if ent and ent._owner == player_name and ent.objtype=="fishing" then + noent = false + break end end --If no bobber or flying_bobber exists then throw bobber. @@ -349,7 +346,6 @@ vl_projectile.register("mcl_fishing:flying_bobber_entity", { }, _lastpos={}, - _thrower = nil, objtype="fishing", }) @@ -365,7 +361,7 @@ minetest.register_on_leaveplayer(function(player) if ent then if ent.player and ent.objtype=="fishing" then ent.object:remove() - elseif ent._thrower and ent.objtype=="fishing" then + elseif ent._owner and ent.objtype=="fishing" then ent.object:remove() end end @@ -384,7 +380,7 @@ minetest.register_on_dieplayer(function(player) if ent then if ent.player and ent.objtype=="fishing" then ent.object:remove() - elseif ent._thrower and ent.objtype=="fishing" then + elseif ent._owner and ent.objtype=="fishing" then ent.object:remove() end end From 9df4a579455c614f22a20c1fafff2273275a6e05 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 5 Jan 2025 07:26:08 -0600 Subject: [PATCH 5/6] Remove unused locals, resolve all but one luacheck finding (incorrect finding of value not used) --- mods/ITEMS/mcl_fishing/init.lua | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 8b632d7a3..fa693f02e 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -35,8 +35,7 @@ local fish = function(itemstack, player, pointed_thing) local pos = player:get_pos() local objs = minetest.get_objects_inside_radius(pos, 125) - local num = 0 - local ent = nil + local ent local noent = true local durability = FISHING_ROD_DURABILITY @@ -53,9 +52,7 @@ local fish = function(itemstack, player, pointed_thing) if (player:get_player_name() == ent.player) then noent = false if ent._dive == true then - local itemname local items - local itemcount = 1 local pr = PseudoRandom(os.time() * math.random(1, 100)) local r = pr:next(1, 100) local fish_values = {85, 84.8, 84.7, 84.5} @@ -354,10 +351,8 @@ mcl_throwing.register_throwable_object("mcl_fishing:flying_bobber", "mcl_fishing -- If player leaves area, remove bobber. minetest.register_on_leaveplayer(function(player) local objs = minetest.get_objects_inside_radius(player:get_pos(), 250) - local ent = nil - local noent = true for n = 1, #objs do - ent = objs[n]:get_luaentity() + local ent = objs[n]:get_luaentity() if ent then if ent.player and ent.objtype=="fishing" then ent.object:remove() @@ -371,12 +366,9 @@ end) -- If player dies, remove bobber. minetest.register_on_dieplayer(function(player) local objs = minetest.get_objects_inside_radius(player:get_pos(), 250) - local num = 0 - local ent = nil - local noent = true for n = 1, #objs do - ent = objs[n]:get_luaentity() + local ent = objs[n]:get_luaentity() if ent then if ent.player and ent.objtype=="fishing" then ent.object:remove() @@ -515,10 +507,8 @@ minetest.register_craftitem("mcl_fishing:pufferfish_raw", { minetest.register_on_item_eat(function (hp_change, replace_with_item, itemstack, user, pointed_thing) - if itemstack:get_name() == "mcl_fishing:pufferfish_raw" then mcl_potions.give_effect_by_level("poison", user, 3, 60) mcl_potions.give_effect_by_level("nausea", user, 2, 20) end - end ) From 5009d403c12fdaf5d55de27baca050834b7f7862 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 5 Jan 2025 09:34:05 -0600 Subject: [PATCH 6/6] Ensure the bobber remains after it collides with something solid --- mods/ITEMS/mcl_fishing/init.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index fa693f02e..897a3ace7 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -175,6 +175,7 @@ local fish = function(itemstack, player, pointed_thing) ent = objs[n]:get_luaentity() if ent and ent._owner == player_name and ent.objtype=="fishing" then noent = false + mcl_util.remove_entity(ent) break end end @@ -319,6 +320,7 @@ vl_projectile.register("mcl_fishing:flying_bobber_entity", { on_activate = mcl_throwing.on_activate, _vl_projectile = { + survive_collision = true, behaviors = { vl_projectile.collides_with_solids, }, @@ -326,8 +328,6 @@ vl_projectile.register("mcl_fishing:flying_bobber_entity", { on_collide_with_solid = function(self, pos, node) local player = self._owner - mcl_util.remove_entity(self) - -- Make sure the player field is valid for when we create the floating bobber if not player then return end @@ -338,6 +338,11 @@ vl_projectile.register("mcl_fishing:flying_bobber_entity", { local ent = core.add_entity(pos, "mcl_fishing:bobber_entity"):get_luaentity() ent.player = player ent.child = true + mcl_util.remove_entity(self) + else + local obj = self.object + obj:set_velocity(vector.zero()) + obj:set_acceleration(vector.zero()) end end },