001 package net.minecraft.client.gui.inventory; 002 003 import cpw.mods.fml.relauncher.Side; 004 import cpw.mods.fml.relauncher.SideOnly; 005 import net.minecraft.client.Minecraft; 006 import net.minecraft.client.gui.GuiButton; 007 import net.minecraft.client.gui.achievement.GuiAchievements; 008 import net.minecraft.client.gui.achievement.GuiStats; 009 import net.minecraft.client.renderer.InventoryEffectRenderer; 010 import net.minecraft.client.renderer.OpenGlHelper; 011 import net.minecraft.client.renderer.RenderHelper; 012 import net.minecraft.client.renderer.entity.RenderManager; 013 import net.minecraft.entity.player.EntityPlayer; 014 import net.minecraft.stats.AchievementList; 015 import net.minecraft.util.StatCollector; 016 import org.lwjgl.opengl.GL11; 017 import org.lwjgl.opengl.GL12; 018 019 @SideOnly(Side.CLIENT) 020 public class GuiInventory extends InventoryEffectRenderer 021 { 022 /** 023 * x size of the inventory window in pixels. Defined as float, passed as int 024 */ 025 private float xSize_lo; 026 027 /** 028 * y size of the inventory window in pixels. Defined as float, passed as int. 029 */ 030 private float ySize_lo; 031 032 public GuiInventory(EntityPlayer par1EntityPlayer) 033 { 034 super(par1EntityPlayer.inventoryContainer); 035 this.allowUserInput = true; 036 par1EntityPlayer.addStat(AchievementList.openInventory, 1); 037 } 038 039 /** 040 * Called from the main game loop to update the screen. 041 */ 042 public void updateScreen() 043 { 044 if (this.mc.playerController.isInCreativeMode()) 045 { 046 this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer)); 047 } 048 } 049 050 /** 051 * Adds the buttons (and other controls) to the screen in question. 052 */ 053 public void initGui() 054 { 055 this.controlList.clear(); 056 057 if (this.mc.playerController.isInCreativeMode()) 058 { 059 this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer)); 060 } 061 else 062 { 063 super.initGui(); 064 } 065 } 066 067 /** 068 * Draw the foreground layer for the GuiContainer (everything in front of the items) 069 */ 070 protected void drawGuiContainerForegroundLayer(int par1, int par2) 071 { 072 this.fontRenderer.drawString(StatCollector.translateToLocal("container.crafting"), 86, 16, 4210752); 073 } 074 075 /** 076 * Draws the screen and all the components in it. 077 */ 078 public void drawScreen(int par1, int par2, float par3) 079 { 080 super.drawScreen(par1, par2, par3); 081 this.xSize_lo = (float)par1; 082 this.ySize_lo = (float)par2; 083 } 084 085 /** 086 * Draw the background layer for the GuiContainer (everything behind the items) 087 */ 088 protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) 089 { 090 int var4 = this.mc.renderEngine.getTexture("/gui/inventory.png"); 091 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 092 this.mc.renderEngine.bindTexture(var4); 093 int var5 = this.guiLeft; 094 int var6 = this.guiTop; 095 this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize); 096 func_74223_a(this.mc, var5 + 51, var6 + 75, 30, (float)(var5 + 51) - this.xSize_lo, (float)(var6 + 75 - 50) - this.ySize_lo); 097 } 098 099 public static void func_74223_a(Minecraft par0Minecraft, int par1, int par2, int par3, float par4, float par5) 100 { 101 GL11.glEnable(GL11.GL_COLOR_MATERIAL); 102 GL11.glPushMatrix(); 103 GL11.glTranslatef((float)par1, (float)par2, 50.0F); 104 GL11.glScalef((float)(-par3), (float)par3, (float)par3); 105 GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); 106 float var6 = par0Minecraft.thePlayer.renderYawOffset; 107 float var7 = par0Minecraft.thePlayer.rotationYaw; 108 float var8 = par0Minecraft.thePlayer.rotationPitch; 109 GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); 110 RenderHelper.enableStandardItemLighting(); 111 GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); 112 GL11.glRotatef(-((float)Math.atan((double)(par5 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); 113 par0Minecraft.thePlayer.renderYawOffset = (float)Math.atan((double)(par4 / 40.0F)) * 20.0F; 114 par0Minecraft.thePlayer.rotationYaw = (float)Math.atan((double)(par4 / 40.0F)) * 40.0F; 115 par0Minecraft.thePlayer.rotationPitch = -((float)Math.atan((double)(par5 / 40.0F))) * 20.0F; 116 par0Minecraft.thePlayer.rotationYawHead = par0Minecraft.thePlayer.rotationYaw; 117 GL11.glTranslatef(0.0F, par0Minecraft.thePlayer.yOffset, 0.0F); 118 RenderManager.instance.playerViewY = 180.0F; 119 RenderManager.instance.renderEntityWithPosYaw(par0Minecraft.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); 120 par0Minecraft.thePlayer.renderYawOffset = var6; 121 par0Minecraft.thePlayer.rotationYaw = var7; 122 par0Minecraft.thePlayer.rotationPitch = var8; 123 GL11.glPopMatrix(); 124 RenderHelper.disableStandardItemLighting(); 125 GL11.glDisable(GL12.GL_RESCALE_NORMAL); 126 OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); 127 GL11.glDisable(GL11.GL_TEXTURE_2D); 128 OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); 129 } 130 131 /** 132 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 133 */ 134 protected void actionPerformed(GuiButton par1GuiButton) 135 { 136 if (par1GuiButton.id == 0) 137 { 138 this.mc.displayGuiScreen(new GuiAchievements(this.mc.statFileWriter)); 139 } 140 141 if (par1GuiButton.id == 1) 142 { 143 this.mc.displayGuiScreen(new GuiStats(this, this.mc.statFileWriter)); 144 } 145 } 146 }