BlockChangedUpdate.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. if( id )
  19. {
  20. bool d = 1;
  21. zReader->lese( (char*)&d, 1 );
  22. Block* b = currentGame->zBlockAt( pos, dimension );
  23. if( !d )
  24. {
  25. if( !b || b->zBlockType()->getId() != id )
  26. {
  27. if( STATIC_REGISTRY( BlockType ).zElement( id )->needsInstance() )
  28. {
  29. b = STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos );
  30. currentGame->zDimension( dimension )->setBlock( b );
  31. }
  32. else if( b )
  33. currentGame->zDimension( dimension )->removeBlock( b );
  34. }
  35. }
  36. else
  37. {
  38. if( b )
  39. STATIC_REGISTRY( BlockType ).zElement( id )->updateBlock( b, zReader );
  40. else
  41. {
  42. b = STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos );
  43. STATIC_REGISTRY( BlockType ).zElement( id )->updateBlock( b, zReader );
  44. currentGame->zDimension( dimension )->setBlock( b );
  45. }
  46. }
  47. }
  48. }