BlockChangedUpdate.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "BlockChangedUpdate.h"
  2. #include "Game.h"
  3. BlockChangedUpdate::BlockChangedUpdate( Framework::Vec3<int> pos, int dimension )
  4. : WorldUpdate( BlockChangedUpdateType::ID, dimension, pos, pos )
  5. {}
  6. BlockChangedUpdate::~BlockChangedUpdate()
  7. {
  8. auto b = Game::INSTANCE->zBlockAt( getMinAffectedPoint(), getAffectedDimension() );
  9. if( b.isA() && b.getA() )
  10. b.getA()->onAfterTransmission();
  11. }
  12. void BlockChangedUpdate::onUpdate( Dimension* zDimension )
  13. {}
  14. void BlockChangedUpdate::write( Framework::StreamWriter* zWriter )
  15. {
  16. int dimensionID = getAffectedDimension();
  17. zWriter->schreibe( (char*)&dimensionID, 4 );
  18. auto pos = getMinAffectedPoint();
  19. zWriter->schreibe( (char*)&pos.x, 4 );
  20. zWriter->schreibe( (char*)&pos.y, 4 );
  21. zWriter->schreibe( (char*)&pos.z, 4 );
  22. auto b = Game::INSTANCE->zBlockAt( pos, getAffectedDimension() );
  23. unsigned short blockType = b.isA() ? (unsigned short)b.getA()->zBlockType()->getId() : (unsigned short)b.getB();
  24. if( b.isA() && b.getA()->isDeadAndRemoved() )
  25. {
  26. blockType = 0;
  27. zWriter->schreibe( (char*)&blockType, 2 );
  28. }
  29. else
  30. {
  31. zWriter->schreibe( (char*)&blockType, 2 );
  32. if( b.isA() )
  33. {
  34. bool d = 1;
  35. zWriter->schreibe( (char*)&d, 1 );
  36. StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->saveBlock( b.getA(), zWriter );
  37. }
  38. else
  39. {
  40. bool d = 0;
  41. zWriter->schreibe( (char*)&d, 1 );
  42. }
  43. }
  44. }
  45. BlockChangedUpdateType::BlockChangedUpdateType()
  46. : WorldUpdateType( ID )
  47. {}