Convert flying bobber to vl_projectile, modify mcl_throwing.register_throwable_object() to check for _vl_projectile field

This commit is contained in:
teknomunk 2024-09-15 19:12:21 -05:00
parent 106646db61
commit 538ab13473
5 changed files with 33 additions and 30 deletions

@ -312,7 +312,7 @@ bobber_ENTITY.on_step = bobber_on_step
minetest.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY) minetest.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY)
local flying_bobber_ENTITY={ vl_projectile.register("mcl_fishing:flying_bobber_entity", {
physical = false, physical = false,
timer=0, timer=0,
textures = {"mcl_fishing_bobber.png"}, --FIXME: Replace with correct texture. textures = {"mcl_fishing_bobber.png"}, --FIXME: Replace with correct texture.
@ -323,35 +323,35 @@ local flying_bobber_ENTITY={
get_staticdata = mcl_throwing.get_staticdata, get_staticdata = mcl_throwing.get_staticdata,
on_activate = mcl_throwing.on_activate, 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={}, _lastpos={},
_thrower = nil, _thrower = nil,
objtype="fishing", 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) mcl_throwing.register_throwable_object("mcl_fishing:flying_bobber", "mcl_fishing:flying_bobber_entity", 5)

@ -17,7 +17,6 @@ minetest.register_craftitem("mcl_throwing:egg", {
_on_dispense = mcl_throwing.dispense_function, _on_dispense = mcl_throwing.dispense_function,
groups = { craftitem = 1 }, groups = { craftitem = 1 },
}) })
mcl_throwing.register_throwable_object("mcl_throwing:egg", "mcl_throwing:egg_entity", 22)
minetest.register_entity("mcl_throwing:egg_entity",{ minetest.register_entity("mcl_throwing:egg_entity",{
physical = false, 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)

@ -20,7 +20,6 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", {
on_use = mcl_throwing.get_player_throw_function("mcl_throwing:ender_pearl_entity"), on_use = mcl_throwing.get_player_throw_function("mcl_throwing:ender_pearl_entity"),
groups = { transport = 1 }, groups = { transport = 1 },
}) })
mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22)
-- Ender pearl entity -- Ender pearl entity
vl_projectile.register("mcl_throwing:ender_pearl_entity",{ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
@ -125,3 +124,5 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
end end
}, },
}) })
mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22)

@ -14,6 +14,8 @@ local velocities = {}
function mcl_throwing.register_throwable_object(name, entity, velocity) function mcl_throwing.register_throwable_object(name, entity, velocity)
entity_mapping[name] = entity entity_mapping[name] = entity
velocities[name] = velocity velocities[name] = velocity
assert(minetest.registered_entities[entity], entity.." not registered")
assert(minetest.registered_entities[entity]._vl_projectile)
end end
function mcl_throwing.throw(throw_item, pos, dir, velocity, thrower) function mcl_throwing.throw(throw_item, pos, dir, velocity, thrower)

@ -16,7 +16,6 @@ minetest.register_craftitem("mcl_throwing:snowball", {
on_use = mcl_throwing.get_player_throw_function("mcl_throwing:snowball_entity"), on_use = mcl_throwing.get_player_throw_function("mcl_throwing:snowball_entity"),
_on_dispense = mcl_throwing.dispense_function, _on_dispense = mcl_throwing.dispense_function,
}) })
mcl_throwing.register_throwable_object("mcl_throwing:snowball", "mcl_throwing:snowball_entity", 22)
-- The snowball entity -- The snowball entity
local function snowball_particles(pos, vel) local function snowball_particles(pos, vel)
@ -72,4 +71,5 @@ vl_projectile.register("mcl_throwing:snowball_entity", {
damage_groups = { snowball_vulnerable = 3 }, damage_groups = { snowball_vulnerable = 3 },
}, },
}) })
mcl_throwing.register_throwable_object("mcl_throwing:snowball", "mcl_throwing:snowball_entity", 22)