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.entity.animal.h"
3#include "net.minecraft.world.level.tile.h"
4#include "net.minecraft.world.item.h"
5#include "net.minecraft.world.item.crafting.h"
6#include "ArmorDyeRecipe.h"
7
8bool ArmorDyeRecipe::matches(shared_ptr<CraftingContainer> craftSlots, Level *level)
9{
10 shared_ptr<ItemInstance> target = nullptr;
11 vector<shared_ptr<ItemInstance> > dyes;
12
13 for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
14 {
15 shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
16 if (item == NULL) continue;
17
18 ArmorItem *armor = dynamic_cast<ArmorItem *>(item->getItem());
19 if (armor)
20 {
21 if (armor->getMaterial() == ArmorItem::ArmorMaterial::CLOTH && target == NULL)
22 {
23 target = item;
24 }
25 else
26 {
27 return false;
28 }
29 }
30 else if (item->id == Item::dye_powder_Id)
31 {
32 dyes.push_back(item);
33 }
34 else
35 {
36 return false;
37 }
38 }
39
40 return target != NULL && !dyes.empty();
41}
42
43shared_ptr<ItemInstance> ArmorDyeRecipe::assembleDyedArmor(shared_ptr<CraftingContainer> craftSlots)
44{
45 shared_ptr<ItemInstance> target = nullptr;
46 int colorTotals[3] = {0,0,0};
47 int intensityTotal = 0;
48 int colourCounts = 0;
49 ArmorItem *armor = NULL;
50
51 if(craftSlots != NULL)
52 {
53 for (int slot = 0; slot < craftSlots->getContainerSize(); slot++)
54 {
55 shared_ptr<ItemInstance> item = craftSlots->getItem(slot);
56 if (item == NULL) continue;
57
58 armor = dynamic_cast<ArmorItem *>(item->getItem());
59 if (armor)
60 {
61 if (armor->getMaterial() == ArmorItem::ArmorMaterial::CLOTH && target == NULL)
62 {
63 target = item->copy();
64 target->count = 1;
65
66 if (armor->hasCustomColor(item))
67 {
68 int color = armor->getColor(target);
69 float red = (float) ((color >> 16) & 0xFF) / 0xFF;
70 float green = (float) ((color >> 8) & 0xFF) / 0xFF;
71 float blue = (float) (color & 0xFF) / 0xFF;
72
73 intensityTotal += max(red, max(green, blue)) * 0xFF;
74
75 colorTotals[0] += red * 0xFF;
76 colorTotals[1] += green * 0xFF;
77 colorTotals[2] += blue * 0xFF;
78 colourCounts++;
79 }
80 }
81 else
82 {
83 return nullptr;
84 }
85 }
86 else if (item->id == Item::dye_powder_Id)
87 {
88 int tileData = ColoredTile::getTileDataForItemAuxValue(item->getAuxValue());
89 int red = (int) (Sheep::COLOR[tileData][0] * 0xFF);
90 int green = (int) (Sheep::COLOR[tileData][1] * 0xFF);
91 int blue = (int) (Sheep::COLOR[tileData][2] * 0xFF);
92
93 intensityTotal += max(red, max(green, blue));
94
95 colorTotals[0] += red;
96 colorTotals[1] += green;
97 colorTotals[2] += blue;
98 colourCounts++;
99 }
100 else
101 {
102 return nullptr;
103 }
104 }
105 }
106
107 if (armor == NULL) return nullptr;
108
109 int red = (colorTotals[0] / colourCounts);
110 int green = (colorTotals[1] / colourCounts);
111 int blue = (colorTotals[2] / colourCounts);
112
113 float averageIntensity = (float) intensityTotal / colourCounts;
114 float resultIntensity = (float) max(red, max(green, blue));
115 // System.out.println(averageIntensity + ", " + resultIntensity);
116
117 red = (int) ((float) red * averageIntensity / resultIntensity);
118 green = (int) ((float) green * averageIntensity / resultIntensity);
119 blue = (int) ((float) blue * averageIntensity / resultIntensity);
120
121 int rgb = red;
122 rgb = (rgb << 8) + green;
123 rgb = (rgb << 8) + blue;
124
125 armor->setColor(target, rgb);
126 return target;
127}
128
129shared_ptr<ItemInstance> ArmorDyeRecipe::assemble(shared_ptr<CraftingContainer> craftSlots)
130{
131 return ArmorDyeRecipe::assembleDyedArmor(craftSlots);
132}
133
134int ArmorDyeRecipe::size()
135{
136 return 10;
137}
138
139const ItemInstance *ArmorDyeRecipe::getResultItem()
140{
141 return NULL;
142}
143
144const int ArmorDyeRecipe::getGroup()
145{
146 return ShapedRecipy::eGroupType_Armour;
147}
148
149// 4J-PB
150bool ArmorDyeRecipe::requires(int iRecipe)
151{
152 return false;
153}
154
155void ArmorDyeRecipe::requires(INGREDIENTS_REQUIRED *pIngReq)
156{
157 //int iCount=0;
158 //bool bFound;
159 //int j;
160 INGREDIENTS_REQUIRED TempIngReq;
161
162 // shapeless doesn't have the 3x3 shape, but we'll just use this to store the ingredients anyway
163 TempIngReq.iIngC=0;
164 TempIngReq.iType = RECIPE_TYPE_2x2; // all the dyes can be made in a 2x2
165 TempIngReq.uiGridA = new unsigned int [9];
166 TempIngReq.iIngIDA= new int [3*3];
167 TempIngReq.iIngValA = new int [3*3];
168 TempIngReq.iIngAuxValA = new int [3*3];
169
170 ZeroMemory(TempIngReq.iIngIDA,sizeof(int)*9);
171 ZeroMemory(TempIngReq.iIngValA,sizeof(int)*9);
172 memset(TempIngReq.iIngAuxValA,Recipes::ANY_AUX_VALUE,sizeof(int)*9);
173 ZeroMemory(TempIngReq.uiGridA,sizeof(unsigned int)*9);
174
175#if 0
176 AUTO_VAR(citEnd, ingredients->end());
177
178 for (vector<ItemInstance *>::const_iterator ingredient = ingredients->begin(); ingredient != citEnd; ingredient++)
179 {
180 ItemInstance *expected = *ingredient;
181
182 if (expected!=NULL)
183 {
184 int iAuxVal = (*ingredient)->getAuxValue();
185 TempIngReq.uiGridA[iCount++]=expected->id | iAuxVal<<24;
186 // 4J-PB - put the ingredients in boxes 1,2,4,5 so we can see them in a 2x2 crafting screen
187 if(iCount==2) iCount=3;
188 bFound=false;
189 for(j=0;j<TempIngReq.iIngC;j++)
190 {
191 if((TempIngReq.iIngIDA[j]==expected->id) && (iAuxVal == Recipes::ANY_AUX_VALUE || TempIngReq.iIngAuxValA[j] == iAuxVal))
192 {
193 bFound= true;
194 break;
195 }
196 }
197 if(bFound)
198 {
199 TempIngReq.iIngValA[j]++;
200 }
201 else
202 {
203 TempIngReq.iIngIDA[TempIngReq.iIngC]=expected->id;
204 TempIngReq.iIngAuxValA[TempIngReq.iIngC]=iAuxVal;
205 TempIngReq.iIngValA[TempIngReq.iIngC++]++;
206 }
207 }
208 }
209#endif
210
211 pIngReq->iIngIDA = new int [TempIngReq.iIngC];
212 pIngReq->iIngValA = new int [TempIngReq.iIngC];
213 pIngReq->iIngAuxValA = new int [TempIngReq.iIngC];
214 pIngReq->uiGridA = new unsigned int [9];
215
216 pIngReq->pRecipy=this;
217
218 for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i)
219 {
220 pIngReq->bCanMake[i]=false;
221 }
222
223 pIngReq->iIngC=TempIngReq.iIngC;
224 pIngReq->iType=TempIngReq.iType;
225
226 if(pIngReq->iIngC!=0)
227 {
228 memcpy(pIngReq->iIngIDA,TempIngReq.iIngIDA,sizeof(int)*TempIngReq.iIngC);
229 memcpy(pIngReq->iIngValA,TempIngReq.iIngValA,sizeof(int)*TempIngReq.iIngC);
230 memcpy(pIngReq->iIngAuxValA,TempIngReq.iIngAuxValA,sizeof(int)*TempIngReq.iIngC);
231 }
232 memcpy(pIngReq->uiGridA,TempIngReq.uiGridA,sizeof(unsigned int) *9);
233
234 delete [] TempIngReq.iIngIDA;
235 delete [] TempIngReq.iIngValA;
236 delete [] TempIngReq.iIngAuxValA;
237 delete [] TempIngReq.uiGridA;
238}