From 948aceae21cc2b910f14bd66841663a1a02aaf8e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 23 Sep 2024 21:36:50 -0500 Subject: [PATCH] Fix dispenser arrows so they hit players and entities, minetest.register_entity -> vl_projectile.register for mcl_throwing:egg --- mods/ITEMS/mcl_bows/arrow.lua | 2 +- mods/ITEMS/mcl_throwing/egg.lua | 2 +- mods/ITEMS/vl_projectile/init.lua | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 3c478f59e..9e0824c3a 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -297,7 +297,7 @@ local arrow_entity = { end local pos = self.object:get_pos() - self._allow_punch = self._allow_punch or not self._startpos or pos and vector.distance(self._startpos, pos) > 1.5 + self._allow_punch = self._allow_punch or not self._owner or not self._startpos or pos and vector.distance(self._startpos, pos) > 1.5 if self._stuck then return stuck_arrow_on_step(self, dtime) diff --git a/mods/ITEMS/mcl_throwing/egg.lua b/mods/ITEMS/mcl_throwing/egg.lua index d5b5c7e61..816596f7b 100644 --- a/mods/ITEMS/mcl_throwing/egg.lua +++ b/mods/ITEMS/mcl_throwing/egg.lua @@ -35,7 +35,7 @@ local function egg_spawn_chicks(pos) mcl_mobs.spawn_child(vector.offset(pos, -0.7, 0, 0.7), "mobs_mc:chicken") end -minetest.register_entity("mcl_throwing:egg_entity",{ +vl_projectile.register("mcl_throwing:egg_entity",{ physical = false, timer=0, textures = {"mcl_throwing_egg.png"}, diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 216b3ff36..0569e954f 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -205,13 +205,18 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def) -- 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 math.abs(vel.x) >= 0.0001 and math.abs(vel.z) >= 0.0001 and math.abs(vel.y) >= 0.0001 then - self._last_pos = pos + if not self._last_velocity then + self._last_velocity = vel return end + + local delta_v = (vel - self._last_velocity) / vector.length(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 + self._last_velocity = vel 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 - self._last_pos = pos return end end @@ -364,7 +369,6 @@ function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_ closest_distance = dist end end - end if closest_object then