Compare commits

...

2 Commits

4 changed files with 34 additions and 42 deletions

View File

@ -157,10 +157,6 @@ function mesecon.register_button(basename, description, texture, recipeitem, sou
-- Push the button! Push, push, push the button! -- Push the button! Push, push, push the button!
if node_def.groups.button_push_by_arrow == 1 then if node_def.groups.button_push_by_arrow == 1 then
minetest.log("hit"..dump({
pos = pos,
node = node,
}))
mesecon.push_button(pos, node) mesecon.push_button(pos, node)
end end
end end

View File

@ -7,12 +7,6 @@ local enable_pvp = minetest.settings:get_bool("enable_pvp")
local math = math local math = math
local vector = vector local vector = vector
-- Time in seconds after which a stuck arrow is deleted
local ARROW_TIMEOUT = 60
-- Time after which stuck arrow is rechecked for being stuck
local STUCK_RECHECK_TIME = 5
local YAW_OFFSET = -math.pi/2 local YAW_OFFSET = -math.pi/2
local mod_awards = minetest.get_modpath("awards") and minetest.get_modpath("mcl_achievements") local mod_awards = minetest.get_modpath("awards") and minetest.get_modpath("mcl_achievements")
@ -70,6 +64,7 @@ local arrow_entity = {
survive_collision = true, survive_collision = true,
sticks_in_players = true, sticks_in_players = true,
damages_players = true, damages_players = true,
maximum_time = 60,
damage_groups = function(self) damage_groups = function(self)
return { fleshy = self._damage } return { fleshy = self._damage }
end, end,
@ -87,14 +82,6 @@ local arrow_entity = {
local pos = self.object:get_pos() local pos = self.object:get_pos()
self._allow_punch = self._allow_punch or not self._owner 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
-- Give the arrows a maximum flight time
self._time_in_air = (self._time_in_air or 0) + dtime
if self._time_in_air > ARROW_TIMEOUT then
self._removed = true
self.object:remove()
return true
end
if self._deflection_cooloff > 0 then if self._deflection_cooloff > 0 then
self._deflection_cooloff = self._deflection_cooloff - dtime self._deflection_cooloff = self._deflection_cooloff - dtime
end end
@ -165,7 +152,7 @@ local arrow_entity = {
-- Otherwise, punching has no effect. -- Otherwise, punching has no effect.
on_punch = function(self) on_punch = function(self)
if self._stuck then if self._stuck then
self._stuckrechecktimer = STUCK_RECHECK_TIME self._stuckrechecktimer = 5
end end
end, end,
get_staticdata = function(self) get_staticdata = function(self)
@ -176,14 +163,6 @@ local arrow_entity = {
out[field] = self["_"..field] out[field] = self["_"..field]
end end
if self._stuck then
-- If _stucktimer is missing for some reason, assume the maximum
if not self._stucktimer then
self._stucktimer = ARROW_TIMEOUT
end
out.stuckstarttime = minetest.get_gametime() - self._stucktimer
end
if self._owner then if self._owner then
out._owner = self._owner:get_player_name() out._owner = self._owner:get_player_name()
end end
@ -204,15 +183,6 @@ local arrow_entity = {
self["_"..field] = data[field] self["_"..field] = data[field]
end end
if data.stuckstarttime then
-- First, check if the stuck arrow is aleady past its life timer.
-- If yes, delete it.
self._stucktimer = minetest.get_gametime() - data.stuckstarttime
end
-- Perform a stuck recheck on the next step.
self._stuckrechecktimer = STUCK_RECHECK_TIME
local vl_projectile_data = {} local vl_projectile_data = {}
if data._owner then if data._owner then
vl_projectile_data.owner = minetest.get_player_by_name(data._owner) vl_projectile_data.owner = minetest.get_player_by_name(data._owner)

View File

@ -23,6 +23,7 @@ Arguments:
* If `type` is "entity" then the additional parameter `objet` will be provided. * If `type` is "entity" then the additional parameter `objet` will be provided.
* `behaviors`: a list of behavior callbacks that define the projectile's behavior. This mod provides the following * `behaviors`: a list of behavior callbacks that define the projectile's behavior. This mod provides the following
behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities` behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities`
* `maximum_time`: number of seconds until projectiles are removed.
* `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the * `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the
three parameters for `minetest.play_sound()`. Supported sounds are: three parameters for `minetest.play_sound()`. Supported sounds are:
* `on_collision`: played when no other more specific sound is defined. May be a function of type `function(projectile, entity_def, projectile_def, type, ...)` * `on_collision`: played when no other more specific sound is defined. May be a function of type `function(projectile, entity_def, projectile_def, type, ...)`
@ -57,6 +58,18 @@ Arguments:
* `owner`: passed thru unmodified * `owner`: passed thru unmodified
* `extra`: 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 ## Custom Projectile Behaviors
The projectile API supports specifying the behaviors that a projectile will exhibit. There are several The projectile API supports specifying the behaviors that a projectile will exhibit. There are several

View File

@ -78,8 +78,14 @@ function mod.update_projectile(self, dtime)
local entity_def = minetest.registered_entities[entity_name] or {} local entity_def = minetest.registered_entities[entity_name] or {}
local entity_vl_projectile = entity_def._vl_projectile or {} local entity_vl_projectile = entity_def._vl_projectile or {}
-- Update entity timer -- Update entity timer and remove expired projectiles
self.timer = (self.timer or 0) + dtime self.timer = (self.timer or 0) + dtime
local maximum_flight_time = entity_vl_projectile.maximum_time
if self.timer > maximum_flight_time then
self.removed = true
self.object:remove()
return
end
-- Run behaviors -- Run behaviors
local behaviors = entity_vl_projectile.behaviors or {} local behaviors = entity_vl_projectile.behaviors or {}
@ -233,8 +239,15 @@ function mod.has_tracer(self, dtime, entity_def, projectile_def)
}) })
end end
function mod.replace_with_item_drop(self, pos, entity_def, projectile_def) function mod.replace_with_item_drop(self, pos, projectile_def)
local item = self._arrow_item or projectile_def.item 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 if self._collectable and not minetest.is_creative_enabled("") then
local item = minetest.add_item(pos, item) local item = minetest.add_item(pos, item)
@ -252,7 +265,7 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
local pos = self.object:get_pos() local pos = self.object:get_pos()
if not pos then return true end if not pos then return true end
self._stucktimer = self._stucktimer + dtime self._stucktimer = (self._stucktimer or 0) + dtime
if self._stucktimer > STUCK_TIMEOUT then if self._stucktimer > STUCK_TIMEOUT then
mcl_burning.extinguish(self.object) mcl_burning.extinguish(self.object)
self._removed = true self._removed = true
@ -262,14 +275,14 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
-- Drop arrow as item when it is no longer stuck -- Drop arrow as item when it is no longer stuck
-- TODO: revist after observer rework -- TODO: revist after observer rework
self._stuckrechecktimer = self._stuckrechecktimer + dtime self._stuckrechecktimer = (self._stuckrechecktimer or 0) + dtime
if self._stuckrechecktimer > 1 then if self._stuckrechecktimer > 1 then
self._stuckrechecktimer = 0 self._stuckrechecktimer = 0
if self._stuckin then if self._stuckin then
local node = minetest.get_node(self._stuckin) local node = minetest.get_node(self._stuckin)
local node_def = minetest.registered_nodes[node.name] local node_def = minetest.registered_nodes[node.name]
if node_def and node_def.walkable == false then 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 return
end end
end end