init.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. if not def.movement_speed_multiplier then
  49. if def.drawtype == "nodebox" or def.drawtype == "mesh" then
  50. if not string.find(name, "^vines:") then
  51. def.movement_speed_multiplier = default.SLOW_SPEED
  52. end
  53. end
  54. end
  55. if type(def.stack_max) == "nil" then
  56. def.stack_max = 64
  57. end
  58. -- Every node that overrides 'on_punch' must have its 'on_punch'
  59. -- handler wrapped in one that calls punchnode callbacks.
  60. if def.on_punch then
  61. local on_punch = def.on_punch
  62. def.on_punch = function(pos, node, puncher, pointed_thing)
  63. -- Run script hook
  64. for _, callback in ipairs(core.registered_on_punchnodes) do
  65. -- Copy pos and node because callback can modify them
  66. local pos_copy = vector.new(pos)
  67. local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
  68. local pointed_thing_copy = pointed_thing and copy_pointed_thing(pointed_thing) or nil
  69. callback(pos_copy, node_copy, puncher, pointed_thing_copy)
  70. end
  71. return on_punch(pos, node, puncher, pointed_thing)
  72. end
  73. end
  74. -- If the node defines 'can_dig' then we must create a wrapper
  75. -- that calls 'minetest.is_protected' if that function returns false.
  76. -- This is because the engine will skip the protection check in core.
  77. if def.can_dig then
  78. local can_dig = def.can_dig
  79. function def.can_dig(pos, digger)
  80. local result = can_dig(pos, digger) -- Call old function.
  81. if not result then
  82. -- Old function returned false, we must check protection (because MT core will not do this).
  83. local pname = ""
  84. if digger and digger:is_player() then
  85. pname = digger:get_player_name()
  86. end
  87. if minetest.test_protection(pos, pname) then
  88. protector.punish_player(pos, pname)
  89. end
  90. end
  91. return result
  92. -- If the old function returned true (i.e., player can dig)
  93. -- the MT core will follow up with a protection check.
  94. end
  95. end
  96. if type(def.tiles) == "table" then
  97. for k, v in pairs(def.tiles) do
  98. if type(v) == "string" then
  99. def.tiles[k] = image.get(v)
  100. end
  101. end
  102. end
  103. if type(def.inventory_image) == "string" then
  104. def.inventory_image = image.get(def.inventory_image)
  105. end
  106. if type(def.wield_image) == "string" then
  107. def.wield_image = image.get(def.wield_image)
  108. end
  109. if def.groups.notify_construct and def.groups.notify_construct > 0 then
  110. if def.on_construct then
  111. local old = def.on_construct
  112. def.on_construct = function(pos)
  113. notify.notify_adjacent(pos)
  114. return old(pos)
  115. end
  116. else
  117. def.on_construct = function(pos)
  118. notify.notify_adjacent(pos)
  119. end
  120. end
  121. end
  122. if def.groups.notify_destruct and def.groups.notify_destruct > 0 then
  123. if def.on_destruct then
  124. local old = def.on_destruct
  125. def.on_destruct = function(pos)
  126. notify.notify_adjacent(pos)
  127. return old(pos)
  128. end
  129. else
  130. def.on_destruct = function(pos)
  131. notify.notify_adjacent(pos)
  132. end
  133. end
  134. end
  135. --clumpfall.update_nodedef(name, def)
  136. falldamage.apply_range_checks(def)
  137. falldamage.apply_liquid_interaction_mod(name, def)
  138. old_register_node(name, def)
  139. -- Populate table of all non-stair nodes.
  140. if not name:find("^%:?stairs:") then
  141. local first, second = name:match("^%:?([%w_]+)%:([%w_]+)$")
  142. local n = first .. ":" .. second
  143. local def = minetest.registered_nodes[n]
  144. minetest.reg_ns_nodes[n] = def
  145. end
  146. end
  147. minetest.register_node = register_node
  148. -- Make sure our custom node tables contain entries for air and ignore.
  149. minetest.reg_ns_nodes["air"] = minetest.registered_nodes["air"]
  150. minetest.reg_ns_nodes["ignore"] = minetest.registered_nodes["ignore"]