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