2015-08-18 20:40:55 -04:00
|
|
|
package team.chisel.client.gui;
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2020-02-20 16:09:17 +01:00
|
|
|
import com.cricketcraft.chisel.api.IAdvancedChisel;
|
|
|
|
|
import com.cricketcraft.chisel.api.IChiselItem;
|
|
|
|
|
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-01-18 15:58:13 -05:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2014-04-21 19:13:15 +01:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
2014-09-11 02:13:41 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2014-04-21 19:13:15 +01:00
|
|
|
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;
|
2015-03-31 17:16:07 -04:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-02-20 16:09:17 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2014-04-21 19:13:15 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
2020-02-20 16:09:17 +01:00
|
|
|
import team.chisel.client.gui.widgets.GuiButtonChiselMode;
|
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;
|
2014-12-15 00:11:48 +00:00
|
|
|
|
2020-02-20 16:09:17 +01:00
|
|
|
import static team.chisel.Chisel.MOD_ID;
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2015-01-07 19:50:18 -05:00
|
|
|
public class GuiChisel extends GuiContainer {
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2020-02-20 16:09:17 +01:00
|
|
|
public static final ResourceLocation TEXTURE_RESOURCE_LOCATION = new ResourceLocation(MOD_ID, "textures/chisel2GuiScroll.png");
|
|
|
|
|
public static final int TEXTURE_WIDTH = 266;
|
|
|
|
|
public static final int TEXTURE_HEIGHT = 250;
|
|
|
|
|
public static final int GUI_WIDTH = 266;
|
|
|
|
|
public static final int GUI_HEIGHT = 202;
|
|
|
|
|
public static final int CHISEL_INPUT_SIZE = 48;
|
|
|
|
|
private EntityPlayer player;
|
|
|
|
|
private ContainerChisel container;
|
2015-01-21 14:02:47 -05:00
|
|
|
private IChiselMode currentMode;
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
public GuiChisel(InventoryPlayer iinventory, InventoryChiselSelection menu) {
|
|
|
|
|
super(new ContainerChisel(iinventory, menu));
|
|
|
|
|
player = iinventory.player;
|
2020-02-20 16:09:17 +01:00
|
|
|
xSize = GUI_WIDTH;
|
|
|
|
|
ySize = GUI_HEIGHT;
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
container = (ContainerChisel) inventorySlots;
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
|
|
|
|
public void onGuiClosed() {
|
|
|
|
|
super.onGuiClosed();
|
|
|
|
|
inventorySlots.onContainerClosed(player);
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-01-18 15:58:13 -05:00
|
|
|
@Override
|
2020-02-20 16:09:17 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2015-01-18 15:58:13 -05:00
|
|
|
public void initGui() {
|
|
|
|
|
super.initGui();
|
|
|
|
|
currentMode = General.getChiselMode(container.chisel);
|
|
|
|
|
|
2015-01-19 11:23:11 -05:00
|
|
|
if (showMode()) {
|
2020-02-20 16:09:17 +01:00
|
|
|
buttonList.add(new GuiButtonChiselMode(0, guiLeft + 12, guiTop + 132, this));
|
2015-01-19 11:23:11 -05:00
|
|
|
}
|
2015-01-18 15:58:13 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-31 17:16:07 -04:00
|
|
|
@Override
|
|
|
|
|
public void updateScreen() {
|
|
|
|
|
super.updateScreen();
|
2020-02-20 16:09:17 +01:00
|
|
|
final ItemStack held = player.getCurrentEquippedItem();
|
2015-03-31 17:16:07 -04:00
|
|
|
if (held == null || !(held.getItem() instanceof IChiselItem)) {
|
|
|
|
|
mc.displayGuiScreen(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 11:23:11 -05:00
|
|
|
private boolean showMode() {
|
2020-02-20 16:09:17 +01:00
|
|
|
return container.chisel != null
|
|
|
|
|
&& container.chisel.getItem() instanceof IChiselItem
|
|
|
|
|
&& ((IChiselItem) container.chisel.getItem()).hasModes(container.chisel);
|
2015-01-19 11:23:11 -05:00
|
|
|
}
|
|
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
2020-02-20 16:09:17 +01:00
|
|
|
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
|
2015-01-07 19:50:18 -05:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2020-02-20 16:09:17 +01:00
|
|
|
final String titleText = I18n.format(container.inventory.getInventoryName() + ".title");
|
|
|
|
|
fontRendererObj.drawSplitString(titleText, 50 - fontRendererObj.getStringWidth(titleText) / 2, 60, 40, 0x404040);
|
2015-01-19 11:23:11 -05:00
|
|
|
|
|
|
|
|
if (showMode()) {
|
2020-02-20 16:09:17 +01:00
|
|
|
final String modeText = I18n.format(container.inventory.getInventoryName() + ".mode");
|
|
|
|
|
fontRendererObj.drawString(modeText, 12 + (GuiButtonChiselMode.BUTTON_WIDTH - fontRendererObj.getStringWidth(modeText)) / 2, 122, 0x404040);
|
2015-01-19 11:23:11 -05:00
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2015-01-07 19:50:18 -05:00
|
|
|
@Override
|
2020-02-20 16:09:17 +01:00
|
|
|
protected void drawGuiContainerBackgroundLayer(final float partialTicks, final int mouseX, final int mouseY) {
|
2015-01-07 19:50:18 -05:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2020-02-20 16:09:17 +01:00
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
2014-04-21 19:13:15 +01:00
|
|
|
|
2020-02-20 16:09:17 +01:00
|
|
|
mc.getTextureManager().bindTexture(TEXTURE_RESOURCE_LOCATION);
|
|
|
|
|
// drawModalRectWithCustomSizedTexture: x, y, u, v, width, height, textureWidth, textureHeight
|
|
|
|
|
func_146110_a(guiLeft, guiTop, 0, 0, xSize, ySize, TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
2015-01-18 15:58:13 -05:00
|
|
|
|
2015-01-13 21:37:04 -05:00
|
|
|
Slot main = (Slot) container.inventorySlots.get(InventoryChiselSelection.normalSlots);
|
|
|
|
|
if (main.getStack() == null) {
|
2020-02-20 16:09:17 +01:00
|
|
|
func_146110_a(guiLeft + 8, guiTop + 8, 0, GUI_HEIGHT, CHISEL_INPUT_SIZE, CHISEL_INPUT_SIZE, TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
2015-01-13 21:37:04 -05:00
|
|
|
}
|
2015-01-07 19:50:18 -05:00
|
|
|
}
|
2015-01-12 19:24:29 -05:00
|
|
|
|
2015-01-18 15:58:13 -05:00
|
|
|
@Override
|
2020-02-20 16:09:17 +01:00
|
|
|
protected void actionPerformed(final GuiButton button) {
|
2015-01-18 15:58:13 -05:00
|
|
|
if (button.id == 0) {
|
2015-01-21 14:02:47 -05:00
|
|
|
if (container.chisel != null && container.chisel.getItem() instanceof IAdvancedChisel) {
|
2020-02-20 16:09:17 +01:00
|
|
|
final IAdvancedChisel item = (IAdvancedChisel) container.chisel.getItem();
|
2015-01-21 14:02:47 -05:00
|
|
|
currentMode = item.getNextMode(container.chisel, currentMode);
|
|
|
|
|
} else {
|
|
|
|
|
currentMode = ChiselMode.next(currentMode);
|
|
|
|
|
}
|
2020-02-20 16:09:17 +01:00
|
|
|
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
|
2015-01-18 15:58:13 -05:00
|
|
|
}
|
|
|
|
|
super.actionPerformed(button);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 19:24:29 -05:00
|
|
|
@Override
|
2020-02-20 16:09:17 +01:00
|
|
|
protected void func_146977_a(final Slot slot) {
|
2015-01-12 19:24:29 -05:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-20 16:09:17 +01:00
|
|
|
|
|
|
|
|
public IChiselMode getCurrentMode() {
|
|
|
|
|
return currentMode;
|
|
|
|
|
}
|
2014-04-21 19:13:15 +01:00
|
|
|
}
|