mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Allow overriding tool capabilities through itemstack metadata
This makes it possible to modify the tool capabilities of individual itemstacks by calling a method on itemstack metadata references.
This commit is contained in:
parent
610ea6f216
commit
a637107a4e
10 changed files with 206 additions and 14 deletions
|
@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#pragma once
|
||||
|
||||
#include "metadata.h"
|
||||
#include "tool.h"
|
||||
|
||||
class Inventory;
|
||||
class IItemDefManager;
|
||||
|
@ -27,6 +28,27 @@ class IItemDefManager;
|
|||
class ItemStackMetadata : public Metadata
|
||||
{
|
||||
public:
|
||||
ItemStackMetadata() : toolcaps_overridden(false) {}
|
||||
|
||||
// Overrides
|
||||
void clear() override;
|
||||
bool setString(const std::string &name, const std::string &var) override;
|
||||
|
||||
void serialize(std::ostream &os) const;
|
||||
void deSerialize(std::istream &is);
|
||||
|
||||
const ToolCapabilities &getToolCapabilities(
|
||||
const ToolCapabilities &default_caps) const
|
||||
{
|
||||
return toolcaps_overridden ? toolcaps_override : default_caps;
|
||||
}
|
||||
|
||||
void setToolCapabilities(const ToolCapabilities &caps);
|
||||
void clearToolCapabilities();
|
||||
|
||||
private:
|
||||
void updateToolCapabilities();
|
||||
|
||||
bool toolcaps_overridden;
|
||||
ToolCapabilities toolcaps_override;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue