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