blocks.cpp 24 KB

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