/
RecipeTransferButton.java
53 lines (45 loc) · 1.85 KB
/
RecipeTransferButton.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
package mezz.jei.gui;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.config.Constants;
import mezz.jei.transfer.RecipeTransferErrorInternal;
import mezz.jei.transfer.RecipeTransferUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraftforge.fml.client.config.GuiButtonExt;
public class RecipeTransferButton extends GuiButtonExt {
private RecipeLayout recipeLayout;
private IRecipeTransferError recipeTransferError;
public RecipeTransferButton(int id, int xPos, int yPos, int width, int height, String displayString) {
super(id, xPos, yPos, width, height, displayString);
}
public void init(@Nullable Container container, @Nonnull RecipeLayout recipeLayout, @Nonnull EntityPlayer player) {
this.recipeLayout = recipeLayout;
if (container != null) {
this.recipeTransferError = RecipeTransferUtil.getTransferRecipeError(container, recipeLayout, player);
} else {
this.recipeTransferError = RecipeTransferErrorInternal.INSTANCE;
}
if (this.recipeTransferError == null) {
this.enabled = true;
this.visible = true;
} else {
this.enabled = false;
IRecipeTransferError.Type type = this.recipeTransferError.getType();
this.visible = (type == IRecipeTransferError.Type.USER_FACING);
}
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
super.drawButton(mc, mouseX, mouseY);
if (hovered && visible) {
if (recipeTransferError != null) {
recipeTransferError.showError(mc, mouseX, mouseY, recipeLayout, recipeLayout.getPosX(), recipeLayout.getPosY());
} else {
TooltipRenderer.drawHoveringText(mc, Constants.RECIPE_TRANSFER_TOOLTIP, mouseX, mouseY);
}
}
}
}