Minetest  5.4.0
itemdef.h
Go to the documentation of this file.
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013 Kahrl <kahrl@gmx.net>
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 
21 #pragma once
22 
24 #include <string>
25 #include <iostream>
26 #include <set>
27 #include "itemgroup.h"
28 #include "sound.h"
29 #include "texture_override.h" // TextureOverride
30 class IGameDef;
31 class Client;
32 struct ToolCapabilities;
33 #ifndef SERVER
34 #include "client/tile.h"
35 struct ItemMesh;
36 struct ItemStack;
37 #endif
38 
39 /*
40  Base item definition
41 */
42 
44 {
49 };
50 
52 {
53  /*
54  Basic item properties
55  */
57  std::string name; // "" = hand
58  std::string description; // Shown in tooltip.
59  std::string short_description;
60 
61  /*
62  Visual properties
63  */
64  std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
65  std::string inventory_overlay; // Overlay of inventory_image.
66  std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
67  std::string wield_overlay; // Overlay of wield_image.
68  std::string palette_image; // If specified, the item will be colorized based on this
69  video::SColor color; // The fallback color of the node.
71 
72  /*
73  Item stack and interaction properties
74  */
75  u16 stack_max;
76  bool usable;
78  // May be NULL. If non-NULL, deleted by destructor
83  f32 range;
84 
85  // Client shall immediately place this node when player places the item.
86  // Server will update the precise end result a moment later.
87  // "" = no prediction
89 
90  /*
91  Some helpful methods
92  */
94  ItemDefinition(const ItemDefinition &def);
97  void reset();
98  void serialize(std::ostream &os, u16 protocol_version) const;
99  void deSerialize(std::istream &is);
100 private:
101  void resetInitial();
102 };
103 
105 {
106 public:
107  IItemDefManager() = default;
108 
109  virtual ~IItemDefManager() = default;
110 
111  // Get item definition
112  virtual const ItemDefinition& get(const std::string &name) const=0;
113  // Get alias definition
114  virtual const std::string &getAlias(const std::string &name) const=0;
115  // Get set of all defined item names and aliases
116  virtual void getAll(std::set<std::string> &result) const=0;
117  // Check if item is known
118  virtual bool isKnown(const std::string &name) const=0;
119 #ifndef SERVER
120  // Get item inventory texture
121  virtual video::ITexture* getInventoryTexture(const std::string &name,
122  Client *client) const=0;
123  // Get item wield mesh
124  virtual ItemMesh* getWieldMesh(const std::string &name,
125  Client *client) const=0;
126  // Get item palette
127  virtual Palette* getPalette(const std::string &name,
128  Client *client) const = 0;
129  // Returns the base color of an item stack: the color of all
130  // tiles that do not define their own color.
131  virtual video::SColor getItemstackColor(const ItemStack &stack,
132  Client *client) const = 0;
133 #endif
134 
135  virtual void serialize(std::ostream &os, u16 protocol_version)=0;
136 };
137 
139 {
140 public:
142 
143  virtual ~IWritableItemDefManager() = default;
144 
145  // Get item definition
146  virtual const ItemDefinition& get(const std::string &name) const=0;
147  // Get alias definition
148  virtual const std::string &getAlias(const std::string &name) const=0;
149  // Get set of all defined item names and aliases
150  virtual void getAll(std::set<std::string> &result) const=0;
151  // Check if item is known
152  virtual bool isKnown(const std::string &name) const=0;
153 #ifndef SERVER
154  // Get item inventory texture
155  virtual video::ITexture* getInventoryTexture(const std::string &name,
156  Client *client) const=0;
157  // Get item wield mesh
158  virtual ItemMesh* getWieldMesh(const std::string &name,
159  Client *client) const=0;
160 #endif
161 
162  // Replace the textures of registered nodes with the ones specified in
163  // the texture pack's override.txt files
164  virtual void applyTextureOverrides(const std::vector<TextureOverride> &overrides)=0;
165 
166  // Remove all registered item and node definitions and aliases
167  // Then re-add the builtin item definitions
168  virtual void clear()=0;
169  // Register item definition
170  virtual void registerItem(const ItemDefinition &def)=0;
171  virtual void unregisterItem(const std::string &name)=0;
172  // Set an alias so that items named <name> will load as <convert_to>.
173  // Alias is not set if <name> has already been defined.
174  // Alias will be removed if <name> is defined at a later point of time.
175  virtual void registerAlias(const std::string &name,
176  const std::string &convert_to)=0;
177 
178  virtual void serialize(std::ostream &os, u16 protocol_version)=0;
179  virtual void deSerialize(std::istream &is)=0;
180 
181  // Do stuff asked by threads that can only be done in the main thread
182  virtual void processQueue(IGameDef *gamedef)=0;
183 };
184 
Definition: client.h:109
Definition: gamedef.h:49
Definition: itemdef.h:105
virtual void getAll(std::set< std::string > &result) const =0
IItemDefManager()=default
virtual void serialize(std::ostream &os, u16 protocol_version)=0
virtual const ItemDefinition & get(const std::string &name) const =0
virtual video::ITexture * getInventoryTexture(const std::string &name, Client *client) const =0
virtual ItemMesh * getWieldMesh(const std::string &name, Client *client) const =0
virtual const std::string & getAlias(const std::string &name) const =0
virtual bool isKnown(const std::string &name) const =0
virtual ~IItemDefManager()=default
virtual video::SColor getItemstackColor(const ItemStack &stack, Client *client) const =0
virtual Palette * getPalette(const std::string &name, Client *client) const =0
Definition: itemdef.h:139
virtual void applyTextureOverrides(const std::vector< TextureOverride > &overrides)=0
virtual video::ITexture * getInventoryTexture(const std::string &name, Client *client) const =0
virtual ~IWritableItemDefManager()=default
IWritableItemDefManager()=default
virtual void clear()=0
virtual bool isKnown(const std::string &name) const =0
virtual void serialize(std::ostream &os, u16 protocol_version)=0
virtual void registerItem(const ItemDefinition &def)=0
virtual ItemMesh * getWieldMesh(const std::string &name, Client *client) const =0
virtual void registerAlias(const std::string &name, const std::string &convert_to)=0
virtual void processQueue(IGameDef *gamedef)=0
virtual void getAll(std::set< std::string > &result) const =0
virtual const std::string & getAlias(const std::string &name) const =0
virtual void unregisterItem(const std::string &name)=0
virtual const ItemDefinition & get(const std::string &name) const =0
virtual void deSerialize(std::istream &is)=0
core::vector3df v3f
Definition: irr_v3d.h:26
ItemType
Definition: itemdef.h:44
@ ITEM_TOOL
Definition: itemdef.h:48
@ ITEM_NODE
Definition: itemdef.h:46
@ ITEM_CRAFT
Definition: itemdef.h:47
@ ITEM_NONE
Definition: itemdef.h:45
IWritableItemDefManager * createItemDefManager()
Definition: itemdef.cpp:596
std::unordered_map< std::string, int > ItemGroupList
Definition: itemgroup.h:25
Definition: activeobjectmgr.cpp:25
Definition: itemdef.h:52
SimpleSoundSpec sound_place_failed
Definition: itemdef.h:82
u16 stack_max
Definition: itemdef.h:75
SimpleSoundSpec sound_place
Definition: itemdef.h:81
ItemGroupList groups
Definition: itemdef.h:80
std::string wield_image
Definition: itemdef.h:66
ItemDefinition()
Definition: itemdef.cpp:44
ItemType type
Definition: itemdef.h:56
f32 range
Definition: itemdef.h:83
std::string palette_image
Definition: itemdef.h:68
std::string node_placement_prediction
Definition: itemdef.h:88
ToolCapabilities * tool_capabilities
Definition: itemdef.h:79
std::string inventory_overlay
Definition: itemdef.h:65
void deSerialize(std::istream &is)
Definition: itemdef.cpp:171
void reset()
Definition: itemdef.cpp:101
std::string short_description
Definition: itemdef.h:59
std::string name
Definition: itemdef.h:57
~ItemDefinition()
Definition: itemdef.cpp:89
bool usable
Definition: itemdef.h:76
ItemDefinition & operator=(const ItemDefinition &def)
Definition: itemdef.cpp:55
v3f wield_scale
Definition: itemdef.h:70
std::string wield_overlay
Definition: itemdef.h:67
std::string inventory_image
Definition: itemdef.h:64
video::SColor color
Definition: itemdef.h:69
void serialize(std::ostream &os, u16 protocol_version) const
Definition: itemdef.cpp:127
std::string description
Definition: itemdef.h:58
void resetInitial()
Definition: itemdef.cpp:94
bool liquids_pointable
Definition: itemdef.h:77
Definition: wieldmesh.h:56
Definition: inventory.h:34
Definition: sound.h:28
Definition: tool.h:58
std::vector< video::SColor > Palette
Definition: tile.h:37