firestarting.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local ItemStack, math, minetest, nodecore
  3. = ItemStack, math, minetest, nodecore
  4. local math_random
  5. = math.random
  6. -- LUALOCALS > ---------------------------------------------------------
  7. nodecore.register_craft({
  8. label = "stick fire starting",
  9. action = "pummel",
  10. wield = {
  11. groups = {firestick = true}
  12. },
  13. indexkeys = {"group:firestick"},
  14. nodes = {
  15. {match = {groups = {firestick = true}}}
  16. },
  17. consumewield = 1,
  18. duration = 5,
  19. before = function(pos, data)
  20. local w = data.wield and ItemStack(data.wield):get_name() or ""
  21. local wd = minetest.registered_items[w] or {}
  22. local wg = wd.groups or {}
  23. local fs = wg.firestick or 1
  24. local nd = minetest.registered_items[data.node.name] or {}
  25. local ng = nd.groups or {}
  26. fs = fs * (ng.firestick or 1)
  27. local r = math_random(1, 4)
  28. if r > fs then
  29. nodecore.smokefx(pos, 1, 5 + fs - r)
  30. nodecore.sound_play("nc_api_toolbreak", {pos = pos, gain = 1})
  31. return
  32. end
  33. nodecore.fire_ignite(pos)
  34. minetest.add_particlespawner({
  35. amount = 50,
  36. time = 0.02,
  37. minpos = {x = pos.x, y = pos.y - 0.25, z = pos.z},
  38. maxpos = {x = pos.x, y = pos.y + 0.5, z = pos.z},
  39. minvel = {x = -2, y = 0, z = -2},
  40. maxvel = {x = 2, y = 0, z = 2},
  41. minacc = {x = 0, y = -0.5, z = 0},
  42. maxacc = {x = 0, y = -0.5, z = 0},
  43. minxeptime = 0.4,
  44. maxexptime = 0.5,
  45. minsize = 0.4,
  46. maxsize = 0.5,
  47. texture = "nc_fire_spark.png",
  48. glow = 7
  49. })
  50. if math_random(1, 4) > fs then return end
  51. local dir = nodecore.pickrand(nodecore.dirs())
  52. return nodecore.fire_check_ignite({
  53. x = pos.x + dir.x,
  54. y = pos.y + dir.y,
  55. z = pos.z + dir.z
  56. })
  57. end
  58. })