moved most of the code into api.lua and definitions.lua
This commit is contained in:
parent
ecef6f5a28
commit
cc27c88ef0
120
api.lua
Normal file
120
api.lua
Normal file
@ -0,0 +1,120 @@
|
||||
|
||||
|
||||
local function register_recipes( node_name, shapeless )
|
||||
local recipe_type = "shaped"
|
||||
if( shapeless ) then recipe_type = "shapeless" end
|
||||
local smallblock_recipes = {
|
||||
[1] = {
|
||||
type = recipe_type,
|
||||
output = "k_smallblocks:smallblock_"..node_name.." 8",
|
||||
recipe = {
|
||||
{ "default:"..node_name, "", "" },
|
||||
{ "", "", "" },
|
||||
{ "", "", "" }
|
||||
}
|
||||
},
|
||||
[2] = {
|
||||
type = recipe_type,
|
||||
output = "k_smallblocks:smallblock_"..node_name.." 2",
|
||||
recipe = {
|
||||
{ "default:"..node_name.."halfslab", "", "" },
|
||||
{ "", "", "" },
|
||||
{ "", "", "" }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
local halfslab_recipe = {
|
||||
type = recipe_type,
|
||||
output = "k_smallblocks:halfslab_"..node_name,
|
||||
recipe = {
|
||||
{ "k_smallblocks:smallblock_"..node_name, "k_smallblocks:smallblock_"..node_name,"" },
|
||||
{ "", "", "" },
|
||||
{ "", "", "" }
|
||||
}
|
||||
}
|
||||
local slab_recipes = {
|
||||
[1] = {
|
||||
type = recipe_type,
|
||||
output = "k_smallblocks:slab_"..node_name,
|
||||
recipe = {
|
||||
{ "k_smallblocks:smallblock_"..node_name, "k_smallblocks:smallblock_"..node_name,"" },
|
||||
{ "k_smallblocks:smallblock_"..node_name, "k_smallblocks:smallblock_"..node_name, "" },
|
||||
{ "", "", "" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local stair_recipe = {
|
||||
type= recipe_type,
|
||||
output = "k_smallblocks:stair_"..node_name,
|
||||
recipe = {
|
||||
{ "k_smallblocks:halfslab_"..node_name, "", "" },
|
||||
{ "k_smallblocks:halfslab_"..node_name, "k_smallblocks:halfslab_"..node_name, "" },
|
||||
{ "", "", "" }
|
||||
}
|
||||
}
|
||||
for key_int, val_recipe in pairs( smallblock_recipes ) do
|
||||
minetest.register_craft( val_recipe )
|
||||
end
|
||||
minetest.register_craft( halfslab_recipe )
|
||||
for key_int, val_recipe in pairs( slab_recipes ) do
|
||||
minetest.register_craft( val_recipe )
|
||||
end
|
||||
minetest.register_craft( stair_recipe )
|
||||
end
|
||||
|
||||
local function register_nodes( node_name )
|
||||
for key_int, val_bitmap_name in pairs( smallblocks.origin_bitmaps ) do
|
||||
local origin_bitmap_nodebox = smallblocks.nodeboxes[key_int]
|
||||
if( bitmap_name_definition_map[val_bitmap_name] ) then
|
||||
minetest.register_node("k_smallblocks:".. bitmap_name_definition_map[val_bitmap_name].name .."_"..node_name,
|
||||
{
|
||||
description = bitmap_name_definition_map[val_bitmap_name].description,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
tiles = { {name="default_stone_brick.png", align_style="world"} },
|
||||
is_ground_content = false,
|
||||
groups = { cracky=2, not_in_creative_inventory= 0},
|
||||
sunlight_propagates = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = origin_bitmap_nodebox
|
||||
},
|
||||
on_rightclick = common.on_right_click,
|
||||
|
||||
on_use = bitmap_name_definition_map[val_bitmap_name].on_use
|
||||
}
|
||||
)
|
||||
else
|
||||
minetest.register_node("k_smallblocks:"..val_bitmap_name.."_"..node_name,
|
||||
{
|
||||
description = node_name.." odd shape",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
tiles = { {name="default_stone_brick.png", align_style="world"} },
|
||||
is_ground_content = false,
|
||||
groups = { cracky=2, not_in_creative_inventory= 1},
|
||||
sunlight_propagates = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = origin_bitmap_nodebox
|
||||
},
|
||||
on_rightclick = common.on_right_click,
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
smallblocks.register_node = function( node_name, generate_recipes, shapeless )
|
||||
register_nodes( node_name )
|
||||
if( generate_recipes ) then register_recipes( node_name, shapeless ) end
|
||||
end
|
||||
|
||||
|
208
definitions.lua
Normal file
208
definitions.lua
Normal file
@ -0,0 +1,208 @@
|
||||
|
||||
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 )]
|
||||
if( finalNode_name == "1" ) then
|
||||
finalNode_name = "smallblock"
|
||||
end
|
||||
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:smallblock_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
|
||||
|
||||
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 = function() end,
|
||||
|
||||
on_rightclick = common.on_right_click
|
||||
},
|
||||
[15] = {
|
||||
name = "slab",
|
||||
description = "slab",
|
||||
on_use = function() end,
|
||||
|
||||
on_rightclick = common.on_right_click
|
||||
},
|
||||
[63] = {
|
||||
name = "stair",
|
||||
description = "stair",
|
||||
on_use = function() end,
|
||||
|
||||
on_rightclick = common.on_right_click
|
||||
}
|
||||
}
|
||||
|
248
init.lua
248
init.lua
@ -44,253 +44,25 @@ with k_smallblocks. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
-- definitions of named nodes will contain a recipe, logic for correct orientation when placed and dug
|
||||
|
||||
modpath = minetest.get_modpath("k_smallblocks")
|
||||
|
||||
smallblocks = {}
|
||||
|
||||
local modpath = minetest.get_modpath("k_smallblocks")
|
||||
|
||||
smallblocks.int_facedir_map = { [255]=0 } -- maps an int that represents a bitmap to a facedir
|
||||
smallblocks.int_name_map = { [255]="" } -- maps an int that represents a bitmap to a name. many ints can map to a single name. a name is a string of the interger that represents the bitmap
|
||||
smallblocks.name_int_map = {} -- inverse of the above map, might be usefull in the future
|
||||
-- smallblocks.name_int_map = {} -- inverse of the above map, might be usefull in the future
|
||||
-- definitions of named (and craftable) nodes
|
||||
smallblock = {}
|
||||
halfslab = {}
|
||||
slab = {}
|
||||
stair = {}
|
||||
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 )]
|
||||
if( finalNode_name == "1" ) then
|
||||
finalNode_name = "smallblock"
|
||||
end
|
||||
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:smallblock_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 )
|
||||
minetest.chat_send_all( "materials match" )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
dofile(modpath .. "/util.lua")
|
||||
test_bitmap = util.integer_to_bitmap( 182 )
|
||||
test_int = util.bitmap_to_integer( test_bitmap )
|
||||
minetest.log("warning", test_int )
|
||||
for i = 0, 7, 1 do
|
||||
minetest.log("warning", test_bitmap[i] )
|
||||
end
|
||||
dofile(modpath .. "/definitions.lua")
|
||||
dofile(modpath .. "/generate_shapes.lua")
|
||||
dofile(modpath .. "/generate_nodeboxes.lua")
|
||||
dofile(modpath .. "/generate_map.lua") -- maps int to shape, facedir
|
||||
dofile(modpath .. "/generate_map.lua")
|
||||
dofile(modpath .. "/api.lua")
|
||||
|
||||
smallblocks.name_int_map = util.table_invert( smallblocks.int_name_map )
|
||||
|
||||
for k,v in pairs(origin_bitmaps) do
|
||||
minetest.log("error", " ".. v)
|
||||
end
|
||||
-- smallblocks.name_int_map = util.table_invert( smallblocks.int_name_map )
|
||||
|
||||
for k, v in pairs(smallblocks.origin_bitmaps) do
|
||||
local shape_int = v
|
||||
local shape_nb = smallblocks.nodeboxes[k]
|
||||
if( v == 1 ) then
|
||||
minetest.register_node("k_smallblocks:smallblock_stonebrick",
|
||||
{
|
||||
description = "Stone Brick Smallblock",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
tiles = { {name="default_stone_brick.png", align_style="world"} },
|
||||
groups = { cracky=2 },
|
||||
sunlight_propagates = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = shape_nb
|
||||
},
|
||||
on_use = smallblock.on_use,
|
||||
on_rightclick = common.on_right_click,
|
||||
on_place = function( itemstack, placer, pointed_thing )
|
||||
if( string.sub(minetest.get_node( pointed_thing.under ).name, 1, 13 ) == "k_smallblocks" ) then
|
||||
minetest.chat_send_all( "on_place" .. pointed_thing.under.x .. " "..
|
||||
pointed_thing.under.y.." ".. pointed_thing.under.z )
|
||||
minetest.item_place( itemstack, placer, pointed_thing, 0)
|
||||
-- doesnt actually place any item, but calls target node on_rightclick if its defined
|
||||
end
|
||||
end
|
||||
}
|
||||
)
|
||||
else
|
||||
minetest.register_node("k_smallblocks:"..shape_int.."_".."stonebrick",
|
||||
{
|
||||
description = "Stone Brick",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
tiles = { {name="default_stone_brick.png", align_style="world"} },
|
||||
is_ground_content = false,
|
||||
groups = { cracky=2},
|
||||
sunlight_propagates = true,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = shape_nb
|
||||
},
|
||||
on_place = function() end,
|
||||
on_rightclick = common.on_right_click
|
||||
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
-- example of how a mod would make smallblocks for a base node
|
||||
smallblocks.register_node( "stonebrick", true, false )
|
||||
|
Loading…
x
Reference in New Issue
Block a user