EntityChangedUpdate.cpp 974 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "EntityChangedUpdate.h"
  2. #include "Game.h"
  3. #include "EntityType.h"
  4. EntityChangedUpdate::EntityChangedUpdate( int entityId, Framework::Vec3<int> pos, int dimension )
  5. : WorldUpdate( EntityChangedUpdateType::ID, dimension, pos, pos ),
  6. entityId( entityId )
  7. {}
  8. EntityChangedUpdate::~EntityChangedUpdate()
  9. {}
  10. void EntityChangedUpdate::onUpdate( Dimension* zDimension )
  11. {}
  12. void EntityChangedUpdate::write( Framework::StreamWriter* zWriter )
  13. {
  14. Entity* entity = Game::INSTANCE->zEntity( entityId, getAffectedDimension() );
  15. if( entity )
  16. {
  17. int type = entity->zType()->getId();
  18. zWriter->schreibe( (char*)&entityId, 4 );
  19. zWriter->schreibe( (char*)&type, 4 );
  20. StaticRegistry<EntityType>::INSTANCE.zElement( type )->saveEntity( entity, zWriter );
  21. }
  22. else
  23. {
  24. int id = -1;
  25. zWriter->schreibe( (char*)&id, 4 );
  26. }
  27. }
  28. EntityChangedUpdateType::EntityChangedUpdateType()
  29. : WorldUpdateType( ID )
  30. {}