Add nodevoxel array

master
Le Sanglier des Ardennes 2018-01-25 23:39:51 +01:00
parent 90f18e89b6
commit 1872abd76f
1 changed files with 42 additions and 16 deletions

View File

@ -1,3 +1,21 @@
-- Array functions
function tprint(t)
for key,value in pairs(t) do
print(key, value)
end
end
function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
-- File functions -- File functions
-- http://lua-users.org/wiki/FileInputOutput -- http://lua-users.org/wiki/FileInputOutput
@ -26,28 +44,36 @@ end
function generateNodeVoxel(file) function generateNodeVoxel(file)
local lines = lines_from(file) local lines = lines_from(file)
local aNodevoxel = {}
-- print all line numbers and their contents -- print all line numbers and their contents
for k,v in pairs(lines) do for k,v in pairs(lines) do
if k >= 4 then -- Pass the description header if k >= 4 then -- Pass the description header
x, y, z, cubeColor = v:match("([^,]+) ([^,]+) ([^,]+) ([^,]+)") x, y, z, cubeColor = v:match("([^,]+) ([^,]+) ([^,]+) ([^,]+)")
minetest.register_node("nodevoxel:cube" .. cubeColor, { if has_value(aNodevoxel, cubeColor) then
description = "Nodevoxel Cube" .. cubeColor, print 'Nodevoxel exists, does not create it'
tiles = { else
"nodevoxel_cube_up.png^[colorize:#" .. cubeColor .. "50", print("Nodevoxel does not exist, create it: " .. cubeColor)
"nodevoxel_cube_down.png^[colorize:#" .. cubeColor .. "50", table.insert(aNodevoxel, cubeColor)
"nodevoxel_cube_right.png^[colorize:#" .. cubeColor .. "50",
"nodevoxel_cube_left.png^[colorize:#" .. cubeColor .. "50", minetest.register_node("nodevoxel:cube" .. cubeColor, {
"nodevoxel_cube_back.png^[colorize:#" .. cubeColor .. "50", description = "Nodevoxel Cube" .. cubeColor,
"nodevoxel_cube_front.png^[colorize:#" .. cubeColor .. "50" tiles = {
}, "nodevoxel_cube_up.png^[colorize:#" .. cubeColor .. "50",
is_ground_content = true, "nodevoxel_cube_down.png^[colorize:#" .. cubeColor .. "50",
"nodevoxel_cube_right.png^[colorize:#" .. cubeColor .. "50",
groups = { "nodevoxel_cube_left.png^[colorize:#" .. cubeColor .. "50",
cracky = 3 "nodevoxel_cube_back.png^[colorize:#" .. cubeColor .. "50",
}, "nodevoxel_cube_front.png^[colorize:#" .. cubeColor .. "50"
}) },
is_ground_content = true,
groups = {
cracky = 3
},
})
end
print (k .. ' : ', x, y, z, cubeColor) print (k .. ' : ', x, y, z, cubeColor)
end end
end end