123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- --[[
- k_smallblocks is a Minetest mod that adds smaller blocks to minetest aswell as
- its own node placement prediction/system
- Copyright (C) 2019 Kurtzmusch
- This file is part of k_smallblocks
- k_smallblocks is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the Free
- Software Foundation; either version 2.1 of the License, or (at your option) any
- later version.
- k_smallblocks is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along
- with k_smallblocks. If not, see <https://www.gnu.org/licenses/>.
- --]]
- smallblock = {}
- halfslab = {}
- slab = {}
- stair = {}
- full_node = {}
- common = {} -- common for all nodes
- common.on_right_click = function( position, node, clicker, itemstack, pointed_thing )
- -- find world coordinates for smallblock removal
- local camera_position = clicker:get_pos()
- camera_position.y = camera_position.y + clicker:get_properties().eye_height
- local raycaster = Raycast(
- camera_position,
- vector.add( camera_position, vector.multiply(clicker:get_look_dir(), 5) ),
- false, false
- )
- local intersected_thing = raycaster:next()
- if( intersected_thing == nil ) then return end
- --pushes the intersection inside the face to resolve ambiguity and get a rogh position in the world
- local small_normal = vector.divide( intersected_thing.intersection_normal, 4 )
- minetest.chat_send_all( small_normal.x .." ".. small_normal.y .." ".. small_normal.z )
- small_normal = vector.multiply( small_normal, -1 ) -- reverse vector so it points inside the face
- minetest.chat_send_all( small_normal.x .." ".. small_normal.y .." ".. small_normal.z )
- local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
-
- local target_node_position = {
- x = math.floor(world_rough_position.x+0.5),
- y = math.floor(world_rough_position.y+0.5),
- z = math.floor(world_rough_position.z+0.5),
- }
- local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
- local bitmap = util.nodePoint_to_bitmap( point_within_node ) -- bitmap representing the smallblock to be removed
- local underscore_index
- local targetNode_fullName = minetest.get_node( target_node_position ).name
- underscore_index = string.find( targetNode_fullName, "_", 3 )
- local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
- minetest.log( "warning", targetNode_fullName )
- minetest.log( "warning", targetNode_materialName )
-
- local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
- local colon_index = string.find( targetNode_fullName, ":" )
- targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
- if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
- minetest.chat_send_all( targetNode_bitmapName )
- -- find bitmap from name and facedir
- local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
- local index = 1
- for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
- if( val_bitmap_name == targetNode_bitmapName ) then
- bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
- index = index + 1
- minetest.chat_send_all( key_bitmap_as_int )
- end
- end
- local targetNode_bitmap
- -- find the bitmap that corresponds to the targetNode facedir
- for i=1, index-1 do
- if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
- targetNode_bitmap = bitmap_list[i]
- minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
- end
- end
- if( targetNode_bitmap ~= nil ) then --this should always happen
- --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
- local tnb = util.integer_to_bitmap( targetNode_bitmap )
- minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
- local finalBitmap = util.xor_bitmap( tnb, bitmap )
- if( util.bitmap_to_integer( finalBitmap ) == 0 ) then
- minetest.remove_node( target_node_position )
- return
- end
- minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
- local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
- minetest.swap_node( target_node_position, finalNode )
- minetest.chat_send_all( "materials match" )
- end
-
- end
- smallblock.on_use = function( itemstack, user, pointed_thing )
- -- find world coordinates for smallblock placement
- local camera_position = user:get_pos()
- camera_position.y = camera_position.y + user:get_properties().eye_height
- local raycaster = Raycast(
- camera_position,
- vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
- false, false
- )
- local intersected_thing = raycaster:next()
- if( intersected_thing == nil ) then return end
- --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
- local small_normal = vector.divide( intersected_thing.intersection_normal, 4 )
- local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
-
- local target_node_position = {
- x = math.floor(world_rough_position.x+0.5),
- y = math.floor(world_rough_position.y+0.5),
- z = math.floor(world_rough_position.z+0.5),
- }
- local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
- minetest.chat_send_all( "x: "..point_within_node.x )
- minetest.chat_send_all( "y: "..point_within_node.y )
- minetest.chat_send_all( "z: "..point_within_node.z )
- local bitmap = util.nodePoint_to_bitmap( point_within_node )
- minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
- if( minetest.get_node( target_node_position ).name == "air" ) then
- minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
- local bitmap_string = ""
- for i = 0, 7, 1 do
- bitmap_string = bitmap_string .. bitmap[i]
- end
- minetest.log( bitmap_string )
- minetest.set_node( target_node_position, {
- name="k_smallblocks:1_stonebrick",
- param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
- } )
- else
- local underscore_index
- local wieldedNode_fullName = itemstack:get_name()
- underscore_index = string.find( wieldedNode_fullName, "_", 3 )
- local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
- local targetNode_fullName = minetest.get_node( target_node_position ).name
- underscore_index = string.find( targetNode_fullName, "_", 3 )
- local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
-
- if( targetNode_materialName == wieldedNode_materialName ) then
- local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
- local colon_index = string.find( targetNode_fullName, ":" )
- targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
- if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
- minetest.chat_send_all( targetNode_bitmapName )
- -- find bitmap from name and facedir
- local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
- local index = 1
- for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
- if( val_bitmap_name == targetNode_bitmapName ) then
- bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
- index = index + 1
- minetest.chat_send_all( key_bitmap_as_int )
- end
- end
- local targetNode_bitmap
- -- find the bitmap that corresponds to the targetNode facedir
- for i=1, index-1 do
- if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
- targetNode_bitmap = bitmap_list[i]
- minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
- end
- end
- if( targetNode_bitmap ~= nil ) then --this should always happen
- --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
- local tnb = util.integer_to_bitmap( targetNode_bitmap )
- minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
- local finalBitmap = util.or_bitmap( tnb, bitmap )
- minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
- local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
- minetest.swap_node( target_node_position, finalNode )
- end
- end
- end
- end
- halfslab.on_use = function( itemstack, user, pointed_thing )
- -- find world coordinates
- local camera_position = user:get_pos()
- camera_position.y = camera_position.y + user:get_properties().eye_height
- local raycaster = Raycast(
- camera_position,
- vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
- false, false
- )
- local intersected_thing = raycaster:next()
- if( intersected_thing == nil ) then return end
- --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
- local small_normal = vector.divide( intersected_thing.intersection_normal, 8 )
- local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
-
- local target_node_position = {
- x = math.floor(world_rough_position.x+0.5),
- y = math.floor(world_rough_position.y+0.5),
- z = math.floor(world_rough_position.z+0.5),
- }
- local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
- minetest.chat_send_all( "x: "..point_within_node.x )
- minetest.chat_send_all( "y: "..point_within_node.y )
- minetest.chat_send_all( "z: "..point_within_node.z )
- local bitmap4x4 = util.nodePoint_to_bitmap4x4( point_within_node )
- local face_type = util.bitmap4x4_to_facetype( bitmap4x4 )
- minetest.chat_send_all( face_type )
- local bitmap = nil
- if( face_type == "edge" ) then
- util.bitmap4x4_expand_edge( bitmap4x4 )
-
- bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
- end
- if( face_type == "corner" ) then
- util.bitmap4x4_expand_normal( bitmap4x4, small_normal )
- bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
- end
- if( bitmap ~= nil ) then bitmap = util.array3d_to_bitmap( bitmap )
- minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
- if( minetest.get_node( target_node_position ).name == "air" ) then --TODO change this so its air or material
- minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
- local bitmap_string = ""
- for i = 0, 7, 1 do
- bitmap_string = bitmap_string .. bitmap[i]
- end
- minetest.log( bitmap_string )
- minetest.set_node( target_node_position, {
- name="k_smallblocks:3_stonebrick",
- param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
- } )
- else
- local underscore_index
- local wieldedNode_fullName = itemstack:get_name()
- underscore_index = string.find( wieldedNode_fullName, "_", 3 )
- local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
- local targetNode_fullName = minetest.get_node( target_node_position ).name
- underscore_index = string.find( targetNode_fullName, "_", 3 )
- local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
-
- if( targetNode_materialName == wieldedNode_materialName ) then
- local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
- local colon_index = string.find( targetNode_fullName, ":" )
- targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
- if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
- minetest.chat_send_all( targetNode_bitmapName )
- -- find bitmap from name and facedir
- local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
- local index = 1
- for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
- if( val_bitmap_name == targetNode_bitmapName ) then
- bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
- index = index + 1
- minetest.chat_send_all( key_bitmap_as_int )
- end
- end
- local targetNode_bitmap
- -- find the bitmap that corresponds to the targetNode facedir
- for i=1, index-1 do
- if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
- targetNode_bitmap = bitmap_list[i]
- minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
- end
- end
- if( targetNode_bitmap ~= nil ) then --this should always happen
- --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
- local tnb = util.integer_to_bitmap( targetNode_bitmap )
- minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
- local finalBitmap = util.or_bitmap( tnb, bitmap )
- minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
- local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
- minetest.swap_node( target_node_position, finalNode )
- end
- end
- end
- end
- end
- slab.on_use = function( itemstack, user, pointed_thing )
- -- find world coordinates
- local camera_position = user:get_pos()
- camera_position.y = camera_position.y + user:get_properties().eye_height
- local raycaster = Raycast(
- camera_position,
- vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
- false, false
- )
- local intersected_thing = raycaster:next()
- if( intersected_thing == nil ) then return end
- --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
- local small_normal = vector.divide( intersected_thing.intersection_normal, 8 )
- local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
-
- local target_node_position = {
- x = math.floor(world_rough_position.x+0.5),
- y = math.floor(world_rough_position.y+0.5),
- z = math.floor(world_rough_position.z+0.5),
- }
- local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
- minetest.chat_send_all( "x: "..point_within_node.x )
- minetest.chat_send_all( "y: "..point_within_node.y )
- minetest.chat_send_all( "z: "..point_within_node.z )
- local bitmap4x4 = util.nodePoint_to_bitmap4x4( point_within_node )
- local face_type = util.bitmap4x4_to_facetype( bitmap4x4 )
- minetest.chat_send_all( face_type )
- local bitmap = nil
- if( face_type == "edge" ) then
- util.bitmap4x4_expand_edge( bitmap4x4 )
- util.bitmap4x4_expand_normal( bitmap4x4, small_normal )
- bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
- end
- if( face_type == "face" ) then
- util.bitmap4x4_expand_face( bitmap4x4 )
- bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
- end
-
- if( bitmap ~= nil ) then bitmap = util.array3d_to_bitmap( bitmap )
- minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
- if( minetest.get_node( target_node_position ).name == "air" ) then --TODO change this so its air or material
- minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
- local bitmap_string = ""
- for i = 0, 7, 1 do
- bitmap_string = bitmap_string .. bitmap[i]
- end
- minetest.log( bitmap_string )
- minetest.set_node( target_node_position, {
- name="k_smallblocks:15_stonebrick",
- param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
- } )
- else
- local underscore_index
- local wieldedNode_fullName = itemstack:get_name()
- underscore_index = string.find( wieldedNode_fullName, "_", 3 )
- local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
- local targetNode_fullName = minetest.get_node( target_node_position ).name
- underscore_index = string.find( targetNode_fullName, "_", 3 )
- local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
-
- if( targetNode_materialName == wieldedNode_materialName ) then
- local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
- local colon_index = string.find( targetNode_fullName, ":" )
- targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
- if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
- minetest.chat_send_all( targetNode_bitmapName )
- -- find bitmap from name and facedir
- local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
- local index = 1
- for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
- if( val_bitmap_name == targetNode_bitmapName ) then
- bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
- index = index + 1
- minetest.chat_send_all( key_bitmap_as_int )
- end
- end
- local targetNode_bitmap
- -- find the bitmap that corresponds to the targetNode facedir
- for i=1, index-1 do
- if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
- targetNode_bitmap = bitmap_list[i]
- minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
- end
- end
- if( targetNode_bitmap ~= nil ) then --this should always happen
- --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
- local tnb = util.integer_to_bitmap( targetNode_bitmap )
- minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
- local finalBitmap = util.or_bitmap( tnb, bitmap )
- minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
- local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
- minetest.swap_node( target_node_position, finalNode )
- end
- end
- end
- end
- end
- stair.on_use = function( itemstack, user, pointed_thing )
- -- find world coordinates
- local camera_position = user:get_pos()
- camera_position.y = camera_position.y + user:get_properties().eye_height
- local raycaster = Raycast(
- camera_position,
- vector.add( camera_position, vector.multiply(user:get_look_dir(), 5) ),
- false, false
- )
- local intersected_thing = raycaster:next()
- if( intersected_thing == nil ) then return end
- --pushes the intersection away from the face to resolve ambiguity and get a rogh position in the world
- local small_normal = vector.divide( intersected_thing.intersection_normal, 8 )
- local world_rough_position = vector.add( small_normal, intersected_thing.intersection_point )
-
- local target_node_position = {
- x = math.floor(world_rough_position.x+0.5),
- y = math.floor(world_rough_position.y+0.5),
- z = math.floor(world_rough_position.z+0.5),
- }
- local point_within_node = util.worldPoint_to_nodePoint( world_rough_position )
- minetest.chat_send_all( "x: "..point_within_node.x )
- minetest.chat_send_all( "y: "..point_within_node.y )
- minetest.chat_send_all( "z: "..point_within_node.z )
- local bitmap4x4 = util.nodePoint_to_bitmap4x4( point_within_node )
- local face_type = util.bitmap4x4_to_facetype( bitmap4x4 )
- minetest.chat_send_all( face_type )
- local bitmap = nil
- if( face_type == "edge" ) then
- util.bitmap4x4_expand_edge( bitmap4x4 )
- util.bitmap4x4_expand_faces( bitmap4x4 )
- bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
- end
- if( face_type == "corner" ) then
- util.bitmap4x4_expand_normal( bitmap4x4, small_normal )
- util.bitmap4x4_expand_faces( bitmap4x4 )
- bitmap = util.bitmap4x4_to_bitmap2x2( bitmap4x4 )
- end
- if( bitmap ~= nil ) then bitmap = util.array3d_to_bitmap( bitmap )
- minetest.log("warning", "placing at" .. util.bitmap_to_integer( bitmap ) )
- if( minetest.get_node( target_node_position ).name == "air" ) then --TODO change this so its air or material
- minetest.log( smallblocks.int_name_map[util.bitmap_to_integer(bitmap)] )
- local bitmap_string = ""
- for i = 0, 7, 1 do
- bitmap_string = bitmap_string .. bitmap[i]
- end
- minetest.log( bitmap_string )
- minetest.set_node( target_node_position, {
- name="k_smallblocks:63_stonebrick",
- param2=smallblocks.int_facedir_map[util.bitmap_to_integer(bitmap)]
- } )
- else
- local underscore_index
- local wieldedNode_fullName = itemstack:get_name()
- underscore_index = string.find( wieldedNode_fullName, "_", 3 )
- local wieldedNode_materialName = string.sub( wieldedNode_fullName, underscore_index+1 )
- local targetNode_fullName = minetest.get_node( target_node_position ).name
- underscore_index = string.find( targetNode_fullName, "_", 3 )
- local targetNode_materialName = string.sub( targetNode_fullName, underscore_index+1 )
-
- if( targetNode_materialName == wieldedNode_materialName ) then
- local targetNode_bitmapName = string.sub( targetNode_fullName, 0, underscore_index-1 )
- local colon_index = string.find( targetNode_fullName, ":" )
- targetNode_bitmapName = string.sub( targetNode_bitmapName, colon_index+1 )
- if( targetNode_bitmapName == "smallblock" ) then targetNode_bitmapName = "1" end
- minetest.chat_send_all( targetNode_bitmapName )
- -- find bitmap from name and facedir
- local bitmap_list = {} -- list of bitmaps that are a rotation of targetNode bitmapName
- local index = 1
- for key_bitmap_as_int, val_bitmap_name in pairs(smallblocks.int_name_map) do
- if( val_bitmap_name == targetNode_bitmapName ) then
- bitmap_list[index] = key_bitmap_as_int -- grabing keys that map to the target node name
- index = index + 1
- minetest.chat_send_all( key_bitmap_as_int )
- end
- end
- local targetNode_bitmap
- -- find the bitmap that corresponds to the targetNode facedir
- for i=1, index-1 do
- if( smallblocks.int_facedir_map[bitmap_list[i]] == minetest.get_node( target_node_position ).param2 ) then
- targetNode_bitmap = bitmap_list[i]
- minetest.chat_send_all( "TN bitmap: " .. targetNode_bitmap )
- end
- end
- if( targetNode_bitmap ~= nil ) then --this should always happen
- --targetNode_bitmap = util.integer_to_bitmap( targetNode_bitmap )
- local tnb = util.integer_to_bitmap( targetNode_bitmap )
- minetest.log( "none", "oring "..targetNode_bitmap .. " with ".. util.bitmap_to_integer( bitmap ) )
- local finalBitmap = util.or_bitmap( tnb, bitmap )
- minetest.log("none", "result " .. util.bitmap_to_integer( finalBitmap ) )
- local finalNode_name = smallblocks.int_name_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode_facedir = smallblocks.int_facedir_map[util.bitmap_to_integer( finalBitmap )]
- local finalNode = { name="k_smallblocks:"..finalNode_name.."_"..targetNode_materialName, param2=finalNode_facedir }
- minetest.swap_node( target_node_position, finalNode )
- end
- end
- end
- end
- end
- bitmap_name_definition_map = { -- maps a bitmap name to a definiton
- [1] = {
- name = "smallblock",
- description = "smallblock",
- on_use = smallblock.on_use,
- on_rightclick = common.on_right_click
- },
- [3] = {
- name = "halfslab",
- description = "half-slab",
- on_use = halfslab.on_use,
-
- on_rightclick = common.on_right_click
- },
- [15] = {
- name = "slab",
- description = "slab",
- on_use = slab.on_use,
- on_rightclick = common.on_right_click
- },
- [63] = {
- name = "stair",
- description = "stair",
- on_use = stair.on_use,
- on_rightclick = common.on_right_click
- }
- }
|