Block.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "Block.h"
  2. #include "Inventory.h"
  3. #include "Globals.h"
  4. Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
  5. : Inventory( pos, hasInventory ),
  6. Model3D(),
  7. zType( zType )
  8. {
  9. transparent = false;
  10. passable = false;
  11. hp = 1;
  12. maxHP = 1;
  13. hardness = 1;
  14. this->zTool = zTool;
  15. speedModifier = 1;
  16. Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
  17. }
  18. Block::~Block()
  19. {}
  20. bool Block::isTransparent() const
  21. {
  22. return transparent;
  23. }
  24. const BlockType* Block::zBlockType() const
  25. {
  26. return zType;
  27. }
  28. BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
  29. : Item( zType, name )
  30. {
  31. placeable = 1;
  32. transparent = 0;
  33. passable = 0;
  34. hp = 0;
  35. maxHP = 0;
  36. hardness = 0;
  37. toolId = 0;
  38. speedModifier = 0;
  39. }
  40. BasicBlockItemType::BasicBlockItemType( int id )
  41. : ItemType( id )
  42. {}
  43. void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
  44. {
  45. ItemType::loadSuperItem( zItem, zReader );
  46. BasicBlockItem* item = dynamic_cast<BasicBlockItem*>(zItem);
  47. if( !item )
  48. throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
  49. zReader->lese( (char*)&item->transparent, 1 );
  50. zReader->lese( (char*)&item->passable, 1 );
  51. zReader->lese( (char*)&item->hp, 4 );
  52. zReader->lese( (char*)&item->maxHP, 4 );
  53. zReader->lese( (char*)&item->hardness, 4 );
  54. zReader->lese( (char*)&item->toolId, 4 );
  55. zReader->lese( (char*)&item->speedModifier, 4 );
  56. }