package invtweaks;

import invtweaks.api.container.ContainerSection;
import invtweaks.container.ContainerSectionManager;
import net.minecraft.client.Minecraft;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.TimeoutException;

/**
 * Button that opens the inventory & chest settings screen.
 *
 * @author Jimeo Wan
 */
public class InvTweaksGuiSettingsButton extends InvTweaksGuiIconButton {

    private static final Logger log = InvTweaks.log;

    public InvTweaksGuiSettingsButton(InvTweaksConfigManager cfgManager_, int id_, int x, int y, int w, int h,
                                      String displayString_, String tooltip, boolean useCustomTexture) {
        super(cfgManager_, id_, x, y, w, h, displayString_, tooltip, useCustomTexture);
    }

    @Override
    public void drawButton(Minecraft minecraft, int i, int j) {
        super.drawButton(minecraft, i, j);

        // Display string
        InvTweaksObfuscation obf = new InvTweaksObfuscation(minecraft);
        drawCenteredString(obf.getFontRenderer(), displayString, xPosition + 5, yPosition - 1,
                getTextColor(i, j));
    }

    /**
     * Displays inventory settings GUI
     */
    @Override
    public boolean mousePressed(Minecraft minecraft, int i, int j) {

        InvTweaksObfuscation obf = new InvTweaksObfuscation(minecraft);
        InvTweaksConfig config = cfgManager.getConfig();

        if(super.mousePressed(minecraft, i, j)) {
            // Put hold item down if necessary
            ContainerSectionManager containerMgr;

            try {
                containerMgr = new ContainerSectionManager(ContainerSection.INVENTORY);
                if(obf.getHeldStack() != null) {
                    try {
                        // Put hold item down
                        for(int k = containerMgr.getSize() - 1; k >= 0; k--) {
                            if(containerMgr.getItemStack(k) == null) {
                                containerMgr.leftClick(k);
                                break;
                            }
                        }
                    } catch(TimeoutException e) {
                        InvTweaks.logInGameErrorStatic("invtweaks.sort.releaseitem.error", e);
                    }
                }
            } catch(Exception e) {
                log.error("mousePressed", e);
            }

            // Refresh config
            cfgManager.makeSureConfigurationIsLoaded();

            // Display menu
            obf.displayGuiScreen(new InvTweaksGuiSettings(minecraft, obf.getCurrentScreen(), config));
            return true;
        } else {
            return false;
        }
    }

}

@@ -1707,38 +1707,8 @@
 ) %7B%0A
-                    try %7B%0A    
     
@@ -1745,20 +1745,16 @@
 em down%0A
-    
         
@@ -1844,20 +1844,16 @@
         
-    
 if(conta
@@ -1879,36 +1879,32 @@
 k(k) == null) %7B%0A
-    
                 
@@ -1970,20 +1970,16 @@
         
-    
 break;%0A 
@@ -2005,184 +2005,9 @@
     
-    %7D%0A                        %7D%0A                    %7D catch(TimeoutException e) %7B%0A                        InvTweaks.logInGameErrorStatic(%22invtweaks.sort.releaseitem.error%22, e);
+%7D
 %0A   

Fix compile error.