1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
package jp.plusplus.fbs.nei;
import codechicken.core.ReflectionManager;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.DefaultOverlayRenderer;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.api.IRecipeOverlayRenderer;
import codechicken.nei.api.IStackPositioner;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import jp.plusplus.fbs.Registry;
import jp.plusplus.fbs.gui.GuiWorkbench;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiCrafting;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe;
import java.awt.*;
import java.awt.List;
import java.util.*;
/**
* Createdby pluslus_Fon 2015/06/15.
*/
public class FBSShapedRecipeHandler extends TemplateRecipeHandler {
protected LinkedList<Integer> manas=new LinkedList<Integer>();
public void loadTransferRects() {
this.transferRects.add(new RecipeTransferRect(new Rectangle(90, 35, 22, 15), "fbs.crafting", new Object[0]));
}
public Class<? extends GuiContainer> getGuiClass() {
return GuiWorkbench.class;
}
public String getRecipeName() {
return NEIClientUtils.translate("recipe.fbs.shaped", new Object[0]);
}
public void drawExtras(int recipe) {
String str=""+manas.get(recipe)+"mb";
GuiDraw.fontRenderer.drawString(str, (196-GuiDraw.fontRenderer.getStringWidth(str))/2, 45, 0x404040);
}
public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals("fbs.crafting") && this.getClass() == FBSShapedRecipeHandler.class) {
Iterator i$ = Registry.getCraftingRecipes().iterator();
while(i$.hasNext()) {
Registry.RecipePair rp=((Registry.RecipePair)i$.next());
IRecipe irecipe = rp.recipe;
FBSShapedRecipeHandler.CachedShapedRecipe recipe = null;
if(irecipe instanceof ShapedRecipes) {
recipe = new FBSShapedRecipeHandler.CachedShapedRecipe((ShapedRecipes)irecipe);
} else if(irecipe instanceof ShapedOreRecipe) {
recipe = this.forgeShapedRecipe((ShapedOreRecipe)irecipe);
}
if(recipe != null) {
recipe.computeVisuals();
this.arecipes.add(recipe);
manas.add(rp.mana);
}
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
public void loadCraftingRecipes(ItemStack result) {
Iterator i$ = Registry.getCraftingRecipes().iterator();
while(i$.hasNext()) {
Registry.RecipePair rp=((Registry.RecipePair)i$.next());
IRecipe irecipe = rp.recipe;
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
FBSShapedRecipeHandler.CachedShapedRecipe recipe = null;
if(irecipe instanceof ShapedRecipes) {
recipe = new FBSShapedRecipeHandler.CachedShapedRecipe((ShapedRecipes)irecipe);
} else if(irecipe instanceof ShapedOreRecipe) {
recipe = this.forgeShapedRecipe((ShapedOreRecipe)irecipe);
}
if(recipe != null) {
recipe.computeVisuals();
this.arecipes.add(recipe);
manas.add(rp.mana);
}
}
}
}
public void loadUsageRecipes(ItemStack ingredient) {
Iterator i$ = Registry.getCraftingRecipes().iterator();
while(i$.hasNext()) {
Registry.RecipePair rp=((Registry.RecipePair)i$.next());
IRecipe irecipe = rp.recipe;
FBSShapedRecipeHandler.CachedShapedRecipe recipe = null;
if(irecipe instanceof ShapedRecipes) {
recipe = new FBSShapedRecipeHandler.CachedShapedRecipe((ShapedRecipes)irecipe);
} else if(irecipe instanceof ShapedOreRecipe) {
recipe = this.forgeShapedRecipe((ShapedOreRecipe)irecipe);
}
if(recipe != null && recipe.contains(recipe.ingredients, ingredient.getItem())) {
recipe.computeVisuals();
if(recipe.contains(recipe.ingredients, ingredient)) {
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
this.arecipes.add(recipe);
manas.add(rp.mana);
}
}
}
}
public FBSShapedRecipeHandler.CachedShapedRecipe forgeShapedRecipe(ShapedOreRecipe recipe) {
int width;
int height;
try {
width = ((Integer) ReflectionManager.getField(ShapedOreRecipe.class, Integer.class, recipe, 4)).intValue();
height = ((Integer)ReflectionManager.getField(ShapedOreRecipe.class, Integer.class, recipe, 5)).intValue();
} catch (Exception var9) {
NEIClientConfig.logger.error("Error loading recipe", var9);
return null;
}
Object[] items = recipe.getInput();
Object[] arr$ = items;
int len$ = items.length;
for(int i$ = 0; i$ < len$; ++i$) {
Object item = arr$[i$];
if(item instanceof java.util.List && ((java.util.List)item).isEmpty()) {
return null;
}
}
return new FBSShapedRecipeHandler.CachedShapedRecipe(width, height, items, recipe.getRecipeOutput());
}
public String getGuiTexture() {
return "textures/gui/container/crafting_table.png";
}
public String getOverlayIdentifier() {
return "fbs.crafting.shaped";
}
public boolean hasOverlay(GuiContainer gui, net.minecraft.inventory.Container container, int recipe) {
return super.hasOverlay(gui, container, recipe) || this.isRecipe2x2(recipe) && RecipeInfo.hasDefaultOverlay(gui, "crafting2x2");
}
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) {
IRecipeOverlayRenderer renderer = super.getOverlayRenderer(gui, recipe);
if(renderer != null) {
return renderer;
} else {
IStackPositioner positioner = RecipeInfo.getStackPositioner(gui, "crafting2x2");
return positioner == null?null:new DefaultOverlayRenderer(this.getIngredientStacks(recipe), positioner);
}
}
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe) {
IOverlayHandler handler = super.getOverlayHandler(gui, recipe);
return handler != null?handler:RecipeInfo.getOverlayHandler(gui, "crafting2x2");
}
public boolean isRecipe2x2(int recipe) {
Iterator i$ = this.getIngredientStacks(recipe).iterator();
PositionedStack stack;
do {
if(!i$.hasNext()) {
return true;
}
stack = (PositionedStack)i$.next();
} while(stack.relx <= 43 && stack.rely <= 24);
return false;
}
public class CachedShapedRecipe extends CachedRecipe {
public ArrayList<PositionedStack> ingredients;
public PositionedStack result;
public CachedShapedRecipe(int width, int height, Object[] items, ItemStack out) {
//super(FBSShapedRecipeHandler.this);
this.result = new PositionedStack(out, 119, 24);
this.ingredients = new ArrayList();
this.setIngredients(width, height, items);
}
public CachedShapedRecipe(ShapedRecipes recipe) {
this(recipe.recipeWidth, recipe.recipeHeight, recipe.recipeItems, recipe.getRecipeOutput());
}
public void setIngredients(int width, int height, Object[] items) {
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
if(items[y * width + x] != null) {
PositionedStack stack = new PositionedStack(items[y * width + x], 25 + x * 18, 6 + y * 18, false);
stack.setMaxSize(1);
this.ingredients.add(stack);
}
}
}
}
public java.util.List<PositionedStack> getIngredients() {
return this.getCycledIngredients(FBSShapedRecipeHandler.this.cycleticks / 20, this.ingredients);
}
public PositionedStack getResult() {
return this.result;
}
public void computeVisuals() {
Iterator i$ = this.ingredients.iterator();
while(i$.hasNext()) {
PositionedStack p = (PositionedStack)i$.next();
p.generatePermutations();
}
}
}
}
|