537 lines
24 KiB
Lua
537 lines
24 KiB
Lua
--[[
|
|
|
|
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
|
|
}
|
|
}
|
|
|