the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1// package net.minecraft.world.item.crafting;
2//
3// import java.util.*;
4//
5// import net.minecraft.world.inventory.CraftingContainer;
6// import net.minecraft.world.item.ItemInstance;
7#include "stdafx.h"
8#include "net.minecraft.world.item.h"
9#include "net.minecraft.world.inventory.h"
10#include "Tile.h"
11#include "Recipy.h"
12#include "Recipes.h"
13#include "ShapelessRecipy.h"
14
15ShapelessRecipy::ShapelessRecipy(ItemInstance *result, vector<ItemInstance *> *ingredients, _eGroupType egroup) :
16 result(result),
17 ingredients(ingredients),
18 group(egroup)
19{
20}
21
22const int ShapelessRecipy::getGroup()
23{
24 return group;
25}
26
27const ItemInstance *ShapelessRecipy::getResultItem()
28{
29 return result;
30}
31
32bool ShapelessRecipy::matches(shared_ptr<CraftingContainer> craftSlots, Level *level)
33{
34 vector <ItemInstance *> tempList = *ingredients;
35
36 for (int y = 0; y < 3; y++)
37 {
38 for (int x = 0; x < 3; x++)
39 {
40 shared_ptr<ItemInstance> item = craftSlots->getItem(x, y);
41
42 if (item != NULL)
43 {
44 bool found = false;
45
46 AUTO_VAR(citEnd, ingredients->end());
47 for (AUTO_VAR(cit, ingredients->begin()); cit != citEnd; ++cit)
48 {
49 ItemInstance *ingredient = *cit;
50 if (item->id == ingredient->id && (ingredient->getAuxValue() == Recipes::ANY_AUX_VALUE || item->getAuxValue() == ingredient->getAuxValue()))
51 {
52 found = true;
53 AUTO_VAR( it, find(tempList.begin(), tempList.end(), ingredient ) );
54 if(it != tempList.end() ) tempList.erase(it);
55 break;
56 }
57 }
58
59 if (!found)
60 {
61 return false;
62 }
63 }
64 }
65 }
66
67 return tempList.empty();
68}
69
70shared_ptr<ItemInstance> ShapelessRecipy::assemble(shared_ptr<CraftingContainer> craftSlots)
71{
72 return result->copy();
73}
74
75int ShapelessRecipy::size()
76{
77 return (int)ingredients->size();
78}
79
80// 4J-PB
81bool ShapelessRecipy::requires(int iRecipe)
82{
83 vector <ItemInstance *> *tempList = new vector<ItemInstance *>;
84
85 *tempList=*ingredients;
86
87 //printf("ShapelessRecipy %d\n",iRecipe);
88
89 AUTO_VAR(citEnd, ingredients->end());
90 int iCount=0;
91 for (vector<ItemInstance *>::iterator ingredient = ingredients->begin(); ingredient != citEnd; ingredient++)
92 {
93 //printf("\tIngredient %d is %d\n",iCount++,(*ingredient)->id);
94 //if (item->id == (*ingredient)->id && ((*ingredient)->getAuxValue() == Recipes::ANY_AUX_VALUE || item->getAuxValue() == (*ingredient)->getAuxValue()))
95 tempList->erase(ingredient);
96 }
97
98 delete tempList;
99 return false;
100}
101
102void ShapelessRecipy::requires(INGREDIENTS_REQUIRED *pIngReq)
103{
104 int iCount=0;
105 bool bFound;
106 int j;
107 INGREDIENTS_REQUIRED TempIngReq;
108
109 // shapeless doesn't have the 3x3 shape, but we'll just use this to store the ingredients anyway
110 TempIngReq.iIngC=0;
111 TempIngReq.iType = RECIPE_TYPE_2x2; // all the dyes can be made in a 2x2
112 TempIngReq.uiGridA = new unsigned int [9];
113 TempIngReq.iIngIDA= new int [3*3];
114 TempIngReq.iIngValA = new int [3*3];
115 TempIngReq.iIngAuxValA = new int [3*3];
116
117 ZeroMemory(TempIngReq.iIngIDA,sizeof(int)*9);
118 ZeroMemory(TempIngReq.iIngValA,sizeof(int)*9);
119 memset(TempIngReq.iIngAuxValA,Recipes::ANY_AUX_VALUE,sizeof(int)*9);
120 ZeroMemory(TempIngReq.uiGridA,sizeof(unsigned int)*9);
121
122 AUTO_VAR(citEnd, ingredients->end());
123
124 for (vector<ItemInstance *>::const_iterator ingredient = ingredients->begin(); ingredient != citEnd; ingredient++)
125 {
126 ItemInstance *expected = *ingredient;
127
128 if (expected!=NULL)
129 {
130 int iAuxVal = (*ingredient)->getAuxValue();
131 TempIngReq.uiGridA[iCount++]=expected->id | iAuxVal<<24;
132 // 4J-PB - put the ingredients in boxes 1,2,4,5 so we can see them in a 2x2 crafting screen
133 if(iCount==2) iCount=3;
134 bFound=false;
135 for(j=0;j<TempIngReq.iIngC;j++)
136 {
137 if((TempIngReq.iIngIDA[j]==expected->id) && (iAuxVal == Recipes::ANY_AUX_VALUE || TempIngReq.iIngAuxValA[j] == iAuxVal))
138 {
139 bFound= true;
140 break;
141 }
142 }
143 if(bFound)
144 {
145 TempIngReq.iIngValA[j]++;
146 }
147 else
148 {
149 TempIngReq.iIngIDA[TempIngReq.iIngC]=expected->id;
150 TempIngReq.iIngAuxValA[TempIngReq.iIngC]=iAuxVal;
151 TempIngReq.iIngValA[TempIngReq.iIngC++]++;
152 }
153 }
154 }
155 pIngReq->iIngIDA = new int [TempIngReq.iIngC];
156 pIngReq->iIngValA = new int [TempIngReq.iIngC];
157 pIngReq->iIngAuxValA = new int [TempIngReq.iIngC];
158 pIngReq->uiGridA = new unsigned int [9];
159
160 pIngReq->pRecipy=this;
161
162 for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i)
163 {
164 pIngReq->bCanMake[i]=false;
165 }
166
167 pIngReq->iIngC=TempIngReq.iIngC;
168 pIngReq->iType=TempIngReq.iType;
169
170 if(pIngReq->iIngC!=0)
171 {
172 memcpy(pIngReq->iIngIDA,TempIngReq.iIngIDA,sizeof(int)*TempIngReq.iIngC);
173 memcpy(pIngReq->iIngValA,TempIngReq.iIngValA,sizeof(int)*TempIngReq.iIngC);
174 memcpy(pIngReq->iIngAuxValA,TempIngReq.iIngAuxValA,sizeof(int)*TempIngReq.iIngC);
175 }
176 memcpy(pIngReq->uiGridA,TempIngReq.uiGridA,sizeof(unsigned int) *9);
177
178 delete [] TempIngReq.iIngIDA;
179 delete [] TempIngReq.iIngValA;
180 delete [] TempIngReq.iIngAuxValA;
181 delete [] TempIngReq.uiGridA;
182}