BasicBlock.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. #include "BasicBlocks.h"
  2. BasicBlock::BasicBlock(const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos)
  3. : Block(zType, zTool, pos, false)
  4. {}
  5. bool BasicBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
  6. {
  7. return 0;
  8. }
  9. void BasicBlock::onPostTick()
  10. {}
  11. BasicBlockType::BasicBlockType(int typeId, int itemTypeId, ModelInfo model)
  12. : BlockType(typeId, 0, model, 1, 100, 0),
  13. itemType(itemTypeId),
  14. transparent(0),
  15. passable(0),
  16. hardness(1.f),
  17. zTool(0),
  18. speedModifier(1.f),
  19. interactable(1)
  20. {}
  21. void BasicBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
  22. {
  23. BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
  24. if (!block)
  25. throw "DirtBlockType::createSuperBlock was called with a block witch is not an instance of BasicBlock";
  26. block->transparent = transparent;
  27. block->passable = passable;
  28. block->hp = (float)getInitialMaxHP();
  29. block->maxHP = (float)getInitialMaxHP();
  30. block->hardness = hardness;
  31. block->zTool = zTool;
  32. block->speedModifier = speedModifier;
  33. block->interactable = interactable;
  34. BlockType::createSuperBlock(zBlock, zItem);
  35. }
  36. Block* BasicBlockType::createBlock(Framework::Vec3<int> position) const
  37. {
  38. return new BasicBlock(this, 0, position);
  39. }
  40. Item* BasicBlockType::createItem() const
  41. {
  42. return StaticRegistry<ItemType>::INSTANCE.zElement(itemType)->createItem();
  43. }
  44. // Dirt
  45. DirtBlockType::DirtBlockType()
  46. : BasicBlockType(ID, DirtBlockItemType::ID, ModelInfo("cube", { "blocks.ltdb/dirt.png", "blocks.ltdb/dirt.png", "blocks.ltdb/dirt.png", "blocks.ltdb/dirt.png", "blocks.ltdb/lawn.png", "blocks.ltdb/dirt.png" }))
  47. {
  48. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  49. }
  50. DirtBlockItemType::DirtBlockItemType()
  51. : BasicBlockItemType(ID, "Dirt", 0, 0, ModelInfo("itemCube", "blocks.ltdb/dirt.png", 6))
  52. {}
  53. Item* DirtBlockItemType::createItem() const
  54. {
  55. BasicBlockItem* item = new BasicBlockItem(this, DirtBlockType::INSTANCE, "Dirt");
  56. initializeItem(item, 0, 0, 1, 0, 1);
  57. return item;
  58. }
  59. // Stone
  60. StoneBlockType::StoneBlockType()
  61. : BasicBlockType(ID, StoneBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/stone.png", 6))
  62. {
  63. hardness = 2.f;
  64. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  65. }
  66. StoneBlockItemType::StoneBlockItemType()
  67. : BasicBlockItemType(ID, "Stone", 0, 0, ModelInfo("itemCube", "blocks.ltdb/stone.png", 6))
  68. {}
  69. Item* StoneBlockItemType::createItem() const
  70. {
  71. BasicBlockItem* item = new BasicBlockItem(this, StoneBlockType::INSTANCE, "Stone");
  72. initializeItem(item, 0, 0, 2, 0, 1);
  73. return item;
  74. }
  75. // Sand
  76. SandBlockType::SandBlockType()
  77. : BasicBlockType(ID, SandBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/sand.png", 6))
  78. {
  79. hardness = 0.5f;
  80. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  81. }
  82. SandBlockItemType::SandBlockItemType()
  83. : BasicBlockItemType(ID, "Sand", 0, 0, ModelInfo("itemCube", "blocks.ltdb/sand.png", 6))
  84. {}
  85. Item* SandBlockItemType::createItem() const
  86. {
  87. BasicBlockItem* item = new BasicBlockItem(this, SandBlockType::INSTANCE, "Sand");
  88. initializeItem(item, 0, 0, 0.5f, 0, 1);
  89. return item;
  90. }
  91. // Oak Wood
  92. OakBlockType::OakBlockType()
  93. : BasicBlockType(ID, OakBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/oak.png", 6))
  94. {
  95. hardness = 1.5f;
  96. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  97. }
  98. OakBlockItemType::OakBlockItemType()
  99. : BasicBlockItemType(ID, "Oak", 0, 0, ModelInfo("itemCube", "blocks.ltdb/oak.png", 6))
  100. {}
  101. Item* OakBlockItemType::createItem() const
  102. {
  103. BasicBlockItem* item = new BasicBlockItem(this, OakBlockType::INSTANCE, "Oak");
  104. initializeItem(item, 0, 0, 1.5f, 0, 1);
  105. return item;
  106. }
  107. // Leaves Wood
  108. LeavesBlockType::LeavesBlockType()
  109. : BasicBlockType(ID, LeavesBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/leaves.png", 6))
  110. {
  111. hardness = 0.1f;
  112. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  113. }
  114. LeavesBlockItemType::LeavesBlockItemType()
  115. : BasicBlockItemType(ID, "Leaves", 0, 0, ModelInfo("itemCube", "blocks.ltdb/leaves.png", 6))
  116. {}
  117. Item* LeavesBlockItemType::createItem() const
  118. {
  119. BasicBlockItem* item = new BasicBlockItem(this, LeavesBlockType::INSTANCE, "Leaves");
  120. initializeItem(item, 0, 0, 0.1f, 0, 1);
  121. return item;
  122. }
  123. // Gravel
  124. GravelBlockType::GravelBlockType()
  125. : BasicBlockType(ID, GravelBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/gravel.png", 6))
  126. {
  127. hardness = 0.75f;
  128. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  129. }
  130. GravelBlockItemType::GravelBlockItemType()
  131. : BasicBlockItemType(ID, "Gravel", 0, 0, ModelInfo("itemCube", "blocks.ltdb/gravel.png", 6))
  132. {}
  133. Item* GravelBlockItemType::createItem() const
  134. {
  135. BasicBlockItem* item = new BasicBlockItem(this, GravelBlockType::INSTANCE, "Gravel");
  136. initializeItem(item, 0, 0, 0.75f, 0, 1);
  137. return item;
  138. }
  139. // Granite
  140. GraniteBlockType::GraniteBlockType()
  141. : BasicBlockType(ID, GraniteBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/granite.png", 6))
  142. {
  143. hardness = 3.f;
  144. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  145. }
  146. GraniteBlockItemType::GraniteBlockItemType()
  147. : BasicBlockItemType(ID, "Granite", 0, 0, ModelInfo("itemCube", "blocks.ltdb/granite.png", 6))
  148. {}
  149. Item* GraniteBlockItemType::createItem() const
  150. {
  151. BasicBlockItem* item = new BasicBlockItem(this, GraniteBlockType::INSTANCE, "Granite");
  152. initializeItem(item, 0, 0, 3.f, 0, 1);
  153. return item;
  154. }
  155. // Cobble
  156. CobbleBlockType::CobbleBlockType()
  157. : BasicBlockType(ID, CobbleBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/cobble.png", 6))
  158. {
  159. hardness = 1.f;
  160. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  161. }
  162. CobbleBlockItemType::CobbleBlockItemType()
  163. : BasicBlockItemType(ID, "Cobble", 0, 0, ModelInfo("itemCube", "blocks.ltdb/cobble.png", 6))
  164. {}
  165. Item* CobbleBlockItemType::createItem() const
  166. {
  167. BasicBlockItem* item = new BasicBlockItem(this, CobbleBlockType::INSTANCE, "Cobble");
  168. initializeItem(item, 0, 0, 1.f, 0, 1);
  169. return item;
  170. }
  171. // Birch Wood
  172. BirchBlockType::BirchBlockType()
  173. : BasicBlockType(ID, BirchBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/birch.png", 6))
  174. {
  175. hardness = 1.5f;
  176. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  177. }
  178. BirchBlockItemType::BirchBlockItemType()
  179. : BasicBlockItemType(ID, "Birch", 0, 0, ModelInfo("itemCube", "blocks.ltdb/birch.png", 6))
  180. {}
  181. Item* BirchBlockItemType::createItem() const
  182. {
  183. BasicBlockItem* item = new BasicBlockItem(this, BirchBlockType::INSTANCE, "Birch");
  184. initializeItem(item, 0, 0, 1.5f, 0, 1);
  185. return item;
  186. }
  187. // Beech Wood
  188. BeechBlockType::BeechBlockType()
  189. : BasicBlockType(ID, BeechBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/beech.png", 6))
  190. {
  191. hardness = 1.5f;
  192. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  193. }
  194. BeechBlockItemType::BeechBlockItemType()
  195. : BasicBlockItemType(ID, "Beech", 0, 0, ModelInfo("itemCube", "blocks.ltdb/beech.png", 6))
  196. {}
  197. Item* BeechBlockItemType::createItem() const
  198. {
  199. BasicBlockItem* item = new BasicBlockItem(this, BeechBlockType::INSTANCE, "Beech");
  200. initializeItem(item, 0, 0, 1.5f, 0, 1);
  201. return item;
  202. }
  203. // Basalt
  204. BasaltBlockType::BasaltBlockType()
  205. : BasicBlockType(ID, BasaltBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/basalt.png", 6))
  206. {
  207. hardness = 2.f;
  208. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  209. }
  210. BasaltBlockItemType::BasaltBlockItemType()
  211. : BasicBlockItemType(ID, "Basalt", 0, 0, ModelInfo("itemCube", "blocks.ltdb/basalt.png", 6))
  212. {}
  213. Item* BasaltBlockItemType::createItem() const
  214. {
  215. BasicBlockItem* item = new BasicBlockItem(this, BasaltBlockType::INSTANCE, "Basalt");
  216. initializeItem(item, 0, 0, 2.f, 0, 1);
  217. return item;
  218. }
  219. // Pine Wood
  220. PineBlockType::PineBlockType()
  221. : BasicBlockType(ID, PineBlockItemType::ID, ModelInfo("cube", "blocks.ltdb/pine.png", 6))
  222. {
  223. hardness = 1.4f;
  224. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  225. }
  226. PineBlockItemType::PineBlockItemType()
  227. : BasicBlockItemType(ID, "Pine", 0, 0, ModelInfo("itemCube", "blocks.ltdb/pine.png", 6))
  228. {}
  229. Item* PineBlockItemType::createItem() const
  230. {
  231. BasicBlockItem* item = new BasicBlockItem(this, PineBlockType::INSTANCE, "Pine");
  232. initializeItem(item, 0, 0, 1.4f, 0, 1);
  233. return item;
  234. }