Document vl_projectile.replace_with_item_drop

This commit is contained in:
teknomunk 2024-10-20 20:47:47 -05:00
parent 1a4c5c8749
commit 1a7c0b1f9b
2 changed files with 22 additions and 3 deletions

View File

@ -57,6 +57,18 @@ Arguments:
* `owner`: passed thru unmodified
* `extra`: passed thru unmodified
## `vl_projectile.replace_with_item_drop(projectile_lua_entity, pos, projectile_def)`
Removes the projectile and replaces it with an item entity based on either the entity's `_arrow_item` field or
the value `self._vl_projectile.item`.
Arguments:
* `projectile_lua_entity`: the lua entity of the projectile to be replaced.
* `pos`: the position to create the item entity
* `projectile_def`: The projectile's `_vl_projectile` field. If not provided, it will be
extracted from the projectile's lua entity.
## Custom Projectile Behaviors
The projectile API supports specifying the behaviors that a projectile will exhibit. There are several

View File

@ -233,8 +233,15 @@ function mod.has_tracer(self, dtime, entity_def, projectile_def)
})
end
function mod.replace_with_item_drop(self, pos, entity_def, projectile_def)
local item = self._arrow_item or projectile_def.item
function mod.replace_with_item_drop(self, pos, projectile_def)
local item = self._arrow_item
if not item then
projectile_def = projectile_def or self._vl_projectile
if not projectile_def then return end
item = projectile_def.item
end
if self._collectable and not minetest.is_creative_enabled("") then
local item = minetest.add_item(pos, item)
@ -269,7 +276,7 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
local node = minetest.get_node(self._stuckin)
local node_def = minetest.registered_nodes[node.name]
if node_def and node_def.walkable == false then
mod.replace_with_item_drop(self, pos, entity_def, projectile_def)
mod.replace_with_item_drop(self, pos, projectile_def)
return
end
end