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