/
RecipeLayout.java
141 lines (115 loc) · 4.46 KB
/
RecipeLayout.java
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
package mezz.jei.gui;
import javax.annotation.Nonnull;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiFluidStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.config.Config;
import mezz.jei.gui.ingredients.GuiFluidStackGroup;
import mezz.jei.gui.ingredients.GuiIngredient;
import mezz.jei.gui.ingredients.GuiItemStackGroup;
public class RecipeLayout implements IRecipeLayout {
private static final int RECIPE_BUTTON_SIZE = 12;
public static final int recipeTransferButtonIndex = 100;
@Nonnull
private final IRecipeCategory recipeCategory;
@Nonnull
private final GuiItemStackGroup guiItemStackGroup;
@Nonnull
private final GuiFluidStackGroup guiFluidStackGroup;
@Nonnull
private final RecipeTransferButton recipeTransferButton;
@Nonnull
private final IRecipeWrapper recipeWrapper;
private final int posX;
private final int posY;
public RecipeLayout(int index, int posX, int posY, @Nonnull IRecipeCategory recipeCategory, @Nonnull IRecipeWrapper recipeWrapper, @Nonnull Focus focus) {
this.recipeCategory = recipeCategory;
this.guiItemStackGroup = new GuiItemStackGroup();
this.guiFluidStackGroup = new GuiFluidStackGroup();
int width = recipeCategory.getBackground().getWidth();
int height = recipeCategory.getBackground().getHeight();
this.recipeTransferButton = new RecipeTransferButton(recipeTransferButtonIndex + index, posX + width + 2, posY + height - RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE, "+");
this.posX = posX;
this.posY = posY;
this.recipeWrapper = recipeWrapper;
this.guiItemStackGroup.setFocus(focus);
this.guiFluidStackGroup.setFocus(focus);
this.recipeCategory.setRecipe(this, recipeWrapper);
}
public void draw(@Nonnull Minecraft minecraft, int mouseX, int mouseY) {
GlStateManager.pushMatrix();
GlStateManager.translate(posX, posY, 0.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();
IDrawable background = recipeCategory.getBackground();
background.draw(minecraft);
recipeCategory.drawExtras(minecraft);
if (Config.isRecipeAnimationsEnabled()) {
recipeCategory.drawAnimations(minecraft);
recipeWrapper.drawAnimations(minecraft, background.getWidth(), background.getHeight());
}
GlStateManager.translate(-posX, -posY, 0.0F);
recipeTransferButton.drawButton(minecraft, mouseX, mouseY);
GlStateManager.disableBlend();
GlStateManager.translate(posX, posY, 0.0F);
recipeWrapper.drawInfo(minecraft, background.getWidth(), background.getHeight());
RenderHelper.enableGUIStandardItemLighting();
GuiIngredient hoveredItemStack = guiItemStackGroup.draw(minecraft, mouseX - posX, mouseY - posY);
RenderHelper.disableStandardItemLighting();
GuiIngredient hoveredFluidStack = guiFluidStackGroup.draw(minecraft, mouseX - posX, mouseY - posY);
if (hoveredItemStack != null) {
RenderHelper.enableGUIStandardItemLighting();
hoveredItemStack.drawHovered(minecraft, mouseX - posX, mouseY - posY);
RenderHelper.disableStandardItemLighting();
}
if (hoveredFluidStack != null) {
hoveredFluidStack.drawHovered(minecraft, mouseX - posX, mouseY - posY);
}
GlStateManager.popMatrix();
}
public Focus getFocusUnderMouse(int mouseX, int mouseY) {
Focus focus = guiItemStackGroup.getFocusUnderMouse(mouseX - posX, mouseY - posY);
if (focus == null) {
focus = guiFluidStackGroup.getFocusUnderMouse(mouseX - posX, mouseY - posY);
}
return focus;
}
@Override
@Nonnull
public GuiItemStackGroup getItemStacks() {
return guiItemStackGroup;
}
@Override
@Nonnull
public IGuiFluidStackGroup getFluidStacks() {
return guiFluidStackGroup;
}
@Override
public void setRecipeTransferButton(int posX, int posY) {
recipeTransferButton.xPosition = posX + this.posX;
recipeTransferButton.yPosition = posY + this.posY;
}
@Nonnull
public RecipeTransferButton getRecipeTransferButton() {
return recipeTransferButton;
}
@Nonnull
public IRecipeWrapper getRecipeWrapper() {
return recipeWrapper;
}
@Nonnull
public IRecipeCategory getRecipeCategory() {
return recipeCategory;
}
public int getPosX() {
return posX;
}
public int getPosY() {
return posY;
}
}