Compare commits

...

3 Commits

7 changed files with 44 additions and 43 deletions

View File

@ -741,3 +741,12 @@ function mcl_util.get_entity_from_id(id)
return nil
end
function mcl_util.remove_entity(luaentity)
if luaentity._removed then return end
luaentity._removed = true
local hook = luaentity._on_remove
if hook then hook(luaentity) end
luaentity.object:remove()
end

View File

@ -434,14 +434,12 @@ function mcl_mobs.register_arrow(name, def)
minetest.add_item(self.lastpos, self.object:get_luaentity().name)
end
self._removed = true
self.object:remove();
mcl_util.remove_entity(self)
end,
on_collide_with_entity = function(self, pos, object)
if self.hit_player and object:is_player() then
self.hit_player(self, object)
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
return
end
@ -451,13 +449,11 @@ function mcl_mobs.register_arrow(name, def)
if self.hit_mob and entity.is_mob == true then
self.hit_mob(self, object)
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
return
elseif self.hit_object then
self.hit_object(self, object)
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
return
end
end
@ -481,8 +477,7 @@ function mcl_mobs.register_arrow(name, def)
if self.switch == 0 or self.timer > self._lifetime or not within_limits(pos, 0) then
mcl_burning.extinguish(self.object)
self._removed = true
self.object:remove();
mcl_util.remove_entity(self)
return
end

View File

@ -201,8 +201,7 @@ mcl_mobs.register_mob("mobs_mc:wither", {
self._death_timer = self._death_timer + self.health - self._health_old
if self.health == self._health_old then self._death_timer = self._death_timer + dtime end
if self._death_timer > 100 then
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
return false
end
self._health_old = self.health

View File

@ -138,8 +138,9 @@ local arrow_entity = {
-- Because arrows are flagged to survive collisions to allow sticking into blocks, manually remove it now that it
-- has collided with an entity
self._removed = true
self.object:remove()
if not is_player then
mcl_util.remove_entity(self)
end
end
},
@ -186,8 +187,7 @@ local arrow_entity = {
end
if data.stuckin_player then
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
end
end,
}
@ -201,7 +201,7 @@ minetest.register_on_respawnplayer(function(player)
for _, obj in pairs(player:get_children()) do
local ent = obj:get_luaentity()
if ent and ent.name and string.find(ent.name, "mcl_bows:arrow_entity") then
obj:remove()
mcl_util.remove_entity(self)
end
end
end)

View File

@ -241,7 +241,7 @@ minetest.register_craftitem("mcl_bows:rocket", {
local eploded_particle = particle_explosion(pos)
damage_explosion(self, eploded_particle * 17, pos)
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
end
end,
})
@ -268,7 +268,7 @@ rocket_entity.on_step = function(self, dtime)
local eploded_particle = particle_explosion(self)
damage_explosion(self, eploded_particle * 17)
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
return
end

View File

@ -331,8 +331,7 @@ vl_projectile.register("mcl_fishing:flying_bobber_entity", {
on_collide_with_solid = function(self, pos, node)
local player = self._owner
self._remove = true
self.object:remove()
mcl_util.remove_entity(self)
-- Make sure the player field is valid for when we create the floating bobber
if not player then return end

View File

@ -53,8 +53,8 @@ function mod.projectile_physics(obj, entity_def, v, a)
-- Update projectile yaw to match velocity direction
if v and le and not le._stuck then
local yaw = minetest.dir_to_yaw(v) + YAW_OFFSET
local pitch = math.asin(vector.normalize(v).y)
local yaw = minetest.dir_to_yaw(v) + YAW_OFFSET + (entity_def._vl_projectile.yaw_offset or 0)
local pitch = math.asin(vector.normalize(v).y) + (entity_def._vl_projectile.pitch_offset or 0)
obj:set_rotation(vector.new(0,yaw,pitch))
end
end
@ -82,8 +82,7 @@ function mod.update_projectile(self, dtime)
self.timer = (self.timer or 0) + dtime
local maximum_flight_time = entity_vl_projectile.maximum_time or 300
if (self.timer or 0) > maximum_flight_time then
self.removed = true
self.object:remove()
mcl_util.remove_entity(self)
return
end
@ -155,10 +154,7 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity)
if self._in_player or self._blocked then return end
if not projectile_def.sticks_in_players then return end
minetest.after(150, function()
self._removed = true
self.object:remove()
end)
minetest.after(150, function() mcl_util.remove_entity(self) end)
-- Handle blocking projectiles
if mcl_shields.is_blocking(entity) then
@ -256,15 +252,14 @@ function mod.replace_with_item_drop(self, pos, projectile_def)
item = projectile_def.item
end
if self._collectable and not minetest.is_creative_enabled("") then
if item and self._collectable and not minetest.is_creative_enabled("") then
local item = minetest.add_item(pos, item)
item:set_velocity(vector.zero())
item:set_yaw(self.object:get_yaw())
end
mcl_burning.extinguish(self.object)
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
end
local function stuck_on_step(self, dtime, entity_def, projectile_def)
@ -275,8 +270,7 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
self._stucktimer = (self._stucktimer or 0) + dtime
if self._stucktimer > STUCK_TIMEOUT then
mcl_burning.extinguish(self.object)
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
return true
end
@ -295,13 +289,17 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
end
end
-- Don't allow players to pick up arrows stuck in them or other players
if self._in_player then return true end
-- Pickup arrow if player is nearby (not in Creative Mode)
local objects = minetest.get_objects_inside_radius(pos, 1)
for i = 1,#objects do
obj = objects[i]
if obj:is_player() then
if self._collectable and not minetest.is_creative_enabled(obj:get_player_name()) then
local arrow_item = self._arrow_item
local player_name = obj:get_player_name()
if self._collectable and not minetest.is_creative_enabled(player_name) then
local arrow_item = self._itemstring or self._arrow_item
if arrow_item and minetest.registered_items[arrow_item] and obj:get_inventory():room_for_item("main", arrow_item) then
obj:get_inventory():add_item("main", arrow_item)
@ -313,7 +311,7 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
end
end
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
return
end
@ -440,8 +438,7 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
survive_collision = survive_collision(self, entity_def, projectile_def, "node", node, node_def)
end
if not survive_collision then
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
end
-- Done with behaviors
@ -473,6 +470,9 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
local object_lua = object:get_luaentity()
-- Normally objects should be removed on collision with entities
local survive_collision = projectile_def.survive_collision
-- Apply damage
-- Note: Damage blocking for shields is handled in mcl_shields with an mcl_damage modifier
local do_damage = false
@ -480,6 +480,7 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
do_damage = true
handle_player_sticking(self, entity_def, projectile_def, object)
survive_collision = true
elseif object_lua and (object_lua.is_mob or object_lua._hittable_by_projectile) then
do_damage = true
end
@ -525,14 +526,12 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
minetest.sound_play(sound[1], arg2, sound[3])
end
-- Normally objects should be removed on collision with entities
local survive_collision = projectile_def.survive_collision
-- Remove the projectile if it didn't survive
if type(survive_collision) == "function" then
survive_collision = survive_collision(self, entity_def, projectile_def, "entity", object)
end
if not survive_collision then
self._removed = true
self.object:remove()
mcl_util.remove_entity(self)
end
return true