From 74882d2bbffba2d96540b2a7020b5ca9e1a3102f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 15 Sep 2024 19:12:21 -0500 Subject: [PATCH] Convert flying bobber to vl_projectile, modify mcl_throwing.register_throwable_object() to check for _vl_projectile field --- mods/ITEMS/mcl_fishing/init.lua | 54 ++++++++++++------------- mods/ITEMS/mcl_throwing/egg.lua | 2 +- mods/ITEMS/mcl_throwing/ender_pearl.lua | 3 +- mods/ITEMS/mcl_throwing/init.lua | 2 + mods/ITEMS/mcl_throwing/snowball.lua | 2 +- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index f381ffefc..2aaf9a348 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -312,7 +312,7 @@ bobber_ENTITY.on_step = bobber_on_step minetest.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY) -local flying_bobber_ENTITY={ +vl_projectile.register("mcl_fishing:flying_bobber_entity", { physical = false, timer=0, textures = {"mcl_fishing_bobber.png"}, --FIXME: Replace with correct texture. @@ -323,35 +323,35 @@ local flying_bobber_ENTITY={ get_staticdata = mcl_throwing.get_staticdata, on_activate = mcl_throwing.on_activate, + _vl_projectile = { + behaviors = { + vl_projectile.collides_with_solids, + }, + collides_with = { "group:liquid" }, + on_collide_with_solid = function(self, pos, node) + if not self._last_pos then return end + + local last_pos = self._last_pos + local player = self._owner + + self._remove = true + self.object:remove() + + local def = minetest.registered_nodes[node.name] + if not def then return end + + if def.walkable or def.liquidtype == "flowing" or def.liquidtype == "source" then + local ent = minetest.add_entity(last_pos, "mcl_fishing:bobber_entity"):get_luaentity() + ent.player = player + ent.child = true + end + end + }, + _lastpos={}, _thrower = nil, objtype="fishing", -} - --- Movement function of flying bobber -local function flying_bobber_on_step(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:get_pos() - local node = minetest.get_node(pos) - local def = minetest.registered_nodes[node.name] - --local player = minetest.get_player_by_name(self._thrower) - - -- Destroy when hitting a solid node - if self._lastpos.x~=nil then - if (def and (def.walkable or def.liquidtype == "flowing" or def.liquidtype == "source")) or not def then - local ent = minetest.add_entity(self._lastpos, "mcl_fishing:bobber_entity"):get_luaentity() - ent.player = self._thrower - ent.child = true - self.object:remove() - return - end - end - self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node -end - -flying_bobber_ENTITY.on_step = flying_bobber_on_step - -minetest.register_entity("mcl_fishing:flying_bobber_entity", flying_bobber_ENTITY) +}) mcl_throwing.register_throwable_object("mcl_fishing:flying_bobber", "mcl_fishing:flying_bobber_entity", 5) diff --git a/mods/ITEMS/mcl_throwing/egg.lua b/mods/ITEMS/mcl_throwing/egg.lua index 80eae061d..da50f4ba2 100644 --- a/mods/ITEMS/mcl_throwing/egg.lua +++ b/mods/ITEMS/mcl_throwing/egg.lua @@ -17,7 +17,6 @@ minetest.register_craftitem("mcl_throwing:egg", { _on_dispense = mcl_throwing.dispense_function, groups = { craftitem = 1 }, }) -mcl_throwing.register_throwable_object("mcl_throwing:egg", "mcl_throwing:egg_entity", 22) minetest.register_entity("mcl_throwing:egg_entity",{ physical = false, @@ -60,4 +59,5 @@ minetest.register_entity("mcl_throwing:egg_entity",{ }, }, }) +mcl_throwing.register_throwable_object("mcl_throwing:egg", "mcl_throwing:egg_entity", 22) diff --git a/mods/ITEMS/mcl_throwing/ender_pearl.lua b/mods/ITEMS/mcl_throwing/ender_pearl.lua index 520a80c6d..a76d48a1d 100644 --- a/mods/ITEMS/mcl_throwing/ender_pearl.lua +++ b/mods/ITEMS/mcl_throwing/ender_pearl.lua @@ -20,7 +20,6 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", { on_use = mcl_throwing.get_player_throw_function("mcl_throwing:ender_pearl_entity"), groups = { transport = 1 }, }) -mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22) -- Ender pearl entity vl_projectile.register("mcl_throwing:ender_pearl_entity",{ @@ -125,3 +124,5 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{ end }, }) +mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22) + diff --git a/mods/ITEMS/mcl_throwing/init.lua b/mods/ITEMS/mcl_throwing/init.lua index 599f757f0..65958c9a1 100644 --- a/mods/ITEMS/mcl_throwing/init.lua +++ b/mods/ITEMS/mcl_throwing/init.lua @@ -14,6 +14,8 @@ local velocities = {} function mcl_throwing.register_throwable_object(name, entity, velocity) entity_mapping[name] = entity velocities[name] = velocity + assert(minetest.registered_entities[entity], entity.." not registered") + assert(minetest.registered_entities[entity]._vl_projectile) end function mcl_throwing.throw(throw_item, pos, dir, velocity, thrower) diff --git a/mods/ITEMS/mcl_throwing/snowball.lua b/mods/ITEMS/mcl_throwing/snowball.lua index 8583697e2..c67ef1c56 100644 --- a/mods/ITEMS/mcl_throwing/snowball.lua +++ b/mods/ITEMS/mcl_throwing/snowball.lua @@ -16,7 +16,6 @@ minetest.register_craftitem("mcl_throwing:snowball", { on_use = mcl_throwing.get_player_throw_function("mcl_throwing:snowball_entity"), _on_dispense = mcl_throwing.dispense_function, }) -mcl_throwing.register_throwable_object("mcl_throwing:snowball", "mcl_throwing:snowball_entity", 22) -- The snowball entity local function snowball_particles(pos, vel) @@ -72,4 +71,5 @@ vl_projectile.register("mcl_throwing:snowball_entity", { damage_groups = { snowball_vulnerable = 3 }, }, }) +mcl_throwing.register_throwable_object("mcl_throwing:snowball", "mcl_throwing:snowball_entity", 22)