the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#pragma once
2using namespace std;
3
4#include "UseAnim.h"
5#include "com.mojang.nbt.h"
6#include "Attribute.h"
7
8class Entity;
9class Level;
10class Player;
11class Mob;
12class LivingEntity;
13class CompoundTag;
14class Enchantment;
15class Rarity;
16class AttributeModifier;
17class Random;
18// 4J-PB - added
19class MapItem;
20class ItemFrame;
21class Icon;
22class HtmlString;
23
24// 4J Stu - While this is not really an abstract class, we don't want to make new instances of it,
25// mainly because there are too many ctors and that doesn't fit well into out macroisation setup
26class ItemInstance: public enable_shared_from_this<ItemInstance>
27{
28public:
29 static const wstring ATTRIBUTE_MODIFIER_FORMAT;
30 static const wchar_t *TAG_ENCH_ID;
31 static const wchar_t *TAG_ENCH_LEVEL;
32
33 int count;
34 int popTime;
35 int id;
36
37 // 4J Stu - Brought forward for enchanting/game rules
38 CompoundTag *tag;
39
40 /**
41 * This was previously the damage value, but is now used for different stuff
42 * depending on item / tile. Use the getter methods to make sure the value
43 * is interpreted correctly.
44 */
45private:
46 int auxValue;
47 // 4J-PB - added for trading menu
48 bool m_bForceNumberDisplay;
49
50 void _init(int id, int count, int auxValue);
51
52 // TU9
53 shared_ptr<ItemFrame> frame;
54
55public:
56 ItemInstance(Tile *tile);
57 ItemInstance(Tile *tile, int count);
58 ItemInstance(Tile *tile, int count, int auxValue);
59 ItemInstance(Item *item);
60 // 4J-PB - added
61 ItemInstance(MapItem *item, int count);
62
63 ItemInstance(Item *item, int count);
64 ItemInstance(Item *item, int count, int auxValue);
65 ItemInstance(int id, int count, int damage);
66
67 static shared_ptr<ItemInstance> fromTag(CompoundTag *itemTag);
68private:
69 ItemInstance() { _init(-1,0,0); }
70
71public:
72 ~ItemInstance();
73 shared_ptr<ItemInstance> remove(int count);
74
75 Item *getItem() const;
76 Icon *getIcon();
77 int getIconType();
78 bool useOn(shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly=false);
79 float getDestroySpeed(Tile *tile);
80 bool TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player);
81 shared_ptr<ItemInstance> use(Level *level, shared_ptr<Player> player);
82 shared_ptr<ItemInstance> useTimeDepleted(Level *level, shared_ptr<Player> player);
83 CompoundTag *save(CompoundTag *compoundTag);
84 void load(CompoundTag *compoundTag);
85 int getMaxStackSize() const;
86 bool isStackable();
87 bool isDamageableItem();
88 bool isStackedByData();
89 bool isDamaged();
90 int getDamageValue();
91 int getAuxValue() const;
92 void setAuxValue(int value);
93 int getMaxDamage();
94 bool hurt(int dmg, Random *random);
95 void hurtAndBreak(int dmg, shared_ptr<LivingEntity> owner);
96 void hurtEnemy(shared_ptr<LivingEntity> mob, shared_ptr<Player> attacker);
97 void mineBlock(Level *level, int tile, int x, int y, int z, shared_ptr<Player> owner);
98 bool canDestroySpecial(Tile *tile);
99 bool interactEnemy(shared_ptr<Player> player, shared_ptr<LivingEntity> mob);
100 shared_ptr<ItemInstance> copy() const;
101 ItemInstance *copy_not_shared() const; // 4J Stu - Added for use in recipes
102 static bool tagMatches(shared_ptr<ItemInstance> a, shared_ptr<ItemInstance> b); // 4J Brought forward from 1.2
103 static bool matches(shared_ptr<ItemInstance> a, shared_ptr<ItemInstance> b);
104
105 // 4J-PB
106 int GetCount() {return count;}
107 void ForceNumberDisplay(bool bForce) {m_bForceNumberDisplay=bForce;} // to force the display of 0 and 1 on the required trading items when you have o or 1 of the item
108 bool GetForceNumberDisplay() {return m_bForceNumberDisplay;} // to force the display of 0 and 1 on the required trading items when you have o or 1 of the item
109
110private:
111 bool matches(shared_ptr<ItemInstance> b);
112
113public:
114 bool sameItem(shared_ptr<ItemInstance> b);
115 bool sameItemWithTags(shared_ptr<ItemInstance> b); //4J Added
116 bool sameItem_not_shared(const ItemInstance *b); // 4J Stu - Added this for the one time I need it
117 virtual unsigned int getUseDescriptionId(); // 4J Added
118 virtual unsigned int getDescriptionId(int iData = -1);
119 virtual ItemInstance *setDescriptionId(unsigned int id);
120 static shared_ptr<ItemInstance> clone(shared_ptr<ItemInstance> item);
121 wstring toString();
122 void inventoryTick(Level *level, shared_ptr<Entity> owner, int slot, bool selected);
123 void onCraftedBy(Level *level, shared_ptr<Player> player, int craftCount);
124 bool equals(shared_ptr<ItemInstance> ii);
125
126 int getUseDuration();
127 UseAnim getUseAnimation();
128 void releaseUsing(Level *level, shared_ptr<Player> player, int durationLeft);
129
130 // 4J Stu - Brought forward these functions for enchanting/game rules
131 bool hasTag();
132 CompoundTag *getTag();
133 ListTag<CompoundTag> *getEnchantmentTags();
134 void setTag(CompoundTag *tag);
135 wstring getHoverName();
136 void setHoverName(const wstring &name);
137 void resetHoverName();
138 bool hasCustomHoverName();
139 vector<HtmlString> *getHoverText(shared_ptr<Player> player, bool advanced);
140 vector<HtmlString> *getHoverTextOnly(shared_ptr<Player> player, bool advanced); // 4J Added
141 bool isFoil();
142 const Rarity *getRarity();
143 bool isEnchantable();
144 void enchant(const Enchantment *enchantment, int level);
145 bool isEnchanted();
146 void addTagElement(wstring name, Tag *tag);
147 bool mayBePlacedInAdventureMode();
148 bool isFramed();
149 void setFramed(shared_ptr<ItemFrame> frame);
150 shared_ptr<ItemFrame> getFrame();
151 int getBaseRepairCost();
152 void setRepairCost(int cost);
153 attrAttrModMap *getAttributeModifiers();
154
155 // 4J Added
156 void set4JData(int data);
157 int get4JData();
158 bool hasPotionStrengthBar();
159 int GetPotionStrength();
160};