init.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. -- Use whenever you would use `minetest.registered_nodes' but don't need stairs.
  2. minetest.reg_ns_nodes = {}
  3. falldamage = falldamage or {}
  4. falldamage.modpath = minetest.get_modpath("falldamage")
  5. dofile(falldamage.modpath .. "/tilesheet.lua")
  6. dofile(falldamage.modpath .. "/rangecheck.lua")
  7. dofile(falldamage.modpath .. "/liquidinteraction.lua")
  8. local function copy_pointed_thing(pointed_thing)
  9. return {
  10. type = pointed_thing.type,
  11. above = vector.new(pointed_thing.above),
  12. under = vector.new(pointed_thing.under),
  13. ref = pointed_thing.ref,
  14. }
  15. end
  16. local old_register_craftitem = minetest.register_craftitem
  17. function minetest.register_craftitem(name, def2)
  18. local def = table.copy(def2)
  19. if type(def.stack_max) == "nil" then
  20. def.stack_max = 64
  21. end
  22. if type(def.inventory_image) == "string" then
  23. def.inventory_image = image.get(def.inventory_image)
  24. end
  25. if type(def.wield_image) == "string" then
  26. def.wield_image = image.get(def.wield_image)
  27. end
  28. return old_register_craftitem(name, def)
  29. end
  30. local old_register_tool = minetest.register_tool
  31. function minetest.register_tool(name, def)
  32. local ndef = table.copy(def)
  33. if ndef.tool_capabilities then
  34. if ndef.tool_capabilities.range_modifier then
  35. ndef.range = (ndef.range or 4.0) * ndef.tool_capabilities.range_modifier
  36. end
  37. end
  38. return old_register_tool(name, ndef)
  39. end
  40. -- Override minetest.register_node so that we can modify the falling damage GLOBALLY.
  41. local old_register_node = minetest.register_node;
  42. local function register_node(name, def2)
  43. local def = table.copy(def2)
  44. if not def.groups then def.groups = {} end
  45. if not def.groups.fall_damage_add_percent then
  46. def.groups.fall_damage_add_percent = 30
  47. end
  48. -- Any nodes dealing env damage get added to the 'env_damage' group.
  49. if def.damage_per_second ~= 0 then
  50. def.groups.env_damage = 1
  51. end
  52. if not def.movement_speed_multiplier then
  53. if def.drawtype == "nodebox" or def.drawtype == "mesh" then
  54. if not string.find(name, "^vines:") then
  55. def.movement_speed_multiplier = default.SLOW_SPEED
  56. end
  57. end
  58. end
  59. if type(def.stack_max) == "nil" then
  60. def.stack_max = 64
  61. end
  62. -- Every node that overrides 'on_punch' must have its 'on_punch'
  63. -- handler wrapped in one that calls punchnode callbacks.
  64. if def.on_punch then
  65. local on_punch = def.on_punch
  66. def.on_punch = function(pos, node, puncher, pointed_thing)
  67. -- Run script hook
  68. for _, callback in ipairs(core.registered_on_punchnodes) do
  69. -- Copy pos and node because callback can modify them
  70. local pos_copy = vector.new(pos)
  71. local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
  72. local pointed_thing_copy = pointed_thing and copy_pointed_thing(pointed_thing) or nil
  73. callback(pos_copy, node_copy, puncher, pointed_thing_copy)
  74. end
  75. return on_punch(pos, node, puncher, pointed_thing)
  76. end
  77. end
  78. -- If the node defines 'can_dig' then we must create a wrapper
  79. -- that calls 'minetest.is_protected' if that function returns false.
  80. -- This is because the engine will skip the protection check in core.
  81. if def.can_dig then
  82. local can_dig = def.can_dig
  83. function def.can_dig(pos, digger)
  84. local result = can_dig(pos, digger) -- Call old function.
  85. if not result then
  86. -- Old function returned false, we must check protection (because MT core will not do this).
  87. local pname = ""
  88. if digger and digger:is_player() then
  89. pname = digger:get_player_name()
  90. end
  91. if minetest.test_protection(pos, pname) then
  92. protector.punish_player(pos, pname)
  93. end
  94. end
  95. return result
  96. -- If the old function returned true (i.e., player can dig)
  97. -- the MT core will follow up with a protection check.
  98. end
  99. end
  100. if type(def.tiles) == "table" then
  101. for k, v in pairs(def.tiles) do
  102. if type(v) == "string" then
  103. def.tiles[k] = image.get(v)
  104. end
  105. end
  106. end
  107. if type(def.inventory_image) == "string" then
  108. def.inventory_image = image.get(def.inventory_image)
  109. end
  110. if type(def.wield_image) == "string" then
  111. def.wield_image = image.get(def.wield_image)
  112. end
  113. if def.groups.notify_construct and def.groups.notify_construct > 0 then
  114. if def.on_construct then
  115. local old = def.on_construct
  116. def.on_construct = function(pos)
  117. notify.notify_adjacent(pos)
  118. return old(pos)
  119. end
  120. else
  121. def.on_construct = function(pos)
  122. notify.notify_adjacent(pos)
  123. end
  124. end
  125. end
  126. if def.groups.notify_destruct and def.groups.notify_destruct > 0 then
  127. if def.on_destruct then
  128. local old = def.on_destruct
  129. def.on_destruct = function(pos)
  130. notify.notify_adjacent(pos)
  131. return old(pos)
  132. end
  133. else
  134. def.on_destruct = function(pos)
  135. notify.notify_adjacent(pos)
  136. end
  137. end
  138. end
  139. --clumpfall.update_nodedef(name, def)
  140. falldamage.apply_range_checks(def)
  141. falldamage.apply_liquid_interaction_mod(name, def)
  142. old_register_node(name, def)
  143. -- Populate table of all non-stair nodes.
  144. if not name:find("^%:?stairs:") then
  145. local first, second = name:match("^%:?([%w_]+)%:([%w_]+)$")
  146. local n = first .. ":" .. second
  147. local def = minetest.registered_nodes[n]
  148. minetest.reg_ns_nodes[n] = def
  149. end
  150. end
  151. minetest.register_node = register_node
  152. -- Make sure our custom node tables contain entries for air and ignore.
  153. minetest.reg_ns_nodes["air"] = minetest.registered_nodes["air"]
  154. minetest.reg_ns_nodes["ignore"] = minetest.registered_nodes["ignore"]