blocks.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. #include "blocks.h"
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <platformTools.h>
  5. #include <string>
  6. int blockReorder[] = {
  7. // Basic Blocks
  8. air, grassBlock, dirt, stone, stone_stairts, stone_slabs, stone_wall, cobblestone, cobbleStone_stairts, cobbleStone_slabs, cobbleStone_wall, gravel, water,
  9. // Ores & Resources
  10. copperOre, leadOre, ironOre, silverOre, goldOre, gold_block,
  11. // Natural Blocks
  12. sand, sand_stone, sandStone_stairts, sandStone_slabs, sandStone_wall, hardSandStone, hardSandStone_stairs, hardSandStone_slabs, hardSandStone_wall,
  13. clay, clayBricks, redClay, redClayBricks, mud,
  14. snow_dirt, snow_block, ice, glowstone, pathBlock, coarseDirt,
  15. limeStone, smoothLimeStone, smoothLimeStone_stairs, smoothLimeStone_slabs, smoothLimeStone_wall,
  16. // Wood & Planks
  17. woodLog, jungle_log, birch_log, palm_log, spruce_log, strippedOakLog, strippedBirchLog, strippedSpruceLog,
  18. wooden_plank, wooden_stairs, wooden_slab, wooden_wall, jungle_planks,
  19. birchPlanks, birchPlanks_stairs, birchPlanks_slabs, birchPlanks_wall,
  20. sprucePlank, sprucePlank_stairs, sprucePlank_slabs, sprucePlank_wall,
  21. // Leaves & Plants
  22. leaves, jungle_leaves, birch_leaves, palm_leaves, spruce_leaves, spruce_leaves_red,
  23. grass, rose, dead_bush, cactus_bud, vines, yellowGrass, hayBalde,
  24. // Decorative & Special Blocks
  25. bricks, bricks_stairs, bricks_slabs, bricks_wall, blueBricks, blueBricks_stairs, blueBricks_slabs, blueBricks_wall,
  26. mossyCobblestone,mossyCobblestone_stairs,mossyCobblestone_slab,mossyCobblestone_wall,
  27. stoneBrick, stoneBricks_stairts, stoneBricks_slabs, stoneBricks_wall,
  28. tiledStoneBricks, tiledStoneBricks_stairs, tiledStoneBricks_slab, tiledStoneBricks_wall,
  29. clothBlock, cloth_stairs, cloth_slabs, cloth_wall,
  30. terracotta, terracotta_stairs, terracotta_slabs, terracotta_wall,
  31. volcanicHotRock, volcanicRock, volcanicRock_stairts, volcanicRock_slabs, volcanicRock_wall,
  32. smoothStone, smoothStone_stairts, smoothStone_slabs, smoothStone_wall,
  33. marbleBlock, marbleBlock_stairs, marbleBlock_slabs, marbleBlock_wall, smoothMarbleBlock,
  34. marbleBricks, marbleBricks_stairs, marbleBricks_slabs, marbleBricks_wall, marblePillar,
  35. // Walls
  36. plankedWallBlock, plankedWallBlock_stairs, plankedWallBlock_wall,
  37. // Glass Variants
  38. glass, glassNotClear, glassNotClear2, glass2,
  39. vitral1, vitral2,
  40. magenta_stained_glass, pink_stained_glass,
  41. // Structures & Functional Blocks
  42. workBench, furnace, cookingPot, ladder, trainingDummy, target,
  43. // Furniture
  44. bookShelf,
  45. oakChair, oakBigChair, oakLogChair, oakLogBigChair, oakTable, oakLogTable,
  46. woddenChest, goblinChest, copperChest, ironChest, silverChest, goldChest,
  47. crate, smallCrate,
  48. // Decorations
  49. torch, torchWood, goblinTorch, skull, skullTorch, book, candleHolder, pot, jar, globe, keg, wineBottle, goblet, mug,
  50. lamp, goblinStitchingPost, goblinWorkBench, goblinChair, goblinTable,
  51. // Miscellaneous
  52. smallRock, oakLogSlab, logWall, craftingItems, chickenCaracas, chickenWingsPlate, fishPlate,
  53. cobweb,
  54. // Dungeon Stuff
  55. dungeonBricks, dungeonBricks_stairts, dungeonBricks_slabs, dungeonBricks_wall,
  56. dungeonStone, dungeonStone_stairs, dungeonStone_slabs, dungeonStone_wall,
  57. dungeonCobblestone, dungeonCobblestone_stairs, dungeonCobblestone_slabs, dungeonCobblestone_wall,
  58. dungeonSmoothStone, dungeonSmoothStone_stairs, dungeonSmoothStone_slabs, dungeonSmoothStone_wall,
  59. dungeonPillar, dungeonSkullBlock, chiseledDungeonBrick, dungeonGlass,
  60. // Creative
  61. testBlock, control1, control2, control3, control4, structureBase,
  62. };
  63. int getBlockReorder(int index)
  64. {
  65. static_assert(sizeof(blockReorder) / sizeof(blockReorder[0]) == BlocksCount);
  66. return blockReorder[index];
  67. }
  68. bool isBlockMesh(BlockType type)
  69. {
  70. return !isCrossMesh(type)
  71. && !(type == torch)
  72. && !(type == torchWood)
  73. && !(type == goblinTorch)
  74. && !(type == lamp)
  75. && !(type == ladder)
  76. && !(type == vines)
  77. && !isStairsMesh(type)
  78. && !isWallMesh(type)
  79. && !isSlabMesh(type)
  80. && !isDecorativeFurniture(type)
  81. && !isWallMountedBlock(type)
  82. ;
  83. }
  84. bool canWallMountedBlocksBePlacedOn(BlockType type)
  85. {
  86. return isBlockMesh(type) ||
  87. isStairsMesh(type) ||
  88. isWallMesh(type);
  89. }
  90. bool isStairsMesh(BlockType type)
  91. {
  92. return
  93. type == wooden_stairs ||
  94. type == bricks_stairs ||
  95. type == stone_stairts ||
  96. type == birchPlanks_stairs ||
  97. type == cobbleStone_stairts ||
  98. type == stoneBricks_stairts ||
  99. type == hardSandStone_stairs ||
  100. type == sandStone_stairts ||
  101. type == dungeonBricks_stairts ||
  102. type == dungeonStone_stairs ||
  103. type == dungeonCobblestone_stairs ||
  104. type == dungeonSmoothStone_stairs ||
  105. type == volcanicRock_stairts ||
  106. type == smoothStone_stairts ||
  107. type == smoothLimeStone_stairs ||
  108. type == sprucePlank_stairs ||
  109. type == marbleBlock_stairs ||
  110. type == marbleBricks_stairs ||
  111. type == mossyCobblestone_stairs ||
  112. type == cloth_stairs ||
  113. type == terracotta_stairs ||
  114. type == plankedWallBlock_stairs ||
  115. type == blueBricks_stairs ||
  116. type == tiledStoneBricks_stairs
  117. ;
  118. }
  119. bool isSlabMesh(BlockType type)
  120. {
  121. return type == wooden_slab ||
  122. type == bricks_slabs ||
  123. type == stone_slabs ||
  124. type == cobbleStone_slabs ||
  125. type == stoneBricks_slabs ||
  126. type == hardSandStone_slabs ||
  127. type == birchPlanks_slabs ||
  128. type == sandStone_slabs ||
  129. type == terracotta_slabs ||
  130. type == dungeonBricks_slabs ||
  131. type == dungeonStone_slabs ||
  132. type == dungeonCobblestone_slabs ||
  133. type == dungeonSmoothStone_slabs ||
  134. type == volcanicRock_slabs ||
  135. type == smoothStone_slabs ||
  136. type == smoothLimeStone_slabs ||
  137. type == cloth_slabs ||
  138. type == marbleBlock_slabs ||
  139. type == sprucePlank_slabs ||
  140. type == marbleBricks_slabs ||
  141. type == blueBricks_slabs ||
  142. type == oakLogSlab ||
  143. type == mossyCobblestone_slab ||
  144. type == tiledStoneBricks_slab;
  145. }
  146. bool isWallMesh(BlockType type)
  147. {
  148. return type == wooden_wall ||
  149. type == bricks_wall ||
  150. type == stone_wall ||
  151. type == cobbleStone_wall ||
  152. type == birchPlanks_wall ||
  153. type == stoneBricks_wall ||
  154. type == terracotta_wall ||
  155. type == hardSandStone_wall ||
  156. type == sandStone_wall ||
  157. type == dungeonBricks_wall ||
  158. type == dungeonStone_wall ||
  159. type == dungeonCobblestone_wall ||
  160. type == dungeonSmoothStone_wall ||
  161. type == volcanicRock_wall ||
  162. type == smoothStone_wall ||
  163. type == sprucePlank_wall ||
  164. type == plankedWallBlock_wall ||
  165. type == smoothLimeStone_wall ||
  166. type == marbleBlock_wall ||
  167. type == cloth_wall ||
  168. type == marbleBricks_wall ||
  169. type == logWall ||
  170. type == blueBricks_wall ||
  171. type == mossyCobblestone_wall ||
  172. type == tiledStoneBricks_wall;
  173. }
  174. bool isCrossMesh(BlockType type)
  175. {
  176. return isGrassMesh(type) || type == cobweb;
  177. }
  178. bool isControlBlock(BlockType type)
  179. {
  180. return
  181. type == BlockTypes::control1 ||
  182. type == BlockTypes::control2 ||
  183. type == BlockTypes::control3 ||
  184. type == BlockTypes::control4;
  185. }
  186. bool isWallMountedBlock(BlockType type)
  187. {
  188. return type == BlockTypes::ladder || type == BlockTypes::vines;
  189. }
  190. bool isWallMountedOrStangingBlock(BlockType type)
  191. {
  192. return type == BlockTypes::torch
  193. || type == BlockTypes::torchWood
  194. || type == BlockTypes::goblinTorch
  195. || type == BlockTypes::lamp
  196. ;
  197. }
  198. bool isOpaque(BlockType type)
  199. {
  200. return
  201. type != BlockTypes::air
  202. && type != BlockTypes::torch
  203. && type != BlockTypes::torchWood
  204. && type != BlockTypes::goblinTorch
  205. && type != BlockTypes::lamp
  206. && type != BlockTypes::cobweb
  207. && !isWallMountedBlock(type)
  208. && !isDecorativeFurniture(type)
  209. //&& type != BlockTypes::glowstone
  210. && !(isStairsMesh(type))
  211. && !(isSlabMesh(type))
  212. && !(isWallMesh(type))
  213. && !(isAnyLeaves(type))
  214. && !(isTransparentGeometry(type))
  215. && !(isGrassMesh(type));
  216. }
  217. bool isDecorativeFurniture(BlockType type)
  218. {
  219. return type == mug || isChairMesh(type) || isGobletMesh(type) || type == wineBottle ||
  220. type == skull ||
  221. type == skullTorch ||
  222. type == book ||
  223. type == candleHolder ||
  224. type == pot ||
  225. type == jar ||
  226. type == keg ||
  227. type == cookingPot ||
  228. type == chickenCaracas ||
  229. type == chickenWingsPlate ||
  230. type == fishPlate ||
  231. type == workBench ||
  232. type == oakTable ||
  233. type == craftingItems ||
  234. type == oakLogTable ||
  235. type == oakBigChair ||
  236. type == oakLogBigChair ||
  237. type == smallRock ||
  238. type == woddenChest ||
  239. type == goblinChest ||
  240. type == copperChest ||
  241. type == ironChest ||
  242. type == silverChest ||
  243. type == goldChest ||
  244. type == smallCrate ||
  245. type == lamp ||
  246. type == torch ||
  247. type == torchWood ||
  248. type == goblinTorch ||
  249. type == trainingDummy ||
  250. type == target ||
  251. type == furnace ||
  252. type == goblinWorkBench ||
  253. type == goblinChair ||
  254. type == goblinTable ||
  255. type == goblinStitchingPost ||
  256. type == globe
  257. ;
  258. }
  259. bool isLightEmitor(BlockType type)
  260. {
  261. return type == BlockTypes::glowstone
  262. || type == BlockTypes::torch
  263. || type == BlockTypes::torchWood
  264. || type == BlockTypes::goblinTorch
  265. || type == BlockTypes::lamp
  266. || type == BlockTypes::candleHolder
  267. || type == BlockTypes::skullTorch;
  268. }
  269. bool isTransparentGeometry(BlockType type)
  270. {
  271. return type == BlockTypes::ice || type == BlockTypes::water ||
  272. ::isAnyGlass(type);
  273. }
  274. bool isGrassMesh(BlockType type)
  275. {
  276. return type == BlockTypes::grass
  277. || type == BlockTypes::rose
  278. || type == BlockTypes::cactus_bud
  279. || type == BlockTypes::dead_bush
  280. ;
  281. }
  282. bool isColidable(BlockType type)
  283. {
  284. return
  285. type != BlockTypes::air &&
  286. type != BlockTypes::grass &&
  287. type != BlockTypes::rose &&
  288. type != BlockTypes::cactus_bud &&
  289. type != BlockTypes::dead_bush &&
  290. type != BlockTypes::torch &&
  291. type != BlockTypes::lamp &&
  292. type != BlockTypes::torchWood &&
  293. type != BlockTypes::goblinTorch &&
  294. type != BlockTypes::water &&
  295. type != BlockTypes::jar &&
  296. type != BlockTypes::globe &&
  297. type != BlockTypes::skull &&
  298. type != BlockTypes::skullTorch &&
  299. type != BlockTypes::book &&
  300. type != BlockTypes::candleHolder &&
  301. type != BlockTypes::goblet &&
  302. type != BlockTypes::wineBottle &&
  303. type != BlockTypes::chickenWingsPlate &&
  304. type != BlockTypes::chickenCaracas &&
  305. type != BlockTypes::fishPlate &&
  306. type != BlockTypes::ladder &&
  307. type != BlockTypes::vines &&
  308. type != BlockTypes::smallRock &&
  309. type != BlockTypes::cobweb &&
  310. type != BlockTypes::trainingDummy &&
  311. type != BlockTypes::craftingItems &&
  312. type != BlockTypes::target &&
  313. type != BlockTypes::mug;
  314. }
  315. bool isWoodPlank(BlockType type)
  316. {
  317. return type == BlockTypes::wooden_plank ||
  318. type == BlockTypes::jungle_planks ||
  319. type == BlockTypes::sprucePlank ||
  320. type == BlockTypes::birchPlanks;
  321. }
  322. bool isChairMesh(BlockType type)
  323. {
  324. return type == oakChair || type == oakLogChair;
  325. }
  326. bool isGobletMesh(BlockType type)
  327. {
  328. return type == BlockTypes::goblet;
  329. }
  330. //used for breaking related things
  331. bool isAnyWoddenBlock(BlockType type)
  332. {
  333. return isWoodPlank(type) ||
  334. type == woodLog ||
  335. type == sprucePlank_stairs ||
  336. type == sprucePlank_slabs ||
  337. type == sprucePlank_wall ||
  338. type == bookShelf ||
  339. type == birch_log ||
  340. type == jungle_log ||
  341. type == palm_log ||
  342. type == wooden_stairs ||
  343. type == wooden_wall ||
  344. type == oakLogSlab ||
  345. type == ladder ||
  346. type == oakTable ||
  347. type == oakLogTable ||
  348. type == wooden_slab ||
  349. type == birchPlanks ||
  350. type == birchPlanks_slabs ||
  351. type == birchPlanks_stairs ||
  352. type == birchPlanks_wall ||
  353. type == spruce_log ||
  354. type == oakChair ||
  355. type == crate ||
  356. type == oakLogChair ||
  357. type == strippedOakLog ||
  358. type == strippedBirchLog ||
  359. type == strippedSpruceLog ||
  360. type == logWall;
  361. }
  362. bool isBricksSound(BlockType type)
  363. {
  364. return type == bricks ||
  365. type == tiledStoneBricks ||
  366. type == bricks_stairs ||
  367. type == bricks_slabs ||
  368. type == marbleBricks ||
  369. type == marbleBricks_stairs ||
  370. type == marbleBricks_slabs ||
  371. type == marbleBricks_wall ||
  372. type == blueBricks ||
  373. type == blueBricks_stairs ||
  374. type == blueBricks_wall ||
  375. type == blueBricks_slabs ||
  376. type == bricks_wall;
  377. }
  378. bool isVolcanicActiveSound(BlockType type)
  379. {
  380. return type == volcanicHotRock;
  381. }
  382. bool isVolcanicInActiveSound(BlockType type)
  383. {
  384. return type == volcanicRock ||
  385. type == volcanicRock_stairts ||
  386. type == volcanicRock_slabs ||
  387. type == volcanicRock_wall;
  388. }
  389. bool isAnyWoddenLOG(BlockType type)
  390. {
  391. return
  392. type == woodLog ||
  393. type == birch_log ||
  394. type == jungle_log ||
  395. type == palm_log ||
  396. type == strippedOakLog ||
  397. type == strippedBirchLog ||
  398. type == strippedSpruceLog ||
  399. type == spruce_log;
  400. }
  401. bool isAnyWool(BlockType type)
  402. {
  403. return type == clothBlock || type == cloth_stairs || type == cloth_slabs || type == cloth_wall;
  404. }
  405. bool isAnyDirtBlock(BlockType type)
  406. {
  407. return
  408. type == grassBlock ||
  409. type == dirt ||
  410. type == pathBlock ||
  411. type == snow_dirt ||
  412. type == coarseDirt ||
  413. type == yellowGrass ||
  414. type == mud;
  415. }
  416. bool isAnyClayBlock(BlockType type)
  417. {
  418. return
  419. type == clay ||
  420. type == redClay;
  421. }
  422. bool isAnySandyBlock(BlockType type)
  423. {
  424. return
  425. type == sand ||
  426. type == gravel;
  427. }
  428. bool isAnySemiHardBlock(BlockType type)
  429. {
  430. return type == clayBricks ||
  431. type == redClayBricks ||
  432. type == sand_stone ||
  433. type == sandStone_wall ||
  434. type == sandStone_slabs ||
  435. type == sandStone_stairts||
  436. type == terracotta ||
  437. type == terracotta_wall ||
  438. type == terracotta_slabs ||
  439. type == terracotta_stairs
  440. ;
  441. }
  442. //used for breaking
  443. bool isAnyStone(BlockType type)
  444. {
  445. return type == stone ||
  446. type == cobblestone ||
  447. type == bricks ||
  448. type == blueBricks ||
  449. type == blueBricks_stairs ||
  450. type == plankedWallBlock_stairs ||
  451. type == plankedWallBlock_wall ||
  452. type == blueBricks_wall ||
  453. type == blueBricks_slabs ||
  454. type == stoneBrick ||
  455. type == copperOre ||
  456. type == leadOre ||
  457. type == ironOre ||
  458. type == silverOre ||
  459. type == goldOre ||
  460. type == plankedWallBlock ||
  461. type == tiledStoneBricks ||
  462. type == gold_block ||
  463. type == limeStone ||
  464. type == smoothLimeStone ||
  465. type == smoothLimeStone_wall ||
  466. type == smoothLimeStone_stairs ||
  467. type == smoothLimeStone_slabs ||
  468. type == mossyCobblestone ||
  469. type == mossyCobblestone_stairs ||
  470. type == mossyCobblestone_slab ||
  471. type == mossyCobblestone_wall ||
  472. type == marbleBlock ||
  473. type == marbleBlock_stairs ||
  474. type == marbleBlock_slabs ||
  475. type == marbleBlock_wall ||
  476. type == smoothMarbleBlock ||
  477. type == marbleBricks ||
  478. type == marbleBricks_stairs ||
  479. type == marbleBricks_slabs ||
  480. type == marbleBricks_wall ||
  481. type == marblePillar ||
  482. type == stone_stairts ||
  483. type == stone_slabs ||
  484. type == stone_wall ||
  485. type == cobbleStone_stairts ||
  486. type == cobbleStone_slabs ||
  487. type == cobbleStone_wall ||
  488. type == tiledStoneBricks_stairs ||
  489. type == tiledStoneBricks_slab ||
  490. type == tiledStoneBricks_wall ||
  491. type == bricks_stairs ||
  492. type == bricks_slabs ||
  493. type == bricks_wall ||
  494. type == volcanicHotRock ||
  495. type == volcanicRock ||
  496. type == volcanicRock_slabs ||
  497. type == volcanicRock_stairts ||
  498. type == volcanicRock_wall ||
  499. type == hardSandStone ||
  500. type == hardSandStone_slabs ||
  501. type == hardSandStone_stairs ||
  502. type == hardSandStone_wall ||
  503. type == smoothStone ||
  504. type == smoothStone_stairts ||
  505. type == smoothStone_slabs ||
  506. type == smoothStone_wall ||
  507. type == stoneBricks_stairts ||
  508. type == stoneBricks_slabs ||
  509. type == stoneBricks_wall;
  510. }
  511. bool isDungeonBrick(BlockType type)
  512. {
  513. return
  514. type == dungeonBricks ||
  515. type == dungeonBricks_slabs ||
  516. type == dungeonBricks_stairts ||
  517. type == dungeonBricks_wall ||
  518. type == dungeonStone ||
  519. type == dungeonStone_stairs ||
  520. type == dungeonStone_slabs ||
  521. type == dungeonStone_wall ||
  522. type == dungeonCobblestone ||
  523. type == dungeonCobblestone_stairs ||
  524. type == dungeonCobblestone_slabs ||
  525. type == dungeonCobblestone_wall ||
  526. type == dungeonSmoothStone ||
  527. type == dungeonSmoothStone_stairs ||
  528. type == dungeonSmoothStone_slabs ||
  529. type == dungeonSmoothStone_wall ||
  530. type == dungeonPillar ||
  531. type == chiseledDungeonBrick ||
  532. type == dungeonGlass ||
  533. type == dungeonSkullBlock;
  534. }
  535. bool isAnyPlant(BlockType type)
  536. {
  537. return type == grass ||
  538. type == rose ||
  539. type == dead_bush ||
  540. type == vines ||
  541. type == cactus_bud;
  542. }
  543. bool isAnyGlass(BlockType type)
  544. {
  545. return isStainedGlass(type) || type == glass || type == glass2 ||
  546. type == glassNotClear || type == vitral1 || type == vitral2 || type == glassNotClear2
  547. || type == dungeonGlass;
  548. }
  549. bool isChest(BlockType type)
  550. {
  551. return
  552. type == woddenChest ||
  553. type == goblinChest ||
  554. type == copperChest ||
  555. type == ironChest ||
  556. type == silverChest ||
  557. type == goldChest;
  558. }
  559. bool isTriviallyBreakable(BlockType type)
  560. {
  561. return type == torch || type == torchWood || type == lamp || type == goblinTorch;
  562. }
  563. bool isAnyUnbreakable(BlockType type)
  564. {
  565. //todo make sure this can't get to the client or just make them breakable
  566. return isControlBlock(type);
  567. }
  568. bool isAnyHotSoundingBlock(BlockType type)
  569. {
  570. return type == volcanicHotRock;
  571. }
  572. bool isAnyLeaves(BlockType type)
  573. {
  574. return type == leaves ||
  575. type == palm_leaves ||
  576. type == spruce_leaves ||
  577. type == spruce_leaves_red ||
  578. type == jungle_leaves ||
  579. type == birch_leaves;
  580. }
  581. bool isStainedGlass(BlockType type)
  582. {
  583. return type >= magenta_stained_glass && type <= pink_stained_glass;
  584. }
  585. unsigned char isInteractable(BlockType type)
  586. {
  587. int craftingStation = isCraftingStation(type);
  588. if (craftingStation)
  589. {
  590. return craftingStation;
  591. }else if (type == BlockTypes::structureBase)
  592. {
  593. return InteractionTypes::structureBaseBlock;
  594. }
  595. else if (isChest(type))
  596. {
  597. return InteractionTypes::chestInteraction;
  598. }
  599. return InteractionTypes::none;
  600. }
  601. bool isBlock(std::uint16_t type) //todo == 0 ???????????????????/
  602. {
  603. return type > 0 && type < BlocksCount;
  604. }
  605. bool Block::normalize()
  606. {
  607. auto type = getType();
  608. //remove wierd blocks!
  609. if (type >= BlockTypes::BlocksCount)
  610. {
  611. typeAndFlags = {};
  612. return true;
  613. }
  614. //we have flags...
  615. if (getFlagsBytes())
  616. {
  617. //todo
  618. }
  619. return false;
  620. }
  621. float Block::getFriction()
  622. {
  623. if (getType() == BlockTypes::ice)
  624. {
  625. return 1.f;
  626. }
  627. return BLOCK_DEFAULT_FRICTION;
  628. }
  629. int isCraftingStation(unsigned short type)
  630. {
  631. switch (type)
  632. {
  633. case craftingItems:
  634. case goblinWorkBench:
  635. case workBench: return WorkStationType_WorkBench;
  636. case cookingPot: return WorkStationType_CookingPot;
  637. case furnace: return WorkStationType_Furnace;
  638. case goblinStitchingPost: return WorkStationType_GoblinStitchingPost;
  639. }
  640. return 0;
  641. }
  642. float getBlockBaseMineDuration(BlockType type)
  643. {
  644. if (!isBlock(type)) { return 0; }
  645. if (type == water) { return 0; }
  646. if (isAnyWoddenBlock(type))
  647. {
  648. return 2.5;
  649. }
  650. if (isAnyDirtBlock(type))
  651. {
  652. return 0.75;
  653. }
  654. if (isAnyClayBlock(type))
  655. {
  656. return 0.75;
  657. }
  658. if (isAnySandyBlock(type))
  659. {
  660. return 0.75;
  661. }
  662. if (type == snow_block)
  663. { return 0.75; }
  664. if (isAnySemiHardBlock(type) || type == testBlock)
  665. {
  666. return 2.5;
  667. }
  668. if (isDungeonBrick(type))
  669. {
  670. return 9999999.0;
  671. }
  672. if (isAnyStone(type))
  673. {
  674. return 3.5;
  675. }
  676. if (isAnyPlant(type))
  677. {
  678. return 0.2;
  679. }
  680. if (isAnyGlass(type) || type == ice || type == glowstone)
  681. {
  682. return 0.75;
  683. }
  684. if (isAnyLeaves(type))
  685. {
  686. return 0.75 / 3.f;
  687. }
  688. if (isAnyWool(type))
  689. {
  690. return 0.75;
  691. }
  692. if (isAnyUnbreakable(type))
  693. {
  694. return 9999999.0f;
  695. }
  696. if (isTriviallyBreakable(type))
  697. {
  698. return 0.2;
  699. }
  700. if (type == cobweb)
  701. {
  702. return 1;
  703. }
  704. if (type == structureBase)
  705. {
  706. return 1;
  707. }
  708. if (isDecorativeFurniture(type))
  709. {
  710. return 0.2;
  711. }
  712. if (type == hayBalde)
  713. {
  714. return 0.3;
  715. }
  716. std::cout << "Block without base mine duration assigned!: " << type << "\n";
  717. permaAssertComment(0, ("Block without base mine duration assigned!: " + std::to_string(type)).c_str());
  718. return 0.0f;
  719. }
  720. bool canBeMinedByHand(std::uint16_t type)
  721. {
  722. if (!isBlock(type)) { return 0; }
  723. if (
  724. isAnyWoddenBlock(type) ||
  725. isAnyDirtBlock(type) ||
  726. isAnyClayBlock(type) ||
  727. isAnySandyBlock(type) ||
  728. type == snow_block ||
  729. isAnySemiHardBlock(type) || type == testBlock ||
  730. isAnyPlant(type) || isAnyGlass(type) || type == ice || type == glowstone ||
  731. isAnyWool(type) ||
  732. isTriviallyBreakable(type)
  733. )
  734. {
  735. return true;
  736. }
  737. return false;
  738. }
  739. bool canBeMinedByPickaxe(std::uint16_t type)
  740. {
  741. if (!isBlock(type)) { return 0; }
  742. if (
  743. isAnySemiHardBlock(type) || type == testBlock ||
  744. isAnyPlant(type) || isAnyGlass(type) || type == ice || type == glowstone ||
  745. isTriviallyBreakable(type) ||
  746. isAnyStone(type)
  747. )
  748. {
  749. return true;
  750. }
  751. return false;
  752. }
  753. bool canBeMinedByShovel(std::uint16_t type)
  754. {
  755. if (!isBlock(type)) { return 0; }
  756. if (
  757. isAnyDirtBlock(type) ||
  758. isAnyClayBlock(type) ||
  759. type == snow_block ||
  760. isAnyPlant(type) ||
  761. isTriviallyBreakable(type)
  762. )
  763. {
  764. return true;
  765. }
  766. return false;
  767. }
  768. bool canBeMinedByAxe(std::uint16_t type)
  769. {
  770. if (!isBlock(type)) { return 0; }
  771. if (!isBlock(type)) { return 0; }
  772. if (
  773. isAnyWoddenBlock(type) ||
  774. isAnyPlant(type) ||
  775. isTriviallyBreakable(type)
  776. )
  777. {
  778. return true;
  779. }
  780. return false;
  781. }
  782. BlockType fromAnyShapeToNormalBlockType(BlockType b)
  783. {
  784. switch (b)
  785. {
  786. case oakLogChair:
  787. case oakLogSlab:
  788. case logWall: {return woodLog; }
  789. case oakChair:
  790. case wooden_slab:
  791. case wooden_wall:
  792. case wooden_stairs: { return wooden_plank; };
  793. case bricks_slabs:
  794. case bricks_wall:
  795. case bricks_stairs: { return bricks; };
  796. case stone_slabs:
  797. case stone_wall:
  798. case stone_stairts: { return stone; };
  799. case cobbleStone_slabs:
  800. case cobbleStone_wall:
  801. case cobbleStone_stairts: { return cobblestone; };
  802. case stoneBricks_slabs:
  803. case stoneBricks_wall:
  804. case stoneBricks_stairts: { return stoneBrick; };
  805. case hardSandStone_slabs:
  806. case hardSandStone_wall:
  807. case hardSandStone_stairs: { return hardSandStone; };
  808. case sandStone_slabs:
  809. case sandStone_wall:
  810. case sandStone_stairts: { return sand_stone; };
  811. case dungeonBricks_slabs:
  812. case dungeonBricks_wall:
  813. case dungeonBricks_stairts: { return dungeonBricks; };
  814. case volcanicRock_slabs:
  815. case volcanicRock_wall:
  816. case volcanicRock_stairts: { return volcanicRock_stairts; };
  817. case smoothStone_slabs:
  818. case smoothStone_wall:
  819. case smoothStone_stairts: { return smoothStone; };
  820. case smoothLimeStone_slabs:
  821. case smoothLimeStone_wall:
  822. case smoothLimeStone_stairs: { return limeStone; };
  823. case marbleBlock_slabs:
  824. case marbleBlock_wall:
  825. case marbleBlock_stairs: { return marbleBlock; };
  826. case marbleBricks_slabs:
  827. case marbleBricks_wall:
  828. case marbleBricks_stairs: { return marbleBlock_stairs; };
  829. case blueBricks_slabs:
  830. case blueBricks_wall:
  831. case blueBricks_stairs: { return blueBricks; };
  832. case tiledStoneBricks_slab:
  833. case tiledStoneBricks_wall:
  834. case tiledStoneBricks_stairs: { return tiledStoneBricks; };
  835. case cloth_slabs:
  836. case cloth_wall:
  837. case cloth_stairs: { return clothBlock; };
  838. case plankedWallBlock_wall:
  839. case plankedWallBlock_stairs: { return plankedWallBlock; };
  840. case terracotta_slabs:
  841. case terracotta_wall:
  842. case terracotta_stairs: { return terracotta; };
  843. case birchPlanks_slabs:
  844. case birchPlanks_wall:
  845. case birchPlanks_stairs: { return birchPlanks; };
  846. case sprucePlank_stairs:
  847. case sprucePlank_slabs:
  848. case sprucePlank_wall: { return sprucePlank; };
  849. case dungeonStone_stairs :
  850. case dungeonStone_slabs :
  851. case dungeonStone_wall: { return dungeonStone; }
  852. case dungeonCobblestone_stairs:
  853. case dungeonCobblestone_slabs:
  854. case dungeonCobblestone_wall: { return dungeonCobblestone; }
  855. case dungeonSmoothStone_stairs:
  856. case dungeonSmoothStone_slabs:
  857. case dungeonSmoothStone_wall: { return dungeonSmoothStone; }
  858. case mossyCobblestone_stairs:
  859. case mossyCobblestone_slab:
  860. case mossyCobblestone_wall: { return mossyCobblestone; }
  861. };
  862. if (INTERNAL_BUILD == 1)
  863. {
  864. permaAssertComment(!isStairsMesh(b), "error you forgot to add a stair here!");
  865. permaAssertComment(!isWallMesh(b), "error you forgot to add a wall here!");
  866. permaAssertComment(!isSlabMesh(b), "error you forgot to add a slab here!");
  867. }
  868. return b;
  869. }