Add the basis of item drop

This commit is contained in:
jordan4ibanez 2023-11-07 21:38:54 -05:00
parent 83e669cb70
commit 4634bf8bbb
2 changed files with 28 additions and 16 deletions

View File

@ -1,9 +1,10 @@
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; function minetest.handle_node_drops(pos, drops, digger)
print("test", pos.x, pos.y, pos.z)
minetest.add_particle({
pos = pos,
texture = "default_dirt.png",
})
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs
function minetest.handle_node_drops(pos, drops, digger)
@ -11,12 +12,17 @@ local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 th
print(dump(drops))
for _, drop in ipairs(drops) do
local item = minetest.add_item(pos, drop)
if item then
(item):add_velocity(vector.new())
(item):add_velocity(
vector.random(
-1, 1,
1, 2,
-1, 1))
end
end
end

View File

@ -1,22 +1,28 @@
function minetest.handle_node_drops(pos: Vec3, drops: {string}, digger: ObjectRef)
print("test", pos.x, pos.y, pos.z)
minetest.add_particle({
pos = pos,
texture = "default_dirt.png"
})
-- print("test", pos.x, pos.y, pos.z)
-- minetest.add_particle({
-- pos = pos,
-- texture = "default_dirt.png"
-- })
--[[
! fixme: Need to look into:
! - drop chance
! - multiple items
unless it's handled automatically of course.
]]
print(dump(drops))
-- Needs to handle multiple drops in an ItemStack.
for _,drop in ipairs(drops) do
local item: ObjectRef = minetest.add_item(pos, drop)
if item then
(item as ObjectRef):add_velocity(vector.new())
(item as ObjectRef):add_velocity(
vector.random(
-1,1,
1,2,
-1,1
)
)
end
end
end