    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import cpw.mods.fml.common.network.FMLNetworkHandler;
    006
    007    import java.io.BufferedReader;
    008    import java.io.ByteArrayInputStream;
    009    import java.io.DataInputStream;
    010    import java.io.IOException;
    011    import java.io.InputStreamReader;
    012    import java.math.BigInteger;
    013    import java.net.InetAddress;
    014    import java.net.Socket;
    015    import java.net.URL;
    016    import java.net.URLEncoder;
    017    import java.security.PublicKey;
    018    import java.util.ArrayList;
    019    import java.util.HashMap;
    020    import java.util.List;
    021    import java.util.Map;
    022    import java.util.Random;
    023    import javax.crypto.SecretKey;
    024    import net.minecraft.client.Minecraft;
    025    import net.minecraftforge.client.ForgeHooksClient;
    026    import net.minecraftforge.client.event.ClientChatReceivedEvent;
    027    import net.minecraftforge.common.ForgeHooks;
    028    import net.minecraftforge.common.MinecraftForge;
    029
    030    import org.lwjgl.input.Keyboard;
    031
    032    @SideOnly(Side.CLIENT)
    033    public class NetClientHandler extends NetHandler
    034    {
    035        /** True if kicked or disconnected from the server. */
    036        private boolean disconnected = false;
    037
    038        /** Reference to the NetworkManager object. */
    039        private INetworkManager netManager;
    040        public String field_72560_a;
    041
    042        /** Reference to the Minecraft object. */
    043        private Minecraft mc;
    044        private WorldClient worldClient;
    045
    046        /**
    047         * True if the client has finished downloading terrain and may spawn. Set upon receipt of a player position packet,
    048         * reset upon respawning.
    049         */
    050        private boolean doneLoadingTerrain = false;
    051        public MapStorage mapStorage = new MapStorage((ISaveHandler)null);
    052
    053        /** A HashMap of all player names and their player information objects */
    054        private Map playerInfoMap = new HashMap();
    055
    056        /**
    057         * An ArrayList of GuiPlayerInfo (includes all the players' GuiPlayerInfo on the current server)
    058         */
    059        public List playerInfoList = new ArrayList();
    060        public int currentServerMaxPlayers = 20;
    061
    062        /** RNG. */
    063        Random rand = new Random();
    064
    065        private static byte connectionCompatibilityLevel;
    066
    067        public NetClientHandler(Minecraft par1Minecraft, String par2Str, int par3) throws IOException
    068        {
    069            this.mc = par1Minecraft;
    070            Socket var4 = new Socket(InetAddress.getByName(par2Str), par3);
    071            this.netManager = new TcpConnection(var4, "Client", this);
    072            FMLNetworkHandler.onClientConnectionToRemoteServer(this, par2Str, par3, this.netManager);
    073        }
    074
    075        public NetClientHandler(Minecraft par1Minecraft, IntegratedServer par2IntegratedServer) throws IOException
    076        {
    077            this.mc = par1Minecraft;
    078            this.netManager = new MemoryConnection(this);
    079            par2IntegratedServer.getServerListeningThread().func_71754_a((MemoryConnection)this.netManager, par1Minecraft.session.username);
    080            FMLNetworkHandler.onClientConnectionToIntegratedServer(this, par2IntegratedServer, this.netManager);
    081        }
    082
    083        /**
    084         * sets netManager and worldClient to null
    085         */
    086        public void cleanup()
    087        {
    088            if (this.netManager != null)
    089            {
    090                this.netManager.wakeThreads();
    091            }
    092
    093            this.netManager = null;
    094            this.worldClient = null;
    095        }
    096
    097        /**
    098         * Processes the packets that have been read since the last call to this function.
    099         */
    100        public void processReadPackets()
    101        {
    102            if (!this.disconnected && this.netManager != null)
    103            {
    104                this.netManager.processReadPackets();
    105            }
    106
    107            if (this.netManager != null)
    108            {
    109                this.netManager.wakeThreads();
    110            }
    111        }
    112
    113        public void handleServerAuthData(Packet253ServerAuthData par1Packet253ServerAuthData)
    114        {
    115            String var2 = par1Packet253ServerAuthData.getServerId().trim();
    116            PublicKey var3 = par1Packet253ServerAuthData.getPublicKey();
    117            SecretKey var4 = CryptManager.func_75890_a();
    118
    119            if (!"-".equals(var2))
    120            {
    121                String var5 = (new BigInteger(CryptManager.func_75895_a(var2, var3, var4))).toString(16);
    122                String var6 = this.func_72550_a(this.mc.session.username, this.mc.session.sessionId, var5);
    123
    124                if (!"ok".equalsIgnoreCase(var6))
    125                {
    126                    this.netManager.networkShutdown("disconnect.loginFailedInfo", new Object[] {var6});
    127                    return;
    128                }
    129            }
    130
    131            this.addToSendQueue(new Packet252SharedKey(var4, var3, par1Packet253ServerAuthData.getVerifyToken()));
    132        }
    133
    134        private String func_72550_a(String par1Str, String par2Str, String par3Str)
    135        {
    136            try
    137            {
    138                URL var4 = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + urlEncode(par1Str) + "&sessionId=" + urlEncode(par2Str) + "&serverId=" + urlEncode(par3Str));
    139                BufferedReader var5 = new BufferedReader(new InputStreamReader(var4.openStream()));
    140                String var6 = var5.readLine();
    141                var5.close();
    142                return var6;
    143            }
    144            catch (IOException var7)
    145            {
    146                return var7.toString();
    147            }
    148        }
    149
    150        /**
    151         * Encode the given string for insertion into a URL
    152         */
    153        private static String urlEncode(String par0Str) throws IOException
    154        {
    155            return URLEncoder.encode(par0Str, "UTF-8");
    156        }
    157
    158        public void handleSharedKey(Packet252SharedKey par1Packet252SharedKey)
    159        {
    160            this.addToSendQueue(FMLNetworkHandler.getFMLFakeLoginPacket());
    161            this.addToSendQueue(new Packet205ClientCommand(0));
    162        }
    163
    164        public void handleLogin(Packet1Login par1Packet1Login)
    165        {
    166            this.mc.playerController = new PlayerControllerMP(this.mc, this);
    167            this.mc.statFileWriter.readStat(StatList.joinMultiplayerStat, 1);
    168            this.worldClient = new WorldClient(this, new WorldSettings(0L, par1Packet1Login.gameType, false, par1Packet1Login.field_73560_c, par1Packet1Login.terrainType), par1Packet1Login.dimension, par1Packet1Login.difficultySetting, this.mc.mcProfiler);
    169            this.worldClient.isRemote = true;
    170            this.mc.loadWorld(this.worldClient);
    171            this.mc.thePlayer.dimension = par1Packet1Login.dimension;
    172            this.mc.displayGuiScreen(new GuiDownloadTerrain(this));
    173            this.mc.thePlayer.entityId = par1Packet1Login.clientEntityId;
    174            this.currentServerMaxPlayers = par1Packet1Login.maxPlayers;
    175            this.mc.playerController.setGameType(par1Packet1Login.gameType);
    176            FMLNetworkHandler.onConnectionEstablishedToServer(this, netManager, par1Packet1Login);
    177            this.mc.gameSettings.sendSettingsToServer();
    178        }
    179
    180        public void handlePickupSpawn(Packet21PickupSpawn par1Packet21PickupSpawn)
    181        {
    182            double var2 = (double)par1Packet21PickupSpawn.xPosition / 32.0D;
    183            double var4 = (double)par1Packet21PickupSpawn.yPosition / 32.0D;
    184            double var6 = (double)par1Packet21PickupSpawn.zPosition / 32.0D;
    185            EntityItem var8 = new EntityItem(this.worldClient, var2, var4, var6, par1Packet21PickupSpawn.itemID);
    186            var8.motionX = (double)par1Packet21PickupSpawn.rotation / 128.0D;
    187            var8.motionY = (double)par1Packet21PickupSpawn.pitch / 128.0D;
    188            var8.motionZ = (double)par1Packet21PickupSpawn.roll / 128.0D;
    189            var8.serverPosX = par1Packet21PickupSpawn.xPosition;
    190            var8.serverPosY = par1Packet21PickupSpawn.yPosition;
    191            var8.serverPosZ = par1Packet21PickupSpawn.zPosition;
    192            this.worldClient.addEntityToWorld(par1Packet21PickupSpawn.entityId, var8);
    193        }
    194
    195        public void handleVehicleSpawn(Packet23VehicleSpawn par1Packet23VehicleSpawn)
    196        {
    197            double var2 = (double)par1Packet23VehicleSpawn.xPosition / 32.0D;
    198            double var4 = (double)par1Packet23VehicleSpawn.yPosition / 32.0D;
    199            double var6 = (double)par1Packet23VehicleSpawn.zPosition / 32.0D;
    200            Object var8 = null;
    201            boolean var9 = true;
    202
    203            if (par1Packet23VehicleSpawn.type == 10)
    204            {
    205                var8 = new EntityMinecart(this.worldClient, var2, var4, var6, 0);
    206            }
    207            else if (par1Packet23VehicleSpawn.type == 11)
    208            {
    209                var8 = new EntityMinecart(this.worldClient, var2, var4, var6, 1);
    210            }
    211            else if (par1Packet23VehicleSpawn.type == 12)
    212            {
    213                var8 = new EntityMinecart(this.worldClient, var2, var4, var6, 2);
    214            }
    215            else if (par1Packet23VehicleSpawn.type == 90)
    216            {
    217                Entity var10 = this.getEntityByID(par1Packet23VehicleSpawn.throwerEntityId);
    218
    219                if (var10 instanceof EntityPlayer)
    220                {
    221                    var8 = new EntityFishHook(this.worldClient, var2, var4, var6, (EntityPlayer)var10);
    222                }
    223
    224                par1Packet23VehicleSpawn.throwerEntityId = 0;
    225            }
    226            else if (par1Packet23VehicleSpawn.type == 60)
    227            {
    228                var8 = new EntityArrow(this.worldClient, var2, var4, var6);
    229            }
    230            else if (par1Packet23VehicleSpawn.type == 61)
    231            {
    232                var8 = new EntitySnowball(this.worldClient, var2, var4, var6);
    233            }
    234            else if (par1Packet23VehicleSpawn.type == 71)
    235            {
    236                var8 = new EntityItemFrame(this.worldClient, (int)var2, (int)var4, (int)var6, par1Packet23VehicleSpawn.throwerEntityId);
    237                par1Packet23VehicleSpawn.throwerEntityId = 0;
    238                var9 = false;
    239            }
    240            else if (par1Packet23VehicleSpawn.type == 65)
    241            {
    242                var8 = new EntityEnderPearl(this.worldClient, var2, var4, var6);
    243            }
    244            else if (par1Packet23VehicleSpawn.type == 72)
    245            {
    246                var8 = new EntityEnderEye(this.worldClient, var2, var4, var6);
    247            }
    248            else if (par1Packet23VehicleSpawn.type == 63)
    249            {
    250                var8 = new EntityLargeFireball(this.worldClient, var2, var4, var6, (double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    251                par1Packet23VehicleSpawn.throwerEntityId = 0;
    252            }
    253            else if (par1Packet23VehicleSpawn.type == 64)
    254            {
    255                var8 = new EntitySmallFireball(this.worldClient, var2, var4, var6, (double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    256                par1Packet23VehicleSpawn.throwerEntityId = 0;
    257            }
    258            else if (par1Packet23VehicleSpawn.type == 66)
    259            {
    260                var8 = new EntityWitherSkull(this.worldClient, var2, var4, var6, (double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    261                par1Packet23VehicleSpawn.throwerEntityId = 0;
    262            }
    263            else if (par1Packet23VehicleSpawn.type == 62)
    264            {
    265                var8 = new EntityEgg(this.worldClient, var2, var4, var6);
    266            }
    267            else if (par1Packet23VehicleSpawn.type == 73)
    268            {
    269                var8 = new EntityPotion(this.worldClient, var2, var4, var6, par1Packet23VehicleSpawn.throwerEntityId);
    270                par1Packet23VehicleSpawn.throwerEntityId = 0;
    271            }
    272            else if (par1Packet23VehicleSpawn.type == 75)
    273            {
    274                var8 = new EntityExpBottle(this.worldClient, var2, var4, var6);
    275                par1Packet23VehicleSpawn.throwerEntityId = 0;
    276            }
    277            else if (par1Packet23VehicleSpawn.type == 1)
    278            {
    279                var8 = new EntityBoat(this.worldClient, var2, var4, var6);
    280            }
    281            else if (par1Packet23VehicleSpawn.type == 50)
    282            {
    283                var8 = new EntityTNTPrimed(this.worldClient, var2, var4, var6);
    284            }
    285            else if (par1Packet23VehicleSpawn.type == 51)
    286            {
    287                var8 = new EntityEnderCrystal(this.worldClient, var2, var4, var6);
    288            }
    289            else if (par1Packet23VehicleSpawn.type == 70)
    290            {
    291                var8 = new EntityFallingSand(this.worldClient, var2, var4, var6, par1Packet23VehicleSpawn.throwerEntityId & 65535, par1Packet23VehicleSpawn.throwerEntityId >> 16);
    292                par1Packet23VehicleSpawn.throwerEntityId = 0;
    293            }
    294
    295            if (var8 != null)
    296            {
    297                ((Entity)var8).serverPosX = par1Packet23VehicleSpawn.xPosition;
    298                ((Entity)var8).serverPosY = par1Packet23VehicleSpawn.yPosition;
    299                ((Entity)var8).serverPosZ = par1Packet23VehicleSpawn.zPosition;
    300
    301                if (var9)
    302                {
    303                    ((Entity)var8).rotationYaw = 0.0F;
    304                    ((Entity)var8).rotationPitch = 0.0F;
    305                }
    306
    307                Entity[] var14 = ((Entity)var8).getParts();
    308
    309                if (var14 != null)
    310                {
    311                    int var11 = par1Packet23VehicleSpawn.entityId - ((Entity)var8).entityId;
    312
    313                    for (int var12 = 0; var12 < var14.length; ++var12)
    314                    {
    315                        var14[var12].entityId += var11;
    316                    }
    317                }
    318
    319                ((Entity)var8).entityId = par1Packet23VehicleSpawn.entityId;
    320                this.worldClient.addEntityToWorld(par1Packet23VehicleSpawn.entityId, (Entity)var8);
    321
    322                if (par1Packet23VehicleSpawn.throwerEntityId > 0)
    323                {
    324                    if (par1Packet23VehicleSpawn.type == 60)
    325                    {
    326                        Entity var13 = this.getEntityByID(par1Packet23VehicleSpawn.throwerEntityId);
    327
    328                        if (var13 instanceof EntityLiving)
    329                        {
    330                            EntityArrow var15 = (EntityArrow)var8;
    331                            var15.shootingEntity = var13;
    332                        }
    333                    }
    334
    335                    ((Entity)var8).setVelocity((double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    336                }
    337            }
    338        }
    339
    340        /**
    341         * Handle a entity experience orb packet.
    342         */
    343        public void handleEntityExpOrb(Packet26EntityExpOrb par1Packet26EntityExpOrb)
    344        {
    345            EntityXPOrb var2 = new EntityXPOrb(this.worldClient, (double)par1Packet26EntityExpOrb.posX, (double)par1Packet26EntityExpOrb.posY, (double)par1Packet26EntityExpOrb.posZ, par1Packet26EntityExpOrb.xpValue);
    346            var2.serverPosX = par1Packet26EntityExpOrb.posX;
    347            var2.serverPosY = par1Packet26EntityExpOrb.posY;
    348            var2.serverPosZ = par1Packet26EntityExpOrb.posZ;
    349            var2.rotationYaw = 0.0F;
    350            var2.rotationPitch = 0.0F;
    351            var2.entityId = par1Packet26EntityExpOrb.entityId;
    352            this.worldClient.addEntityToWorld(par1Packet26EntityExpOrb.entityId, var2);
    353        }
    354
    355        /**
    356         * Handles weather packet
    357         */
    358        public void handleWeather(Packet71Weather par1Packet71Weather)
    359        {
    360            double var2 = (double)par1Packet71Weather.posX / 32.0D;
    361            double var4 = (double)par1Packet71Weather.posY / 32.0D;
    362            double var6 = (double)par1Packet71Weather.posZ / 32.0D;
    363            EntityLightningBolt var8 = null;
    364
    365            if (par1Packet71Weather.isLightningBolt == 1)
    366            {
    367                var8 = new EntityLightningBolt(this.worldClient, var2, var4, var6);
    368            }
    369
    370            if (var8 != null)
    371            {
    372                var8.serverPosX = par1Packet71Weather.posX;
    373                var8.serverPosY = par1Packet71Weather.posY;
    374                var8.serverPosZ = par1Packet71Weather.posZ;
    375                var8.rotationYaw = 0.0F;
    376                var8.rotationPitch = 0.0F;
    377                var8.entityId = par1Packet71Weather.entityID;
    378                this.worldClient.addWeatherEffect(var8);
    379            }
    380        }
    381
    382        /**
    383         * Packet handler
    384         */
    385        public void handleEntityPainting(Packet25EntityPainting par1Packet25EntityPainting)
    386        {
    387            EntityPainting var2 = new EntityPainting(this.worldClient, par1Packet25EntityPainting.xPosition, par1Packet25EntityPainting.yPosition, par1Packet25EntityPainting.zPosition, par1Packet25EntityPainting.direction, par1Packet25EntityPainting.title);
    388            this.worldClient.addEntityToWorld(par1Packet25EntityPainting.entityId, var2);
    389        }
    390
    391        /**
    392         * Packet handler
    393         */
    394        public void handleEntityVelocity(Packet28EntityVelocity par1Packet28EntityVelocity)
    395        {
    396            Entity var2 = this.getEntityByID(par1Packet28EntityVelocity.entityId);
    397
    398            if (var2 != null)
    399            {
    400                var2.setVelocity((double)par1Packet28EntityVelocity.motionX / 8000.0D, (double)par1Packet28EntityVelocity.motionY / 8000.0D, (double)par1Packet28EntityVelocity.motionZ / 8000.0D);
    401            }
    402        }
    403
    404        /**
    405         * Packet handler
    406         */
    407        public void handleEntityMetadata(Packet40EntityMetadata par1Packet40EntityMetadata)
    408        {
    409            Entity var2 = this.getEntityByID(par1Packet40EntityMetadata.entityId);
    410
    411            if (var2 != null && par1Packet40EntityMetadata.getMetadata() != null)
    412            {
    413                var2.getDataWatcher().updateWatchedObjectsFromList(par1Packet40EntityMetadata.getMetadata());
    414            }
    415        }
    416
    417        public void handleNamedEntitySpawn(Packet20NamedEntitySpawn par1Packet20NamedEntitySpawn)
    418        {
    419            double var2 = (double)par1Packet20NamedEntitySpawn.xPosition / 32.0D;
    420            double var4 = (double)par1Packet20NamedEntitySpawn.yPosition / 32.0D;
    421            double var6 = (double)par1Packet20NamedEntitySpawn.zPosition / 32.0D;
    422            float var8 = (float)(par1Packet20NamedEntitySpawn.rotation * 360) / 256.0F;
    423            float var9 = (float)(par1Packet20NamedEntitySpawn.pitch * 360) / 256.0F;
    424            EntityOtherPlayerMP var10 = new EntityOtherPlayerMP(this.mc.theWorld, par1Packet20NamedEntitySpawn.name);
    425            var10.prevPosX = var10.lastTickPosX = (double)(var10.serverPosX = par1Packet20NamedEntitySpawn.xPosition);
    426            var10.prevPosY = var10.lastTickPosY = (double)(var10.serverPosY = par1Packet20NamedEntitySpawn.yPosition);
    427            var10.prevPosZ = var10.lastTickPosZ = (double)(var10.serverPosZ = par1Packet20NamedEntitySpawn.zPosition);
    428            int var11 = par1Packet20NamedEntitySpawn.currentItem;
    429
    430            if (var11 == 0)
    431            {
    432                var10.inventory.mainInventory[var10.inventory.currentItem] = null;
    433            }
    434            else
    435            {
    436                var10.inventory.mainInventory[var10.inventory.currentItem] = new ItemStack(var11, 1, 0);
    437            }
    438
    439            var10.setPositionAndRotation(var2, var4, var6, var8, var9);
    440            this.worldClient.addEntityToWorld(par1Packet20NamedEntitySpawn.entityId, var10);
    441            List var12 = par1Packet20NamedEntitySpawn.func_73509_c();
    442
    443            if (var12 != null)
    444            {
    445                var10.getDataWatcher().updateWatchedObjectsFromList(var12);
    446            }
    447        }
    448
    449        public void handleEntityTeleport(Packet34EntityTeleport par1Packet34EntityTeleport)
    450        {
    451            Entity var2 = this.getEntityByID(par1Packet34EntityTeleport.entityId);
    452
    453            if (var2 != null)
    454            {
    455                var2.serverPosX = par1Packet34EntityTeleport.xPosition;
    456                var2.serverPosY = par1Packet34EntityTeleport.yPosition;
    457                var2.serverPosZ = par1Packet34EntityTeleport.zPosition;
    458                double var3 = (double)var2.serverPosX / 32.0D;
    459                double var5 = (double)var2.serverPosY / 32.0D + 0.015625D;
    460                double var7 = (double)var2.serverPosZ / 32.0D;
    461                float var9 = (float)(par1Packet34EntityTeleport.yaw * 360) / 256.0F;
    462                float var10 = (float)(par1Packet34EntityTeleport.pitch * 360) / 256.0F;
    463                var2.setPositionAndRotation2(var3, var5, var7, var9, var10, 3);
    464            }
    465        }
    466
    467        public void handleEntity(Packet30Entity par1Packet30Entity)
    468        {
    469            Entity var2 = this.getEntityByID(par1Packet30Entity.entityId);
    470
    471            if (var2 != null)
    472            {
    473                var2.serverPosX += par1Packet30Entity.xPosition;
    474                var2.serverPosY += par1Packet30Entity.yPosition;
    475                var2.serverPosZ += par1Packet30Entity.zPosition;
    476                double var3 = (double)var2.serverPosX / 32.0D;
    477                double var5 = (double)var2.serverPosY / 32.0D;
    478                double var7 = (double)var2.serverPosZ / 32.0D;
    479                float var9 = par1Packet30Entity.rotating ? (float)(par1Packet30Entity.yaw * 360) / 256.0F : var2.rotationYaw;
    480                float var10 = par1Packet30Entity.rotating ? (float)(par1Packet30Entity.pitch * 360) / 256.0F : var2.rotationPitch;
    481                var2.setPositionAndRotation2(var3, var5, var7, var9, var10, 3);
    482            }
    483        }
    484
    485        public void handleEntityHeadRotation(Packet35EntityHeadRotation par1Packet35EntityHeadRotation)
    486        {
    487            Entity var2 = this.getEntityByID(par1Packet35EntityHeadRotation.entityId);
    488
    489            if (var2 != null)
    490            {
    491                float var3 = (float)(par1Packet35EntityHeadRotation.headRotationYaw * 360) / 256.0F;
    492                var2.setHeadRotationYaw(var3);
    493            }
    494        }
    495
    496        public void handleDestroyEntity(Packet29DestroyEntity par1Packet29DestroyEntity)
    497        {
    498            for (int var2 = 0; var2 < par1Packet29DestroyEntity.entityId.length; ++var2)
    499            {
    500                this.worldClient.removeEntityFromWorld(par1Packet29DestroyEntity.entityId[var2]);
    501            }
    502        }
    503
    504        public void handleFlying(Packet10Flying par1Packet10Flying)
    505        {
    506            EntityClientPlayerMP var2 = this.mc.thePlayer;
    507            double var3 = var2.posX;
    508            double var5 = var2.posY;
    509            double var7 = var2.posZ;
    510            float var9 = var2.rotationYaw;
    511            float var10 = var2.rotationPitch;
    512
    513            if (par1Packet10Flying.moving)
    514            {
    515                var3 = par1Packet10Flying.xPosition;
    516                var5 = par1Packet10Flying.yPosition;
    517                var7 = par1Packet10Flying.zPosition;
    518            }
    519
    520            if (par1Packet10Flying.rotating)
    521            {
    522                var9 = par1Packet10Flying.yaw;
    523                var10 = par1Packet10Flying.pitch;
    524            }
    525
    526            var2.ySize = 0.0F;
    527            var2.motionX = var2.motionY = var2.motionZ = 0.0D;
    528            var2.setPositionAndRotation(var3, var5, var7, var9, var10);
    529            par1Packet10Flying.xPosition = var2.posX;
    530            par1Packet10Flying.yPosition = var2.boundingBox.minY;
    531            par1Packet10Flying.zPosition = var2.posZ;
    532            par1Packet10Flying.stance = var2.posY;
    533            this.netManager.addToSendQueue(par1Packet10Flying);
    534
    535            if (!this.doneLoadingTerrain)
    536            {
    537                this.mc.thePlayer.prevPosX = this.mc.thePlayer.posX;
    538                this.mc.thePlayer.prevPosY = this.mc.thePlayer.posY;
    539                this.mc.thePlayer.prevPosZ = this.mc.thePlayer.posZ;
    540                this.doneLoadingTerrain = true;
    541                this.mc.displayGuiScreen((GuiScreen)null);
    542            }
    543        }
    544
    545        public void handleMultiBlockChange(Packet52MultiBlockChange par1Packet52MultiBlockChange)
    546        {
    547            int var2 = par1Packet52MultiBlockChange.xPosition * 16;
    548            int var3 = par1Packet52MultiBlockChange.zPosition * 16;
    549
    550            if (par1Packet52MultiBlockChange.metadataArray != null)
    551            {
    552                DataInputStream var4 = new DataInputStream(new ByteArrayInputStream(par1Packet52MultiBlockChange.metadataArray));
    553
    554                try
    555                {
    556                    for (int var5 = 0; var5 < par1Packet52MultiBlockChange.size; ++var5)
    557                    {
    558                        short var6 = var4.readShort();
    559                        short var7 = var4.readShort();
    560                        int var8 = var7 >> 4 & 4095;
    561                        int var9 = var7 & 15;
    562                        int var10 = var6 >> 12 & 15;
    563                        int var11 = var6 >> 8 & 15;
    564                        int var12 = var6 & 255;
    565                        this.worldClient.setBlockAndMetadataAndInvalidate(var10 + var2, var12, var11 + var3, var8, var9);
    566                    }
    567                }
    568                catch (IOException var13)
    569                {
    570                    ;
    571                }
    572            }
    573        }
    574
    575        /**
    576         * Handle Packet51MapChunk (full chunk update of blocks, metadata, light levels, and optionally biome data)
    577         */
    578        public void handleMapChunk(Packet51MapChunk par1Packet51MapChunk)
    579        {
    580            if (par1Packet51MapChunk.includeInitialize)
    581            {
    582                if (par1Packet51MapChunk.yChMin == 0)
    583                {
    584                    this.worldClient.doPreChunk(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh, false);
    585                    return;
    586                }
    587
    588                this.worldClient.doPreChunk(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh, true);
    589            }
    590
    591            this.worldClient.invalidateBlockReceiveRegion(par1Packet51MapChunk.xCh << 4, 0, par1Packet51MapChunk.zCh << 4, (par1Packet51MapChunk.xCh << 4) + 15, 256, (par1Packet51MapChunk.zCh << 4) + 15);
    592            Chunk var2 = this.worldClient.getChunkFromChunkCoords(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh);
    593
    594            if (par1Packet51MapChunk.includeInitialize && var2 == null)
    595            {
    596                this.worldClient.doPreChunk(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh, true);
    597                var2 = this.worldClient.getChunkFromChunkCoords(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh);
    598            }
    599
    600            if (var2 != null)
    601            {
    602                var2.fillChunk(par1Packet51MapChunk.func_73593_d(), par1Packet51MapChunk.yChMin, par1Packet51MapChunk.yChMax, par1Packet51MapChunk.includeInitialize);
    603                this.worldClient.markBlocksDirty(par1Packet51MapChunk.xCh << 4, 0, par1Packet51MapChunk.zCh << 4, (par1Packet51MapChunk.xCh << 4) + 15, 256, (par1Packet51MapChunk.zCh << 4) + 15);
    604
    605                if (!par1Packet51MapChunk.includeInitialize || !(this.worldClient.provider instanceof WorldProviderSurface))
    606                {
    607                    var2.resetRelightChecks();
    608                }
    609            }
    610        }
    611
    612        public void handleBlockChange(Packet53BlockChange par1Packet53BlockChange)
    613        {
    614            this.worldClient.setBlockAndMetadataAndInvalidate(par1Packet53BlockChange.xPosition, par1Packet53BlockChange.yPosition, par1Packet53BlockChange.zPosition, par1Packet53BlockChange.type, par1Packet53BlockChange.metadata);
    615        }
    616
    617        public void handleKickDisconnect(Packet255KickDisconnect par1Packet255KickDisconnect)
    618        {
    619            this.netManager.networkShutdown("disconnect.kicked", par1Packet255KickDisconnect.reason);
    620            this.disconnected = true;
    621            this.mc.loadWorld((WorldClient)null);
    622            this.mc.displayGuiScreen(new GuiDisconnected("disconnect.disconnected", "disconnect.genericReason", new Object[] {par1Packet255KickDisconnect.reason}));
    623        }
    624
    625        public void handleErrorMessage(String par1Str, Object[] par2ArrayOfObj)
    626        {
    627            if (!this.disconnected)
    628            {
    629                this.disconnected = true;
    630                this.mc.loadWorld((WorldClient)null);
    631                this.mc.displayGuiScreen(new GuiDisconnected("disconnect.lost", par1Str, par2ArrayOfObj));
    632            }
    633        }
    634
    635        public void quitWithPacket(Packet par1Packet)
    636        {
    637            if (!this.disconnected)
    638            {
    639                this.netManager.addToSendQueue(par1Packet);
    640                this.netManager.serverShutdown();
    641                FMLNetworkHandler.onConnectionClosed(this.netManager, this.getPlayer());
    642            }
    643        }
    644
    645        /**
    646         * Adds the packet to the send queue
    647         */
    648        public void addToSendQueue(Packet par1Packet)
    649        {
    650            if (!this.disconnected)
    651            {
    652                this.netManager.addToSendQueue(par1Packet);
    653            }
    654        }
    655
    656        public void handleCollect(Packet22Collect par1Packet22Collect)
    657        {
    658            Entity var2 = this.getEntityByID(par1Packet22Collect.collectedEntityId);
    659            Object var3 = (EntityLiving)this.getEntityByID(par1Packet22Collect.collectorEntityId);
    660
    661            if (var3 == null)
    662            {
    663                var3 = this.mc.thePlayer;
    664            }
    665
    666            if (var2 != null)
    667            {
    668                if (var2 instanceof EntityXPOrb)
    669                {
    670                    this.worldClient.playSoundAtEntity(var2, "random.orb", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    671                }
    672                else
    673                {
    674                    this.worldClient.playSoundAtEntity(var2, "random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    675                }
    676
    677                this.mc.effectRenderer.addEffect(new EntityPickupFX(this.mc.theWorld, var2, (Entity)var3, -0.5F));
    678                this.worldClient.removeEntityFromWorld(par1Packet22Collect.collectedEntityId);
    679            }
    680        }
    681
    682        public void handleChat(Packet3Chat par1Packet3Chat)
    683        {
    684            par1Packet3Chat = FMLNetworkHandler.handleChatMessage(this, par1Packet3Chat);
    685            ClientChatReceivedEvent event = new ClientChatReceivedEvent(par1Packet3Chat.message);
    686            if (!MinecraftForge.EVENT_BUS.post(event) && event.message != null)
    687            {
    688                this.mc.ingameGUI.getChatGUI().printChatMessage(par1Packet3Chat.message);
    689            }
    690        }
    691
    692        public void handleAnimation(Packet18Animation par1Packet18Animation)
    693        {
    694            Entity var2 = this.getEntityByID(par1Packet18Animation.entityId);
    695
    696            if (var2 != null)
    697            {
    698                if (par1Packet18Animation.animate == 1)
    699                {
    700                    EntityLiving var3 = (EntityLiving)var2;
    701                    var3.swingItem();
    702                }
    703                else if (par1Packet18Animation.animate == 2)
    704                {
    705                    var2.performHurtAnimation();
    706                }
    707                else if (par1Packet18Animation.animate == 3)
    708                {
    709                    EntityPlayer var4 = (EntityPlayer)var2;
    710                    var4.wakeUpPlayer(false, false, false);
    711                }
    712                else if (par1Packet18Animation.animate != 4)
    713                {
    714                    if (par1Packet18Animation.animate == 6)
    715                    {
    716                        this.mc.effectRenderer.addEffect(new EntityCrit2FX(this.mc.theWorld, var2));
    717                    }
    718                    else if (par1Packet18Animation.animate == 7)
    719                    {
    720                        EntityCrit2FX var5 = new EntityCrit2FX(this.mc.theWorld, var2, "magicCrit");
    721                        this.mc.effectRenderer.addEffect(var5);
    722                    }
    723                    else if (par1Packet18Animation.animate == 5 && var2 instanceof EntityOtherPlayerMP)
    724                    {
    725                        ;
    726                    }
    727                }
    728            }
    729        }
    730
    731        public void handleSleep(Packet17Sleep par1Packet17Sleep)
    732        {
    733            Entity var2 = this.getEntityByID(par1Packet17Sleep.entityID);
    734
    735            if (var2 != null)
    736            {
    737                if (par1Packet17Sleep.field_73622_e == 0)
    738                {
    739                    EntityPlayer var3 = (EntityPlayer)var2;
    740                    var3.sleepInBedAt(par1Packet17Sleep.bedX, par1Packet17Sleep.bedY, par1Packet17Sleep.bedZ);
    741                }
    742            }
    743        }
    744
    745        /**
    746         * Disconnects the network connection.
    747         */
    748        public void disconnect()
    749        {
    750            this.disconnected = true;
    751            this.netManager.wakeThreads();
    752            this.netManager.networkShutdown("disconnect.closed", new Object[0]);
    753        }
    754
    755        public void handleMobSpawn(Packet24MobSpawn par1Packet24MobSpawn)
    756        {
    757            double var2 = (double)par1Packet24MobSpawn.xPosition / 32.0D;
    758            double var4 = (double)par1Packet24MobSpawn.yPosition / 32.0D;
    759            double var6 = (double)par1Packet24MobSpawn.zPosition / 32.0D;
    760            float var8 = (float)(par1Packet24MobSpawn.yaw * 360) / 256.0F;
    761            float var9 = (float)(par1Packet24MobSpawn.pitch * 360) / 256.0F;
    762            EntityLiving var10 = (EntityLiving)EntityList.createEntityByID(par1Packet24MobSpawn.type, this.mc.theWorld);
    763            var10.serverPosX = par1Packet24MobSpawn.xPosition;
    764            var10.serverPosY = par1Packet24MobSpawn.yPosition;
    765            var10.serverPosZ = par1Packet24MobSpawn.zPosition;
    766            var10.rotationYawHead = (float)(par1Packet24MobSpawn.headYaw * 360) / 256.0F;
    767            Entity[] var11 = var10.getParts();
    768
    769            if (var11 != null)
    770            {
    771                int var12 = par1Packet24MobSpawn.entityId - var10.entityId;
    772
    773                for (int var13 = 0; var13 < var11.length; ++var13)
    774                {
    775                    var11[var13].entityId += var12;
    776                }
    777            }
    778
    779            var10.entityId = par1Packet24MobSpawn.entityId;
    780            var10.setPositionAndRotation(var2, var4, var6, var8, var9);
    781            var10.motionX = (double)((float)par1Packet24MobSpawn.velocityX / 8000.0F);
    782            var10.motionY = (double)((float)par1Packet24MobSpawn.velocityY / 8000.0F);
    783            var10.motionZ = (double)((float)par1Packet24MobSpawn.velocityZ / 8000.0F);
    784            this.worldClient.addEntityToWorld(par1Packet24MobSpawn.entityId, var10);
    785            List var14 = par1Packet24MobSpawn.getMetadata();
    786
    787            if (var14 != null)
    788            {
    789                var10.getDataWatcher().updateWatchedObjectsFromList(var14);
    790            }
    791        }
    792
    793        public void handleUpdateTime(Packet4UpdateTime par1Packet4UpdateTime)
    794        {
    795            this.mc.theWorld.func_82738_a(par1Packet4UpdateTime.field_82562_a);
    796            this.mc.theWorld.setWorldTime(par1Packet4UpdateTime.time);
    797        }
    798
    799        public void handleSpawnPosition(Packet6SpawnPosition par1Packet6SpawnPosition)
    800        {
    801            this.mc.thePlayer.setSpawnChunk(new ChunkCoordinates(par1Packet6SpawnPosition.xPosition, par1Packet6SpawnPosition.yPosition, par1Packet6SpawnPosition.zPosition), true);
    802            this.mc.theWorld.getWorldInfo().setSpawnPosition(par1Packet6SpawnPosition.xPosition, par1Packet6SpawnPosition.yPosition, par1Packet6SpawnPosition.zPosition);
    803        }
    804
    805        /**
    806         * Packet handler
    807         */
    808        public void handleAttachEntity(Packet39AttachEntity par1Packet39AttachEntity)
    809        {
    810            Object var2 = this.getEntityByID(par1Packet39AttachEntity.entityId);
    811            Entity var3 = this.getEntityByID(par1Packet39AttachEntity.vehicleEntityId);
    812
    813            if (par1Packet39AttachEntity.entityId == this.mc.thePlayer.entityId)
    814            {
    815                var2 = this.mc.thePlayer;
    816
    817                if (var3 instanceof EntityBoat)
    818                {
    819                    ((EntityBoat)var3).func_70270_d(false);
    820                }
    821            }
    822            else if (var3 instanceof EntityBoat)
    823            {
    824                ((EntityBoat)var3).func_70270_d(true);
    825            }
    826
    827            if (var2 != null)
    828            {
    829                ((Entity)var2).mountEntity(var3);
    830            }
    831        }
    832
    833        /**
    834         * Packet handler
    835         */
    836        public void handleEntityStatus(Packet38EntityStatus par1Packet38EntityStatus)
    837        {
    838            Entity var2 = this.getEntityByID(par1Packet38EntityStatus.entityId);
    839
    840            if (var2 != null)
    841            {
    842                var2.handleHealthUpdate(par1Packet38EntityStatus.entityStatus);
    843            }
    844        }
    845
    846        private Entity getEntityByID(int par1)
    847        {
    848            return (Entity)(par1 == this.mc.thePlayer.entityId ? this.mc.thePlayer : this.worldClient.getEntityByID(par1));
    849        }
    850
    851        /**
    852         * Recieves player health from the server and then proceeds to set it locally on the client.
    853         */
    854        public void handleUpdateHealth(Packet8UpdateHealth par1Packet8UpdateHealth)
    855        {
    856            this.mc.thePlayer.setHealth(par1Packet8UpdateHealth.healthMP);
    857            this.mc.thePlayer.getFoodStats().setFoodLevel(par1Packet8UpdateHealth.food);
    858            this.mc.thePlayer.getFoodStats().setFoodSaturationLevel(par1Packet8UpdateHealth.foodSaturation);
    859        }
    860
    861        /**
    862         * Handle an experience packet.
    863         */
    864        public void handleExperience(Packet43Experience par1Packet43Experience)
    865        {
    866            this.mc.thePlayer.setXPStats(par1Packet43Experience.experience, par1Packet43Experience.experienceTotal, par1Packet43Experience.experienceLevel);
    867        }
    868
    869        /**
    870         * respawns the player
    871         */
    872        public void handleRespawn(Packet9Respawn par1Packet9Respawn)
    873        {
    874            if (par1Packet9Respawn.respawnDimension != this.mc.thePlayer.dimension)
    875            {
    876                this.doneLoadingTerrain = false;
    877                this.worldClient = new WorldClient(this, new WorldSettings(0L, par1Packet9Respawn.gameType, false, this.mc.theWorld.getWorldInfo().isHardcoreModeEnabled(), par1Packet9Respawn.terrainType), par1Packet9Respawn.respawnDimension, par1Packet9Respawn.difficulty, this.mc.mcProfiler);
    878                this.worldClient.isRemote = true;
    879                this.mc.loadWorld(this.worldClient);
    880                this.mc.thePlayer.dimension = par1Packet9Respawn.respawnDimension;
    881                this.mc.displayGuiScreen(new GuiDownloadTerrain(this));
    882            }
    883
    884            this.mc.setDimensionAndSpawnPlayer(par1Packet9Respawn.respawnDimension);
    885            this.mc.playerController.setGameType(par1Packet9Respawn.gameType);
    886        }
    887
    888        public void handleExplosion(Packet60Explosion par1Packet60Explosion)
    889        {
    890            Explosion var2 = new Explosion(this.mc.theWorld, (Entity)null, par1Packet60Explosion.explosionX, par1Packet60Explosion.explosionY, par1Packet60Explosion.explosionZ, par1Packet60Explosion.explosionSize);
    891            var2.affectedBlockPositions = par1Packet60Explosion.chunkPositionRecords;
    892            var2.doExplosionB(true);
    893            this.mc.thePlayer.motionX += (double)par1Packet60Explosion.func_73607_d();
    894            this.mc.thePlayer.motionY += (double)par1Packet60Explosion.func_73609_f();
    895            this.mc.thePlayer.motionZ += (double)par1Packet60Explosion.func_73608_g();
    896        }
    897
    898        public void handleOpenWindow(Packet100OpenWindow par1Packet100OpenWindow)
    899        {
    900            EntityClientPlayerMP var2 = this.mc.thePlayer;
    901
    902            switch (par1Packet100OpenWindow.inventoryType)
    903            {
    904                case 0:
    905                    var2.displayGUIChest(new InventoryBasic(par1Packet100OpenWindow.windowTitle, par1Packet100OpenWindow.slotsCount));
    906                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    907                    break;
    908                case 1:
    909                    var2.displayGUIWorkbench(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ));
    910                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    911                    break;
    912                case 2:
    913                    var2.displayGUIFurnace(new TileEntityFurnace());
    914                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    915                    break;
    916                case 3:
    917                    var2.displayGUIDispenser(new TileEntityDispenser());
    918                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    919                    break;
    920                case 4:
    921                    var2.displayGUIEnchantment(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ));
    922                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    923                    break;
    924                case 5:
    925                    var2.displayGUIBrewingStand(new TileEntityBrewingStand());
    926                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    927                    break;
    928                case 6:
    929                    var2.displayGUIMerchant(new NpcMerchant(var2));
    930                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    931                    break;
    932                case 7:
    933                    var2.displayGUIBeacon(new TileEntityBeacon());
    934                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    935                    break;
    936                case 8:
    937                    var2.displayGUIAnvil(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ));
    938                    var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
    939            }
    940        }
    941
    942        public void handleSetSlot(Packet103SetSlot par1Packet103SetSlot)
    943        {
    944            EntityClientPlayerMP var2 = this.mc.thePlayer;
    945
    946            if (par1Packet103SetSlot.windowId == -1)
    947            {
    948                var2.inventory.setItemStack(par1Packet103SetSlot.myItemStack);
    949            }
    950            else
    951            {
    952                boolean var3 = false;
    953
    954                if (this.mc.currentScreen instanceof GuiContainerCreative)
    955                {
    956                    GuiContainerCreative var4 = (GuiContainerCreative)this.mc.currentScreen;
    957                    var3 = var4.func_74230_h() != CreativeTabs.tabInventory.getTabIndex();
    958                }
    959
    960                if (par1Packet103SetSlot.windowId == 0 && par1Packet103SetSlot.itemSlot >= 36 && par1Packet103SetSlot.itemSlot < 45)
    961                {
    962                    ItemStack var5 = var2.inventorySlots.getSlot(par1Packet103SetSlot.itemSlot).getStack();
    963
    964                    if (par1Packet103SetSlot.myItemStack != null && (var5 == null || var5.stackSize < par1Packet103SetSlot.myItemStack.stackSize))
    965                    {
    966                        par1Packet103SetSlot.myItemStack.animationsToGo = 5;
    967                    }
    968
    969                    var2.inventorySlots.putStackInSlot(par1Packet103SetSlot.itemSlot, par1Packet103SetSlot.myItemStack);
    970                }
    971                else if (par1Packet103SetSlot.windowId == var2.craftingInventory.windowId && (par1Packet103SetSlot.windowId != 0 || !var3))
    972                {
    973                    var2.craftingInventory.putStackInSlot(par1Packet103SetSlot.itemSlot, par1Packet103SetSlot.myItemStack);
    974                }
    975            }
    976        }
    977
    978        public void handleTransaction(Packet106Transaction par1Packet106Transaction)
    979        {
    980            Container var2 = null;
    981            EntityClientPlayerMP var3 = this.mc.thePlayer;
    982
    983            if (par1Packet106Transaction.windowId == 0)
    984            {
    985                var2 = var3.inventorySlots;
    986            }
    987            else if (par1Packet106Transaction.windowId == var3.craftingInventory.windowId)
    988            {
    989                var2 = var3.craftingInventory;
    990            }
    991
    992            if (var2 != null && !par1Packet106Transaction.accepted)
    993            {
    994                this.addToSendQueue(new Packet106Transaction(par1Packet106Transaction.windowId, par1Packet106Transaction.shortWindowId, true));
    995            }
    996        }
    997
    998        public void handleWindowItems(Packet104WindowItems par1Packet104WindowItems)
    999        {
    1000            EntityClientPlayerMP var2 = this.mc.thePlayer;
    1001
    1002            if (par1Packet104WindowItems.windowId == 0)
    1003            {
    1004                var2.inventorySlots.putStacksInSlots(par1Packet104WindowItems.itemStack);
    1005            }
    1006            else if (par1Packet104WindowItems.windowId == var2.craftingInventory.windowId)
    1007            {
    1008                var2.craftingInventory.putStacksInSlots(par1Packet104WindowItems.itemStack);
    1009            }
    1010        }
    1011
    1012        /**
    1013         * Updates Client side signs
    1014         */
    1015        public void handleUpdateSign(Packet130UpdateSign par1Packet130UpdateSign)
    1016        {
    1017            boolean var2 = false;
    1018
    1019            if (this.mc.theWorld.blockExists(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition))
    1020            {
    1021                TileEntity var3 = this.mc.theWorld.getBlockTileEntity(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition);
    1022
    1023                if (var3 instanceof TileEntitySign)
    1024                {
    1025                    TileEntitySign var4 = (TileEntitySign)var3;
    1026
    1027                    if (var4.isEditable())
    1028                    {
    1029                        for (int var5 = 0; var5 < 4; ++var5)
    1030                        {
    1031                            var4.signText[var5] = par1Packet130UpdateSign.signLines[var5];
    1032                        }
    1033
    1034                        var4.onInventoryChanged();
    1035                    }
    1036
    1037                    var2 = true;
    1038                }
    1039            }
    1040
    1041            if (!var2 && this.mc.thePlayer != null)
    1042            {
    1043                this.mc.thePlayer.sendChatToPlayer("Unable to locate sign at " + par1Packet130UpdateSign.xPosition + ", " + par1Packet130UpdateSign.yPosition + ", " + par1Packet130UpdateSign.zPosition);
    1044            }
    1045        }
    1046
    1047        public void handleTileEntityData(Packet132TileEntityData par1Packet132TileEntityData)
    1048        {
    1049            if (this.mc.theWorld.blockExists(par1Packet132TileEntityData.xPosition, par1Packet132TileEntityData.yPosition, par1Packet132TileEntityData.zPosition))
    1050            {
    1051                TileEntity var2 = this.mc.theWorld.getBlockTileEntity(par1Packet132TileEntityData.xPosition, par1Packet132TileEntityData.yPosition, par1Packet132TileEntityData.zPosition);
    1052
    1053                if (var2 != null)
    1054                {
    1055                    if (par1Packet132TileEntityData.actionType == 1 && var2 instanceof TileEntityMobSpawner)
    1056                    {
    1057                        var2.readFromNBT(par1Packet132TileEntityData.customParam1);
    1058                    }
    1059                    else if (par1Packet132TileEntityData.actionType == 2 && var2 instanceof TileEntityCommandBlock)
    1060                    {
    1061                        var2.readFromNBT(par1Packet132TileEntityData.customParam1);
    1062                    }
    1063                    else if (par1Packet132TileEntityData.actionType == 3 && var2 instanceof TileEntityBeacon)
    1064                    {
    1065                        var2.readFromNBT(par1Packet132TileEntityData.customParam1);
    1066                    }
    1067                    else if (par1Packet132TileEntityData.actionType == 4 && var2 instanceof TileEntitySkull)
    1068                    {
    1069                        var2.readFromNBT(par1Packet132TileEntityData.customParam1);
    1070                    }
    1071                    else
    1072                    {
    1073                        var2.onDataPacket(netManager,  par1Packet132TileEntityData);
    1074                    }
    1075                }
    1076            }
    1077        }
    1078
    1079        public void handleUpdateProgressbar(Packet105UpdateProgressbar par1Packet105UpdateProgressbar)
    1080        {
    1081            EntityClientPlayerMP var2 = this.mc.thePlayer;
    1082            this.unexpectedPacket(par1Packet105UpdateProgressbar);
    1083
    1084            if (var2.craftingInventory != null && var2.craftingInventory.windowId == par1Packet105UpdateProgressbar.windowId)
    1085            {
    1086                var2.craftingInventory.updateProgressBar(par1Packet105UpdateProgressbar.progressBar, par1Packet105UpdateProgressbar.progressBarValue);
    1087            }
    1088        }
    1089
    1090        public void handlePlayerInventory(Packet5PlayerInventory par1Packet5PlayerInventory)
    1091        {
    1092            Entity var2 = this.getEntityByID(par1Packet5PlayerInventory.entityID);
    1093
    1094            if (var2 != null)
    1095            {
    1096                var2.setCurrentItemOrArmor(par1Packet5PlayerInventory.slot, par1Packet5PlayerInventory.getItemSlot());
    1097            }
    1098        }
    1099
    1100        public void handleCloseWindow(Packet101CloseWindow par1Packet101CloseWindow)
    1101        {
    1102            this.mc.thePlayer.closeScreen();
    1103        }
    1104
    1105        public void handleBlockEvent(Packet54PlayNoteBlock par1Packet54PlayNoteBlock)
    1106        {
    1107            this.mc.theWorld.addBlockEvent(par1Packet54PlayNoteBlock.xLocation, par1Packet54PlayNoteBlock.yLocation, par1Packet54PlayNoteBlock.zLocation, par1Packet54PlayNoteBlock.blockId, par1Packet54PlayNoteBlock.instrumentType, par1Packet54PlayNoteBlock.pitch);
    1108        }
    1109
    1110        public void handleBlockDestroy(Packet55BlockDestroy par1Packet55BlockDestroy)
    1111        {
    1112            this.mc.theWorld.destroyBlockInWorldPartially(par1Packet55BlockDestroy.getEntityId(), par1Packet55BlockDestroy.getPosX(), par1Packet55BlockDestroy.getPosY(), par1Packet55BlockDestroy.getPosZ(), par1Packet55BlockDestroy.getDestroyedStage());
    1113        }
    1114
    1115        public void handleMapChunks(Packet56MapChunks par1Packet56MapChunks)
    1116        {
    1117            for (int var2 = 0; var2 < par1Packet56MapChunks.func_73581_d(); ++var2)
    1118            {
    1119                int var3 = par1Packet56MapChunks.func_73582_a(var2);
    1120                int var4 = par1Packet56MapChunks.func_73580_b(var2);
    1121                this.worldClient.doPreChunk(var3, var4, true);
    1122                this.worldClient.invalidateBlockReceiveRegion(var3 << 4, 0, var4 << 4, (var3 << 4) + 15, 256, (var4 << 4) + 15);
    1123                Chunk var5 = this.worldClient.getChunkFromChunkCoords(var3, var4);
    1124
    1125                if (var5 == null)
    1126                {
    1127                    this.worldClient.doPreChunk(var3, var4, true);
    1128                    var5 = this.worldClient.getChunkFromChunkCoords(var3, var4);
    1129                }
    1130
    1131                if (var5 != null)
    1132                {
    1133                    var5.fillChunk(par1Packet56MapChunks.func_73583_c(var2), par1Packet56MapChunks.field_73590_a[var2], par1Packet56MapChunks.field_73588_b[var2], true);
    1134                    this.worldClient.markBlocksDirty(var3 << 4, 0, var4 << 4, (var3 << 4) + 15, 256, (var4 << 4) + 15);
    1135
    1136                    if (!(this.worldClient.provider instanceof WorldProviderSurface))
    1137                    {
    1138                        var5.resetRelightChecks();
    1139                    }
    1140                }
    1141            }
    1142        }
    1143
    1144        /**
    1145         * packet.processPacket is only called if this returns true
    1146         */
    1147        public boolean canProcessPackets()
    1148        {
    1149            return this.mc != null && this.mc.theWorld != null && this.mc.thePlayer != null && this.worldClient != null;
    1150        }
    1151
    1152        public void handleBed(Packet70GameEvent par1Packet70GameEvent)
    1153        {
    1154            EntityClientPlayerMP var2 = this.mc.thePlayer;
    1155            int var3 = par1Packet70GameEvent.bedState;
    1156            int var4 = par1Packet70GameEvent.gameMode;
    1157
    1158            if (var3 >= 0 && var3 < Packet70GameEvent.bedChat.length && Packet70GameEvent.bedChat[var3] != null)
    1159            {
    1160                var2.addChatMessage(Packet70GameEvent.bedChat[var3]);
    1161            }
    1162
    1163            if (var3 == 1)
    1164            {
    1165                this.worldClient.getWorldInfo().setRaining(true);
    1166                this.worldClient.setRainStrength(0.0F);
    1167            }
    1168            else if (var3 == 2)
    1169            {
    1170                this.worldClient.getWorldInfo().setRaining(false);
    1171                this.worldClient.setRainStrength(1.0F);
    1172            }
    1173            else if (var3 == 3)
    1174            {
    1175                this.mc.playerController.setGameType(EnumGameType.getByID(var4));
    1176            }
    1177            else if (var3 == 4)
    1178            {
    1179                this.mc.displayGuiScreen(new GuiWinGame());
    1180            }
    1181            else if (var3 == 5)
    1182            {
    1183                GameSettings var5 = this.mc.gameSettings;
    1184
    1185                if (var4 == 0)
    1186                {
    1187                    this.mc.displayGuiScreen(new GuiScreenDemo());
    1188                }
    1189                else if (var4 == 101)
    1190                {
    1191                    this.mc.ingameGUI.getChatGUI().addTranslatedMessage("demo.help.movement", new Object[] {Keyboard.getKeyName(var5.keyBindForward.keyCode), Keyboard.getKeyName(var5.keyBindLeft.keyCode), Keyboard.getKeyName(var5.keyBindBack.keyCode), Keyboard.getKeyName(var5.keyBindRight.keyCode)});
    1192                }
    1193                else if (var4 == 102)
    1194                {
    1195                    this.mc.ingameGUI.getChatGUI().addTranslatedMessage("demo.help.jump", new Object[] {Keyboard.getKeyName(var5.keyBindJump.keyCode)});
    1196                }
    1197                else if (var4 == 103)
    1198                {
    1199                    this.mc.ingameGUI.getChatGUI().addTranslatedMessage("demo.help.inventory", new Object[] {Keyboard.getKeyName(var5.keyBindInventory.keyCode)});
    1200                }
    1201            }
    1202        }
    1203
    1204        /**
    1205         * Contains logic for handling packets containing arbitrary unique item data. Currently this is only for maps.
    1206         */
    1207        public void handleMapData(Packet131MapData par1Packet131MapData)
    1208        {
    1209            FMLNetworkHandler.handlePacket131Packet(this, par1Packet131MapData);
    1210        }
    1211
    1212        public void fmlPacket131Callback(Packet131MapData par1Packet131MapData)
    1213        {
    1214            if (par1Packet131MapData.itemID == Item.map.shiftedIndex)
    1215            {
    1216                ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).updateMPMapData(par1Packet131MapData.itemData);
    1217            }
    1218            else
    1219            {
    1220                System.out.println("Unknown itemid: " + par1Packet131MapData.uniqueID);
    1221            }
    1222        }
    1223
    1224        public void handleDoorChange(Packet61DoorChange par1Packet61DoorChange)
    1225        {
    1226            if (par1Packet61DoorChange.func_82560_d())
    1227            {
    1228                this.mc.theWorld.func_82739_e(par1Packet61DoorChange.sfxID, par1Packet61DoorChange.posX, par1Packet61DoorChange.posY, par1Packet61DoorChange.posZ, par1Packet61DoorChange.auxData);
    1229            }
    1230            else
    1231            {
    1232                this.mc.theWorld.playAuxSFX(par1Packet61DoorChange.sfxID, par1Packet61DoorChange.posX, par1Packet61DoorChange.posY, par1Packet61DoorChange.posZ, par1Packet61DoorChange.auxData);
    1233            }
    1234        }
    1235
    1236        /**
    1237         * Increment player statistics
    1238         */
    1239        public void handleStatistic(Packet200Statistic par1Packet200Statistic)
    1240        {
    1241            this.mc.thePlayer.incrementStat(StatList.getOneShotStat(par1Packet200Statistic.statisticId), par1Packet200Statistic.amount);
    1242        }
    1243
    1244        /**
    1245         * Handle an entity effect packet.
    1246         */
    1247        public void handleEntityEffect(Packet41EntityEffect par1Packet41EntityEffect)
    1248        {
    1249            Entity var2 = this.getEntityByID(par1Packet41EntityEffect.entityId);
    1250
    1251            if (var2 instanceof EntityLiving)
    1252            {
    1253                ((EntityLiving)var2).addPotionEffect(new PotionEffect(par1Packet41EntityEffect.effectId, par1Packet41EntityEffect.duration, par1Packet41EntityEffect.effectAmplifier));
    1254            }
    1255        }
    1256
    1257        /**
    1258         * Handle a remove entity effect packet.
    1259         */
    1260        public void handleRemoveEntityEffect(Packet42RemoveEntityEffect par1Packet42RemoveEntityEffect)
    1261        {
    1262            Entity var2 = this.getEntityByID(par1Packet42RemoveEntityEffect.entityId);
    1263
    1264            if (var2 instanceof EntityLiving)
    1265            {
    1266                ((EntityLiving)var2).removePotionEffectClient(par1Packet42RemoveEntityEffect.effectId);
    1267            }
    1268        }
    1269
    1270        /**
    1271         * determine if it is a server handler
    1272         */
    1273        public boolean isServerHandler()
    1274        {
    1275            return false;
    1276        }
    1277
    1278        /**
    1279         * Handle a player information packet.
    1280         */
    1281        public void handlePlayerInfo(Packet201PlayerInfo par1Packet201PlayerInfo)
    1282        {
    1283            GuiPlayerInfo var2 = (GuiPlayerInfo)this.playerInfoMap.get(par1Packet201PlayerInfo.playerName);
    1284
    1285            if (var2 == null && par1Packet201PlayerInfo.isConnected)
    1286            {
    1287                var2 = new GuiPlayerInfo(par1Packet201PlayerInfo.playerName);
    1288                this.playerInfoMap.put(par1Packet201PlayerInfo.playerName, var2);
    1289                this.playerInfoList.add(var2);
    1290            }
    1291
    1292            if (var2 != null && !par1Packet201PlayerInfo.isConnected)
    1293            {
    1294                this.playerInfoMap.remove(par1Packet201PlayerInfo.playerName);
    1295                this.playerInfoList.remove(var2);
    1296            }
    1297
    1298            if (par1Packet201PlayerInfo.isConnected && var2 != null)
    1299            {
    1300                var2.responseTime = par1Packet201PlayerInfo.ping;
    1301            }
    1302        }
    1303
    1304        /**
    1305         * Handle a keep alive packet.
    1306         */
    1307        public void handleKeepAlive(Packet0KeepAlive par1Packet0KeepAlive)
    1308        {
    1309            this.addToSendQueue(new Packet0KeepAlive(par1Packet0KeepAlive.randomId));
    1310        }
    1311
    1312        /**
    1313         * Handle a player abilities packet.
    1314         */
    1315        public void handlePlayerAbilities(Packet202PlayerAbilities par1Packet202PlayerAbilities)
    1316        {
    1317            EntityClientPlayerMP var2 = this.mc.thePlayer;
    1318            var2.capabilities.isFlying = par1Packet202PlayerAbilities.getFlying();
    1319            var2.capabilities.isCreativeMode = par1Packet202PlayerAbilities.isCreativeMode();
    1320            var2.capabilities.disableDamage = par1Packet202PlayerAbilities.getDisableDamage();
    1321            var2.capabilities.allowFlying = par1Packet202PlayerAbilities.getAllowFlying();
    1322            var2.capabilities.setFlySpeed(par1Packet202PlayerAbilities.getFlySpeed());
    1323            var2.capabilities.func_82877_b(par1Packet202PlayerAbilities.func_82558_j());
    1324        }
    1325
    1326        public void handleAutoComplete(Packet203AutoComplete par1Packet203AutoComplete)
    1327        {
    1328            String[] var2 = par1Packet203AutoComplete.getText().split("\u0000");
    1329
    1330            if (this.mc.currentScreen instanceof GuiChat)
    1331            {
    1332                GuiChat var3 = (GuiChat)this.mc.currentScreen;
    1333                var3.func_73894_a(var2);
    1334            }
    1335        }
    1336
    1337        public void handleLevelSound(Packet62LevelSound par1Packet62LevelSound)
    1338        {
    1339            this.mc.theWorld.playSound(par1Packet62LevelSound.getEffectX(), par1Packet62LevelSound.getEffectY(), par1Packet62LevelSound.getEffectZ(), par1Packet62LevelSound.getSoundName(), par1Packet62LevelSound.getVolume(), par1Packet62LevelSound.getPitch());
    1340        }
    1341
    1342        public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload)
    1343        {
    1344            FMLNetworkHandler.handlePacket250Packet(par1Packet250CustomPayload, netManager, this);
    1345        }
    1346
    1347        public void handleVanilla250Packet(Packet250CustomPayload par1Packet250CustomPayload)
    1348        {
    1349            if ("MC|TPack".equals(par1Packet250CustomPayload.channel))
    1350            {
    1351                String[] var2 = (new String(par1Packet250CustomPayload.data)).split("\u0000");
    1352                String var3 = var2[0];
    1353
    1354                if (var2[1].equals("16"))
    1355                {
    1356                    if (this.mc.texturePackList.getAcceptsTextures())
    1357                    {
    1358                        this.mc.texturePackList.requestDownloadOfTexture(var3);
    1359                    }
    1360                    else if (this.mc.texturePackList.func_77300_f())
    1361                    {
    1362                        this.mc.displayGuiScreen(new GuiYesNo(new NetClientWebTextures(this, var3), StringTranslate.getInstance().translateKey("multiplayer.texturePrompt.line1"), StringTranslate.getInstance().translateKey("multiplayer.texturePrompt.line2"), 0));
    1363                    }
    1364                }
    1365            }
    1366            else if ("MC|TrList".equals(par1Packet250CustomPayload.channel))
    1367            {
    1368                DataInputStream var8 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1369
    1370                try
    1371                {
    1372                    int var9 = var8.readInt();
    1373                    GuiScreen var4 = this.mc.currentScreen;
    1374
    1375                    if (var4 != null && var4 instanceof GuiMerchant && var9 == this.mc.thePlayer.craftingInventory.windowId)
    1376                    {
    1377                        IMerchant var5 = ((GuiMerchant)var4).getIMerchant();
    1378                        MerchantRecipeList var6 = MerchantRecipeList.readRecipiesFromStream(var8);
    1379                        var5.setRecipes(var6);
    1380                    }
    1381                }
    1382                catch (IOException var7)
    1383                {
    1384                    var7.printStackTrace();
    1385                }
    1386            }
    1387        }
    1388
    1389        /**
    1390         * Return the NetworkManager instance used by this NetClientHandler
    1391         */
    1392        public INetworkManager getNetManager()
    1393        {
    1394            return this.netManager;
    1395        }
    1396
    1397        @Override
    1398        public EntityPlayer getPlayer()
    1399        {
    1400            return mc.thePlayer;
    1401        }
    1402
    1403        public static void setConnectionCompatibilityLevel(byte connectionCompatibilityLevel)
    1404        {
    1405            NetClientHandler.connectionCompatibilityLevel = connectionCompatibilityLevel;
    1406        }
    1407
    1408        public static byte getConnectionCompatibilityLevel()
    1409        {
    1410            return connectionCompatibilityLevel;
    1411        }
    1412    }