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