nodes.lua 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. local S = meseconductors.gettext
  2. function meseconductors:register_wire_block(mod, node)
  3. if minetest.get_modpath(mod) then
  4. if minetest.registered_nodes[mod ..":"..node] == nil then
  5. print("[Meseconductors] - Warning: The mod " .. mod .." has no node ".. node .. " (anymore?)")
  6. return false
  7. end
  8. local offstate = "meseconductors:"..mod.."_"..node
  9. local onstate = "meseconductors:"..mod.."_"..node.."_on"
  10. local description = minetest.registered_nodes[mod ..":"..node].description .. " (conductable)"
  11. local description_on = minetest.registered_nodes[mod ..":"..node].description .. " (conductable - on - NICI)"
  12. local tiles = minetest.registered_nodes[mod ..":"..node].tiles
  13. local overlay_tiles = minetest.registered_nodes[mod ..":"..node].overlay_tiles
  14. local groups = table.copy(minetest.registered_nodes[mod ..":"..node].groups)
  15. if not meseconductors.use_creative_inventory then
  16. groups["not_in_creative_inventory"] = 1
  17. end
  18. local use_texture_alpha = minetest.registered_nodes[mod ..":"..node].use_texture_alpha
  19. local palette = minetest.registered_nodes[mod ..":"..node].palette
  20. local after_place_node = minetest.registered_nodes[mod ..":"..node].after_place_node
  21. local drawtype = minetest.registered_nodes[mod ..":"..node].drawtype
  22. local paramtype = minetest.registered_nodes[mod ..":"..node].paramtype
  23. local paramtype2 = minetest.registered_nodes[mod ..":"..node].paramtype2
  24. local sounds = minetest.registered_nodes[mod ..":"..node].sounds
  25. local sunlight_propagates = minetest.registered_nodes[mod ..":"..node].sunlight_propagates
  26. local light_source = minetest.registered_nodes[mod ..":"..node].light_source
  27. local mesewire_rules =
  28. {
  29. {x = 1, y = 0, z = 0},
  30. {x =-1, y = 0, z = 0},
  31. {x = 0, y = 1, z = 0},
  32. {x = 0, y =-1, z = 0},
  33. {x = 0, y = 0, z = 1},
  34. {x = 0, y = 0, z =-1},
  35. }
  36. minetest.register_node(offstate, {
  37. tiles = tiles,
  38. overlay_tiles = overlay_tiles,
  39. use_texture_alpha = use_texture_alpha,
  40. after_place_node = after_place_node,
  41. description = description,
  42. drawtype = drawtype,
  43. paramtype = paramtype,
  44. paramtype2 = paramtype2,
  45. sounds = sounds,
  46. sunlight_propagates = sunlight_propagates,
  47. light_source = light_source,
  48. mesecons = {conductor = {
  49. state = "off",
  50. onstate = "meseconductors:"..mod.."_"..node.."_on",
  51. rules = mesewire_rules
  52. }},
  53. groups = groups,
  54. })
  55. local textures_on = table.copy(tiles)
  56. if meseconductors.highlight_conducting then
  57. for i = 1, #textures_on, 1 do
  58. local t = textures_on[i]
  59. minetest.log("error", "type " .. type(t))
  60. if type(t) == "string" then
  61. textures_on[i] = t .."^[brighten"
  62. else
  63. textures_on[i] = tiles[i]
  64. end
  65. end
  66. end
  67. local groups_on = table.copy(groups)
  68. --table.insert(groups_on, 1, not_in_creative_inventory)
  69. groups_on["not_in_creative_inventory"] = 1
  70. minetest.register_node(onstate, {
  71. tiles = textures_on,
  72. overlay_tiles = overlay_tiles,
  73. use_texture_alpha = use_texture_alpha,
  74. after_place_node = after_place_node,
  75. drop = offstate,
  76. description = description_on,
  77. drawtype = drawtype,
  78. paramtype = paramtype,
  79. paramtype2 = paramtype2,
  80. sounds = sounds,
  81. sunlight_propagates = sunlight_propagates,
  82. light_source = light_source,
  83. mesecons = {conductor = {
  84. state = "on",
  85. offstate = "meseconductors:"..mod.."_"..node,
  86. rules = mesewire_rules
  87. }},
  88. groups = groups_on,
  89. --groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2},
  90. })
  91. end
  92. end
  93. --added:
  94. --desert_stonebrick, desert_sandstone, desert_sandstone_brick, desert_sandstone_block, silver_sandstone, silver_sandstone_brick, silver_sandstone_block, dirt_with_rainforest_litter, silver_sand, ice
  95. local default_nodes = { "wood", "tree", "dirt", "cobble", "desert_cobble", "sand", "desert_sand",
  96. "stone", "desert_stone","goldblock", "diamondblock", "jungletree","junglewood", "mossycobble",
  97. "obsidian", "obsidian_glass", "glass", "sandstone", "sandstonebrick", "stonebrick",
  98. "pine_tree", "pine_wood", "acacia_tree", "acacia_wood", "brick", "cactus", "aspen_tree", "aspen_wood",
  99. "snowblock", "gravel", "copperblock", "obsidianbrick", "stone_block", "desert_stone_block", "desert_stonebrick",
  100. "desert_sandstone", "desert_sandstone_brick", "desert_sandstone_block", "silver_sand", "silver_sandstone",
  101. "silver_sandstone_brick", "silver_sandstone_block", "dirt_with_rainforest_litter",
  102. "obsidian_block", "sandstone_block", "dirt_with_grass", "dirt_with_snow", "dirt_with_dry_grass", "clay", "ice", "bronzeblock"}
  103. for i in ipairs(default_nodes) do
  104. local node = default_nodes[i]
  105. meseconductors:register_wire_block(
  106. "default",
  107. node)
  108. end
  109. if meseconductors.use_moreblocks then
  110. local moreblocks_nodes = { "super_glow_glass", "glow_glass", "iron_stone_bricks", "grey_bricks",
  111. "clean_glass", "cactus_brick", "stone_tile", "split_stone_tile", "wood_tile", "wood_tile_full",
  112. "cactus_checker", "circle_stone_bricks", "coal_checker", "coal_glass", "coal_stone", "coal_stone_bricks",
  113. "iron_checker", "iron_glass", "iron_stone", "plankstone", "split_stone_tile_alt",
  114. "all_faces_jungle_tree", "all_faces_tree", "cobble_compressed", "copperpatina"}
  115. for i in ipairs(moreblocks_nodes) do
  116. local node = moreblocks_nodes[i]
  117. meseconductors:register_wire_block(
  118. "moreblocks",
  119. node)
  120. end
  121. end
  122. if meseconductors.use_building_blocks then
  123. local building_blocks_nodes = { "Adobe", "hardwood", "Tar", "grate",
  124. "Marble", "woodglass", "smoothglass"}
  125. for i in ipairs(building_blocks_nodes) do
  126. local node = building_blocks_nodes[i]
  127. meseconductors:register_wire_block(
  128. "building_blocks",
  129. node)
  130. end
  131. end
  132. if meseconductors.use_quartz then
  133. local quartz_nodes = { "block", "chiseled", "pillar" , "polish_quartz", "quartzblock", "quartzbrick"}
  134. for i in ipairs(quartz_nodes) do
  135. local node = quartz_nodes[i]
  136. meseconductors:register_wire_block(
  137. "quartz",
  138. node)
  139. end
  140. end
  141. if meseconductors.use_glooptest then
  142. local glooptest_nodes = { "crystal_glass", "reinforced_crystal_glass", "akalin_crystal_glass",
  143. "alatro_crystal_glass", "arol_crystal_glass", "talinite_crystal_glass" }
  144. for i in ipairs(glooptest_nodes) do
  145. local node = glooptest_nodes[i]
  146. meseconductors:register_wire_block(
  147. "glooptest",
  148. node)
  149. end
  150. end
  151. if meseconductors.use_gloopblocks then
  152. local gloopblocks_nodes = { "rainbow_block", "cement", "pavement",
  153. "stone_mossy", "basalt", "cobble_road", "cobble_road_mossy", "evil_block", "pumice", "scaffolding"}
  154. for i in ipairs(gloopblocks_nodes) do
  155. local node = gloopblocks_nodes[i]
  156. meseconductors:register_wire_block(
  157. "gloopblocks",
  158. node)
  159. end
  160. end
  161. if meseconductors.use_moretrees then
  162. local moretrees_nodes = { "beech", "apple_tree", "oak", "sequoia", "birch", "palm", "spruce", "willow", "rubber_tree", "cedar", "date_palm", "poplar"}
  163. for i in ipairs(moretrees_nodes) do
  164. local node = moretrees_nodes[i]
  165. meseconductors:register_wire_block(
  166. "moretrees",
  167. node .. "_trunk")
  168. meseconductors:register_wire_block(
  169. "moretrees",
  170. node .. "_planks")
  171. end
  172. end
  173. if meseconductors.use_technic then
  174. local technic_nodes = { "brass_block", "carbon_steel_block", "cast_iron_block", "chromium_block",
  175. "concrete", "granite", "lead_block", "marble", "marble_bricks", "zinc_block", "blast_resistant_concrete", "stainless_steel_block", "uranium_block"}
  176. for i in ipairs(technic_nodes) do
  177. local node = technic_nodes[i]
  178. meseconductors:register_wire_block(
  179. "technic",
  180. node)
  181. end
  182. -- not working
  183. --meseconductors:register_wire_block(
  184. -- "moretrees",
  185. -- "rubber_tree_trunk")
  186. end
  187. if meseconductors.use_ethereal then
  188. local ethereal_nodes = { "bamboo_dirt", "banana_trunk", "banana_wood", "birch_trunk",
  189. "birch_wood", "bush", "cold_dirt", "crystal_block", "crystal_dirt", "crystal_moss",
  190. "dry_dirt", "fiery_dirt", "fiery_moss", "frost_tree", "frost_wood", "gray_dirt", "gray_moss",
  191. "green_moss", "grove_dirt", "icebrick", "jungle_dirt", "mushroom", "mushroom_dirt", "mushroom_moss",
  192. "mushroom_pore", "mushroom_trunk", "palm_trunk", "palm_wood", "prairie_dirt", "redwood_trunk",
  193. "redwood_wood", "scorched_tree", "snowbrick", "willow_trunk", "willow_wood", "yellow_trunk", "yellow_wood"}
  194. for i in ipairs(ethereal_nodes) do
  195. local node = ethereal_nodes[i]
  196. meseconductors:register_wire_block(
  197. "ethereal",
  198. node)
  199. end
  200. end
  201. if meseconductors.use_moreores then
  202. local moreores_nodes = { "silver_block", "tin_block", "mithril_block"}
  203. for i in ipairs(moreores_nodes) do
  204. local node = moreores_nodes[i]
  205. meseconductors:register_wire_block(
  206. "moreores",
  207. node)
  208. end
  209. end
  210. if meseconductors.use_castle then
  211. local castle_nodes = { "pavement_brick", "dungeon_stone", "rubble", "stonewall", "stonewall_corner"}
  212. for i in ipairs(castle_nodes) do
  213. local node = castle_nodes[i]
  214. meseconductors:register_wire_block(
  215. "castle",
  216. node)
  217. end
  218. end