    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.validate();
    065        }
    066
    067        public void startMainThread()
    068        {
    069            if (this.mcThread == null)
    070            {
    071                this.mcThread = new Thread(this.mc, "Minecraft main thread");
    072                this.mcThread.start();
    073            }
    074        }
    075
    076        public void start()
    077        {
    078            FMLRelauncher.appletStart(this);
    079        }
    080
    081        public void fmlStartReentry()
    082        {
    083            if (this.mc != null)
    084            {
    085                this.mc.isGamePaused = false;
    086            }
    087        }
    088
    089        public void stop()
    090        {
    091            if (this.mc != null)
    092            {
    093                this.mc.isGamePaused = true;
    094            }
    095        }
    096
    097        public void destroy()
    098        {
    099            this.shutdown();
    100        }
    101
    102        /**
    103         * Called when the applet window is closed.
    104         */
    105        public void shutdown()
    106        {
    107            if (this.mcThread != null)
    108            {
    109                this.mc.shutdown();
    110
    111                try
    112                {
    113                    this.mcThread.join(10000L);
    114                }
    115                catch (InterruptedException var4)
    116                {
    117                    try
    118                    {
    119                        this.mc.shutdownMinecraftApplet();
    120                    }
    121                    catch (Exception var3)
    122                    {
    123                        var3.printStackTrace();
    124                    }
    125                }
    126
    127                this.mcThread = null;
    128            }
    129        }
    130    }