From 69cd063c435e6671c704f97867dfd4eed764f7c0 Mon Sep 17 00:00:00 2001 From: ElCeejo Date: Mon, 1 May 2023 16:24:25 -0700 Subject: [PATCH] Adjustments to item drop code --- api.lua | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/api.lua b/api.lua index b51d27e..a9bd763 100644 --- a/api.lua +++ b/api.lua @@ -415,17 +415,27 @@ creatura.get_nearby_entities = creatura.get_nearby_objects function creatura.drop_items(self) if not self.drops then return end + local pos = self.object:get_pos() + if not pos then return end + + local drop_def, item_name, min_items, max_items, chance, amount, drop_pos for i = 1, #self.drops do - local drop_def = self.drops[i] - local name = drop_def.name - if not name then return end - local min_amount = drop_def.min or 1 - local max_amount = drop_def.max or 2 - local chance = drop_def.chance or 1 - local amount = random(min_amount, max_amount) + drop_def = self.drops[i] + item_name = drop_def.name + if not item_name then return end + chance = drop_def.chance or 1 + if random(chance) < 2 then - local pos = self.object:get_pos() - local item = minetest.add_item(pos, ItemStack(name .. " " .. amount)) + min_items = drop_def.min or 1 + max_items = drop_def.max or 2 + amount = random(min_items, max_items) + drop_pos = { + x = pos.x + random(-5, 5) * 0.1, + y = pos.y, + z = pos.z + random(-5, 5) * 0.1 + } + + local item = minetest.add_item(drop_pos, ItemStack(item_name .. " " .. amount)) if item then item:add_velocity({ x = random(-2, 2),