init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. -- Mod is reloadable.
  2. if not minetest.global_exists("jumping") then jumping = {} end
  3. jumping.modpath = minetest.get_modpath("jumping")
  4. local next_node = {
  5. ["jumping:bouncer_1"] = "jumping:bouncer_2",
  6. ["jumping:bouncer_2"] = "jumping:bouncer_3",
  7. ["jumping:bouncer_3"] = "jumping:bouncer_4",
  8. ["jumping:bouncer_4"] = "jumping:bouncer_5",
  9. ["jumping:bouncer_5"] = "jumping:bouncer_6",
  10. ["jumping:bouncer_6"] = "jumping:bouncer_7",
  11. ["jumping:bouncer_7"] = "jumping:bouncer_1",
  12. }
  13. local node_info = {
  14. ["jumping:bouncer_1"] = "1",
  15. ["jumping:bouncer_2"] = "2",
  16. ["jumping:bouncer_3"] = "3",
  17. ["jumping:bouncer_4"] = "4",
  18. ["jumping:bouncer_5"] = "5",
  19. ["jumping:bouncer_6"] = "6",
  20. ["jumping:bouncer_7"] = "7",
  21. }
  22. function jumping.set_infotext(pos)
  23. local node = minetest.get_node(pos)
  24. local meta = minetest.get_meta(pos)
  25. meta:set_string("infotext", "Bouncer: Strength " .. node_info[node.name])
  26. end
  27. function jumping.on_bouncer_punch(pos, node, puncher, pt)
  28. if not puncher or not puncher:is_player() then
  29. return
  30. end
  31. local pname = puncher:get_player_name()
  32. if minetest.test_protection(pos, pname) then
  33. minetest.chat_send_player(pname, "# Server: Bouncer is protected!")
  34. return
  35. end
  36. local nn = next_node[node.name]
  37. local cn = minetest.get_node(pos)
  38. cn.name = nn
  39. minetest.swap_node(pos, cn)
  40. jumping.set_infotext(pos)
  41. end
  42. -- One-time execution goes here.
  43. if not jumping.run_once then
  44. for i = 1, 7, 1 do
  45. minetest.register_node("jumping:bouncer_"..i, {
  46. description = "Bouncing Cube",
  47. paramtype = "light",
  48. tiles = {"jumping_bouncer.png"},
  49. groups = utility.dig_groups("furniture", {
  50. bouncy = 20 + (i * 15),
  51. fall_damage_add_percent = -50,
  52. }),
  53. drop = "jumping:bouncer_1",
  54. on_construct = function(...)
  55. return jumping.set_infotext(...)
  56. end,
  57. on_punch = function(...)
  58. return jumping.on_bouncer_punch(...)
  59. end,
  60. })
  61. end
  62. minetest.register_node("jumping:cushion", {
  63. description = "Falling Cushion",
  64. paramtype = "light",
  65. tiles = {"jumping_cushion.png"},
  66. groups = utility.dig_groups("furniture", {
  67. disable_jump = 1,
  68. fall_damage_add_percent = -70,
  69. }),
  70. })
  71. minetest.register_craft({
  72. output = "jumping:bouncer_1",
  73. recipe = {
  74. {"default:steel_ingot", "wool:black", "default:steel_ingot"},
  75. {"wool:black", "wool:black", "wool:black"},
  76. {"default:steel_ingot", "wool:black", "default:steel_ingot"}
  77. }
  78. })
  79. minetest.register_craft({
  80. output = "jumping:cushion",
  81. recipe = {
  82. {"default:steel_ingot", "wool:cyan", "default:steel_ingot"},
  83. {"wool:cyan", "wool:cyan", "wool:cyan"},
  84. {"default:steel_ingot", "wool:cyan", "default:steel_ingot"}
  85. }
  86. })
  87. local c = "jumping:core"
  88. local f = jumping.modpath .. "/init.lua"
  89. reload.register_file(c, f, false)
  90. jumping.run_once = true
  91. end