mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-11 04:03:15 +01:00
Move arrow self-collision grace logic to vl_projectile then apply to mob projectiles and splash and linger potions, allow entity luaentity to be passed to mcl_util.get_entity_id()
This commit is contained in:
parent
be26dc9800
commit
42c4d91967
@ -717,6 +717,8 @@ function mcl_util.gen_uuid()
|
||||
return table.concat(u)
|
||||
end
|
||||
function mcl_util.get_entity_id(entity)
|
||||
if entity.object then entity = entity.object end
|
||||
|
||||
if entity:is_player() then
|
||||
return entity:get_player_name()
|
||||
else
|
||||
|
@ -382,7 +382,9 @@ end
|
||||
function mcl_mobs.register_arrow(name, def)
|
||||
if not name or not def then return end -- errorcheck
|
||||
|
||||
local behaviors = {}
|
||||
local behaviors = {
|
||||
vl_projectile.has_owner_grace_distance
|
||||
}
|
||||
if def.hit_node then
|
||||
table.insert(behaviors, vl_projectile.collides_with_solids)
|
||||
end
|
||||
|
@ -46,7 +46,6 @@ local arrow_entity = {
|
||||
"last_pos", "startpos", "damage", "is_critical", "stuck", "stuckin", "stuckin_player", "time_in_air", "vl_projectile",
|
||||
},
|
||||
|
||||
_startpos=nil,
|
||||
_damage=1, -- Damage on impact
|
||||
_is_critical=false, -- Whether this arrow would deal critical damage
|
||||
_stuck=false, -- Whether arrow is stuck
|
||||
@ -76,12 +75,10 @@ local arrow_entity = {
|
||||
vl_projectile.sticks,
|
||||
vl_projectile.burns,
|
||||
vl_projectile.has_tracer,
|
||||
vl_projectile.has_owner_grace_distance,
|
||||
|
||||
-- Custom arrow behaviors
|
||||
function(self, dtime)
|
||||
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
|
||||
|
||||
if self._deflection_cooloff > 0 then
|
||||
self._deflection_cooloff = self._deflection_cooloff - dtime
|
||||
end
|
||||
@ -91,8 +88,6 @@ local arrow_entity = {
|
||||
vl_projectile.raycast_collides_with_entities,
|
||||
},
|
||||
allow_punching = function(self, entity_def, projectile_def, object)
|
||||
if not self._allow_punch then return false end
|
||||
|
||||
local lua = object:get_luaentity()
|
||||
if lua and lua.name == "mobs_mc:rover" then return false end
|
||||
|
||||
|
@ -65,7 +65,6 @@ function mcl_bows.shoot_arrow(arrow_item, pos, dir, yaw, shooter, power, damage,
|
||||
le._source_object = shooter
|
||||
le._damage = damage
|
||||
le._is_critical = is_critical
|
||||
le._startpos = pos
|
||||
le._knockback = knockback
|
||||
le._collectable = collectable
|
||||
le._arrow_item = arrow_item
|
||||
|
@ -208,6 +208,7 @@ function mcl_potions.register_lingering(name, descr, color, def)
|
||||
pointable = false,
|
||||
_vl_projectile = {
|
||||
behaviors = {
|
||||
vl_projectile.has_owner_grace_distance,
|
||||
vl_projectile.collides_with_entities,
|
||||
vl_projectile.collides_with_solids,
|
||||
},
|
||||
|
@ -176,6 +176,7 @@ function mcl_potions.register_splash(name, descr, color, def)
|
||||
collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1},
|
||||
_vl_projectile = {
|
||||
behaviors = {
|
||||
vl_projectile.has_owner_grace_distance,
|
||||
vl_projectile.collides_with_entities,
|
||||
vl_projectile.collides_with_solids,
|
||||
},
|
||||
|
@ -215,6 +215,13 @@ function mod.burns(self, dtime, entity_def, projectile_def)
|
||||
end
|
||||
end
|
||||
|
||||
function mod.has_owner_grace_distance(self, dtime, entity_def, projectile_def)
|
||||
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) > ( projectile_def.grace_distance or 1.5 )
|
||||
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
|
||||
@ -593,10 +600,11 @@ function mod.create(entity_id, options)
|
||||
local luaentity = obj:get_luaentity()
|
||||
if options.owner_id then
|
||||
luaentity._owner = options.owner_id
|
||||
else
|
||||
elseif options.owner then
|
||||
luaentity._owner = mcl_util.get_entity_id(options.owner)
|
||||
end
|
||||
luaentity._starting_velocity = obj:get_velocity()
|
||||
luaentity._startpos = pos
|
||||
luaentity._vl_projectile = {
|
||||
extra = options.extra,
|
||||
}
|
||||
@ -606,11 +614,29 @@ function mod.create(entity_id, options)
|
||||
end
|
||||
|
||||
function mod.register(name, def)
|
||||
assert(def._vl_projectile, "vl_projectile.register() requires definition to define _vl_projectile")
|
||||
assert(def._vl_projectile.behaviors, "vl_projectile.register() requires definition to define _vl_projectile.behaviors")
|
||||
local behaviors = def._vl_projectile.behaviors
|
||||
def_vl_projectile = def._vl_projectile
|
||||
assert(def_vl_projectile, "vl_projectile.register() requires definition to define _vl_projectile")
|
||||
local behaviors = def_vl_projectile.behaviors
|
||||
|
||||
assert(behaviors, "vl_projectile.register() requires definition to define _vl_projectile.behaviors")
|
||||
for i = 1,#behaviors do
|
||||
assert(behaviors[i] and type(behaviors[i]) == "function", "def._vl_projectile.behaviors["..i.." is malformed")
|
||||
if behaviors[i] == vl_projectile.has_owner_grace_distance then
|
||||
local old_allow_punching = def_vl_projectile.allow_punching
|
||||
if old_allow_punching then
|
||||
def_vl_projectile.allow_punching = function(self, ...)
|
||||
if not self._allow_punch then return false end
|
||||
|
||||
return old_allow_punching(self, ...)
|
||||
end
|
||||
else
|
||||
def_vl_projectile.allow_punching = function(self, ...)
|
||||
if not self._allow_punch then return false end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not def.on_step then
|
||||
|
Loading…
Reference in New Issue
Block a user