BasicBlock.cpp 7.3 KB

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