item_entity.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. self.object:remove()
  15. local p = self.object:getpos()
  16. minetest.sound_play("default_item_smoke", {
  17. pos = p,
  18. max_hear_distance = 8,
  19. })
  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
  41. self.ignite_timer = (self.ignite_timer or 0) + dtime
  42. if self.ignite_timer > 10 then
  43. self.ignite_timer = 0
  44. local node = minetest.get_node_or_nil(self.object:getpos())
  45. if not node then
  46. return
  47. end
  48. -- Immediately burn up flammable items in lava
  49. if minetest.get_item_group(node.name, "lava") > 0 then
  50. self:burn_up()
  51. else
  52. -- otherwise there'll be a chance based on its igniter value
  53. local burn_chance = self.flammable
  54. * minetest.get_item_group(node.name, "igniter")
  55. if burn_chance > 0 and math.random(0, burn_chance) ~= 0 then
  56. self:burn_up()
  57. end
  58. end
  59. end
  60. end
  61. end,
  62. }
  63. -- set defined item as new __builtin:item, with the old one as fallback table
  64. setmetatable(item, builtin_item)
  65. minetest.register_entity(":__builtin:item", item)