init.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --U.N.C.M: Unbreakable Node Clone Maker - By Genshin
  2. local path = minetest.get_modpath("uncm")
  3. local nodes_cloned = false
  4. local count = 0
  5. print("[Unbreakable Node Clone Maker] Activated!")
  6. --Dupe dem nodes! :D
  7. local register_unbreakable_duplicate_node = function(name, def)
  8. local nodename = "uncm:"..name
  9. count = count + 1
  10. --Don't even ask...
  11. minetest.register_node(nodename,{
  12. description = def.description.." (Unbreakable)",
  13. drawtype = def.drawtype,
  14. mesh = def.mesh, --For fancy schmancy modelers that made nice looking custom nodes
  15. visual_scale = def.visual_scale,
  16. tiles = def.tiles,
  17. groups = {unbreakable = 1, not_in_creative_inventory = 1},
  18. special_tiles = def. special_tiles,
  19. use_texture_alpha = def.use_texture_alpha,
  20. alpha = def.alpha,
  21. post_effect_color = def.post_effect_color,
  22. inventory_image = def.inventory_image,
  23. wield_image = def.wield_image,
  24. paramtype = def.paramtype,
  25. none = def.none, --I don't even know why this key exists on the node registration table... ¯\_(ツ)_/¯
  26. light = def.light,
  27. paramtype2 = def.paramtype2,
  28. wallmounted = def.wallmounted,
  29. facedir = def.facedir,
  30. is_ground_content = def.is_ground_content,
  31. sunlight_propagates = def.sunlight_propagates,
  32. walkable = def.walkable,
  33. pointable = def.pointable,
  34. diggable = def.diggable,
  35. climbable = def.climbable,
  36. buildable_to = def.buildable_to,
  37. drop = def.drop,
  38. stack_max = def.stack_max,
  39. liquidtype = def.liquidtype,
  40. liquid_alternative_flowing = def.liquid_alternative_flowing,
  41. liquid_alternative_source = def.liquid_alternative_source,
  42. liquid_viscosity = def.liquid_viscosity,
  43. liquid_renewable = def.liquid_renewable,
  44. light_source = def.light_source,
  45. damage_per_second = def.damage_per_second,
  46. node_box = def.node_box,
  47. selection_box = def.selection_box,
  48. collision_box = def.collision_box,
  49. legacy_facedir_simple = def.legacy_facedir_simple,
  50. legacy_wallmounted = def.legacy_wallmounted,
  51. sounds = def.sounds,
  52. dig = def.dig,
  53. dug = def.dug,
  54. on_construct = def.on_construct,
  55. on_destruct = def.on_destruct,
  56. after_destruct = def.after_destruct,
  57. on_place = def.on_place,
  58. on_drop = def.on_drop,
  59. on_use = def.on_use,
  60. on_punch = def.on_punch,
  61. on_blast = function() end, --Ignores explosions
  62. on_dig = def.on_dig,
  63. on_timer = def.on_timer,
  64. on_receive_fields = def.on_receive_fields,
  65. allow_metadata_inventory_move = def.allow_metadata_inventory_move,
  66. allow_metadata_inventory_put = def.allow_metadata_inventory_put,
  67. allow_metadata_inventory_take = def.allow_metadata_inventory_take,
  68. on_metadata_inventory_move = def.on_metadata_inventory_move,
  69. on_metadata_inventory_put = def.on_metadata_inventory_put,
  70. on_metadata_inventory_take = def.on_metadata_inventory_take,
  71. after_place_node = def.after_place_node,
  72. can_dig = def.can_dig,
  73. after_dig_node = def.after_dig_node,
  74. on_rightclick = def.on_rightclick,
  75. on_blast = def.on_blast,
  76. })
  77. --And alias this node too so /give would be convenient
  78. minetest.register_alias("unb_"..name, nodename)
  79. end
  80. --The Node Duplication Code
  81. if nodes_cloned == false then
  82. --Go through every registered node from the game
  83. for k,v in pairs(minetest.registered_nodes) do
  84. local get = tostring(string.match(tostring(k), ":[%w_]+"))
  85. local nodename = tostring(string.match(get, "[%w_]+")) --only get the name of the node without naming convention
  86. local nodedef = v
  87. --Dont make a duplicate of yourself
  88. if k == "uncm:"..nodename then
  89. elseif --Would be pointless to duplicate airlike, liquids or things that are unbreakable or not in creative inventory already...
  90. not (nodedef.drawtype == "airlike" or nodedef.drawtype == "liquid" or nodedef.drawtype == "flowingliquid" or nodedef.groups["unbreakable"] == 1 or nodedef.groups["not_in_creative_inventory"] == 1 ) then
  91. minetest.log("action", "registered node \""..k.."\" is being duplicated.")
  92. register_unbreakable_duplicate_node(nodename, nodedef)
  93. end
  94. end
  95. nodes_cloned = true
  96. end
  97. --To see results, look at your logs :P
  98. minetest.log("action", count.." registered nodes were successfully duplicated, each copied node are unbreakable and properly aliased!")
  99. print("[Unbreakable Node Clone Maker] Node duplication procedure completed!")