#include "MultiblockStructure.h" #include "Game.h" using namespace Framework; MultiblockStructure::MultiblockStructure(int dimensionId, __int64 structureId, Framework::Vec3 uniquePosition) : ReferenceCounter(), uniquePosition(uniquePosition), dimensionId(dimensionId), structureId(structureId) {} MultiblockStructure::~MultiblockStructure() {} void MultiblockStructure::onBlockLoaded(Block* block) { if (isBlockMember(block)) loadedMembers.add(block); else block->release(); } void MultiblockStructure::onBlockUnloaded(Block* zBlock) { for (auto i = loadedMembers.begin(); i; ++i) { if ((Block*)i == zBlock) { i.remove(); return; } } } void MultiblockStructure::addMemberPosition(Framework::Vec3 blockPos) { memberBlockPositions.add(blockPos); Punkt center = Game::INSTANCE->getChunkCenter(blockPos.x, blockPos.y); for (const Punkt& p : affectedChunks) { if (p == center) return; } affectedChunks.add(center); } void MultiblockStructure::onBlockRemoved(Block* zBlock) { for (auto i = memberBlockPositions.begin(); i; ++i) { if (i.val() == zBlock->getPos()) { Punkt center = Game::INSTANCE->getChunkCenter(i.val().x, i.val().y); i.remove(); // check if other blocks in the same chunk exists for (Vec3 pos : memberBlockPositions) { if (center == Game::INSTANCE->getChunkCenter(pos.x, pos.y)) return; } // remove chunk from affected chunks if no other block is in this chunk for (auto p = affectedChunks.begin(); p; ++p) { if (p.val() == center) p.remove(); } return; } } } bool MultiblockStructure::isEmpty() const { return memberBlockPositions.getEintragAnzahl() > 0; } bool MultiblockStructure::isFullyLoaded() const { for (Punkt p : affectedChunks) { if (!Game::INSTANCE->isChunkLoaded(p.x, p.y, dimensionId)) return 0; } return 1; } bool MultiblockStructure::isFullyUnloaded() const { for (Punkt p : affectedChunks) { if (Game::INSTANCE->isChunkLoaded(p.x, p.y, dimensionId)) return 0; } return 1; } bool MultiblockStructure::isBlockMember(Block* zBlock) const { for (const Vec3& pos : memberBlockPositions) { if (pos == zBlock->getPos()) return 1; } return 0; } __int64 MultiblockStructure::getStructureId() const { return structureId; } Framework::Vec3 MultiblockStructure::getUniquePosition() const { return uniquePosition; }