definitions.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. --[[
  2. k_smallblocks is a Minetest mod that adds smaller blocks to minetest aswell as
  3. its own node placement prediction/system
  4. Copyright (C) 2019 Kurtzmusch
  5. This file is part of k_smallblocks
  6. k_smallblocks is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU Lesser General Public License as published by the Free
  8. Software Foundation; either version 2.1 of the License, or (at your option) any
  9. later version.
  10. k_smallblocks is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with k_smallblocks. If not, see <https://www.gnu.org/licenses/>.
  15. --]]
  16. smallblock = {}
  17. halfslab = {}
  18. slab = {}
  19. stair = {}
  20. full_node = {}
  21. common = {} -- common for all nodes
  22. common.on_right_click = function( position, node, clicker, itemstack, pointed_thing )
  23. -- find world coordinates for smallblock removal
  24. local camera_position = clicker:get_pos()
  25. camera_position.y = camera_position.y + clicker:get_properties().eye_height
  26. local raycaster = Raycast(
  27. camera_position,
  28. vector.add( camera_position, vector.multiply(clicker:get_look_dir(), 5) ),
  29. false, false
  30. )
  31. local intersected_thing = raycaster:next()
  32. if( intersected_thing == nil ) then return end
  33. --pushes the intersection inside the face to resolve ambiguity and get a rogh position in the world
  34. local small_normal = vector.divide( intersected_thing.intersection_normal, 4 )
  35. minetest.chat_send_all( small_normal.x .." ".. small_normal.y .." ".. small_normal.z )
  36. small_normal = vector.multiply( small_normal, -1 ) -- reverse vector so it points inside the face
  37. minetest.chat_send_all( small_normal.x .." ".. small_normal.y .." ".. small_normal.z )
  38. local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
  39. local target_node_position = {
  40. x = math.floor(world_rough_position.x+0.5),
  41. y = math.floor(world_rough_position.y+0.5),
  42. z = math.floor(world_rough_position.z+0.5),
  43. }
  44. local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
  45. local bitmap = util.nodePoint_to_bitmap( point_within_node ) -- bitmap representing the smallblock to be removed
  46. local underscore_index
  47. local targetNode_fullName = minetest.get_node( target_node_position ).name
  48. underscore_index = string.find( targetNode_fullName, "_", 3 )
  49. local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
  50. minetest.log( "warning", targetNode_fullName )
  51. minetest.log( "warning", targetNode_materialName )
  52. local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
  53. local colon_index = string.find( targetNode_fullName, ":" )
  54. targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
  55. if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
  56. minetest.chat_send_all( targetNode_bitmapName )
  57. -- find bitmap from name and facedir
  58. local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
  59. local index = 1
  60. for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
  61. if( val_bitmap_name == targetNode_bitmapName ) then
  62. bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
  63. index = index + 1
  64. minetest.chat_send_all( key_bitmap_as_int )
  65. end
  66. end
  67. local targetNode_bitmap
  68. -- find the bitmap that corresponds to the targetNode facedir
  69. for i=1, index-1 do
  70. if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
  71. targetNode_bitmap = bitmap_list[i]
  72. minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
  73. end
  74. end
  75. if( targetNode_bitmap ~= nil ) then --this should always happen
  76. --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
  77. local tnb = util.integer_to_bitmap( targetNode_bitmap )
  78. minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
  79. local finalBitmap = util.xor_bitmap( tnb, bitmap )
  80. if( util.bitmap_to_integer( finalBitmap ) == 0 ) then
  81. minetest.remove_node( target_node_position )
  82. return
  83. end
  84. minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
  85. local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
  86. local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
  87. local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
  88. minetest.swap_node( target_node_position, finalNode )
  89. minetest.chat_send_all( "materials match" )
  90. end
  91. end
  92. smallblock.on_use = function( itemstack, user, pointed_thing )
  93. -- find world coordinates for smallblock placement
  94. local camera_position = user:get_pos()
  95. camera_position.y = camera_position.y + user:get_properties().eye_height
  96. local raycaster = Raycast(
  97. camera_position,
  98. vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
  99. false, false
  100. )
  101. local intersected_thing = raycaster:next()
  102. if( intersected_thing == nil ) then return end
  103. --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
  104. local small_normal = vector.divide( intersected_thing.intersection_normal, 4 )
  105. local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
  106. local target_node_position = {
  107. x = math.floor(world_rough_position.x+0.5),
  108. y = math.floor(world_rough_position.y+0.5),
  109. z = math.floor(world_rough_position.z+0.5),
  110. }
  111. local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
  112. minetest.chat_send_all( "x: "..point_within_node.x )
  113. minetest.chat_send_all( "y: "..point_within_node.y )
  114. minetest.chat_send_all( "z: "..point_within_node.z )
  115. local bitmap = util.nodePoint_to_bitmap( point_within_node )
  116. minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
  117. if( minetest.get_node( target_node_position ).name == "air" ) then
  118. minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
  119. local bitmap_string = ""
  120. for i = 0, 7, 1 do
  121. bitmap_string = bitmap_string .. bitmap[i]
  122. end
  123. minetest.log( bitmap_string )
  124. minetest.set_node( target_node_position, {
  125. name="k_smallblocks:1_stonebrick",
  126. param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
  127. } )
  128. else
  129. local underscore_index
  130. local wieldedNode_fullName = itemstack:get_name()
  131. underscore_index = string.find( wieldedNode_fullName, "_", 3 )
  132. local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
  133. local targetNode_fullName = minetest.get_node( target_node_position ).name
  134. underscore_index = string.find( targetNode_fullName, "_", 3 )
  135. local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
  136. if( targetNode_materialName == wieldedNode_materialName ) then
  137. local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
  138. local colon_index = string.find( targetNode_fullName, ":" )
  139. targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
  140. if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
  141. minetest.chat_send_all( targetNode_bitmapName )
  142. -- find bitmap from name and facedir
  143. local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
  144. local index = 1
  145. for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
  146. if( val_bitmap_name == targetNode_bitmapName ) then
  147. bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
  148. index = index + 1
  149. minetest.chat_send_all( key_bitmap_as_int )
  150. end
  151. end
  152. local targetNode_bitmap
  153. -- find the bitmap that corresponds to the targetNode facedir
  154. for i=1, index-1 do
  155. if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
  156. targetNode_bitmap = bitmap_list[i]
  157. minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
  158. end
  159. end
  160. if( targetNode_bitmap ~= nil ) then --this should always happen
  161. --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
  162. local tnb = util.integer_to_bitmap( targetNode_bitmap )
  163. minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
  164. local finalBitmap = util.or_bitmap( tnb, bitmap )
  165. minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
  166. local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
  167. local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
  168. local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
  169. minetest.swap_node( target_node_position, finalNode )
  170. end
  171. end
  172. end
  173. end
  174. halfslab.on_use = function( itemstack, user, pointed_thing )
  175. -- find world coordinates
  176. local camera_position = user:get_pos()
  177. camera_position.y = camera_position.y + user:get_properties().eye_height
  178. local raycaster = Raycast(
  179. camera_position,
  180. vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
  181. false, false
  182. )
  183. local intersected_thing = raycaster:next()
  184. if( intersected_thing == nil ) then return end
  185. --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
  186. local small_normal = vector.divide( intersected_thing.intersection_normal, 8 )
  187. local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
  188. local target_node_position = {
  189. x = math.floor(world_rough_position.x+0.5),
  190. y = math.floor(world_rough_position.y+0.5),
  191. z = math.floor(world_rough_position.z+0.5),
  192. }
  193. local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
  194. minetest.chat_send_all( "x: "..point_within_node.x )
  195. minetest.chat_send_all( "y: "..point_within_node.y )
  196. minetest.chat_send_all( "z: "..point_within_node.z )
  197. local bitmap4x4 = util.nodePoint_to_bitmap4x4( point_within_node )
  198. local face_type = util.bitmap4x4_to_facetype( bitmap4x4 )
  199. minetest.chat_send_all( face_type )
  200. local bitmap = nil
  201. if( face_type == "edge" ) then
  202. util.bitmap4x4_expand_edge( bitmap4x4 )
  203. bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
  204. end
  205. if( face_type == "corner" ) then
  206. util.bitmap4x4_expand_normal( bitmap4x4, small_normal )
  207. bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
  208. end
  209. if( bitmap ~= nil ) then bitmap = util.array3d_to_bitmap( bitmap )
  210. minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
  211. if( minetest.get_node( target_node_position ).name == "air" ) then --TODO change this so its air or material
  212. minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
  213. local bitmap_string = ""
  214. for i = 0, 7, 1 do
  215. bitmap_string = bitmap_string .. bitmap[i]
  216. end
  217. minetest.log( bitmap_string )
  218. minetest.set_node( target_node_position, {
  219. name="k_smallblocks:3_stonebrick",
  220. param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
  221. } )
  222. else
  223. local underscore_index
  224. local wieldedNode_fullName = itemstack:get_name()
  225. underscore_index = string.find( wieldedNode_fullName, "_", 3 )
  226. local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
  227. local targetNode_fullName = minetest.get_node( target_node_position ).name
  228. underscore_index = string.find( targetNode_fullName, "_", 3 )
  229. local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
  230. if( targetNode_materialName == wieldedNode_materialName ) then
  231. local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
  232. local colon_index = string.find( targetNode_fullName, ":" )
  233. targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
  234. if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
  235. minetest.chat_send_all( targetNode_bitmapName )
  236. -- find bitmap from name and facedir
  237. local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
  238. local index = 1
  239. for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
  240. if( val_bitmap_name == targetNode_bitmapName ) then
  241. bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
  242. index = index + 1
  243. minetest.chat_send_all( key_bitmap_as_int )
  244. end
  245. end
  246. local targetNode_bitmap
  247. -- find the bitmap that corresponds to the targetNode facedir
  248. for i=1, index-1 do
  249. if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
  250. targetNode_bitmap = bitmap_list[i]
  251. minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
  252. end
  253. end
  254. if( targetNode_bitmap ~= nil ) then --this should always happen
  255. --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
  256. local tnb = util.integer_to_bitmap( targetNode_bitmap )
  257. minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
  258. local finalBitmap = util.or_bitmap( tnb, bitmap )
  259. minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
  260. local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
  261. local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
  262. local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
  263. minetest.swap_node( target_node_position, finalNode )
  264. end
  265. end
  266. end
  267. end
  268. end
  269. slab.on_use = function( itemstack, user, pointed_thing )
  270. -- find world coordinates
  271. local camera_position = user:get_pos()
  272. camera_position.y = camera_position.y + user:get_properties().eye_height
  273. local raycaster = Raycast(
  274. camera_position,
  275. vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
  276. false, false
  277. )
  278. local intersected_thing = raycaster:next()
  279. if( intersected_thing == nil ) then return end
  280. --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
  281. local small_normal = vector.divide( intersected_thing.intersection_normal, 8 )
  282. local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
  283. local target_node_position = {
  284. x = math.floor(world_rough_position.x+0.5),
  285. y = math.floor(world_rough_position.y+0.5),
  286. z = math.floor(world_rough_position.z+0.5),
  287. }
  288. local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
  289. minetest.chat_send_all( "x: "..point_within_node.x )
  290. minetest.chat_send_all( "y: "..point_within_node.y )
  291. minetest.chat_send_all( "z: "..point_within_node.z )
  292. local bitmap4x4 = util.nodePoint_to_bitmap4x4( point_within_node )
  293. local face_type = util.bitmap4x4_to_facetype( bitmap4x4 )
  294. minetest.chat_send_all( face_type )
  295. local bitmap = nil
  296. if( face_type == "edge" ) then
  297. util.bitmap4x4_expand_edge( bitmap4x4 )
  298. util.bitmap4x4_expand_normal( bitmap4x4, small_normal )
  299. bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
  300. end
  301. if( face_type == "face" ) then
  302. util.bitmap4x4_expand_face( bitmap4x4 )
  303. bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
  304. end
  305. if( bitmap ~= nil ) then bitmap = util.array3d_to_bitmap( bitmap )
  306. minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
  307. if( minetest.get_node( target_node_position ).name == "air" ) then --TODO change this so its air or material
  308. minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
  309. local bitmap_string = ""
  310. for i = 0, 7, 1 do
  311. bitmap_string = bitmap_string .. bitmap[i]
  312. end
  313. minetest.log( bitmap_string )
  314. minetest.set_node( target_node_position, {
  315. name="k_smallblocks:15_stonebrick",
  316. param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
  317. } )
  318. else
  319. local underscore_index
  320. local wieldedNode_fullName = itemstack:get_name()
  321. underscore_index = string.find( wieldedNode_fullName, "_", 3 )
  322. local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
  323. local targetNode_fullName = minetest.get_node( target_node_position ).name
  324. underscore_index = string.find( targetNode_fullName, "_", 3 )
  325. local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
  326. if( targetNode_materialName == wieldedNode_materialName ) then
  327. local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
  328. local colon_index = string.find( targetNode_fullName, ":" )
  329. targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
  330. if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
  331. minetest.chat_send_all( targetNode_bitmapName )
  332. -- find bitmap from name and facedir
  333. local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
  334. local index = 1
  335. for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
  336. if( val_bitmap_name == targetNode_bitmapName ) then
  337. bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
  338. index = index + 1
  339. minetest.chat_send_all( key_bitmap_as_int )
  340. end
  341. end
  342. local targetNode_bitmap
  343. -- find the bitmap that corresponds to the targetNode facedir
  344. for i=1, index-1 do
  345. if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
  346. targetNode_bitmap = bitmap_list[i]
  347. minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
  348. end
  349. end
  350. if( targetNode_bitmap ~= nil ) then --this should always happen
  351. --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
  352. local tnb = util.integer_to_bitmap( targetNode_bitmap )
  353. minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
  354. local finalBitmap = util.or_bitmap( tnb, bitmap )
  355. minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
  356. local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
  357. local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
  358. local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
  359. minetest.swap_node( target_node_position, finalNode )
  360. end
  361. end
  362. end
  363. end
  364. end
  365. stair.on_use = function( itemstack, user, pointed_thing )
  366. -- find world coordinates
  367. local camera_position = user:get_pos()
  368. camera_position.y = camera_position.y + user:get_properties().eye_height
  369. local raycaster = Raycast(
  370. camera_position,
  371. vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
  372. false, false
  373. )
  374. local intersected_thing = raycaster:next()
  375. if( intersected_thing == nil ) then return end
  376. --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
  377. local small_normal = vector.divide( intersected_thing.intersection_normal, 8 )
  378. local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
  379. local target_node_position = {
  380. x = math.floor(world_rough_position.x+0.5),
  381. y = math.floor(world_rough_position.y+0.5),
  382. z = math.floor(world_rough_position.z+0.5),
  383. }
  384. local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
  385. minetest.chat_send_all( "x: "..point_within_node.x )
  386. minetest.chat_send_all( "y: "..point_within_node.y )
  387. minetest.chat_send_all( "z: "..point_within_node.z )
  388. local bitmap4x4 = util.nodePoint_to_bitmap4x4( point_within_node )
  389. local face_type = util.bitmap4x4_to_facetype( bitmap4x4 )
  390. minetest.chat_send_all( face_type )
  391. local bitmap = nil
  392. if( face_type == "edge" ) then
  393. util.bitmap4x4_expand_edge( bitmap4x4 )
  394. util.bitmap4x4_expand_faces( bitmap4x4 )
  395. bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
  396. end
  397. if( face_type == "corner" ) then
  398. util.bitmap4x4_expand_normal( bitmap4x4, small_normal )
  399. util.bitmap4x4_expand_faces( bitmap4x4 )
  400. bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
  401. end
  402. if( bitmap ~= nil ) then bitmap = util.array3d_to_bitmap( bitmap )
  403. minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
  404. if( minetest.get_node( target_node_position ).name == "air" ) then --TODO change this so its air or material
  405. minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
  406. local bitmap_string = ""
  407. for i = 0, 7, 1 do
  408. bitmap_string = bitmap_string .. bitmap[i]
  409. end
  410. minetest.log( bitmap_string )
  411. minetest.set_node( target_node_position, {
  412. name="k_smallblocks:63_stonebrick",
  413. param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
  414. } )
  415. else
  416. local underscore_index
  417. local wieldedNode_fullName = itemstack:get_name()
  418. underscore_index = string.find( wieldedNode_fullName, "_", 3 )
  419. local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
  420. local targetNode_fullName = minetest.get_node( target_node_position ).name
  421. underscore_index = string.find( targetNode_fullName, "_", 3 )
  422. local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
  423. if( targetNode_materialName == wieldedNode_materialName ) then
  424. local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
  425. local colon_index = string.find( targetNode_fullName, ":" )
  426. targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
  427. if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
  428. minetest.chat_send_all( targetNode_bitmapName )
  429. -- find bitmap from name and facedir
  430. local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
  431. local index = 1
  432. for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
  433. if( val_bitmap_name == targetNode_bitmapName ) then
  434. bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
  435. index = index + 1
  436. minetest.chat_send_all( key_bitmap_as_int )
  437. end
  438. end
  439. local targetNode_bitmap
  440. -- find the bitmap that corresponds to the targetNode facedir
  441. for i=1, index-1 do
  442. if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
  443. targetNode_bitmap = bitmap_list[i]
  444. minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
  445. end
  446. end
  447. if( targetNode_bitmap ~= nil ) then --this should always happen
  448. --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
  449. local tnb = util.integer_to_bitmap( targetNode_bitmap )
  450. minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
  451. local finalBitmap = util.or_bitmap( tnb, bitmap )
  452. minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
  453. local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
  454. local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
  455. local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
  456. minetest.swap_node( target_node_position, finalNode )
  457. end
  458. end
  459. end
  460. end
  461. end
  462. bitmap_name_definition_map = { -- maps a bitmap name to a definiton
  463. [1] = {
  464. name = "smallblock",
  465. description = "smallblock",
  466. on_use = smallblock.on_use,
  467. on_rightclick = common.on_right_click
  468. },
  469. [3] = {
  470. name = "halfslab",
  471. description = "half-slab",
  472. on_use = halfslab.on_use,
  473. on_rightclick = common.on_right_click
  474. },
  475. [15] = {
  476. name = "slab",
  477. description = "slab",
  478. on_use = slab.on_use,
  479. on_rightclick = common.on_right_click
  480. },
  481. [63] = {
  482. name = "stair",
  483. description = "stair",
  484. on_use = stair.on_use,
  485. on_rightclick = common.on_right_click
  486. }
  487. }