inventory.bind_block, unbind_block

This commit is contained in:
MihailRis
2024-02-19 03:15:35 +03:00
parent 8162def157
commit 98a96a9c1b
10 changed files with 190 additions and 122 deletions
+23
View File
@@ -169,3 +169,26 @@ int64_t BlocksController::createBlockInventory(int x, int y, int z) {
}
return inv->getId();
}
void BlocksController::bindInventory(int64_t invid, int x, int y, int z) {
auto chunk = chunks->getChunkByVoxel(x, y, z);
if (chunk == nullptr) {
throw std::runtime_error("block does not exists");
}
if (invid <= 0) {
throw std::runtime_error("unable to bind virtual inventory");
}
int lx = x - chunk->x * CHUNK_W;
int lz = z - chunk->z * CHUNK_D;
chunk->addBlockInventory(level->inventories->get(invid), lx, y, lz);
}
void BlocksController::unbindInventory(int x, int y, int z) {
auto chunk = chunks->getChunkByVoxel(x, y, z);
if (chunk == nullptr) {
throw std::runtime_error("block does not exists");
}
int lx = x - chunk->x * CHUNK_W;
int lz = z - chunk->z * CHUNK_D;
chunk->removeBlockInventory(lx, y, lz);
}