Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
itemdef.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4// Copyright (C) 2013 Kahrl <kahrl@gmx.net>
5
6#pragma once
7
9#include <string>
10#include <iostream>
11#include <optional>
12#include <set>
13#include "itemgroup.h"
14#include "sound.h"
15#include "texture_override.h" // TextureOverride
16#include "tool.h"
17#include "util/pointabilities.h"
18#include "util/pointedthing.h"
19
20class IGameDef;
21class Client;
22struct ToolCapabilities;
23struct ItemMesh;
24struct ItemStack;
25typedef std::vector<video::SColor> Palette; // copied from src/client/texturesource.h
26namespace irr::video { class ITexture; }
27using namespace irr;
28
29/*
30 Base item definition
31*/
32
33enum ItemType : u8
34{
39 ItemType_END // Dummy for validity check
40};
41
43{
46 TouchInteractionMode_USER, // Meaning depends on client-side settings
47 TouchInteractionMode_END, // Dummy for validity check
48};
49
51{
55
57 // Returns the right mode for the pointed thing and resolves any occurrence
58 // of TouchInteractionMode_USER into an actual mode.
60 PointedThingType pointed_type) const;
61 void serialize(std::ostream &os) const;
62 void deSerialize(std::istream &is);
63};
64
66{
67 /*
68 Basic item properties
69 */
71 std::string name; // "" = hand
72 std::string description; // Shown in tooltip.
73 std::string short_description;
74
75 /*
76 Visual properties
77 */
78 std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
79 std::string inventory_overlay; // Overlay of inventory_image.
80 std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
81 std::string wield_overlay; // Overlay of wield_image.
82 std::string palette_image; // If specified, the item will be colorized based on this
83 video::SColor color; // The fallback color of the node.
85
86 /*
87 Item stack and interaction properties
88 */
90 bool usable;
92 std::optional<Pointabilities> pointabilities;
93
94 // They may be NULL. If non-NULL, deleted by destructor
96
97 std::optional<WearBarParams> wear_bar_params;
98
103 f32 range;
104
105 // Client shall immediately place this node when player places the item.
106 // Server will update the precise end result a moment later.
107 // "" = no prediction
109 std::optional<u8> place_param2;
111
113
114 /*
115 Some helpful methods
116 */
118 ItemDefinition(const ItemDefinition &def);
121 void reset();
122 void serialize(std::ostream &os, u16 protocol_version) const;
123 void deSerialize(std::istream &is, u16 protocol_version);
124private:
125 void resetInitial();
126};
127
129{
130public:
131 IItemDefManager() = default;
132
133 virtual ~IItemDefManager() = default;
134
135 // Get item definition
136 virtual const ItemDefinition& get(const std::string &name) const=0;
137 // Get alias definition
138 virtual const std::string &getAlias(const std::string &name) const=0;
139 // Get set of all defined item names and aliases
140 virtual void getAll(std::set<std::string> &result) const=0;
141 // Check if item is known
142 virtual bool isKnown(const std::string &name) const=0;
143
144 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
145
146 /* Client-specific methods */
147 // TODO: should be moved elsewhere in the future
148
149 // Get item inventory texture
150 virtual video::ITexture* getInventoryTexture(const ItemStack &item, Client *client) const
151 { return nullptr; }
152
157 virtual ItemMesh* getWieldMesh(const ItemStack &item, Client *client) const
158 { return nullptr; }
159
160 // Get item palette
161 virtual Palette* getPalette(const ItemStack &item, Client *client) const
162 { return nullptr; }
163
164 // Returns the base color of an item stack: the color of all
165 // tiles that do not define their own color.
166 virtual video::SColor getItemstackColor(const ItemStack &stack,
167 Client *client) const
168 { return video::SColor(0); }
169};
170
172{
173public:
175
176 virtual ~IWritableItemDefManager() = default;
177
178 // Replace the textures of registered nodes with the ones specified in
179 // the texture pack's override.txt files
180 virtual void applyTextureOverrides(const std::vector<TextureOverride> &overrides)=0;
181
182 // Remove all registered item and node definitions and aliases
183 // Then re-add the builtin item definitions
184 virtual void clear()=0;
185 // Register item definition
186 virtual void registerItem(const ItemDefinition &def)=0;
187 virtual void unregisterItem(const std::string &name)=0;
188 // Set an alias so that items named <name> will load as <convert_to>.
189 // Alias is not set if <name> has already been defined.
190 // Alias will be removed if <name> is defined at a later point of time.
191 virtual void registerAlias(const std::string &name,
192 const std::string &convert_to)=0;
193
194 virtual void deSerialize(std::istream &is, u16 protocol_version)=0;
195};
196
Definition client.h:105
Definition gamedef.h:36
Definition itemdef.h:129
virtual void getAll(std::set< std::string > &result) const =0
virtual video::SColor getItemstackColor(const ItemStack &stack, Client *client) const
Definition itemdef.h:166
virtual ItemMesh * getWieldMesh(const ItemStack &item, Client *client) const
Get wield mesh.
Definition itemdef.h:157
IItemDefManager()=default
virtual void serialize(std::ostream &os, u16 protocol_version)=0
virtual const std::string & getAlias(const std::string &name) const =0
virtual const ItemDefinition & get(const std::string &name) const =0
virtual Palette * getPalette(const ItemStack &item, Client *client) const
Definition itemdef.h:161
virtual bool isKnown(const std::string &name) const =0
virtual video::ITexture * getInventoryTexture(const ItemStack &item, Client *client) const
Definition itemdef.h:150
virtual ~IItemDefManager()=default
Definition itemdef.h:172
virtual void applyTextureOverrides(const std::vector< TextureOverride > &overrides)=0
virtual ~IWritableItemDefManager()=default
IWritableItemDefManager()=default
virtual void clear()=0
virtual void registerItem(const ItemDefinition &def)=0
virtual void deSerialize(std::istream &is, u16 protocol_version)=0
virtual void registerAlias(const std::string &name, const std::string &convert_to)=0
virtual void unregisterItem(const std::string &name)=0
core::vector3df v3f
Definition irr_v3d.h:11
IWritableItemDefManager * createItemDefManager()
Definition itemdef.cpp:677
std::vector< video::SColor > Palette
Definition itemdef.h:25
ItemType
Definition itemdef.h:34
@ ITEM_TOOL
Definition itemdef.h:38
@ ITEM_NODE
Definition itemdef.h:36
@ ITEM_CRAFT
Definition itemdef.h:37
@ ItemType_END
Definition itemdef.h:39
@ ITEM_NONE
Definition itemdef.h:35
TouchInteractionMode
Definition itemdef.h:43
@ LONG_DIG_SHORT_PLACE
Definition itemdef.h:44
@ TouchInteractionMode_USER
Definition itemdef.h:46
@ SHORT_DIG_LONG_PLACE
Definition itemdef.h:45
@ TouchInteractionMode_END
Definition itemdef.h:47
std::unordered_map< std::string, int > ItemGroupList
Definition itemgroup.h:10
Definition activeobjectmgr.cpp:11
Definition clientmap.h:35
Definition clientmap.h:30
PointedThingType
Definition pointedthing.h:14
Definition itemdef.h:66
u16 stack_max
Definition itemdef.h:89
bool wallmounted_rotate_vertical
Definition itemdef.h:110
SoundSpec sound_use_air
Definition itemdef.h:102
TouchInteraction touch_interaction
Definition itemdef.h:112
ItemGroupList groups
Definition itemdef.h:99
std::string wield_image
Definition itemdef.h:80
ItemDefinition()
Definition itemdef.cpp:96
ItemType type
Definition itemdef.h:70
f32 range
Definition itemdef.h:103
SoundSpec sound_place_failed
Definition itemdef.h:101
std::optional< Pointabilities > pointabilities
Definition itemdef.h:92
std::string palette_image
Definition itemdef.h:82
std::string node_placement_prediction
Definition itemdef.h:108
ToolCapabilities * tool_capabilities
Definition itemdef.h:95
std::string inventory_overlay
Definition itemdef.h:79
std::optional< u8 > place_param2
Definition itemdef.h:109
std::optional< WearBarParams > wear_bar_params
Definition itemdef.h:97
void reset()
Definition itemdef.cpp:158
std::string short_description
Definition itemdef.h:73
SoundSpec sound_place
Definition itemdef.h:100
std::string name
Definition itemdef.h:71
~ItemDefinition()
Definition itemdef.cpp:145
bool usable
Definition itemdef.h:90
ItemDefinition & operator=(const ItemDefinition &def)
Definition itemdef.cpp:107
v3f wield_scale
Definition itemdef.h:84
void deSerialize(std::istream &is, u16 protocol_version)
Definition itemdef.cpp:267
std::string wield_overlay
Definition itemdef.h:81
std::string inventory_image
Definition itemdef.h:78
video::SColor color
Definition itemdef.h:83
void serialize(std::ostream &os, u16 protocol_version) const
Definition itemdef.cpp:190
std::string description
Definition itemdef.h:72
SoundSpec sound_use
Definition itemdef.h:102
void resetInitial()
Definition itemdef.cpp:150
bool liquids_pointable
Definition itemdef.h:91
Definition wieldmesh.h:71
Definition inventory.h:19
Describes the sound information for playback.
Definition sound.h:20
Definition tool.h:46
Definition itemdef.h:51
TouchInteractionMode getMode(const ItemDefinition &selected_def, PointedThingType pointed_type) const
Definition itemdef.cpp:34
void serialize(std::ostream &os) const
Definition itemdef.cpp:65
TouchInteractionMode pointed_object
Definition itemdef.h:54
TouchInteraction()
Definition itemdef.cpp:27
void deSerialize(std::istream &is)
Definition itemdef.cpp:72
TouchInteractionMode pointed_node
Definition itemdef.h:53
TouchInteractionMode pointed_nothing
Definition itemdef.h:52