    001    package net.minecraft.client;
    002
    003    import cpw.mods.fml.relauncher.FMLRelauncher;
    004    import cpw.mods.fml.relauncher.Side;
    005    import cpw.mods.fml.relauncher.SideOnly;
    006    import java.applet.Applet;
    007    import java.awt.BorderLayout;
    008    import java.awt.Canvas;
    009    import net.minecraft.util.Session;
    010
    011    @SideOnly(Side.CLIENT)
    012    public class MinecraftApplet extends Applet
    013    {
    014        /** Reference to the applet canvas. */
    015        private Canvas mcCanvas;
    016
    017        /** Reference to the Minecraft object. */
    018        private Minecraft mc;
    019
    020        /** Reference to the Minecraft main thread. */
    021        private Thread mcThread = null;
    022
    023        public void init()
    024        {
    025            FMLRelauncher.appletEntry(this);
    026        }
    027
    028        public void fmlInitReentry()
    029        {
    030            this.mcCanvas = new CanvasMinecraftApplet(this);
    031            boolean var1 = "true".equalsIgnoreCase(this.getParameter("fullscreen"));
    032            this.mc = new MinecraftAppletImpl(this, this.mcCanvas, this, this.getWidth(), this.getHeight(), var1);
    033            this.mc.minecraftUri = this.getDocumentBase().getHost();
    034
    035            if (this.getDocumentBase().getPort() > 0)
    036            {
    037                this.mc.minecraftUri = this.mc.minecraftUri + ":" + this.getDocumentBase().getPort();
    038            }
    039
    040            if (this.getParameter("username") != null && this.getParameter("sessionid") != null)
    041            {
    042                this.mc.session = new Session(this.getParameter("username"), this.getParameter("sessionid"));
    043                System.out.println("Setting user: " + this.mc.session.username + ", " + this.mc.session.sessionId);
    044            }
    045            else
    046            {
    047                this.mc.session = new Session("Player", "");
    048            }
    049
    050            this.mc.setDemo("true".equals(this.getParameter("demo")));
    051
    052            if (this.getParameter("server") != null && this.getParameter("port") != null)
    053            {
    054                this.mc.setServer(this.getParameter("server"), Integer.parseInt(this.getParameter("port")));
    055            }
    056
    057            this.mc.hideQuitButton = !"true".equals(this.getParameter("stand-alone"));
    058            this.setLayout(new BorderLayout());
    059            this.add(this.mcCanvas, "Center");
    060            this.mcCanvas.setFocusable(true);
    061            this.mcCanvas.setFocusTraversalKeysEnabled(false);
    062            this.validate();
    063        }
    064
    065        public void startMainThread()
    066        {
    067            if (this.mcThread == null)
    068            {
    069                this.mcThread = new Thread(this.mc, "Minecraft main thread");
    070                this.mcThread.start();
    071            }
    072        }
    073
    074        public void start()
    075        {
    076            FMLRelauncher.appletStart(this);
    077        }
    078
    079        public void fmlStartReentry()
    080        {
    081            if (this.mc != null)
    082            {
    083                this.mc.isGamePaused = false;
    084            }
    085        }
    086
    087        public void stop()
    088        {
    089            if (this.mc != null)
    090            {
    091                this.mc.isGamePaused = true;
    092            }
    093        }
    094
    095        public void destroy()
    096        {
    097            this.shutdown();
    098        }
    099
    100        /**
    101         * Called when the applet window is closed.
    102         */
    103        public void shutdown()
    104        {
    105            if (this.mcThread != null)
    106            {
    107                this.mc.shutdown();
    108
    109                try
    110                {
    111                    this.mcThread.join(10000L);
    112                }
    113                catch (InterruptedException var4)
    114                {
    115                    try
    116                    {
    117                        this.mc.shutdownMinecraftApplet();
    118                    }
    119                    catch (Exception var3)
    120                    {
    121                        var3.printStackTrace();
    122                    }
    123                }
    124
    125                this.mcThread = null;
    126            }
    127        }
    128    }