the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.item.h"
3#include "net.minecraft.world.h"
4#include "FireworksChargeItem.h"
5
6FireworksChargeItem::FireworksChargeItem(int id) : Item(id)
7{
8}
9
10Icon *FireworksChargeItem::getLayerIcon(int auxValue, int spriteLayer)
11{
12 if (spriteLayer > 0)
13 {
14 return overlay;
15 }
16 return Item::getLayerIcon(auxValue, spriteLayer);
17}
18
19int FireworksChargeItem::getColor(shared_ptr<ItemInstance> item, int spriteLayer)
20{
21 if (spriteLayer == 1)
22 {
23 Tag *colorTag = getExplosionTagField(item, FireworksItem::TAG_E_COLORS);
24 if (colorTag != NULL)
25 {
26 IntArrayTag *colors = (IntArrayTag *) colorTag;
27 if (colors->data.length == 1)
28 {
29 return colors->data[0];
30 }
31 int totalRed = 0;
32 int totalGreen = 0;
33 int totalBlue = 0;
34 for (unsigned int i = 0; i < colors->data.length; ++i)
35 {
36 int c = colors->data[i];
37 totalRed += (c & 0xff0000) >> 16;
38 totalGreen += (c & 0x00ff00) >> 8;
39 totalBlue += (c & 0x0000ff) >> 0;
40 }
41 totalRed /= colors->data.length;
42 totalGreen /= colors->data.length;
43 totalBlue /= colors->data.length;
44 return (totalRed << 16) | (totalGreen << 8) | totalBlue;
45 }
46 return 0x8a8a8a;
47 }
48 return Item::getColor(item, spriteLayer);
49}
50
51bool FireworksChargeItem::hasMultipleSpriteLayers()
52{
53 return true;
54}
55
56Tag *FireworksChargeItem::getExplosionTagField(shared_ptr<ItemInstance> instance, const wstring &field)
57{
58 if (instance->hasTag())
59 {
60 CompoundTag *explosion = instance->getTag()->getCompound(FireworksItem::TAG_EXPLOSION);
61 if (explosion != NULL)
62 {
63 return explosion->get(field);
64 }
65 }
66 return NULL;
67}
68
69void FireworksChargeItem::appendHoverText(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, vector<HtmlString> *lines, bool advanced)
70{
71 if (itemInstance->hasTag())
72 {
73 CompoundTag *explosion = itemInstance->getTag()->getCompound(FireworksItem::TAG_EXPLOSION);
74 if (explosion != NULL)
75 {
76 appendHoverText(explosion, lines);
77 }
78 }
79}
80
81const unsigned int FIREWORKS_CHARGE_TYPE_NAME[] =
82{
83 IDS_FIREWORKS_CHARGE_TYPE_0,
84 IDS_FIREWORKS_CHARGE_TYPE_1,
85 IDS_FIREWORKS_CHARGE_TYPE_2,
86 IDS_FIREWORKS_CHARGE_TYPE_3,
87 IDS_FIREWORKS_CHARGE_TYPE_4
88};
89
90const unsigned int FIREWORKS_CHARGE_COLOUR_NAME[] =
91{
92 IDS_FIREWORKS_CHARGE_BLACK,
93 IDS_FIREWORKS_CHARGE_RED,
94 IDS_FIREWORKS_CHARGE_GREEN,
95 IDS_FIREWORKS_CHARGE_BROWN,
96 IDS_FIREWORKS_CHARGE_BLUE,
97 IDS_FIREWORKS_CHARGE_PURPLE,
98 IDS_FIREWORKS_CHARGE_CYAN,
99 IDS_FIREWORKS_CHARGE_SILVER,
100 IDS_FIREWORKS_CHARGE_GRAY,
101 IDS_FIREWORKS_CHARGE_PINK,
102 IDS_FIREWORKS_CHARGE_LIME,
103 IDS_FIREWORKS_CHARGE_YELLOW,
104 IDS_FIREWORKS_CHARGE_LIGHT_BLUE,
105 IDS_FIREWORKS_CHARGE_MAGENTA,
106 IDS_FIREWORKS_CHARGE_ORANGE,
107 IDS_FIREWORKS_CHARGE_WHITE
108};
109
110void FireworksChargeItem::appendHoverText(CompoundTag *expTag, vector<HtmlString> *lines)
111{
112 // shape
113 byte type = expTag->getByte(FireworksItem::TAG_E_TYPE);
114 if (type >= FireworksItem::TYPE_MIN && type <= FireworksItem::TYPE_MAX)
115 {
116 lines->push_back(HtmlString(app.GetString(FIREWORKS_CHARGE_TYPE_NAME[type])));
117 }
118 else
119 {
120 lines->push_back(HtmlString(app.GetString(IDS_FIREWORKS_CHARGE_TYPE)));
121 }
122
123 // colors
124 intArray colorList = expTag->getIntArray(FireworksItem::TAG_E_COLORS);
125 if (colorList.length > 0)
126 {
127
128 bool first = true;
129 wstring output = L"";
130 for (unsigned int i = 0; i < colorList.length; ++i)
131 {
132 int c = colorList[i];
133 if (!first)
134 {
135 output += L",\n"; // 4J-PB - without the newline, they tend to go offscreen in split-screen or localised languages
136 }
137 first = false;
138
139 // find color name by lookup
140 bool found = false;
141 for (int dc = 0; dc < 16; dc++)
142 {
143 if (c == DyePowderItem::COLOR_RGB[dc])
144 {
145 found = true;
146 output += app.GetString(FIREWORKS_CHARGE_COLOUR_NAME[dc]);
147 break;
148 }
149 }
150 if (!found)
151 {
152 output += app.GetString(IDS_FIREWORKS_CHARGE_CUSTOM);
153 }
154 }
155 lines->push_back(output);
156 }
157
158 // has fade?
159 intArray fadeList = expTag->getIntArray(FireworksItem::TAG_E_FADECOLORS);
160 if (fadeList.length > 0)
161 {
162 bool first = true;
163 wstring output = wstring(app.GetString(IDS_FIREWORKS_CHARGE_FADE_TO)) + L" ";
164 for (unsigned int i = 0; i < fadeList.length; ++i)
165 {
166 int c = fadeList[i];
167 if (!first)
168 {
169 output += L",\n";// 4J-PB - without the newline, they tend to go offscreen in split-screen or localised languages
170 }
171 first = false;
172
173 // find color name by lookup
174 bool found = false;
175 for (int dc = 0; dc < 16; dc++)
176 {
177 if (c == DyePowderItem::COLOR_RGB[dc])
178 {
179 found = true;
180 output += app.GetString(FIREWORKS_CHARGE_COLOUR_NAME[dc]);
181 break;
182 }
183 }
184 if (!found)
185 {
186 output += app.GetString(IDS_FIREWORKS_CHARGE_CUSTOM);
187 }
188 }
189 lines->push_back(output);
190 }
191
192 // has trail
193 bool trail = expTag->getBoolean(FireworksItem::TAG_E_TRAIL);
194 if (trail)
195 {
196 lines->push_back(HtmlString(app.GetString(IDS_FIREWORKS_CHARGE_TRAIL)));
197 }
198
199 // has flicker
200 bool flicker = expTag->getBoolean(FireworksItem::TAG_E_FLICKER);
201 if (flicker)
202 {
203 lines->push_back(HtmlString(app.GetString(IDS_FIREWORKS_CHARGE_FLICKER)));
204 }
205}
206
207void FireworksChargeItem::registerIcons(IconRegister *iconRegister)
208{
209 Item::registerIcons(iconRegister);
210 overlay = iconRegister->registerIcon(getIconName() + L"_overlay");
211}