blocks.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include <memory.h>
  3. #include <vector>
  4. #include <stdint.h>
  5. #include <glad/glad.h>
  6. #include <glm/vec3.hpp>
  7. enum BlockTypes
  8. {
  9. air = 0,
  10. grassBlock,
  11. dirt,
  12. stone,
  13. ice,
  14. woodLog,
  15. wooden_plank,
  16. cobblestone,
  17. gold_block,
  18. bricks,
  19. sand,
  20. sand_stone,
  21. snow_dirt,
  22. leaves,
  23. gold_ore,
  24. coar_ore,
  25. stoneBrick,
  26. iron_ore,
  27. diamond_ore,
  28. bookShelf,
  29. birch_wood,
  30. gravel,
  31. grass,
  32. rose,
  33. water,
  34. jungle_log,
  35. jungle_leaves,
  36. palm_log,
  37. palm_leaves,
  38. cactus_bud,
  39. dead_bush,
  40. jungle_planks,
  41. clay,
  42. hardened_clay,
  43. mud,
  44. packed_mud,
  45. mud_bricks,
  46. control1,
  47. control2,
  48. control3,
  49. control4,
  50. snow_block,
  51. birch_leaves,
  52. spruce_log,
  53. spruce_leaves,
  54. spruce_leaves_red,
  55. BlocksCount
  56. };
  57. using BlockType = uint16_t;
  58. bool isBlockMesh(BlockType type);
  59. bool isCrossMesh(BlockType type);
  60. bool isControlBlock(BlockType type);
  61. bool isOpaque(BlockType type);
  62. bool isTransparentGeometry(BlockType type);
  63. bool isGrassMesh(BlockType type);
  64. struct Block
  65. {
  66. BlockType type;
  67. unsigned char lightLevel; //first 4 bytes represent the sun level and bottom 4 bytes the other lights level
  68. unsigned char notUsed;
  69. bool air() { return type == 0; }
  70. bool isOpaque()
  71. {
  72. return ::isOpaque(type);
  73. }
  74. //rename is animated leaves
  75. bool isAnimatedBlock()
  76. {
  77. return
  78. type == BlockTypes::leaves || type == BlockTypes::jungle_leaves
  79. || type == BlockTypes::palm_leaves || type == BlockTypes::birch_leaves
  80. || type == BlockTypes::spruce_leaves || type == BlockTypes::spruce_leaves_red;
  81. }
  82. bool isTransparentGeometry()
  83. {
  84. return ::isTransparentGeometry(type);
  85. }
  86. bool isGrassMesh()
  87. {
  88. return ::isGrassMesh(type);
  89. }
  90. unsigned char getSkyLight()
  91. {
  92. return (lightLevel >> 4);
  93. }
  94. void setSkyLevel(unsigned char s)
  95. {
  96. s = s & 0b1111;
  97. s <<= 4;
  98. lightLevel &= 0b0000'1111;
  99. lightLevel |= s;
  100. }
  101. bool isBlockMesh()
  102. {
  103. return ::isBlockMesh(type);
  104. }
  105. bool isCrossMesh()
  106. {
  107. return ::isCrossMesh(type);
  108. }
  109. };