From ba7dec1fdc679dd1f542d2fb2f3c70a69da15c0c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 25 Nov 2023 01:13:29 +0100 Subject: [PATCH] Add velocity to mob drops --- mods/rp_mobs/api.lua | 16 ++++++++++++++-- mods/rp_mobs_mobs/sheep.lua | 9 +-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/mods/rp_mobs/api.lua b/mods/rp_mobs/api.lua index 123e925f..9c76206e 100644 --- a/mods/rp_mobs/api.lua +++ b/mods/rp_mobs/api.lua @@ -145,6 +145,18 @@ rp_mobs.is_alive = function(mob) end end +rp_mobs.spawn_mob_drop = function(pos, item) + local obj = minetest.add_item(pos, item) + if obj then + obj:set_velocity({ + x = math.random(-1, 1), + y = 5, + z = math.random(-1, 1) + }) + end + return obj +end + rp_mobs.drop_death_items = function(self, pos) if not pos then pos = self.object:get_pos() @@ -155,12 +167,12 @@ rp_mobs.drop_death_items = function(self, pos) end if not self._child and mobdef.drops then for d=1, #mobdef.drops do - minetest.add_item(pos, mobdef.drops[d]) + rp_mobs.spawn_mob_drop(pos, mobdef.drops[d]) end end if self._child and mobdef.child_drops then for d=1, #mobdef.child_drops do - minetest.add_item(pos, mobdef.child_drops[d]) + rp_mobs.spawn_mob_drop(pos, mobdef.child_drops[d]) end end end diff --git a/mods/rp_mobs_mobs/sheep.lua b/mods/rp_mobs_mobs/sheep.lua index b4531d54..5a1a196d 100644 --- a/mods/rp_mobs_mobs/sheep.lua +++ b/mods/rp_mobs_mobs/sheep.lua @@ -163,15 +163,8 @@ rp_mobs.register_mob("rp_mobs_mobs:sheep", { self._custom_state.shorn = true local pos = self.object:get_pos() pos.y = pos.y + 0.5 - local obj = minetest.add_item(pos, ItemStack("mobs:wool")) + local obj = rp_mobs.spawn_mob_drop(pos, ItemStack("mobs:wool")) minetest.sound_play({name = "default_shears_cut", gain = 0.5}, {pos = clicker:get_pos(), max_hear_distance = 8}, true) - if obj then - obj:set_velocity({ - x = math.random(-1,1), - y = 5, - z = math.random(-1,1) - }) - end if not minetest.is_creative_enabled(clicker:get_player_name()) then local def = item:get_definition() local cuts = minetest.get_item_group(itemname, "sheep_cuts")