Files
Chisel/src/main/java/team/chisel/client/gui/GuiChisel.java
T

146 lines
4.3 KiB
Java
Raw Normal View History

2015-08-18 20:40:55 -04:00
package team.chisel.client.gui;
2015-01-18 15:58:13 -05:00
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
2014-09-11 02:13:41 +02:00
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
2015-01-12 19:24:29 -05:00
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
2014-12-14 20:05:39 +00:00
import org.lwjgl.opengl.GL11;
2015-01-21 15:15:23 -05:00
import com.cricketcraft.chisel.api.IAdvancedChisel;
import com.cricketcraft.chisel.api.IChiselItem;
import com.cricketcraft.chisel.api.carving.IChiselMode;
2015-08-18 20:40:55 -04:00
import team.chisel.inventory.ContainerChisel;
import team.chisel.inventory.InventoryChiselSelection;
import team.chisel.inventory.SlotChiselInput;
import team.chisel.item.chisel.ChiselMode;
import team.chisel.network.PacketHandler;
import team.chisel.network.message.MessageChiselMode;
import team.chisel.utils.General;
import team.chisel.utils.GeneralClient;
2014-12-15 00:11:48 +00:00
public class GuiChisel extends GuiContainer {
public EntityPlayer player;
public ContainerChisel container;
private IChiselMode currentMode;
public GuiChisel(InventoryPlayer iinventory, InventoryChiselSelection menu) {
super(new ContainerChisel(iinventory, menu));
player = iinventory.player;
2015-01-12 19:24:29 -05:00
xSize = 252;
ySize = 202;
container = (ContainerChisel) inventorySlots;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
inventorySlots.onContainerClosed(player);
}
2015-01-18 15:58:13 -05:00
@SuppressWarnings("unchecked")
@Override
public void initGui() {
super.initGui();
currentMode = General.getChiselMode(container.chisel);
if (showMode()) {
int x = this.width / 2 - 120;
int y = this.height / 2 - 6;
buttonList.add(new GuiButton(0, x, y, 53, 20, ""));
setButtonText();
}
2015-01-18 15:58:13 -05:00
}
@Override
public void updateScreen() {
super.updateScreen();
ItemStack held = player.getCurrentEquippedItem();
if (held == null || !(held.getItem() instanceof IChiselItem)) {
mc.displayGuiScreen(null);
}
}
2015-01-18 15:58:13 -05:00
private void setButtonText() {
((GuiButton) buttonList.get(0)).displayString = I18n.format(container.inventory.getInventoryName() + ".mode." + currentMode.name().toLowerCase());
}
private boolean showMode() {
if (container.chisel != null && container.chisel.getItem() instanceof IChiselItem) {
return ((IChiselItem) container.chisel.getItem()).hasModes(container.chisel);
}
return false;
}
@Override
protected void drawGuiContainerForegroundLayer(int j, int i) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2015-01-12 19:24:29 -05:00
String line = I18n.format(this.container.inventory.getInventoryName() + ".title");
fontRendererObj.drawSplitString(line, 50 - fontRendererObj.getStringWidth(line) / 2, 60, 40, 0x404040);
if (showMode()) {
line = I18n.format(this.container.inventory.getInventoryName() + ".mode");
fontRendererObj.drawString(line, fontRendererObj.getStringWidth(line) / 2 + 6, 85, 0x404040);
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mx, int my) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int i = width - xSize >> 1;
int j = height - ySize >> 1;
2015-01-12 19:24:29 -05:00
String texture = "chisel:textures/chisel2Gui.png";
GeneralClient.bind(texture);
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
2015-01-18 15:58:13 -05:00
Slot main = (Slot) container.inventorySlots.get(InventoryChiselSelection.normalSlots);
if (main.getStack() == null) {
GuiAutoChisel.drawSlotOverlay(this, x + 14, y + 14, main, 0, ySize, 60);
}
}
2015-01-12 19:24:29 -05:00
2015-01-18 15:58:13 -05:00
@Override
protected void actionPerformed(GuiButton button) {
if (button.id == 0) {
if (container.chisel != null && container.chisel.getItem() instanceof IAdvancedChisel) {
IAdvancedChisel item = (IAdvancedChisel) container.chisel.getItem();
currentMode = item.getNextMode(container.chisel, currentMode);
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
} else {
currentMode = ChiselMode.next(currentMode);
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
setButtonText();
}
2015-01-18 15:58:13 -05:00
}
super.actionPerformed(button);
}
2015-01-12 19:24:29 -05:00
@Override
protected void func_146977_a(Slot slot) {
if (slot instanceof SlotChiselInput) {
GL11.glPushMatrix();
GL11.glScalef(2, 2, 2);
slot.xDisplayPosition -= 16;
slot.yDisplayPosition -= 16;
super.func_146977_a(slot);
slot.xDisplayPosition += 16;
slot.yDisplayPosition += 16;
GL11.glPopMatrix();
} else {
super.func_146977_a(slot);
}
}
}