    001package net.minecraft.client.gui.inventory;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.Minecraft;
    006import net.minecraft.client.gui.GuiButton;
    007import net.minecraft.client.gui.achievement.GuiAchievements;
    008import net.minecraft.client.gui.achievement.GuiStats;
    009import net.minecraft.client.renderer.InventoryEffectRenderer;
    010import net.minecraft.client.renderer.OpenGlHelper;
    011import net.minecraft.client.renderer.RenderHelper;
    012import net.minecraft.client.renderer.entity.RenderManager;
    013import net.minecraft.entity.player.EntityPlayer;
    014import net.minecraft.stats.AchievementList;
    015import net.minecraft.util.StatCollector;
    016import org.lwjgl.opengl.GL11;
    017import org.lwjgl.opengl.GL12;
    018
    019@SideOnly(Side.CLIENT)
    020public 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.buttonList.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        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    091        this.mc.renderEngine.func_98187_b("/gui/inventory.png");
    092        int k = this.guiLeft;
    093        int l = this.guiTop;
    094        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
    095        drawPlayerOnGui(this.mc, k + 51, l + 75, 30, (float)(k + 51) - this.xSize_lo, (float)(l + 75 - 50) - this.ySize_lo);
    096    }
    097
    098    public static void drawPlayerOnGui(Minecraft par0Minecraft, int par1, int par2, int par3, float par4, float par5)
    099    {
    100        GL11.glEnable(GL11.GL_COLOR_MATERIAL);
    101        GL11.glPushMatrix();
    102        GL11.glTranslatef((float)par1, (float)par2, 50.0F);
    103        GL11.glScalef((float)(-par3), (float)par3, (float)par3);
    104        GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
    105        float f2 = par0Minecraft.thePlayer.renderYawOffset;
    106        float f3 = par0Minecraft.thePlayer.rotationYaw;
    107        float f4 = par0Minecraft.thePlayer.rotationPitch;
    108        GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
    109        RenderHelper.enableStandardItemLighting();
    110        GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
    111        GL11.glRotatef(-((float)Math.atan((double)(par5 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
    112        par0Minecraft.thePlayer.renderYawOffset = (float)Math.atan((double)(par4 / 40.0F)) * 20.0F;
    113        par0Minecraft.thePlayer.rotationYaw = (float)Math.atan((double)(par4 / 40.0F)) * 40.0F;
    114        par0Minecraft.thePlayer.rotationPitch = -((float)Math.atan((double)(par5 / 40.0F))) * 20.0F;
    115        par0Minecraft.thePlayer.rotationYawHead = par0Minecraft.thePlayer.rotationYaw;
    116        GL11.glTranslatef(0.0F, par0Minecraft.thePlayer.yOffset, 0.0F);
    117        RenderManager.instance.playerViewY = 180.0F;
    118        RenderManager.instance.renderEntityWithPosYaw(par0Minecraft.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
    119        par0Minecraft.thePlayer.renderYawOffset = f2;
    120        par0Minecraft.thePlayer.rotationYaw = f3;
    121        par0Minecraft.thePlayer.rotationPitch = f4;
    122        GL11.glPopMatrix();
    123        RenderHelper.disableStandardItemLighting();
    124        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    125        OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
    126        GL11.glDisable(GL11.GL_TEXTURE_2D);
    127        OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
    128    }
    129
    130    /**
    131     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    132     */
    133    protected void actionPerformed(GuiButton par1GuiButton)
    134    {
    135        if (par1GuiButton.id == 0)
    136        {
    137            this.mc.displayGuiScreen(new GuiAchievements(this.mc.statFileWriter));
    138        }
    139
    140        if (par1GuiButton.id == 1)
    141        {
    142            this.mc.displayGuiScreen(new GuiStats(this, this.mc.statFileWriter));
    143        }
    144    }
    145}