Address more review comments

This commit is contained in:
teknomunk 2024-09-08 09:41:32 -05:00
parent f09cd7a37c
commit 9f423a73e9
5 changed files with 45 additions and 60 deletions

@ -36,13 +36,15 @@ S("Arrows might get stuck on solid blocks and can be retrieved again. They are a
})
-- Destroy arrow entity self at pos and drops it as an item
local function spawn_item(self, pos)
local function replace_with_item_drop(self, pos)
if not minetest.is_creative_enabled("") then
local item = minetest.add_item(pos, "mcl_bows:arrow")
item:set_velocity(vector.zero())
item:set_yaw(self.object:get_yaw())
end
mcl_burning.extinguish(self.object)
self._removed = true
self.object:remove()
end
@ -62,13 +64,10 @@ local function stuck_arrow_on_step(self, dtime)
-- Drop arrow as item when it is no longer stuck
-- FIXME: Arrows are a bit slow to react and continue to float in mid air for a few seconds.
if self._stuckrechecktimer > STUCK_RECHECK_TIME then
local stuckin_def
if self._stuckin then
stuckin_def = minetest.registered_nodes[minetest.get_node(self._stuckin).name]
end
local stuckin_def = self._stuckin and minetest.registered_nodes[minetest.get_node(self._stuckin).name]
-- TODO: In MC, arrow just falls down without turning into an item
if stuckin_def and stuckin_def.walkable == false then
spawn_item(self, pos)
replace_with_item_drop(self, pos)
return
end
self._stuckrechecktimer = 0
@ -153,9 +152,8 @@ local arrow_entity = {
end
},
on_collide_with_solid = function(self, pos, node, node_def)
local def = node_def
local vel = self.object:get_velocity()
local dpos = vector.round(vector.new(pos)) -- digital pos
local dpos = vector.round(pos) -- digital pos
-- Check for the node to which the arrow is pointing
local dir
@ -244,7 +242,7 @@ local arrow_entity = {
elseif pointed_thing.type == "node" then
local nn = minetest.get_node(minetest.get_pointed_thing_position(pointed_thing)).name
local def = minetest.registered_nodes[nn]
if (not def) or def.walkable then
if not def or def.walkable then
-- There's a node in the way. Delete arrow without damage
mcl_burning.extinguish(self.object)
self.object:remove()
@ -334,9 +332,6 @@ local arrow_entity = {
-- Process as projectile
vl_projectile.update_projectile(self, dtime)
-- Update yaw
local vel = self.object:get_velocity()
end,
-- Force recheck of stuck arrows when punched.

@ -125,14 +125,16 @@ function mcl_potions.register_splash(name, descr, color, def)
-- Apply effect list
if def._effect_list then
local ef_level
local dur
for name, details in pairs(def._effect_list) do
local ef_level
local dur
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
ef_level = details.level + details.level_scaling * potency
else
ef_level = details.level
end
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
if potency>0 and details.uses_level then
@ -142,9 +144,11 @@ function mcl_potions.register_splash(name, descr, color, def)
else
dur = details.dur
end
if details.effect_stacks then
ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
end
if rad > 0 then
mcl_potions.give_effect_by_level(name, obj, ef_level, REDUX_MAP[rad]*dur)
else

@ -58,7 +58,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
for name, details in pairs(def._effect_list) do
local ef_level = details.level
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
ef_level = details.level + details.level_scaling * potency
end
local dur = details.dur

@ -71,10 +71,8 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
-- Node is walkable, we have to find a place somewhere outside of that node
vc = vector.normalize(vc)
-- Zero-out the two axes with a lower absolute value than
-- the axis with the strongest force
local lv, ld
lv, ld = math.abs(vc.y), "y"
-- Zero-out the two axes with a lower absolute value than the axis with the strongest force
local lv, ld = math.abs(vc.y), "y"
if math.abs(vc.x) > lv then
lv, ld = math.abs(vc.x), "x"
end
@ -122,8 +120,7 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
player:set_hp(player:get_hp() - 5, { type = "fall", from = "mod" })
-- 5% chance to spawn endermite at the player's origin
local r = math.random(1,20)
if r == 1 then
if math.random(1,20) == 1 then
minetest.add_entity(oldpos, "mobs_mc:endermite")
end
end

@ -22,8 +22,8 @@ function mod.projectile_physics(obj, entity_def, v, a)
v,a = vl_physics.apply_entity_environmental_physics(obj)
else
-- Simple physics
if not v then v = obj:get_velocity() end
if not a then a = vector.zero() end
v = v or obj:get_velocity()
a = a or vector.zero()
if not entity_def.ignore_gravity then
a = a + vector.new(0,-GRAVITY,0)
@ -72,8 +72,7 @@ function mod.update_projectile(self, dtime)
-- Run behaviors
local behaviors = entity_vl_projectile.behaviors or {}
for i=1,#behaviors do
local behavior = behaviors[i]
if behavior(self, dtime, entity_def, entity_vl_projectile) then
if behaviors[i](self, dtime, entity_def, entity_vl_projectile) then
return
end
end
@ -81,8 +80,6 @@ function mod.update_projectile(self, dtime)
mod.projectile_physics(self.object, entity_def)
end
local function no_op()
end
local function damage_particles(pos, is_critical)
if is_critical then
minetest.add_particlespawner({
@ -102,20 +99,6 @@ local function damage_particles(pos, is_critical)
})
end
end
local function random_arrow_positions(positions, placement)
if positions == "x" then
return math.random(-4, 4)
elseif positions == "y" then
return math.random(0, 10)
end
if placement == "front" and positions == "z" then
return 3
elseif placement == "back" and positions == "z" then
return -3
end
return 0
end
local function random_hit_positions(positions, placement)
if positions == "x" then
return math.random(-4, 4)
@ -170,8 +153,8 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity)
local placement = self._placement == 1 and "front" or "back"
self._rotation_station = self.placement == 1 and -90 or 90
self._in_player = true
self._y_position = random_arrow_positions("y", placement)
self._x_position = random_arrow_positions("x", placement)
self._y_position = random_hit_positions("y", placement)
self._x_position = random_hit_positions("x", placement)
if self._y_position > 6 and self._x_position < 2 and self._x_position > -2 then
self._attach_parent = "Head"
self._y_position = self._y_position - 6
@ -187,10 +170,10 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity)
self._attach_parent = "Body"
end
self._z_rotation = math.random(-30, 30)
self._y_rotation = math.random( -30, 30)
self._y_rotation = math.random(-30, 30)
self.object:set_attach(
entity, self._attach_parent,
vector.new(self._x_position, self._y_position, random_arrow_positions("z", placement)),
vector.new(self._x_position, self._y_position, random_hit_positions("z", placement)),
vector.new(0, self._rotation_station + self._y_rotation, self._z_rotation)
)
end
@ -226,12 +209,12 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
end
-- Call entity collied hook
local hook = projectile_def.on_collide_with_solid or no_op
hook(self, pos, node, node_def)
local hook = projectile_def.on_collide_with_solid
if hook then hook(self, pos, node, node_def) end
-- Call node collided hook
local hook = ((node_def and node_def._vl_projectile) or {}).on_collide or no_op
hook(self, pos, node, node_def)
local hook = node_def and node_def._vl_projectile and node_def._vl_projectile.on_collide
if hook then hook(self, pos, node, node_def) end
-- Play sounds
local sounds = projectile_def.sounds or {}
@ -280,7 +263,7 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
do_damage = true
handle_player_sticking(self, entity_def, projectile_def, object)
elseif object_lua and (object_lua.is_mob == true or object_lua._hittable_by_projectile) and (self_vl_projectile.owner ~= object) then
elseif object_lua and (object_lua.is_mob or object_lua._hittable_by_projectile) and self_vl_projectile.owner ~= object then
do_damage = true
end
@ -298,16 +281,17 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
end
-- Call entity collision hook
(projectile_def.on_collide_with_entity or no_op)(self, pos, object)
local hook = projectile_def.on_collide_with_entity
if hook then hook(self, pos, object) end
-- Call reverse entity collision hook
local other_entity_def = minetest.registered_entities[object.name] or {}
local other_entity_vl_projectile = other_entity_def._vl_projectile or {}
local hook = (other_entity_vl_projectile or {}).on_collide or no_op
hook(object, self)
local hook = other_entity_vl_projectile and other_entity_vl_projectile.on_collide
if hook then hook(object, self) end
-- Play sounds
local sounds = (projectile_def.sounds or {})
local sounds = projectile_def.sounds or {}
local sound = sounds.on_entity_collion or sounds.on_collision
if type(sound) == "function" then sound = sound(self, entity_def, projectile_def, "entity", object) end
if sound then
@ -339,7 +323,7 @@ function mod.collides_with_entities(self, dtime, entity_def, projectile_def)
if entity and entity.name ~= self.object:get_luaentity().name then
if object:is_player() and owner ~= object:get_player_name() then
return handle_entity_collision(self, entity_def, projectile_def, object)
elseif (entity.is_mob == true or entity._hittable_by_projectile) and (owner ~= object) then
elseif (entity.is_mob or entity._hittable_by_projectile) and owner ~= object then
return handle_entity_collision(self, entity_def, projectile_def, object)
end
end
@ -347,8 +331,7 @@ function mod.collides_with_entities(self, dtime, entity_def, projectile_def)
end
function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_def)
local closest_object
local closest_distance
local closest_object, closest_distance
local pos = self.object:get_pos()
local arrow_dir = self.object:get_velocity()
@ -377,8 +360,14 @@ function mod.create(entity_id, options)
local obj = minetest.add_entity(pos, entity_id, options.staticdata)
-- Set initial velocity and acceleration
local v = vector.multiply(options.dir or vector.zero(), options.velocity or 0)
local a = vector.multiply(v, -math.abs(options.drag))
local a, v
if options.dir then
v = vector.multiply(options.dir, options.velocity or 0)
a = vector.multiply(v, -math.abs(options.drag))
else
a = vector.zero()
v = a
end
mod.projectile_physics(obj, entity_def, v, a)
-- Update projectile parameters