From 90f18e89b6b3025c5a271dd9958cdc999b491f9e Mon Sep 17 00:00:00 2001 From: Le Sanglier des Ardennes Date: Wed, 24 Jan 2018 22:35:10 +0100 Subject: [PATCH] Generate node voxel --- init.lua | 73 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/init.lua b/init.lua index 43a0af7..8fa3090 100644 --- a/init.lua +++ b/init.lua @@ -1,22 +1,5 @@ --- Node Voxel - -minetest.register_node("nodevoxel:cube", { - description = "Nodevoxel Cube", - tiles = { - "nodevoxel_cube_up.png^[colorize:#FF000050", - "nodevoxel_cube_down.png^[colorize:#FF000050", - "nodevoxel_cube_right.png^[colorize:#FF000050", - "nodevoxel_cube_left.png^[colorize:#FF000050", - "nodevoxel_cube_back.png^[colorize:#FF000050", - "nodevoxel_cube_front.png^[colorize:#FF000050" -}, - is_ground_content = true, - - groups = { - cracky = 3 -}, -}) +-- File functions -- http://lua-users.org/wiki/FileInputOutput -- see if the file exists @@ -37,6 +20,48 @@ function lines_from(file) return lines end +-- Node Voxel + + +function generateNodeVoxel(file) + local lines = lines_from(file) + + -- print all line numbers and their contents + for k,v in pairs(lines) do + if k >= 4 then -- Pass the description header + x, y, z, cubeColor = v:match("([^,]+) ([^,]+) ([^,]+) ([^,]+)") + + minetest.register_node("nodevoxel:cube" .. cubeColor, { + description = "Nodevoxel Cube" .. cubeColor, + tiles = { + "nodevoxel_cube_up.png^[colorize:#" .. cubeColor .. "50", + "nodevoxel_cube_down.png^[colorize:#" .. cubeColor .. "50", + "nodevoxel_cube_right.png^[colorize:#" .. cubeColor .. "50", + "nodevoxel_cube_left.png^[colorize:#" .. cubeColor .. "50", + "nodevoxel_cube_back.png^[colorize:#" .. cubeColor .. "50", + "nodevoxel_cube_front.png^[colorize:#" .. cubeColor .. "50" + }, + is_ground_content = true, + + groups = { + cracky = 3 + }, + }) + + print (k .. ' : ', x, y, z, cubeColor) + end + end +end + +-- Object voxel list +local aObjectVoxel = {'obj01.txt'} + +for key,value in pairs(aObjectVoxel) do + print(key, value) + generateNodeVoxel(value) +end + +-- Chat commands minetest.register_chatcommand("nodevoxel", { params = " ", @@ -66,19 +91,19 @@ minetest.register_chatcommand("nodevoxel", { if nodevoxelAction == "add" then minetest.chat_send_player(user, "Add nodevoxel " .. nodevoxelParam) - if nodevoxelParam == "1" then + if nodevoxelParam == "01" then -- y = height - -- tests the functions above - local file = 'obj01.txt' + local file = "obj" .. nodevoxelParam .. ".txt" local lines = lines_from(file) -- print all line numbers and their contents for k,v in pairs(lines) do if k >= 4 then - x, y, z, c = v:match("([^,]+) ([^,]+) ([^,]+) ([^,]+)") - minetest.set_node({x=pos.x + x, y=pos.y + z, z=pos.z + y}, {name="nodevoxel:cube"}) - print (k .. ' : ', x, y, z, c) + x, y, z, cubeColor = v:match("([^,]+) ([^,]+) ([^,]+) ([^,]+)") + + minetest.set_node({x=pos.x + x, y=pos.y + z, z=pos.z + y}, {name="nodevoxel:cube" .. cubeColor}) + print (k .. ' : ', x, y, z, cubeColor) end end