item_entity.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. -- mods/default/item_entity.lua
  2. local builtin_item = minetest.registered_entities["__builtin:item"]
  3. local item = {
  4. set_item = function(self, itemstring)
  5. builtin_item.set_item(self, itemstring)
  6. local stack = ItemStack(itemstring)
  7. local itemdef = minetest.registered_items[stack:get_name()]
  8. if itemdef and itemdef.groups.flammable ~= 0 then
  9. self.flammable = itemdef.groups.flammable
  10. end
  11. end,
  12. burn_up = function(self)
  13. -- disappear in a smoke puff
  14. local p = self.object:get_pos()
  15. self.object:remove()
  16. minetest.sound_play("default_item_smoke", {
  17. pos = p,
  18. max_hear_distance = 8,
  19. }, true)
  20. minetest.add_particlespawner({
  21. amount = 3,
  22. time = 0.1,
  23. minpos = {x = p.x - 0.1, y = p.y + 0.1, z = p.z - 0.1 },
  24. maxpos = {x = p.x + 0.1, y = p.y + 0.2, z = p.z + 0.1 },
  25. minvel = {x = 0, y = 2.5, z = 0},
  26. maxvel = {x = 0, y = 2.5, z = 0},
  27. minacc = {x = -0.15, y = -0.02, z = -0.15},
  28. maxacc = {x = 0.15, y = -0.01, z = 0.15},
  29. minexptime = 4,
  30. maxexptime = 6,
  31. minsize = 5,
  32. maxsize = 5,
  33. collisiondetection = true,
  34. texture = "default_item_smoke.png"
  35. })
  36. end,
  37. on_step = function(self, dtime, ...)
  38. builtin_item.on_step(self, dtime, ...)
  39. if self.flammable then
  40. -- flammable, check for igniters every 10 s
  41. self.ignite_timer = (self.ignite_timer or 0) + dtime
  42. if self.ignite_timer > 10 then
  43. self.ignite_timer = 0
  44. local pos = self.object:get_pos()
  45. if pos == nil then
  46. return -- object already deleted
  47. end
  48. local node = minetest.get_node_or_nil(pos)
  49. if not node then
  50. return
  51. end
  52. -- Immediately burn up flammable items in lava
  53. if minetest.get_item_group(node.name, "lava") > 0 then
  54. self:burn_up()
  55. else
  56. -- otherwise there'll be a chance based on its igniter value
  57. local burn_chance = self.flammable
  58. * minetest.get_item_group(node.name, "igniter")
  59. if burn_chance > 0 and math.random(0, burn_chance) ~= 0 then
  60. self:burn_up()
  61. end
  62. end
  63. end
  64. end
  65. end,
  66. }
  67. -- set defined item as new __builtin:item, with the old one as fallback table
  68. setmetatable(item, builtin_item)
  69. minetest.register_entity(":__builtin:item", item)