mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
Address more review comments
This commit is contained in:
parent
ea671cef73
commit
eae62ca427
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
|
-- 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
|
if not minetest.is_creative_enabled("") then
|
||||||
local item = minetest.add_item(pos, "mcl_bows:arrow")
|
local item = minetest.add_item(pos, "mcl_bows:arrow")
|
||||||
item:set_velocity(vector.zero())
|
item:set_velocity(vector.zero())
|
||||||
item:set_yaw(self.object:get_yaw())
|
item:set_yaw(self.object:get_yaw())
|
||||||
end
|
end
|
||||||
|
|
||||||
mcl_burning.extinguish(self.object)
|
mcl_burning.extinguish(self.object)
|
||||||
|
self._removed = true
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,13 +64,10 @@ local function stuck_arrow_on_step(self, dtime)
|
||||||
-- Drop arrow as item when it is no longer stuck
|
-- 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.
|
-- 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
|
if self._stuckrechecktimer > STUCK_RECHECK_TIME then
|
||||||
local stuckin_def
|
local stuckin_def = self._stuckin and minetest.registered_nodes[minetest.get_node(self._stuckin).name]
|
||||||
if self._stuckin then
|
|
||||||
stuckin_def = minetest.registered_nodes[minetest.get_node(self._stuckin).name]
|
|
||||||
end
|
|
||||||
-- TODO: In MC, arrow just falls down without turning into an item
|
-- TODO: In MC, arrow just falls down without turning into an item
|
||||||
if stuckin_def and stuckin_def.walkable == false then
|
if stuckin_def and stuckin_def.walkable == false then
|
||||||
spawn_item(self, pos)
|
replace_with_item_drop(self, pos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self._stuckrechecktimer = 0
|
self._stuckrechecktimer = 0
|
||||||
|
@ -153,9 +152,8 @@ local arrow_entity = {
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
on_collide_with_solid = function(self, pos, node, node_def)
|
on_collide_with_solid = function(self, pos, node, node_def)
|
||||||
local def = node_def
|
|
||||||
local vel = self.object:get_velocity()
|
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
|
-- Check for the node to which the arrow is pointing
|
||||||
local dir
|
local dir
|
||||||
|
@ -244,7 +242,7 @@ local arrow_entity = {
|
||||||
elseif pointed_thing.type == "node" then
|
elseif pointed_thing.type == "node" then
|
||||||
local nn = minetest.get_node(minetest.get_pointed_thing_position(pointed_thing)).name
|
local nn = minetest.get_node(minetest.get_pointed_thing_position(pointed_thing)).name
|
||||||
local def = minetest.registered_nodes[nn]
|
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
|
-- There's a node in the way. Delete arrow without damage
|
||||||
mcl_burning.extinguish(self.object)
|
mcl_burning.extinguish(self.object)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
@ -334,9 +332,6 @@ local arrow_entity = {
|
||||||
|
|
||||||
-- Process as projectile
|
-- Process as projectile
|
||||||
vl_projectile.update_projectile(self, dtime)
|
vl_projectile.update_projectile(self, dtime)
|
||||||
|
|
||||||
-- Update yaw
|
|
||||||
local vel = self.object:get_velocity()
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Force recheck of stuck arrows when punched.
|
-- Force recheck of stuck arrows when punched.
|
||||||
|
|
|
@ -125,14 +125,16 @@ function mcl_potions.register_splash(name, descr, color, def)
|
||||||
|
|
||||||
-- Apply effect list
|
-- Apply effect list
|
||||||
if def._effect_list then
|
if def._effect_list then
|
||||||
local ef_level
|
|
||||||
local dur
|
|
||||||
for name, details in pairs(def._effect_list) do
|
for name, details in pairs(def._effect_list) do
|
||||||
|
local ef_level
|
||||||
|
local dur
|
||||||
|
|
||||||
if details.uses_level then
|
if details.uses_level then
|
||||||
ef_level = details.level + details.level_scaling * (potency)
|
ef_level = details.level + details.level_scaling * potency
|
||||||
else
|
else
|
||||||
ef_level = details.level
|
ef_level = details.level
|
||||||
end
|
end
|
||||||
|
|
||||||
if details.dur_variable then
|
if details.dur_variable then
|
||||||
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
|
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
|
||||||
if potency>0 and details.uses_level then
|
if potency>0 and details.uses_level then
|
||||||
|
@ -142,9 +144,11 @@ function mcl_potions.register_splash(name, descr, color, def)
|
||||||
else
|
else
|
||||||
dur = details.dur
|
dur = details.dur
|
||||||
end
|
end
|
||||||
|
|
||||||
if details.effect_stacks then
|
if details.effect_stacks then
|
||||||
ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
|
ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if rad > 0 then
|
if rad > 0 then
|
||||||
mcl_potions.give_effect_by_level(name, obj, ef_level, REDUX_MAP[rad]*dur)
|
mcl_potions.give_effect_by_level(name, obj, ef_level, REDUX_MAP[rad]*dur)
|
||||||
else
|
else
|
||||||
|
|
|
@ -58,7 +58,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
for name, details in pairs(def._effect_list) do
|
for name, details in pairs(def._effect_list) do
|
||||||
local ef_level = details.level
|
local ef_level = details.level
|
||||||
if details.uses_level then
|
if details.uses_level then
|
||||||
ef_level = details.level + details.level_scaling * (potency)
|
ef_level = details.level + details.level_scaling * potency
|
||||||
end
|
end
|
||||||
|
|
||||||
local dur = details.dur
|
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
|
-- Node is walkable, we have to find a place somewhere outside of that node
|
||||||
vc = vector.normalize(vc)
|
vc = vector.normalize(vc)
|
||||||
|
|
||||||
-- Zero-out the two axes with a lower absolute value than
|
-- Zero-out the two axes with a lower absolute value than the axis with the strongest force
|
||||||
-- the axis with the strongest force
|
local lv, ld = math.abs(vc.y), "y"
|
||||||
local lv, ld
|
|
||||||
lv, ld = math.abs(vc.y), "y"
|
|
||||||
if math.abs(vc.x) > lv then
|
if math.abs(vc.x) > lv then
|
||||||
lv, ld = math.abs(vc.x), "x"
|
lv, ld = math.abs(vc.x), "x"
|
||||||
end
|
end
|
||||||
|
@ -122,8 +120,7 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
|
||||||
player:set_hp(player:get_hp() - 5, { type = "fall", from = "mod" })
|
player:set_hp(player:get_hp() - 5, { type = "fall", from = "mod" })
|
||||||
|
|
||||||
-- 5% chance to spawn endermite at the player's origin
|
-- 5% chance to spawn endermite at the player's origin
|
||||||
local r = math.random(1,20)
|
if math.random(1,20) == 1 then
|
||||||
if r == 1 then
|
|
||||||
minetest.add_entity(oldpos, "mobs_mc:endermite")
|
minetest.add_entity(oldpos, "mobs_mc:endermite")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,8 +22,8 @@ function mod.projectile_physics(obj, entity_def, v, a)
|
||||||
v,a = vl_physics.apply_entity_environmental_physics(obj)
|
v,a = vl_physics.apply_entity_environmental_physics(obj)
|
||||||
else
|
else
|
||||||
-- Simple physics
|
-- Simple physics
|
||||||
if not v then v = obj:get_velocity() end
|
v = v or obj:get_velocity()
|
||||||
if not a then a = vector.zero() end
|
a = a or vector.zero()
|
||||||
|
|
||||||
if not entity_def.ignore_gravity then
|
if not entity_def.ignore_gravity then
|
||||||
a = a + vector.new(0,-GRAVITY,0)
|
a = a + vector.new(0,-GRAVITY,0)
|
||||||
|
@ -72,8 +72,7 @@ function mod.update_projectile(self, dtime)
|
||||||
-- Run behaviors
|
-- Run behaviors
|
||||||
local behaviors = entity_vl_projectile.behaviors or {}
|
local behaviors = entity_vl_projectile.behaviors or {}
|
||||||
for i=1,#behaviors do
|
for i=1,#behaviors do
|
||||||
local behavior = behaviors[i]
|
if behaviors[i](self, dtime, entity_def, entity_vl_projectile) then
|
||||||
if behavior(self, dtime, entity_def, entity_vl_projectile) then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -81,8 +80,6 @@ function mod.update_projectile(self, dtime)
|
||||||
mod.projectile_physics(self.object, entity_def)
|
mod.projectile_physics(self.object, entity_def)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function no_op()
|
|
||||||
end
|
|
||||||
local function damage_particles(pos, is_critical)
|
local function damage_particles(pos, is_critical)
|
||||||
if is_critical then
|
if is_critical then
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
|
@ -102,20 +99,6 @@ local function damage_particles(pos, is_critical)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
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)
|
local function random_hit_positions(positions, placement)
|
||||||
if positions == "x" then
|
if positions == "x" then
|
||||||
return math.random(-4, 4)
|
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"
|
local placement = self._placement == 1 and "front" or "back"
|
||||||
self._rotation_station = self.placement == 1 and -90 or 90
|
self._rotation_station = self.placement == 1 and -90 or 90
|
||||||
self._in_player = true
|
self._in_player = true
|
||||||
self._y_position = random_arrow_positions("y", placement)
|
self._y_position = random_hit_positions("y", placement)
|
||||||
self._x_position = random_arrow_positions("x", 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
|
if self._y_position > 6 and self._x_position < 2 and self._x_position > -2 then
|
||||||
self._attach_parent = "Head"
|
self._attach_parent = "Head"
|
||||||
self._y_position = self._y_position - 6
|
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"
|
self._attach_parent = "Body"
|
||||||
end
|
end
|
||||||
self._z_rotation = math.random(-30, 30)
|
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(
|
self.object:set_attach(
|
||||||
entity, self._attach_parent,
|
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)
|
vector.new(0, self._rotation_station + self._y_rotation, self._z_rotation)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -226,12 +209,12 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Call entity collied hook
|
-- Call entity collied hook
|
||||||
local hook = projectile_def.on_collide_with_solid or no_op
|
local hook = projectile_def.on_collide_with_solid
|
||||||
hook(self, pos, node, node_def)
|
if hook then hook(self, pos, node, node_def) end
|
||||||
|
|
||||||
-- Call node collided hook
|
-- Call node collided hook
|
||||||
local hook = ((node_def and node_def._vl_projectile) or {}).on_collide or no_op
|
local hook = node_def and node_def._vl_projectile and node_def._vl_projectile.on_collide
|
||||||
hook(self, pos, node, node_def)
|
if hook then hook(self, pos, node, node_def) end
|
||||||
|
|
||||||
-- Play sounds
|
-- Play sounds
|
||||||
local sounds = projectile_def.sounds or {}
|
local sounds = projectile_def.sounds or {}
|
||||||
|
@ -280,7 +263,7 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
|
||||||
do_damage = true
|
do_damage = true
|
||||||
|
|
||||||
handle_player_sticking(self, entity_def, projectile_def, object)
|
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
|
do_damage = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -298,16 +281,17 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Call entity collision hook
|
-- 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
|
-- Call reverse entity collision hook
|
||||||
local other_entity_def = minetest.registered_entities[object.name] or {}
|
local other_entity_def = minetest.registered_entities[object.name] or {}
|
||||||
local other_entity_vl_projectile = other_entity_def._vl_projectile or {}
|
local other_entity_vl_projectile = other_entity_def._vl_projectile or {}
|
||||||
local hook = (other_entity_vl_projectile or {}).on_collide or no_op
|
local hook = other_entity_vl_projectile and other_entity_vl_projectile.on_collide
|
||||||
hook(object, self)
|
if hook then hook(object, self) end
|
||||||
|
|
||||||
-- Play sounds
|
-- Play sounds
|
||||||
local sounds = (projectile_def.sounds or {})
|
local sounds = projectile_def.sounds or {}
|
||||||
local sound = sounds.on_entity_collion or sounds.on_collision
|
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 type(sound) == "function" then sound = sound(self, entity_def, projectile_def, "entity", object) end
|
||||||
if sound then
|
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 entity and entity.name ~= self.object:get_luaentity().name then
|
||||||
if object:is_player() and owner ~= object:get_player_name() then
|
if object:is_player() and owner ~= object:get_player_name() then
|
||||||
return handle_entity_collision(self, entity_def, projectile_def, object)
|
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)
|
return handle_entity_collision(self, entity_def, projectile_def, object)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -347,8 +331,7 @@ function mod.collides_with_entities(self, dtime, entity_def, projectile_def)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_def)
|
function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_def)
|
||||||
local closest_object
|
local closest_object, closest_distance
|
||||||
local closest_distance
|
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local arrow_dir = self.object:get_velocity()
|
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)
|
local obj = minetest.add_entity(pos, entity_id, options.staticdata)
|
||||||
|
|
||||||
-- Set initial velocity and acceleration
|
-- Set initial velocity and acceleration
|
||||||
local v = vector.multiply(options.dir or vector.zero(), options.velocity or 0)
|
local a, v
|
||||||
local a = vector.multiply(v, -math.abs(options.drag))
|
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)
|
mod.projectile_physics(obj, entity_def, v, a)
|
||||||
|
|
||||||
-- Update projectile parameters
|
-- Update projectile parameters
|
||||||
|
|
Loading…
Reference in a new issue