BlockChangedUpdate.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "BlockChangedUpdate.h"
  2. #include <Vec3.h>
  3. #include "Globals.h"
  4. #include "Registries.h"
  5. BlockChangedUpdateType::BlockChangedUpdateType()
  6. : WorldUpdateType( ID )
  7. {}
  8. void BlockChangedUpdateType::applyUpdate( Framework::StreamReader* zReader )
  9. {
  10. int dimension = 0;
  11. zReader->lese( (char*)&dimension, 4 );
  12. Framework::Vec3<int> pos;
  13. zReader->lese( (char*)&pos.x, 4 );
  14. zReader->lese( (char*)&pos.y, 4 );
  15. zReader->lese( (char*)&pos.z, 4 );
  16. unsigned short id;
  17. zReader->lese( (char*)&id, 2 );
  18. bool d = 1;
  19. zReader->lese( (char*)&d, 1 );
  20. Block* b = currentGame->zBlockAt( pos, dimension );
  21. if( !d )
  22. {
  23. if( !b || b->zBlockType()->getId() != id )
  24. {
  25. if( STATIC_REGISTRY( BlockType ).zElement( id )->needsInstance() )
  26. {
  27. b = STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos );
  28. currentGame->zDimension( dimension )->setBlock( b );
  29. }
  30. else if( b )
  31. currentGame->zDimension( dimension )->removeBlock( b );
  32. }
  33. }
  34. else
  35. {
  36. if( b )
  37. STATIC_REGISTRY( BlockType ).zElement( id )->updateBlock( b, zReader );
  38. else
  39. {
  40. b = STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos );
  41. STATIC_REGISTRY( BlockType ).zElement( id )->updateBlock( b, zReader );
  42. currentGame->zDimension( dimension )->setBlock( b );
  43. }
  44. }
  45. }