Remove debug dump, move maximum time to live to vl_projectile

This commit is contained in:
teknomunk 2024-10-20 21:01:33 -05:00
parent ba1ad14fc9
commit cf58b79a68
4 changed files with 12 additions and 39 deletions

@ -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

@ -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)

@ -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, ...)`

@ -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 {}
@ -259,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
@ -269,7 +275,7 @@ 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