1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include "BlockChangedUpdate.h"
- #include <Vec3.h>
- #include "Globals.h"
- #include "Registries.h"
- BlockChangedUpdateType::BlockChangedUpdateType()
- : WorldUpdateType( ID )
- {}
- void BlockChangedUpdateType::applyUpdate( Framework::StreamReader* zReader )
- {
- int dimension = 0;
- zReader->lese( (char*)&dimension, 4 );
- Framework::Vec3<int> pos;
- zReader->lese( (char*)&pos.x, 4 );
- zReader->lese( (char*)&pos.y, 4 );
- zReader->lese( (char*)&pos.z, 4 );
- unsigned short id;
- zReader->lese( (char*)&id, 2 );
- if( id )
- {
- bool d = 1;
- zReader->lese( (char*)&d, 1 );
- Block* b = currentGame->zBlockAt( pos, dimension );
- if( !d )
- {
- if( !b || b->zBlockType()->getId() != id )
- {
- if( STATIC_REGISTRY( BlockType ).zElement( id )->needsInstance() )
- {
- b = STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos );
- currentGame->zDimension( dimension )->setBlock( b );
- }
- else if( b )
- currentGame->zDimension( dimension )->removeBlock( b );
- }
- }
- else
- {
- if( b )
- STATIC_REGISTRY( BlockType ).zElement( id )->updateBlock( b, zReader );
- else
- {
- b = STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos );
- STATIC_REGISTRY( BlockType ).zElement( id )->updateBlock( b, zReader );
- currentGame->zDimension( dimension )->setBlock( b );
- }
- }
- }
- }
|