12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "PlaceBlockUpdate.h"
- #include "Block.h"
- #include "Dimension.h"
- PlaceBlockUpdate::PlaceBlockUpdate( Framework::Either<Block*, int> block, Framework::Vec3<int> location, int dimensionId )
- : WorldUpdate( PlaceBlockUpdateType::ID, dimensionId, location, location ),
- block( block )
- {}
- PlaceBlockUpdate::~PlaceBlockUpdate()
- {
- if( block.isA() )
- block.getA()->release();
- }
- void PlaceBlockUpdate::onUpdate( Dimension* zDimension )
- {
- if( block.isA() )
- block.getA()->getThis();
- zDimension->placeBlock( getMaxAffectedPoint(), block );
- }
- void PlaceBlockUpdate::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 );
- unsigned short blockType = block.isA() ? (unsigned short)block.getA()->zBlockType()->getId() : (unsigned short)block.getB();
- zWriter->schreibe( (char*)&blockType, 2 );
- if( block.isA() )
- {
- bool d = 1;
- zWriter->schreibe( (char*)&d, 1 );
- StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->saveBlock( block, zWriter );
- }
- else
- {
- bool d = 0;
- zWriter->schreibe( (char*)&d, 1 );
- }
- }
- Block* PlaceBlockUpdate::zBlock() const
- {
- return block;
- }
- PlaceBlockUpdateType::PlaceBlockUpdateType()
- : WorldUpdateType( ID )
- {}
|