-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathGuiNpcAnvil.java
More file actions
93 lines (81 loc) · 3.83 KB
/
Copy pathGuiNpcAnvil.java
File metadata and controls
93 lines (81 loc) · 3.83 KB
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
package noppes.npcs.client.gui.player;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.containers.ContainerAnvilRepair;
import noppes.npcs.controllers.RecipeController;
import org.lwjgl.opengl.GL11;
public class GuiNpcAnvil extends GuiContainerNPCInterface {
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/anvil.png");
private final ContainerAnvilRepair container;
private GuiNpcButton button;
public GuiNpcAnvil(ContainerAnvilRepair container) {
super(null, container);
this.container = container;
this.title = "";
allowUserInput = false;
closeOnEsc = true;
ySize = 180;
}
@Override
public void initGui() {
super.initGui();
addButton(button = new GuiNpcButton(0, guiLeft + 158, guiTop + 4, 12, 20, "..."));
}
@Override
public void buttonEvent(GuiButton guibutton) {
displayGuiScreen(new GuiAnvilRecipes());
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
// Enable the button if there are any anvil recipes.
// TODO: Checks the shared RecipeController anvil list (entire dataset) before enabling; this player crafting GUI is
// public, so no CustomNpcsPermissions gate applies here.
button.enabled = RecipeController.Instance != null && !RecipeController.Instance.getAnvilList().isEmpty();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(resource);
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
if (!container.canPickupResult()) {
drawRedSlotOutline(guiLeft + 133, guiTop + 47);
}
// Draw title and player's inventory label.
fontRendererObj.drawString(StatCollector.translateToLocal("tile.anvil.name"), guiLeft + 4, guiTop + 4, CustomNpcResourceListener.DefaultTextColor);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), guiLeft + 4, guiTop + 87, CustomNpcResourceListener.DefaultTextColor);
// Compute the repair status message based on container.repairCost and player's XP.
String status = "";
int textColor = CustomNpcResourceListener.DefaultTextColor;
if (container.repairCost > 0) {
if (container.repairCost > mc.thePlayer.experienceTotal) {
status = "Repair cost: " + container.repairCost + " XP";
textColor = 0xFF0000; // red when not enough XP
} else {
status = "Repair cost: " + container.repairCost + " XP";
}
} else {
// If there is a damaged item that is fully repaired.
if (container.anvilMatrix.getStackInRowAndColumn(0, 0) != null &&
container.anvilMatrix.getStackInRowAndColumn(0, 0).isItemStackDamageable() &&
container.anvilMatrix.getStackInRowAndColumn(0, 0).getItemDamage() <= 0) {
status = "Item is already fully repaired";
}
}
fontRendererObj.drawString(status, guiLeft + 5, guiTop + 75, textColor);
}
private void drawRedSlotOutline(int x, int y) {
int c = 0xFFFF0000;
drawRect(x - 1, y - 1, x + 17, y, c);
drawRect(x - 1, y + 16, x + 17, y + 17, c);
drawRect(x - 1, y, x, y + 16, c);
drawRect(x + 16, y, x + 17, y + 16, c);
}
@Override
public void save() {
// Nothing to save.
}
}