123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "BlockChangedUpdate.h"
- #include "Game.h"
- BlockChangedUpdate::BlockChangedUpdate( Framework::Vec3<int> pos, int dimension )
- : WorldUpdate( BlockChangedUpdateType::ID, dimension, pos, pos )
- {}
- BlockChangedUpdate::~BlockChangedUpdate()
- {
- auto b = Game::INSTANCE->zBlockAt( getMinAffectedPoint(), getAffectedDimension() );
- if( b.isA() && b.getA() )
- b.getA()->onAfterTransmission();
- }
- void BlockChangedUpdate::onUpdate( Dimension* zDimension )
- {}
- void BlockChangedUpdate::write( Framework::StreamWriter* zWriter )
- {
- int dimensionID = getAffectedDimension();
- zWriter->schreibe( (char*)&dimensionID, 4 );
- auto pos = getMinAffectedPoint();
- zWriter->schreibe( (char*)&pos.x, 4 );
- zWriter->schreibe( (char*)&pos.y, 4 );
- zWriter->schreibe( (char*)&pos.z, 4 );
- auto b = Game::INSTANCE->zBlockAt( pos, getAffectedDimension() );
- unsigned short blockType = b.isA() ? (unsigned short)b.getA()->zBlockType()->getId() : (unsigned short)b.getB();
- if( b.isA() && b.getA()->isDeadAndRemoved() )
- {
- blockType = 0;
- zWriter->schreibe( (char*)&blockType, 2 );
- }
- else
- {
- zWriter->schreibe( (char*)&blockType, 2 );
- if( b.isA() )
- {
- bool d = 1;
- zWriter->schreibe( (char*)&d, 1 );
- StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->saveBlock( b.getA(), zWriter );
- }
- else
- {
- bool d = 0;
- zWriter->schreibe( (char*)&d, 1 );
- }
- }
- }
- BlockChangedUpdateType::BlockChangedUpdateType()
- : WorldUpdateType( ID )
- {}
|