generate_shapes.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. origin_bitmaps = { [255] = nil }
  17. smallblocks.origin_bitmaps = origin_bitmaps
  18. function check_shapes( bitmap )
  19. for i = 0, 255, 1 do
  20. if( origin_bitmaps[i] ~= nil ) then
  21. if( util.bitmap_to_integer( bitmap ) == origin_bitmaps[i] ) then
  22. return true
  23. end
  24. end
  25. end
  26. return false
  27. end
  28. function check_all_rotations( bitmap_as_int )
  29. local bitmap = util.integer_to_bitmap( bitmap_as_int )
  30. local rotated_bitmap = bitmap
  31. -- rotations around +y
  32. for i = 1, 4, 1 do
  33. rotated_bitmap = util.rotate_bitmap_around_plus_y( rotated_bitmap )
  34. if( check_shapes( rotated_bitmap ) ) then return true end
  35. end
  36. rotated_bitmap = util.orient_bitmap_towards_plus_z( bitmap )
  37. for i = 1, 4, 1 do
  38. rotated_bitmap = util.rotate_bitmap_around_plus_z( rotated_bitmap )
  39. if( check_shapes( rotated_bitmap ) ) then return true end
  40. end
  41. rotated_bitmap = util.orient_bitmap_towards_minus_z( bitmap )
  42. for i = 1, 4, 1 do
  43. rotated_bitmap = util.rotate_bitmap_around_minus_z( rotated_bitmap )
  44. if( check_shapes( rotated_bitmap ) ) then return true end
  45. end
  46. rotated_bitmap = util.orient_bitmap_towards_plus_x( bitmap )
  47. for i = 1, 4, 1 do
  48. rotated_bitmap = util.rotate_bitmap_around_plus_x( rotated_bitmap )
  49. if( check_shapes( rotated_bitmap ) ) then return true end
  50. end
  51. rotated_bitmap = util.orient_bitmap_towards_minus_x( bitmap )
  52. for i = 1, 4, 1 do
  53. rotated_bitmap = util.rotate_bitmap_around_minus_x( rotated_bitmap )
  54. if( check_shapes( rotated_bitmap ) ) then return true end
  55. end
  56. rotated_bitmap = util.orient_bitmap_towards_minus_y( bitmap )
  57. for i = 1, 4, 1 do
  58. rotated_bitmap = util.rotate_bitmap_around_minus_y( rotated_bitmap )
  59. if( check_shapes( rotated_bitmap ) ) then return true end
  60. end
  61. return false
  62. end
  63. local index = 1
  64. for bitmap_as_int = 1, 255, 1 do
  65. shape_exists = check_all_rotations( bitmap_as_int )
  66. if( shape_exists == false ) then
  67. origin_bitmaps[index] = bitmap_as_int
  68. index = index + 1
  69. minetest.log( "none", " found shape "..bitmap_as_int )
  70. end
  71. end