mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-12 12:43:15 +01:00
Move tracer to vl_projectile
This commit is contained in:
parent
77d3dbf33d
commit
6193b2630f
@ -132,8 +132,13 @@ local arrow_entity = {
|
|||||||
damage_groups = function(self)
|
damage_groups = function(self)
|
||||||
return { fleshy = self._damage }
|
return { fleshy = self._damage }
|
||||||
end,
|
end,
|
||||||
|
hide_tracer = function(self)
|
||||||
|
return self._stuck or self._damage < 9 or self._in_player
|
||||||
|
end,
|
||||||
|
tracer_texture = "mobs_mc_arrow_particle.png",
|
||||||
behaviors = {
|
behaviors = {
|
||||||
vl_projectile.burns,
|
vl_projectile.burns,
|
||||||
|
vl_projectile.has_tracer,
|
||||||
|
|
||||||
-- Custom arrow behaviors
|
-- Custom arrow behaviors
|
||||||
function(self, dtime)
|
function(self, dtime)
|
||||||
@ -146,27 +151,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
|
||||||
|
|
||||||
-- Add tracer
|
|
||||||
if self._damage >= 9 and self._in_player == false then
|
|
||||||
minetest.add_particlespawner({
|
|
||||||
amount = 20,
|
|
||||||
time = .2,
|
|
||||||
minpos = vector.zero(),
|
|
||||||
maxpos = vector.zero(),
|
|
||||||
minvel = vector.new(-0.1,-0.1,-0.1),
|
|
||||||
maxvel = vector.new(0.1,0.1,0.1),
|
|
||||||
minexptime = 0.5,
|
|
||||||
maxexptime = 0.5,
|
|
||||||
minsize = 2,
|
|
||||||
maxsize = 2,
|
|
||||||
attached = self.object,
|
|
||||||
collisiondetection = false,
|
|
||||||
vertical = false,
|
|
||||||
texture = "mobs_mc_arrow_particle.png",
|
|
||||||
glow = 1,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Give the arrows a maximum flight time
|
-- Give the arrows a maximum flight time
|
||||||
self._time_in_air = (self._time_in_air or 0) + dtime
|
self._time_in_air = (self._time_in_air or 0) + dtime
|
||||||
if self._time_in_air > ARROW_TIMEOUT then
|
if self._time_in_air > ARROW_TIMEOUT then
|
||||||
|
@ -62,9 +62,11 @@ Arguments:
|
|||||||
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
|
||||||
standard behaviors provided with the API:
|
standard behaviors provided with the API:
|
||||||
|
|
||||||
* `vl_projectile.burns`: Projectiles can be set on fire
|
* `vl_projectile.burns`: projectile can be set on fire
|
||||||
* `vl_projectile.collides_with_solids`: handles collisions between projectiles and solid nodes
|
* `vl_projectile.collides_with_solids`: handles collisions between projectiles and solid nodes
|
||||||
* `vl_projectile.collides_with_entities`: handles collisions between projectiles and entities by checking nearby entities
|
* `vl_projectile.collides_with_entities`: handles collisions between projectiles and entities by checking nearby entities
|
||||||
|
* `vl_projectile.has_tracer`: projectile will have a tracer trail when thrown/shot. Projectile can define
|
||||||
|
`_vl_projectile.hide_tracer = function(self)` to conditionally hide the tracer.
|
||||||
* `vl_projectile.raycast_collides_with_entities`: handles collisions between projectils and entities by performing a raycast
|
* `vl_projectile.raycast_collides_with_entities`: handles collisions between projectils and entities by performing a raycast
|
||||||
check along the path of movement.
|
check along the path of movement.
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ local enable_pvp = minetest.settings:get_bool("enable_pvp")
|
|||||||
|
|
||||||
function mod.projectile_physics(obj, entity_def, v, a)
|
function mod.projectile_physics(obj, entity_def, v, a)
|
||||||
local le = obj:get_luaentity()
|
local le = obj:get_luaentity()
|
||||||
|
if not le then return end
|
||||||
|
|
||||||
local entity_def = minetest.registered_entities[le.name]
|
local entity_def = minetest.registered_entities[le.name]
|
||||||
local pos = obj:get_pos()
|
local pos = obj:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
@ -203,6 +205,30 @@ function mod.burns(self, dtime, entity_def, projectile_def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mod.has_tracer(self, dtime, entity_def, projectile_def)
|
||||||
|
local hide_tracer = projectile_def.hide_tracer
|
||||||
|
if hide_tracer and hide_tracer(self) then return end
|
||||||
|
|
||||||
|
-- Add tracer
|
||||||
|
minetest.add_particlespawner({
|
||||||
|
amount = 20,
|
||||||
|
time = .2,
|
||||||
|
minpos = vector.zero(),
|
||||||
|
maxpos = vector.zero(),
|
||||||
|
minvel = vector.new(-0.1,-0.1,-0.1),
|
||||||
|
maxvel = vector.new(0.1,0.1,0.1),
|
||||||
|
minexptime = 0.5,
|
||||||
|
maxexptime = 0.5,
|
||||||
|
minsize = 2,
|
||||||
|
maxsize = 2,
|
||||||
|
attached = self.object,
|
||||||
|
collisiondetection = false,
|
||||||
|
vertical = false,
|
||||||
|
texture = projectile_def.tracer_texture or "mobs_mc_arrow_particle.png",
|
||||||
|
glow = 1,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
@ -380,6 +406,8 @@ function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_
|
|||||||
local closest_object, closest_distance
|
local closest_object, closest_distance
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
if not pos then return end
|
||||||
|
|
||||||
local arrow_dir = self.object:get_velocity()
|
local arrow_dir = self.object:get_velocity()
|
||||||
|
|
||||||
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||||
|
Loading…
Reference in New Issue
Block a user