Block.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. memset( sideVisible, 1, 6 );
  17. Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
  18. }
  19. Block::~Block()
  20. {}
  21. bool Block::isTransparent() const
  22. {
  23. return transparent;
  24. }
  25. bool Block::isPassable() const
  26. {
  27. return passable;
  28. }
  29. void Block::setSideVisible( Direction dir, bool visible )
  30. {
  31. sideVisible[ getDirectionIndex( dir ) ] = visible;
  32. }
  33. const BlockType* Block::zBlockType() const
  34. {
  35. return zType;
  36. }
  37. BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
  38. : Item( zType, name )
  39. {
  40. placeable = 1;
  41. transparent = 0;
  42. passable = 0;
  43. hp = 0;
  44. maxHP = 0;
  45. hardness = 0;
  46. toolId = 0;
  47. speedModifier = 0;
  48. }
  49. BasicBlockItemType::BasicBlockItemType( int id )
  50. : ItemType( id )
  51. {}
  52. void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
  53. {
  54. ItemType::loadSuperItem( zItem, zReader );
  55. BasicBlockItem* item = dynamic_cast<BasicBlockItem*>(zItem);
  56. if( !item )
  57. throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
  58. zReader->lese( (char*)&item->transparent, 1 );
  59. zReader->lese( (char*)&item->passable, 1 );
  60. zReader->lese( (char*)&item->hp, 4 );
  61. zReader->lese( (char*)&item->maxHP, 4 );
  62. zReader->lese( (char*)&item->hardness, 4 );
  63. zReader->lese( (char*)&item->toolId, 4 );
  64. zReader->lese( (char*)&item->speedModifier, 4 );
  65. }
  66. Framework::Model3DData* BasicBlockItemType::getItemModel() const
  67. {
  68. return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
  69. }
  70. Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const
  71. {
  72. return 0;
  73. }