PlaceBlockUpdate.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "PlaceBlockUpdate.h"
  2. #include "Block.h"
  3. #include "Dimension.h"
  4. PlaceBlockUpdate::PlaceBlockUpdate(Framework::Either<Block*, int> block, Framework::Vec3<int> location, int dimensionId)
  5. : WorldUpdate(PlaceBlockUpdateType::ID, dimensionId, location, location),
  6. block(block)
  7. {}
  8. PlaceBlockUpdate::~PlaceBlockUpdate()
  9. {
  10. if (block.isA())
  11. block.getA()->release();
  12. }
  13. void PlaceBlockUpdate::onUpdate(Dimension* zDimension)
  14. {
  15. if (block.isA())
  16. block.getA()->getThis();
  17. zDimension->placeBlock(getMaxAffectedPoint(), block);
  18. }
  19. void PlaceBlockUpdate::write(Framework::StreamWriter* zWriter)
  20. {
  21. auto pos = getMinAffectedPoint();
  22. zWriter->schreibe((char*)&pos.x, 4);
  23. zWriter->schreibe((char*)&pos.y, 4);
  24. zWriter->schreibe((char*)&pos.z, 4);
  25. unsigned short blockType = block.isA() ? (unsigned short)block.getA()->zBlockType()->getId() : (unsigned short)block.getB();
  26. zWriter->schreibe((char*)&blockType, 2);
  27. }
  28. Block* PlaceBlockUpdate::zBlock() const
  29. {
  30. return block;
  31. }
  32. PlaceBlockUpdateType::PlaceBlockUpdateType()
  33. : WorldUpdateType(ID)
  34. {}