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