Adjustments to item drop code

This commit is contained in:
ElCeejo 2023-05-01 16:24:25 -07:00
parent 36284a04fc
commit 69cd063c43

28
api.lua
View file

@ -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),