mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 12:01:50 +00:00
lua: inventory.clone
This commit is contained in:
parent
60902e69ba
commit
cac963bd7b
5 changed files with 29 additions and 0 deletions
|
|
@ -44,6 +44,16 @@ std::shared_ptr<Inventory> Inventories::get(int64_t id) {
|
|||
return found->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<Inventory> Inventories::clone(int64_t id) {
|
||||
auto original = get(id);
|
||||
if (original == nullptr)
|
||||
return nullptr;
|
||||
auto origptr = reinterpret_cast<const Inventory*>(original.get());
|
||||
auto clone = std::make_shared<Inventory>(*origptr);
|
||||
clone->setId(level.getWorld()->getNextInventoryId());
|
||||
return clone;
|
||||
}
|
||||
|
||||
const inventories_map& Inventories::getMap() const {
|
||||
return map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ public:
|
|||
/* Get inventory by id (works with both real and virtual)*/
|
||||
std::shared_ptr<Inventory> get(int64_t id);
|
||||
|
||||
std::shared_ptr<Inventory> clone(int64_t id);
|
||||
|
||||
const inventories_map& getMap() const;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ public:
|
|||
|
||||
static void convert(dynamic::Map* data, const ContentLUT* lut);
|
||||
|
||||
inline void setId(int64_t id) {
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
inline int64_t getId() const {
|
||||
return id;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue