generate_nodeboxes.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --[[
  2. k_smallblocks is a Minetest mod that adds smaller blocks to minetest aswell as
  3. its own node placement prediction/system
  4. Copyright (C) 2019 Kurtzmusch
  5. This file is part of k_smallblocks
  6. k_smallblocks is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU Lesser General Public License as published by the Free
  8. Software Foundation; either version 2.1 of the License, or (at your option) any
  9. later version.
  10. k_smallblocks is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with k_smallblocks. If not, see <https://www.gnu.org/licenses/>.
  15. --]]
  16. nodeboxes = {}
  17. smallblocks.nodeboxes = nodeboxes
  18. local function box_from_point( point )
  19. local nodebox = { point.x, point.y, point.z, point.x+0.5, point.y+0.5, point.z+0.5 }
  20. return nodebox
  21. end
  22. for key_int, val_bitmap_as_int in pairs(smallblocks.origin_bitmaps) do
  23. local bitmap = util.integer_to_bitmap( val_bitmap_as_int )
  24. local bitmap_as_array = util.bitmap_to_array3d( bitmap )
  25. local index = 1
  26. local max_index = 1
  27. nodeboxes[key_int] = {}
  28. minetest.log("none", "generating nodebox for ".. key_int.. ">>".. val_bitmap_as_int )
  29. local gen_string = ""
  30. local bitmap_string = ""
  31. for ix = 0, max_index, 1 do
  32. for iy = 0, max_index, 1 do
  33. for iz = 0, max_index, 1 do
  34. bitmap_string = bitmap_string .. bitmap_as_array[ix][iy][iz]
  35. if( bitmap_as_array[ix][iy][iz] == 1) then
  36. nodeboxes[key_int][index] = box_from_point( { x=ix/2-0.5, y=iy/2-0.5, z=iz/2-0.5} )
  37. index = index + 1
  38. gen_string = gen_string .."{"
  39. for k, v in pairs(nodeboxes[key_int][index-1]) do
  40. gen_string = gen_string..v..", "
  41. end
  42. gen_string = gen_string .."} "
  43. end
  44. end
  45. end
  46. end
  47. minetest.log("none", bitmap_string)
  48. minetest.log("none", gen_string )
  49. end