    001package net.minecraft.client.multiplayer;
    002
    003import cpw.mods.fml.common.network.FMLNetworkHandler;
    004import cpw.mods.fml.relauncher.Side;
    005import cpw.mods.fml.relauncher.SideOnly;
    006import java.io.BufferedReader;
    007import java.io.ByteArrayInputStream;
    008import java.io.DataInputStream;
    009import java.io.IOException;
    010import java.io.InputStreamReader;
    011import java.math.BigInteger;
    012import java.net.InetAddress;
    013import java.net.Socket;
    014import java.net.URL;
    015import java.net.URLEncoder;
    016import java.security.PublicKey;
    017import java.util.ArrayList;
    018import java.util.HashMap;
    019import java.util.Iterator;
    020import java.util.List;
    021import java.util.Map;
    022import java.util.Random;
    023import javax.crypto.SecretKey;
    024import net.minecraft.client.Minecraft;
    025import net.minecraft.client.entity.EntityClientPlayerMP;
    026import net.minecraft.client.entity.EntityOtherPlayerMP;
    027import net.minecraft.client.gui.GuiChat;
    028import net.minecraft.client.gui.GuiDisconnected;
    029import net.minecraft.client.gui.GuiDownloadTerrain;
    030import net.minecraft.client.gui.GuiMainMenu;
    031import net.minecraft.client.gui.GuiMerchant;
    032import net.minecraft.client.gui.GuiMultiplayer;
    033import net.minecraft.client.gui.GuiPlayerInfo;
    034import net.minecraft.client.gui.GuiScreen;
    035import net.minecraft.client.gui.GuiScreenDemo;
    036import net.minecraft.client.gui.GuiScreenDisconnectedOnline;
    037import net.minecraft.client.gui.GuiWinGame;
    038import net.minecraft.client.gui.GuiYesNo;
    039import net.minecraft.client.gui.inventory.GuiContainerCreative;
    040import net.minecraft.client.particle.EntityCrit2FX;
    041import net.minecraft.client.particle.EntityPickupFX;
    042import net.minecraft.client.settings.GameSettings;
    043import net.minecraft.creativetab.CreativeTabs;
    044import net.minecraft.entity.Entity;
    045import net.minecraft.entity.EntityList;
    046import net.minecraft.entity.EntityLiving;
    047import net.minecraft.entity.IMerchant;
    048import net.minecraft.entity.NpcMerchant;
    049import net.minecraft.entity.effect.EntityLightningBolt;
    050import net.minecraft.entity.item.EntityBoat;
    051import net.minecraft.entity.item.EntityEnderCrystal;
    052import net.minecraft.entity.item.EntityEnderEye;
    053import net.minecraft.entity.item.EntityEnderPearl;
    054import net.minecraft.entity.item.EntityExpBottle;
    055import net.minecraft.entity.item.EntityFallingSand;
    056import net.minecraft.entity.item.EntityFireworkRocket;
    057import net.minecraft.entity.item.EntityItem;
    058import net.minecraft.entity.item.EntityItemFrame;
    059import net.minecraft.entity.item.EntityMinecart;
    060import net.minecraft.entity.item.EntityPainting;
    061import net.minecraft.entity.item.EntityTNTPrimed;
    062import net.minecraft.entity.item.EntityXPOrb;
    063import net.minecraft.entity.player.EntityPlayer;
    064import net.minecraft.entity.player.InventoryPlayer;
    065import net.minecraft.entity.projectile.EntityArrow;
    066import net.minecraft.entity.projectile.EntityEgg;
    067import net.minecraft.entity.projectile.EntityFishHook;
    068import net.minecraft.entity.projectile.EntityLargeFireball;
    069import net.minecraft.entity.projectile.EntityPotion;
    070import net.minecraft.entity.projectile.EntitySmallFireball;
    071import net.minecraft.entity.projectile.EntitySnowball;
    072import net.minecraft.entity.projectile.EntityWitherSkull;
    073import net.minecraft.inventory.Container;
    074import net.minecraft.inventory.InventoryBasic;
    075import net.minecraft.item.Item;
    076import net.minecraft.item.ItemMap;
    077import net.minecraft.item.ItemStack;
    078import net.minecraft.network.INetworkManager;
    079import net.minecraft.network.MemoryConnection;
    080import net.minecraft.network.TcpConnection;
    081import net.minecraft.network.packet.NetHandler;
    082import net.minecraft.network.packet.Packet;
    083import net.minecraft.network.packet.Packet0KeepAlive;
    084import net.minecraft.network.packet.Packet100OpenWindow;
    085import net.minecraft.network.packet.Packet101CloseWindow;
    086import net.minecraft.network.packet.Packet103SetSlot;
    087import net.minecraft.network.packet.Packet104WindowItems;
    088import net.minecraft.network.packet.Packet105UpdateProgressbar;
    089import net.minecraft.network.packet.Packet106Transaction;
    090import net.minecraft.network.packet.Packet10Flying;
    091import net.minecraft.network.packet.Packet130UpdateSign;
    092import net.minecraft.network.packet.Packet131MapData;
    093import net.minecraft.network.packet.Packet132TileEntityData;
    094import net.minecraft.network.packet.Packet16BlockItemSwitch;
    095import net.minecraft.network.packet.Packet17Sleep;
    096import net.minecraft.network.packet.Packet18Animation;
    097import net.minecraft.network.packet.Packet1Login;
    098import net.minecraft.network.packet.Packet200Statistic;
    099import net.minecraft.network.packet.Packet201PlayerInfo;
    100import net.minecraft.network.packet.Packet202PlayerAbilities;
    101import net.minecraft.network.packet.Packet203AutoComplete;
    102import net.minecraft.network.packet.Packet205ClientCommand;
    103import net.minecraft.network.packet.Packet206SetObjective;
    104import net.minecraft.network.packet.Packet207SetScore;
    105import net.minecraft.network.packet.Packet208SetDisplayObjective;
    106import net.minecraft.network.packet.Packet209SetPlayerTeam;
    107import net.minecraft.network.packet.Packet20NamedEntitySpawn;
    108import net.minecraft.network.packet.Packet22Collect;
    109import net.minecraft.network.packet.Packet23VehicleSpawn;
    110import net.minecraft.network.packet.Packet24MobSpawn;
    111import net.minecraft.network.packet.Packet250CustomPayload;
    112import net.minecraft.network.packet.Packet252SharedKey;
    113import net.minecraft.network.packet.Packet253ServerAuthData;
    114import net.minecraft.network.packet.Packet255KickDisconnect;
    115import net.minecraft.network.packet.Packet25EntityPainting;
    116import net.minecraft.network.packet.Packet26EntityExpOrb;
    117import net.minecraft.network.packet.Packet28EntityVelocity;
    118import net.minecraft.network.packet.Packet29DestroyEntity;
    119import net.minecraft.network.packet.Packet30Entity;
    120import net.minecraft.network.packet.Packet34EntityTeleport;
    121import net.minecraft.network.packet.Packet35EntityHeadRotation;
    122import net.minecraft.network.packet.Packet38EntityStatus;
    123import net.minecraft.network.packet.Packet39AttachEntity;
    124import net.minecraft.network.packet.Packet3Chat;
    125import net.minecraft.network.packet.Packet40EntityMetadata;
    126import net.minecraft.network.packet.Packet41EntityEffect;
    127import net.minecraft.network.packet.Packet42RemoveEntityEffect;
    128import net.minecraft.network.packet.Packet43Experience;
    129import net.minecraft.network.packet.Packet4UpdateTime;
    130import net.minecraft.network.packet.Packet51MapChunk;
    131import net.minecraft.network.packet.Packet52MultiBlockChange;
    132import net.minecraft.network.packet.Packet53BlockChange;
    133import net.minecraft.network.packet.Packet54PlayNoteBlock;
    134import net.minecraft.network.packet.Packet55BlockDestroy;
    135import net.minecraft.network.packet.Packet56MapChunks;
    136import net.minecraft.network.packet.Packet5PlayerInventory;
    137import net.minecraft.network.packet.Packet60Explosion;
    138import net.minecraft.network.packet.Packet61DoorChange;
    139import net.minecraft.network.packet.Packet62LevelSound;
    140import net.minecraft.network.packet.Packet63WorldParticles;
    141import net.minecraft.network.packet.Packet6SpawnPosition;
    142import net.minecraft.network.packet.Packet70GameEvent;
    143import net.minecraft.network.packet.Packet71Weather;
    144import net.minecraft.network.packet.Packet8UpdateHealth;
    145import net.minecraft.network.packet.Packet9Respawn;
    146import net.minecraft.potion.PotionEffect;
    147import net.minecraft.scoreboard.Score;
    148import net.minecraft.scoreboard.ScoreObjective;
    149import net.minecraft.scoreboard.ScoreObjectiveCriteria;
    150import net.minecraft.scoreboard.ScorePlayerTeam;
    151import net.minecraft.scoreboard.Scoreboard;
    152import net.minecraft.server.integrated.IntegratedServer;
    153import net.minecraft.stats.StatList;
    154import net.minecraft.tileentity.TileEntity;
    155import net.minecraft.tileentity.TileEntityBeacon;
    156import net.minecraft.tileentity.TileEntityBrewingStand;
    157import net.minecraft.tileentity.TileEntityCommandBlock;
    158import net.minecraft.tileentity.TileEntityDispenser;
    159import net.minecraft.tileentity.TileEntityDropper;
    160import net.minecraft.tileentity.TileEntityFurnace;
    161import net.minecraft.tileentity.TileEntityHopper;
    162import net.minecraft.tileentity.TileEntityMobSpawner;
    163import net.minecraft.tileentity.TileEntitySign;
    164import net.minecraft.tileentity.TileEntitySkull;
    165import net.minecraft.util.ChunkCoordinates;
    166import net.minecraft.util.CryptManager;
    167import net.minecraft.util.MathHelper;
    168import net.minecraft.util.StringTranslate;
    169import net.minecraft.village.MerchantRecipeList;
    170import net.minecraft.world.EnumGameType;
    171import net.minecraft.world.Explosion;
    172import net.minecraft.world.WorldProviderSurface;
    173import net.minecraft.world.WorldSettings;
    174import net.minecraft.world.chunk.Chunk;
    175import net.minecraft.world.storage.ISaveHandler;
    176import net.minecraft.world.storage.MapStorage;
    177import org.lwjgl.input.Keyboard;
    178
    179import net.minecraftforge.client.ForgeHooksClient;
    180import net.minecraftforge.client.event.ClientChatReceivedEvent;
    181import net.minecraftforge.common.ForgeHooks;
    182import net.minecraftforge.common.MinecraftForge;
    183
    184@SideOnly(Side.CLIENT)
    185public class NetClientHandler extends NetHandler
    186{
    187    /** True if kicked or disconnected from the server. */
    188    private boolean disconnected = false;
    189
    190    /** Reference to the NetworkManager object. */
    191    private INetworkManager netManager;
    192    public String field_72560_a;
    193
    194    /** Reference to the Minecraft object. */
    195    private Minecraft mc;
    196    private WorldClient worldClient;
    197
    198    /**
    199     * True if the client has finished downloading terrain and may spawn. Set upon receipt of a player position packet,
    200     * reset upon respawning.
    201     */
    202    private boolean doneLoadingTerrain = false;
    203    public MapStorage mapStorage = new MapStorage((ISaveHandler)null);
    204
    205    /** A HashMap of all player names and their player information objects */
    206    private Map playerInfoMap = new HashMap();
    207
    208    /**
    209     * An ArrayList of GuiPlayerInfo (includes all the players' GuiPlayerInfo on the current server)
    210     */
    211    public List playerInfoList = new ArrayList();
    212    public int currentServerMaxPlayers = 20;
    213    private GuiScreen field_98183_l = null;
    214
    215    /** RNG. */
    216    Random rand = new Random();
    217
    218    private static byte connectionCompatibilityLevel;
    219
    220    public NetClientHandler(Minecraft par1Minecraft, String par2Str, int par3) throws IOException
    221    {
    222        this.mc = par1Minecraft;
    223        Socket socket = new Socket(InetAddress.getByName(par2Str), par3);
    224        this.netManager = new TcpConnection(par1Minecraft.getLogAgent(), socket, "Client", this);
    225        FMLNetworkHandler.onClientConnectionToRemoteServer(this, par2Str, par3, this.netManager);
    226    }
    227
    228    public NetClientHandler(Minecraft par1Minecraft, String par2Str, int par3, GuiScreen par4GuiScreen) throws IOException
    229    {
    230        this.mc = par1Minecraft;
    231        this.field_98183_l = par4GuiScreen;
    232        Socket socket = new Socket(InetAddress.getByName(par2Str), par3);
    233        this.netManager = new TcpConnection(par1Minecraft.getLogAgent(), socket, "Client", this);
    234        FMLNetworkHandler.onClientConnectionToRemoteServer(this, par2Str, par3, this.netManager);
    235    }
    236
    237    public NetClientHandler(Minecraft par1Minecraft, IntegratedServer par2IntegratedServer) throws IOException
    238    {
    239        this.mc = par1Minecraft;
    240        this.netManager = new MemoryConnection(par1Minecraft.getLogAgent(), this);
    241        par2IntegratedServer.getServerListeningThread().func_71754_a((MemoryConnection)this.netManager, par1Minecraft.session.username);
    242        FMLNetworkHandler.onClientConnectionToIntegratedServer(this, par2IntegratedServer, this.netManager);
    243    }
    244
    245    /**
    246     * sets netManager and worldClient to null
    247     */
    248    public void cleanup()
    249    {
    250        if (this.netManager != null)
    251        {
    252            this.netManager.wakeThreads();
    253        }
    254
    255        this.netManager = null;
    256        this.worldClient = null;
    257    }
    258
    259    /**
    260     * Processes the packets that have been read since the last call to this function.
    261     */
    262    public void processReadPackets()
    263    {
    264        if (!this.disconnected && this.netManager != null)
    265        {
    266            this.netManager.processReadPackets();
    267        }
    268
    269        if (this.netManager != null)
    270        {
    271            this.netManager.wakeThreads();
    272        }
    273    }
    274
    275    public void handleServerAuthData(Packet253ServerAuthData par1Packet253ServerAuthData)
    276    {
    277        String s = par1Packet253ServerAuthData.getServerId().trim();
    278        PublicKey publickey = par1Packet253ServerAuthData.getPublicKey();
    279        SecretKey secretkey = CryptManager.createNewSharedKey();
    280
    281        if (!"-".equals(s))
    282        {
    283            String s1 = (new BigInteger(CryptManager.getServerIdHash(s, publickey, secretkey))).toString(16);
    284            String s2 = this.sendSessionRequest(this.mc.session.username, this.mc.session.sessionId, s1);
    285
    286            if (!"ok".equalsIgnoreCase(s2))
    287            {
    288                this.netManager.networkShutdown("disconnect.loginFailedInfo", new Object[] {s2});
    289                return;
    290            }
    291        }
    292
    293        this.addToSendQueue(new Packet252SharedKey(secretkey, publickey, par1Packet253ServerAuthData.getVerifyToken()));
    294    }
    295
    296    /**
    297     * Send request to http://session.minecraft.net with user's sessionId and serverId hash
    298     */
    299    private String sendSessionRequest(String par1Str, String par2Str, String par3Str)
    300    {
    301        try
    302        {
    303            URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + urlEncode(par1Str) + "&sessionId=" + urlEncode(par2Str) + "&serverId=" + urlEncode(par3Str));
    304            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(url.openStream()));
    305            String s3 = bufferedreader.readLine();
    306            bufferedreader.close();
    307            return s3;
    308        }
    309        catch (IOException ioexception)
    310        {
    311            return ioexception.toString();
    312        }
    313    }
    314
    315    /**
    316     * Encode the given string for insertion into a URL
    317     */
    318    private static String urlEncode(String par0Str) throws IOException
    319    {
    320        return URLEncoder.encode(par0Str, "UTF-8");
    321    }
    322
    323    public void handleSharedKey(Packet252SharedKey par1Packet252SharedKey)
    324    {
    325        this.addToSendQueue(FMLNetworkHandler.getFMLFakeLoginPacket());
    326        this.addToSendQueue(new Packet205ClientCommand(0));
    327    }
    328
    329    public void handleLogin(Packet1Login par1Packet1Login)
    330    {
    331        this.mc.playerController = new PlayerControllerMP(this.mc, this);
    332        this.mc.statFileWriter.readStat(StatList.joinMultiplayerStat, 1);
    333        this.worldClient = new WorldClient(this, new WorldSettings(0L, par1Packet1Login.gameType, false, par1Packet1Login.hardcoreMode, par1Packet1Login.terrainType), par1Packet1Login.dimension, par1Packet1Login.difficultySetting, this.mc.mcProfiler, this.mc.getLogAgent());
    334        this.worldClient.isRemote = true;
    335        this.mc.loadWorld(this.worldClient);
    336        this.mc.thePlayer.dimension = par1Packet1Login.dimension;
    337        this.mc.displayGuiScreen(new GuiDownloadTerrain(this));
    338        this.mc.thePlayer.entityId = par1Packet1Login.clientEntityId;
    339        this.currentServerMaxPlayers = par1Packet1Login.maxPlayers;
    340        this.mc.playerController.setGameType(par1Packet1Login.gameType);
    341        FMLNetworkHandler.onConnectionEstablishedToServer(this, netManager, par1Packet1Login);
    342        this.mc.gameSettings.sendSettingsToServer();
    343    }
    344
    345    public void handleVehicleSpawn(Packet23VehicleSpawn par1Packet23VehicleSpawn)
    346    {
    347        double d0 = (double)par1Packet23VehicleSpawn.xPosition / 32.0D;
    348        double d1 = (double)par1Packet23VehicleSpawn.yPosition / 32.0D;
    349        double d2 = (double)par1Packet23VehicleSpawn.zPosition / 32.0D;
    350        Object object = null;
    351
    352        if (par1Packet23VehicleSpawn.type == 10)
    353        {
    354            object = EntityMinecart.createMinecart(this.worldClient, d0, d1, d2, par1Packet23VehicleSpawn.throwerEntityId);
    355        }
    356        else if (par1Packet23VehicleSpawn.type == 90)
    357        {
    358            Entity entity = this.getEntityByID(par1Packet23VehicleSpawn.throwerEntityId);
    359
    360            if (entity instanceof EntityPlayer)
    361            {
    362                object = new EntityFishHook(this.worldClient, d0, d1, d2, (EntityPlayer)entity);
    363            }
    364
    365            par1Packet23VehicleSpawn.throwerEntityId = 0;
    366        }
    367        else if (par1Packet23VehicleSpawn.type == 60)
    368        {
    369            object = new EntityArrow(this.worldClient, d0, d1, d2);
    370        }
    371        else if (par1Packet23VehicleSpawn.type == 61)
    372        {
    373            object = new EntitySnowball(this.worldClient, d0, d1, d2);
    374        }
    375        else if (par1Packet23VehicleSpawn.type == 71)
    376        {
    377            object = new EntityItemFrame(this.worldClient, (int)d0, (int)d1, (int)d2, par1Packet23VehicleSpawn.throwerEntityId);
    378            par1Packet23VehicleSpawn.throwerEntityId = 0;
    379        }
    380        else if (par1Packet23VehicleSpawn.type == 65)
    381        {
    382            object = new EntityEnderPearl(this.worldClient, d0, d1, d2);
    383        }
    384        else if (par1Packet23VehicleSpawn.type == 72)
    385        {
    386            object = new EntityEnderEye(this.worldClient, d0, d1, d2);
    387        }
    388        else if (par1Packet23VehicleSpawn.type == 76)
    389        {
    390            object = new EntityFireworkRocket(this.worldClient, d0, d1, d2, (ItemStack)null);
    391        }
    392        else if (par1Packet23VehicleSpawn.type == 63)
    393        {
    394            object = new EntityLargeFireball(this.worldClient, d0, d1, d2, (double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    395            par1Packet23VehicleSpawn.throwerEntityId = 0;
    396        }
    397        else if (par1Packet23VehicleSpawn.type == 64)
    398        {
    399            object = new EntitySmallFireball(this.worldClient, d0, d1, d2, (double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    400            par1Packet23VehicleSpawn.throwerEntityId = 0;
    401        }
    402        else if (par1Packet23VehicleSpawn.type == 66)
    403        {
    404            object = new EntityWitherSkull(this.worldClient, d0, d1, d2, (double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    405            par1Packet23VehicleSpawn.throwerEntityId = 0;
    406        }
    407        else if (par1Packet23VehicleSpawn.type == 62)
    408        {
    409            object = new EntityEgg(this.worldClient, d0, d1, d2);
    410        }
    411        else if (par1Packet23VehicleSpawn.type == 73)
    412        {
    413            object = new EntityPotion(this.worldClient, d0, d1, d2, par1Packet23VehicleSpawn.throwerEntityId);
    414            par1Packet23VehicleSpawn.throwerEntityId = 0;
    415        }
    416        else if (par1Packet23VehicleSpawn.type == 75)
    417        {
    418            object = new EntityExpBottle(this.worldClient, d0, d1, d2);
    419            par1Packet23VehicleSpawn.throwerEntityId = 0;
    420        }
    421        else if (par1Packet23VehicleSpawn.type == 1)
    422        {
    423            object = new EntityBoat(this.worldClient, d0, d1, d2);
    424        }
    425        else if (par1Packet23VehicleSpawn.type == 50)
    426        {
    427            object = new EntityTNTPrimed(this.worldClient, d0, d1, d2, (EntityLiving)null);
    428        }
    429        else if (par1Packet23VehicleSpawn.type == 51)
    430        {
    431            object = new EntityEnderCrystal(this.worldClient, d0, d1, d2);
    432        }
    433        else if (par1Packet23VehicleSpawn.type == 2)
    434        {
    435            object = new EntityItem(this.worldClient, d0, d1, d2);
    436        }
    437        else if (par1Packet23VehicleSpawn.type == 70)
    438        {
    439            object = new EntityFallingSand(this.worldClient, d0, d1, d2, par1Packet23VehicleSpawn.throwerEntityId & 65535, par1Packet23VehicleSpawn.throwerEntityId >> 16);
    440            par1Packet23VehicleSpawn.throwerEntityId = 0;
    441        }
    442
    443        if (object != null)
    444        {
    445            ((Entity)object).serverPosX = par1Packet23VehicleSpawn.xPosition;
    446            ((Entity)object).serverPosY = par1Packet23VehicleSpawn.yPosition;
    447            ((Entity)object).serverPosZ = par1Packet23VehicleSpawn.zPosition;
    448            ((Entity)object).rotationPitch = (float)(par1Packet23VehicleSpawn.pitch * 360) / 256.0F;
    449            ((Entity)object).rotationYaw = (float)(par1Packet23VehicleSpawn.yaw * 360) / 256.0F;
    450            Entity[] aentity = ((Entity)object).getParts();
    451
    452            if (aentity != null)
    453            {
    454                int i = par1Packet23VehicleSpawn.entityId - ((Entity)object).entityId;
    455
    456                for (int j = 0; j < aentity.length; ++j)
    457                {
    458                    aentity[j].entityId += i;
    459                }
    460            }
    461
    462            ((Entity)object).entityId = par1Packet23VehicleSpawn.entityId;
    463            this.worldClient.addEntityToWorld(par1Packet23VehicleSpawn.entityId, (Entity)object);
    464
    465            if (par1Packet23VehicleSpawn.throwerEntityId > 0)
    466            {
    467                if (par1Packet23VehicleSpawn.type == 60)
    468                {
    469                    Entity entity1 = this.getEntityByID(par1Packet23VehicleSpawn.throwerEntityId);
    470
    471                    if (entity1 instanceof EntityLiving)
    472                    {
    473                        EntityArrow entityarrow = (EntityArrow)object;
    474                        entityarrow.shootingEntity = entity1;
    475                    }
    476                }
    477
    478                ((Entity)object).setVelocity((double)par1Packet23VehicleSpawn.speedX / 8000.0D, (double)par1Packet23VehicleSpawn.speedY / 8000.0D, (double)par1Packet23VehicleSpawn.speedZ / 8000.0D);
    479            }
    480        }
    481    }
    482
    483    /**
    484     * Handle a entity experience orb packet.
    485     */
    486    public void handleEntityExpOrb(Packet26EntityExpOrb par1Packet26EntityExpOrb)
    487    {
    488        EntityXPOrb entityxporb = new EntityXPOrb(this.worldClient, (double)par1Packet26EntityExpOrb.posX, (double)par1Packet26EntityExpOrb.posY, (double)par1Packet26EntityExpOrb.posZ, par1Packet26EntityExpOrb.xpValue);
    489        entityxporb.serverPosX = par1Packet26EntityExpOrb.posX;
    490        entityxporb.serverPosY = par1Packet26EntityExpOrb.posY;
    491        entityxporb.serverPosZ = par1Packet26EntityExpOrb.posZ;
    492        entityxporb.rotationYaw = 0.0F;
    493        entityxporb.rotationPitch = 0.0F;
    494        entityxporb.entityId = par1Packet26EntityExpOrb.entityId;
    495        this.worldClient.addEntityToWorld(par1Packet26EntityExpOrb.entityId, entityxporb);
    496    }
    497
    498    /**
    499     * Handles weather packet
    500     */
    501    public void handleWeather(Packet71Weather par1Packet71Weather)
    502    {
    503        double d0 = (double)par1Packet71Weather.posX / 32.0D;
    504        double d1 = (double)par1Packet71Weather.posY / 32.0D;
    505        double d2 = (double)par1Packet71Weather.posZ / 32.0D;
    506        EntityLightningBolt entitylightningbolt = null;
    507
    508        if (par1Packet71Weather.isLightningBolt == 1)
    509        {
    510            entitylightningbolt = new EntityLightningBolt(this.worldClient, d0, d1, d2);
    511        }
    512
    513        if (entitylightningbolt != null)
    514        {
    515            entitylightningbolt.serverPosX = par1Packet71Weather.posX;
    516            entitylightningbolt.serverPosY = par1Packet71Weather.posY;
    517            entitylightningbolt.serverPosZ = par1Packet71Weather.posZ;
    518            entitylightningbolt.rotationYaw = 0.0F;
    519            entitylightningbolt.rotationPitch = 0.0F;
    520            entitylightningbolt.entityId = par1Packet71Weather.entityID;
    521            this.worldClient.addWeatherEffect(entitylightningbolt);
    522        }
    523    }
    524
    525    /**
    526     * Packet handler
    527     */
    528    public void handleEntityPainting(Packet25EntityPainting par1Packet25EntityPainting)
    529    {
    530        EntityPainting entitypainting = new EntityPainting(this.worldClient, par1Packet25EntityPainting.xPosition, par1Packet25EntityPainting.yPosition, par1Packet25EntityPainting.zPosition, par1Packet25EntityPainting.direction, par1Packet25EntityPainting.title);
    531        this.worldClient.addEntityToWorld(par1Packet25EntityPainting.entityId, entitypainting);
    532    }
    533
    534    /**
    535     * Packet handler
    536     */
    537    public void handleEntityVelocity(Packet28EntityVelocity par1Packet28EntityVelocity)
    538    {
    539        Entity entity = this.getEntityByID(par1Packet28EntityVelocity.entityId);
    540
    541        if (entity != null)
    542        {
    543            entity.setVelocity((double)par1Packet28EntityVelocity.motionX / 8000.0D, (double)par1Packet28EntityVelocity.motionY / 8000.0D, (double)par1Packet28EntityVelocity.motionZ / 8000.0D);
    544        }
    545    }
    546
    547    /**
    548     * Packet handler
    549     */
    550    public void handleEntityMetadata(Packet40EntityMetadata par1Packet40EntityMetadata)
    551    {
    552        Entity entity = this.getEntityByID(par1Packet40EntityMetadata.entityId);
    553
    554        if (entity != null && par1Packet40EntityMetadata.getMetadata() != null)
    555        {
    556            entity.getDataWatcher().updateWatchedObjectsFromList(par1Packet40EntityMetadata.getMetadata());
    557        }
    558    }
    559
    560    public void handleNamedEntitySpawn(Packet20NamedEntitySpawn par1Packet20NamedEntitySpawn)
    561    {
    562        double d0 = (double)par1Packet20NamedEntitySpawn.xPosition / 32.0D;
    563        double d1 = (double)par1Packet20NamedEntitySpawn.yPosition / 32.0D;
    564        double d2 = (double)par1Packet20NamedEntitySpawn.zPosition / 32.0D;
    565        float f = (float)(par1Packet20NamedEntitySpawn.rotation * 360) / 256.0F;
    566        float f1 = (float)(par1Packet20NamedEntitySpawn.pitch * 360) / 256.0F;
    567        EntityOtherPlayerMP entityotherplayermp = new EntityOtherPlayerMP(this.mc.theWorld, par1Packet20NamedEntitySpawn.name);
    568        entityotherplayermp.prevPosX = entityotherplayermp.lastTickPosX = (double)(entityotherplayermp.serverPosX = par1Packet20NamedEntitySpawn.xPosition);
    569        entityotherplayermp.prevPosY = entityotherplayermp.lastTickPosY = (double)(entityotherplayermp.serverPosY = par1Packet20NamedEntitySpawn.yPosition);
    570        entityotherplayermp.prevPosZ = entityotherplayermp.lastTickPosZ = (double)(entityotherplayermp.serverPosZ = par1Packet20NamedEntitySpawn.zPosition);
    571        int i = par1Packet20NamedEntitySpawn.currentItem;
    572
    573        if (i == 0)
    574        {
    575            entityotherplayermp.inventory.mainInventory[entityotherplayermp.inventory.currentItem] = null;
    576        }
    577        else
    578        {
    579            entityotherplayermp.inventory.mainInventory[entityotherplayermp.inventory.currentItem] = new ItemStack(i, 1, 0);
    580        }
    581
    582        entityotherplayermp.setPositionAndRotation(d0, d1, d2, f, f1);
    583        this.worldClient.addEntityToWorld(par1Packet20NamedEntitySpawn.entityId, entityotherplayermp);
    584        List list = par1Packet20NamedEntitySpawn.getWatchedMetadata();
    585
    586        if (list != null)
    587        {
    588            entityotherplayermp.getDataWatcher().updateWatchedObjectsFromList(list);
    589        }
    590    }
    591
    592    public void handleEntityTeleport(Packet34EntityTeleport par1Packet34EntityTeleport)
    593    {
    594        Entity entity = this.getEntityByID(par1Packet34EntityTeleport.entityId);
    595
    596        if (entity != null)
    597        {
    598            entity.serverPosX = par1Packet34EntityTeleport.xPosition;
    599            entity.serverPosY = par1Packet34EntityTeleport.yPosition;
    600            entity.serverPosZ = par1Packet34EntityTeleport.zPosition;
    601            double d0 = (double)entity.serverPosX / 32.0D;
    602            double d1 = (double)entity.serverPosY / 32.0D + 0.015625D;
    603            double d2 = (double)entity.serverPosZ / 32.0D;
    604            float f = (float)(par1Packet34EntityTeleport.yaw * 360) / 256.0F;
    605            float f1 = (float)(par1Packet34EntityTeleport.pitch * 360) / 256.0F;
    606            entity.setPositionAndRotation2(d0, d1, d2, f, f1, 3);
    607        }
    608    }
    609
    610    public void handleBlockItemSwitch(Packet16BlockItemSwitch par1Packet16BlockItemSwitch)
    611    {
    612        if (par1Packet16BlockItemSwitch.id >= 0 && par1Packet16BlockItemSwitch.id < InventoryPlayer.getHotbarSize())
    613        {
    614            this.mc.thePlayer.inventory.currentItem = par1Packet16BlockItemSwitch.id;
    615        }
    616    }
    617
    618    public void handleEntity(Packet30Entity par1Packet30Entity)
    619    {
    620        Entity entity = this.getEntityByID(par1Packet30Entity.entityId);
    621
    622        if (entity != null)
    623        {
    624            entity.serverPosX += par1Packet30Entity.xPosition;
    625            entity.serverPosY += par1Packet30Entity.yPosition;
    626            entity.serverPosZ += par1Packet30Entity.zPosition;
    627            double d0 = (double)entity.serverPosX / 32.0D;
    628            double d1 = (double)entity.serverPosY / 32.0D;
    629            double d2 = (double)entity.serverPosZ / 32.0D;
    630            float f = par1Packet30Entity.rotating ? (float)(par1Packet30Entity.yaw * 360) / 256.0F : entity.rotationYaw;
    631            float f1 = par1Packet30Entity.rotating ? (float)(par1Packet30Entity.pitch * 360) / 256.0F : entity.rotationPitch;
    632            entity.setPositionAndRotation2(d0, d1, d2, f, f1, 3);
    633        }
    634    }
    635
    636    public void handleEntityHeadRotation(Packet35EntityHeadRotation par1Packet35EntityHeadRotation)
    637    {
    638        Entity entity = this.getEntityByID(par1Packet35EntityHeadRotation.entityId);
    639
    640        if (entity != null)
    641        {
    642            float f = (float)(par1Packet35EntityHeadRotation.headRotationYaw * 360) / 256.0F;
    643            entity.setRotationYawHead(f);
    644        }
    645    }
    646
    647    public void handleDestroyEntity(Packet29DestroyEntity par1Packet29DestroyEntity)
    648    {
    649        for (int i = 0; i < par1Packet29DestroyEntity.entityId.length; ++i)
    650        {
    651            this.worldClient.removeEntityFromWorld(par1Packet29DestroyEntity.entityId[i]);
    652        }
    653    }
    654
    655    public void handleFlying(Packet10Flying par1Packet10Flying)
    656    {
    657        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    658        double d0 = entityclientplayermp.posX;
    659        double d1 = entityclientplayermp.posY;
    660        double d2 = entityclientplayermp.posZ;
    661        float f = entityclientplayermp.rotationYaw;
    662        float f1 = entityclientplayermp.rotationPitch;
    663
    664        if (par1Packet10Flying.moving)
    665        {
    666            d0 = par1Packet10Flying.xPosition;
    667            d1 = par1Packet10Flying.yPosition;
    668            d2 = par1Packet10Flying.zPosition;
    669        }
    670
    671        if (par1Packet10Flying.rotating)
    672        {
    673            f = par1Packet10Flying.yaw;
    674            f1 = par1Packet10Flying.pitch;
    675        }
    676
    677        entityclientplayermp.ySize = 0.0F;
    678        entityclientplayermp.motionX = entityclientplayermp.motionY = entityclientplayermp.motionZ = 0.0D;
    679        entityclientplayermp.setPositionAndRotation(d0, d1, d2, f, f1);
    680        par1Packet10Flying.xPosition = entityclientplayermp.posX;
    681        par1Packet10Flying.yPosition = entityclientplayermp.boundingBox.minY;
    682        par1Packet10Flying.zPosition = entityclientplayermp.posZ;
    683        par1Packet10Flying.stance = entityclientplayermp.posY;
    684        this.netManager.addToSendQueue(par1Packet10Flying);
    685
    686        if (!this.doneLoadingTerrain)
    687        {
    688            this.mc.thePlayer.prevPosX = this.mc.thePlayer.posX;
    689            this.mc.thePlayer.prevPosY = this.mc.thePlayer.posY;
    690            this.mc.thePlayer.prevPosZ = this.mc.thePlayer.posZ;
    691            this.doneLoadingTerrain = true;
    692            this.mc.displayGuiScreen((GuiScreen)null);
    693        }
    694    }
    695
    696    public void handleMultiBlockChange(Packet52MultiBlockChange par1Packet52MultiBlockChange)
    697    {
    698        int i = par1Packet52MultiBlockChange.xPosition * 16;
    699        int j = par1Packet52MultiBlockChange.zPosition * 16;
    700
    701        if (par1Packet52MultiBlockChange.metadataArray != null)
    702        {
    703            DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(par1Packet52MultiBlockChange.metadataArray));
    704
    705            try
    706            {
    707                for (int k = 0; k < par1Packet52MultiBlockChange.size; ++k)
    708                {
    709                    short short1 = datainputstream.readShort();
    710                    short short2 = datainputstream.readShort();
    711                    int l = short2 >> 4 & 4095;
    712                    int i1 = short2 & 15;
    713                    int j1 = short1 >> 12 & 15;
    714                    int k1 = short1 >> 8 & 15;
    715                    int l1 = short1 & 255;
    716                    this.worldClient.setBlockAndMetadataAndInvalidate(j1 + i, l1, k1 + j, l, i1);
    717                }
    718            }
    719            catch (IOException ioexception)
    720            {
    721                ;
    722            }
    723        }
    724    }
    725
    726    /**
    727     * Handle Packet51MapChunk (full chunk update of blocks, metadata, light levels, and optionally biome data)
    728     */
    729    public void handleMapChunk(Packet51MapChunk par1Packet51MapChunk)
    730    {
    731        if (par1Packet51MapChunk.includeInitialize)
    732        {
    733            if (par1Packet51MapChunk.yChMin == 0)
    734            {
    735                this.worldClient.doPreChunk(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh, false);
    736                return;
    737            }
    738
    739            this.worldClient.doPreChunk(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh, true);
    740        }
    741
    742        this.worldClient.invalidateBlockReceiveRegion(par1Packet51MapChunk.xCh << 4, 0, par1Packet51MapChunk.zCh << 4, (par1Packet51MapChunk.xCh << 4) + 15, 256, (par1Packet51MapChunk.zCh << 4) + 15);
    743        Chunk chunk = this.worldClient.getChunkFromChunkCoords(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh);
    744
    745        if (par1Packet51MapChunk.includeInitialize && chunk == null)
    746        {
    747            this.worldClient.doPreChunk(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh, true);
    748            chunk = this.worldClient.getChunkFromChunkCoords(par1Packet51MapChunk.xCh, par1Packet51MapChunk.zCh);
    749        }
    750
    751        if (chunk != null)
    752        {
    753            chunk.fillChunk(par1Packet51MapChunk.getCompressedChunkData(), par1Packet51MapChunk.yChMin, par1Packet51MapChunk.yChMax, par1Packet51MapChunk.includeInitialize);
    754            this.worldClient.markBlockRangeForRenderUpdate(par1Packet51MapChunk.xCh << 4, 0, par1Packet51MapChunk.zCh << 4, (par1Packet51MapChunk.xCh << 4) + 15, 256, (par1Packet51MapChunk.zCh << 4) + 15);
    755
    756            if (!par1Packet51MapChunk.includeInitialize || !(this.worldClient.provider instanceof WorldProviderSurface))
    757            {
    758                chunk.resetRelightChecks();
    759            }
    760        }
    761    }
    762
    763    public void handleBlockChange(Packet53BlockChange par1Packet53BlockChange)
    764    {
    765        this.worldClient.setBlockAndMetadataAndInvalidate(par1Packet53BlockChange.xPosition, par1Packet53BlockChange.yPosition, par1Packet53BlockChange.zPosition, par1Packet53BlockChange.type, par1Packet53BlockChange.metadata);
    766    }
    767
    768    public void handleKickDisconnect(Packet255KickDisconnect par1Packet255KickDisconnect)
    769    {
    770        this.netManager.networkShutdown("disconnect.kicked", par1Packet255KickDisconnect.reason);
    771        this.disconnected = true;
    772        this.mc.loadWorld((WorldClient)null);
    773
    774        if (this.field_98183_l != null)
    775        {
    776            this.mc.displayGuiScreen(new GuiScreenDisconnectedOnline(this.field_98183_l, "disconnect.disconnected", "disconnect.genericReason", new Object[] {par1Packet255KickDisconnect.reason}));
    777        }
    778        else
    779        {
    780            this.mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.disconnected", "disconnect.genericReason", new Object[] {par1Packet255KickDisconnect.reason}));
    781        }
    782    }
    783
    784    public void handleErrorMessage(String par1Str, Object[] par2ArrayOfObj)
    785    {
    786        if (!this.disconnected)
    787        {
    788            this.disconnected = true;
    789            this.mc.loadWorld((WorldClient)null);
    790
    791            if (this.field_98183_l != null)
    792            {
    793                this.mc.displayGuiScreen(new GuiScreenDisconnectedOnline(this.field_98183_l, "disconnect.lost", par1Str, par2ArrayOfObj));
    794            }
    795            else
    796            {
    797                this.mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.lost", par1Str, par2ArrayOfObj));
    798            }
    799        }
    800    }
    801
    802    public void quitWithPacket(Packet par1Packet)
    803    {
    804        if (!this.disconnected)
    805        {
    806            this.netManager.addToSendQueue(par1Packet);
    807            this.netManager.serverShutdown();
    808            FMLNetworkHandler.onConnectionClosed(this.netManager, this.getPlayer());
    809        }
    810    }
    811
    812    /**
    813     * Adds the packet to the send queue
    814     */
    815    public void addToSendQueue(Packet par1Packet)
    816    {
    817        if (!this.disconnected)
    818        {
    819            this.netManager.addToSendQueue(par1Packet);
    820        }
    821    }
    822
    823    public void handleCollect(Packet22Collect par1Packet22Collect)
    824    {
    825        Entity entity = this.getEntityByID(par1Packet22Collect.collectedEntityId);
    826        Object object = (EntityLiving)this.getEntityByID(par1Packet22Collect.collectorEntityId);
    827
    828        if (object == null)
    829        {
    830            object = this.mc.thePlayer;
    831        }
    832
    833        if (entity != null)
    834        {
    835            if (entity instanceof EntityXPOrb)
    836            {
    837                this.worldClient.playSoundAtEntity(entity, "random.orb", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    838            }
    839            else
    840            {
    841                this.worldClient.playSoundAtEntity(entity, "random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    842            }
    843
    844            this.mc.effectRenderer.addEffect(new EntityPickupFX(this.mc.theWorld, entity, (Entity)object, -0.5F));
    845            this.worldClient.removeEntityFromWorld(par1Packet22Collect.collectedEntityId);
    846        }
    847    }
    848
    849    public void handleChat(Packet3Chat par1Packet3Chat)
    850    {
    851        par1Packet3Chat = FMLNetworkHandler.handleChatMessage(this, par1Packet3Chat);
    852        ClientChatReceivedEvent event = new ClientChatReceivedEvent(par1Packet3Chat.message);
    853        if (!MinecraftForge.EVENT_BUS.post(event) && event.message != null)
    854        {
    855            this.mc.ingameGUI.getChatGUI().printChatMessage(par1Packet3Chat.message);
    856        }
    857    }
    858
    859    public void handleAnimation(Packet18Animation par1Packet18Animation)
    860    {
    861        Entity entity = this.getEntityByID(par1Packet18Animation.entityId);
    862
    863        if (entity != null)
    864        {
    865            if (par1Packet18Animation.animate == 1)
    866            {
    867                EntityLiving entityliving = (EntityLiving)entity;
    868                entityliving.swingItem();
    869            }
    870            else if (par1Packet18Animation.animate == 2)
    871            {
    872                entity.performHurtAnimation();
    873            }
    874            else if (par1Packet18Animation.animate == 3)
    875            {
    876                EntityPlayer entityplayer = (EntityPlayer)entity;
    877                entityplayer.wakeUpPlayer(false, false, false);
    878            }
    879            else if (par1Packet18Animation.animate != 4)
    880            {
    881                if (par1Packet18Animation.animate == 6)
    882                {
    883                    this.mc.effectRenderer.addEffect(new EntityCrit2FX(this.mc.theWorld, entity));
    884                }
    885                else if (par1Packet18Animation.animate == 7)
    886                {
    887                    EntityCrit2FX entitycrit2fx = new EntityCrit2FX(this.mc.theWorld, entity, "magicCrit");
    888                    this.mc.effectRenderer.addEffect(entitycrit2fx);
    889                }
    890                else if (par1Packet18Animation.animate == 5 && entity instanceof EntityOtherPlayerMP)
    891                {
    892                    ;
    893                }
    894            }
    895        }
    896    }
    897
    898    public void handleSleep(Packet17Sleep par1Packet17Sleep)
    899    {
    900        Entity entity = this.getEntityByID(par1Packet17Sleep.entityID);
    901
    902        if (entity != null)
    903        {
    904            if (par1Packet17Sleep.field_73622_e == 0)
    905            {
    906                EntityPlayer entityplayer = (EntityPlayer)entity;
    907                entityplayer.sleepInBedAt(par1Packet17Sleep.bedX, par1Packet17Sleep.bedY, par1Packet17Sleep.bedZ);
    908            }
    909        }
    910    }
    911
    912    /**
    913     * Disconnects the network connection.
    914     */
    915    public void disconnect()
    916    {
    917        this.disconnected = true;
    918        this.netManager.wakeThreads();
    919        this.netManager.networkShutdown("disconnect.closed", new Object[0]);
    920    }
    921
    922    public void handleMobSpawn(Packet24MobSpawn par1Packet24MobSpawn)
    923    {
    924        double d0 = (double)par1Packet24MobSpawn.xPosition / 32.0D;
    925        double d1 = (double)par1Packet24MobSpawn.yPosition / 32.0D;
    926        double d2 = (double)par1Packet24MobSpawn.zPosition / 32.0D;
    927        float f = (float)(par1Packet24MobSpawn.yaw * 360) / 256.0F;
    928        float f1 = (float)(par1Packet24MobSpawn.pitch * 360) / 256.0F;
    929        EntityLiving entityliving = (EntityLiving)EntityList.createEntityByID(par1Packet24MobSpawn.type, this.mc.theWorld);
    930        entityliving.serverPosX = par1Packet24MobSpawn.xPosition;
    931        entityliving.serverPosY = par1Packet24MobSpawn.yPosition;
    932        entityliving.serverPosZ = par1Packet24MobSpawn.zPosition;
    933        entityliving.rotationYawHead = (float)(par1Packet24MobSpawn.headYaw * 360) / 256.0F;
    934        Entity[] aentity = entityliving.getParts();
    935
    936        if (aentity != null)
    937        {
    938            int i = par1Packet24MobSpawn.entityId - entityliving.entityId;
    939
    940            for (int j = 0; j < aentity.length; ++j)
    941            {
    942                aentity[j].entityId += i;
    943            }
    944        }
    945
    946        entityliving.entityId = par1Packet24MobSpawn.entityId;
    947        entityliving.setPositionAndRotation(d0, d1, d2, f, f1);
    948        entityliving.motionX = (double)((float)par1Packet24MobSpawn.velocityX / 8000.0F);
    949        entityliving.motionY = (double)((float)par1Packet24MobSpawn.velocityY / 8000.0F);
    950        entityliving.motionZ = (double)((float)par1Packet24MobSpawn.velocityZ / 8000.0F);
    951        this.worldClient.addEntityToWorld(par1Packet24MobSpawn.entityId, entityliving);
    952        List list = par1Packet24MobSpawn.getMetadata();
    953
    954        if (list != null)
    955        {
    956            entityliving.getDataWatcher().updateWatchedObjectsFromList(list);
    957        }
    958    }
    959
    960    public void handleUpdateTime(Packet4UpdateTime par1Packet4UpdateTime)
    961    {
    962        this.mc.theWorld.func_82738_a(par1Packet4UpdateTime.worldAge);
    963        this.mc.theWorld.setWorldTime(par1Packet4UpdateTime.time);
    964    }
    965
    966    public void handleSpawnPosition(Packet6SpawnPosition par1Packet6SpawnPosition)
    967    {
    968        this.mc.thePlayer.setSpawnChunk(new ChunkCoordinates(par1Packet6SpawnPosition.xPosition, par1Packet6SpawnPosition.yPosition, par1Packet6SpawnPosition.zPosition), true);
    969        this.mc.theWorld.getWorldInfo().setSpawnPosition(par1Packet6SpawnPosition.xPosition, par1Packet6SpawnPosition.yPosition, par1Packet6SpawnPosition.zPosition);
    970    }
    971
    972    /**
    973     * Packet handler
    974     */
    975    public void handleAttachEntity(Packet39AttachEntity par1Packet39AttachEntity)
    976    {
    977        Object object = this.getEntityByID(par1Packet39AttachEntity.entityId);
    978        Entity entity = this.getEntityByID(par1Packet39AttachEntity.vehicleEntityId);
    979
    980        if (par1Packet39AttachEntity.entityId == this.mc.thePlayer.entityId)
    981        {
    982            object = this.mc.thePlayer;
    983
    984            if (entity instanceof EntityBoat)
    985            {
    986                ((EntityBoat)entity).func_70270_d(false);
    987            }
    988        }
    989        else if (entity instanceof EntityBoat)
    990        {
    991            ((EntityBoat)entity).func_70270_d(true);
    992        }
    993
    994        if (object != null)
    995        {
    996            ((Entity)object).mountEntity(entity);
    997        }
    998    }
    999
    1000    /**
    1001     * Packet handler
    1002     */
    1003    public void handleEntityStatus(Packet38EntityStatus par1Packet38EntityStatus)
    1004    {
    1005        Entity entity = this.getEntityByID(par1Packet38EntityStatus.entityId);
    1006
    1007        if (entity != null)
    1008        {
    1009            entity.handleHealthUpdate(par1Packet38EntityStatus.entityStatus);
    1010        }
    1011    }
    1012
    1013    private Entity getEntityByID(int par1)
    1014    {
    1015        return (Entity)(par1 == this.mc.thePlayer.entityId ? this.mc.thePlayer : this.worldClient.getEntityByID(par1));
    1016    }
    1017
    1018    /**
    1019     * Recieves player health from the server and then proceeds to set it locally on the client.
    1020     */
    1021    public void handleUpdateHealth(Packet8UpdateHealth par1Packet8UpdateHealth)
    1022    {
    1023        this.mc.thePlayer.setHealth(par1Packet8UpdateHealth.healthMP);
    1024        this.mc.thePlayer.getFoodStats().setFoodLevel(par1Packet8UpdateHealth.food);
    1025        this.mc.thePlayer.getFoodStats().setFoodSaturationLevel(par1Packet8UpdateHealth.foodSaturation);
    1026    }
    1027
    1028    /**
    1029     * Handle an experience packet.
    1030     */
    1031    public void handleExperience(Packet43Experience par1Packet43Experience)
    1032    {
    1033        this.mc.thePlayer.setXPStats(par1Packet43Experience.experience, par1Packet43Experience.experienceTotal, par1Packet43Experience.experienceLevel);
    1034    }
    1035
    1036    /**
    1037     * respawns the player
    1038     */
    1039    public void handleRespawn(Packet9Respawn par1Packet9Respawn)
    1040    {
    1041        if (par1Packet9Respawn.respawnDimension != this.mc.thePlayer.dimension)
    1042        {
    1043            this.doneLoadingTerrain = false;
    1044            Scoreboard scoreboard = this.worldClient.getScoreboard();
    1045            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, this.mc.getLogAgent());
    1046            this.worldClient.func_96443_a(scoreboard);
    1047            this.worldClient.isRemote = true;
    1048            this.mc.loadWorld(this.worldClient);
    1049            this.mc.thePlayer.dimension = par1Packet9Respawn.respawnDimension;
    1050            this.mc.displayGuiScreen(new GuiDownloadTerrain(this));
    1051        }
    1052
    1053        this.mc.setDimensionAndSpawnPlayer(par1Packet9Respawn.respawnDimension);
    1054        this.mc.playerController.setGameType(par1Packet9Respawn.gameType);
    1055    }
    1056
    1057    public void handleExplosion(Packet60Explosion par1Packet60Explosion)
    1058    {
    1059        Explosion explosion = new Explosion(this.mc.theWorld, (Entity)null, par1Packet60Explosion.explosionX, par1Packet60Explosion.explosionY, par1Packet60Explosion.explosionZ, par1Packet60Explosion.explosionSize);
    1060        explosion.affectedBlockPositions = par1Packet60Explosion.chunkPositionRecords;
    1061        explosion.doExplosionB(true);
    1062        this.mc.thePlayer.motionX += (double)par1Packet60Explosion.getPlayerVelocityX();
    1063        this.mc.thePlayer.motionY += (double)par1Packet60Explosion.getPlayerVelocityY();
    1064        this.mc.thePlayer.motionZ += (double)par1Packet60Explosion.getPlayerVelocityZ();
    1065    }
    1066
    1067    public void handleOpenWindow(Packet100OpenWindow par1Packet100OpenWindow)
    1068    {
    1069        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1070
    1071        switch (par1Packet100OpenWindow.inventoryType)
    1072        {
    1073            case 0:
    1074                entityclientplayermp.displayGUIChest(new InventoryBasic(par1Packet100OpenWindow.windowTitle, par1Packet100OpenWindow.useProvidedWindowTitle, par1Packet100OpenWindow.slotsCount));
    1075                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1076                break;
    1077            case 1:
    1078                entityclientplayermp.displayGUIWorkbench(MathHelper.floor_double(entityclientplayermp.posX), MathHelper.floor_double(entityclientplayermp.posY), MathHelper.floor_double(entityclientplayermp.posZ));
    1079                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1080                break;
    1081            case 2:
    1082                TileEntityFurnace tileentityfurnace = new TileEntityFurnace();
    1083
    1084                if (par1Packet100OpenWindow.useProvidedWindowTitle)
    1085                {
    1086                    tileentityfurnace.func_94129_a(par1Packet100OpenWindow.windowTitle);
    1087                }
    1088
    1089                entityclientplayermp.displayGUIFurnace(tileentityfurnace);
    1090                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1091                break;
    1092            case 3:
    1093                TileEntityDispenser tileentitydispenser = new TileEntityDispenser();
    1094
    1095                if (par1Packet100OpenWindow.useProvidedWindowTitle)
    1096                {
    1097                    tileentitydispenser.func_94049_a(par1Packet100OpenWindow.windowTitle);
    1098                }
    1099
    1100                entityclientplayermp.displayGUIDispenser(tileentitydispenser);
    1101                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1102                break;
    1103            case 4:
    1104                entityclientplayermp.displayGUIEnchantment(MathHelper.floor_double(entityclientplayermp.posX), MathHelper.floor_double(entityclientplayermp.posY), MathHelper.floor_double(entityclientplayermp.posZ), par1Packet100OpenWindow.useProvidedWindowTitle ? par1Packet100OpenWindow.windowTitle : null);
    1105                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1106                break;
    1107            case 5:
    1108                TileEntityBrewingStand tileentitybrewingstand = new TileEntityBrewingStand();
    1109
    1110                if (par1Packet100OpenWindow.useProvidedWindowTitle)
    1111                {
    1112                    tileentitybrewingstand.func_94131_a(par1Packet100OpenWindow.windowTitle);
    1113                }
    1114
    1115                entityclientplayermp.displayGUIBrewingStand(tileentitybrewingstand);
    1116                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1117                break;
    1118            case 6:
    1119                entityclientplayermp.displayGUIMerchant(new NpcMerchant(entityclientplayermp), par1Packet100OpenWindow.useProvidedWindowTitle ? par1Packet100OpenWindow.windowTitle : null);
    1120                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1121                break;
    1122            case 7:
    1123                TileEntityBeacon tileentitybeacon = new TileEntityBeacon();
    1124                entityclientplayermp.displayGUIBeacon(tileentitybeacon);
    1125
    1126                if (par1Packet100OpenWindow.useProvidedWindowTitle)
    1127                {
    1128                    tileentitybeacon.func_94047_a(par1Packet100OpenWindow.windowTitle);
    1129                }
    1130
    1131                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1132                break;
    1133            case 8:
    1134                entityclientplayermp.displayGUIAnvil(MathHelper.floor_double(entityclientplayermp.posX), MathHelper.floor_double(entityclientplayermp.posY), MathHelper.floor_double(entityclientplayermp.posZ));
    1135                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1136                break;
    1137            case 9:
    1138                TileEntityHopper tileentityhopper = new TileEntityHopper();
    1139
    1140                if (par1Packet100OpenWindow.useProvidedWindowTitle)
    1141                {
    1142                    tileentityhopper.func_96115_a(par1Packet100OpenWindow.windowTitle);
    1143                }
    1144
    1145                entityclientplayermp.func_94064_a(tileentityhopper);
    1146                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1147                break;
    1148            case 10:
    1149                TileEntityDropper tileentitydropper = new TileEntityDropper();
    1150
    1151                if (par1Packet100OpenWindow.useProvidedWindowTitle)
    1152                {
    1153                    tileentitydropper.func_94049_a(par1Packet100OpenWindow.windowTitle);
    1154                }
    1155
    1156                entityclientplayermp.displayGUIDispenser(tileentitydropper);
    1157                entityclientplayermp.openContainer.windowId = par1Packet100OpenWindow.windowId;
    1158        }
    1159    }
    1160
    1161    public void handleSetSlot(Packet103SetSlot par1Packet103SetSlot)
    1162    {
    1163        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1164
    1165        if (par1Packet103SetSlot.windowId == -1)
    1166        {
    1167            entityclientplayermp.inventory.setItemStack(par1Packet103SetSlot.myItemStack);
    1168        }
    1169        else
    1170        {
    1171            boolean flag = false;
    1172
    1173            if (this.mc.currentScreen instanceof GuiContainerCreative)
    1174            {
    1175                GuiContainerCreative guicontainercreative = (GuiContainerCreative)this.mc.currentScreen;
    1176                flag = guicontainercreative.func_74230_h() != CreativeTabs.tabInventory.getTabIndex();
    1177            }
    1178
    1179            if (par1Packet103SetSlot.windowId == 0 && par1Packet103SetSlot.itemSlot >= 36 && par1Packet103SetSlot.itemSlot < 45)
    1180            {
    1181                ItemStack itemstack = entityclientplayermp.inventoryContainer.getSlot(par1Packet103SetSlot.itemSlot).getStack();
    1182
    1183                if (par1Packet103SetSlot.myItemStack != null && (itemstack == null || itemstack.stackSize < par1Packet103SetSlot.myItemStack.stackSize))
    1184                {
    1185                    par1Packet103SetSlot.myItemStack.animationsToGo = 5;
    1186                }
    1187
    1188                entityclientplayermp.inventoryContainer.putStackInSlot(par1Packet103SetSlot.itemSlot, par1Packet103SetSlot.myItemStack);
    1189            }
    1190            else if (par1Packet103SetSlot.windowId == entityclientplayermp.openContainer.windowId && (par1Packet103SetSlot.windowId != 0 || !flag))
    1191            {
    1192                entityclientplayermp.openContainer.putStackInSlot(par1Packet103SetSlot.itemSlot, par1Packet103SetSlot.myItemStack);
    1193            }
    1194        }
    1195    }
    1196
    1197    public void handleTransaction(Packet106Transaction par1Packet106Transaction)
    1198    {
    1199        Container container = null;
    1200        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1201
    1202        if (par1Packet106Transaction.windowId == 0)
    1203        {
    1204            container = entityclientplayermp.inventoryContainer;
    1205        }
    1206        else if (par1Packet106Transaction.windowId == entityclientplayermp.openContainer.windowId)
    1207        {
    1208            container = entityclientplayermp.openContainer;
    1209        }
    1210
    1211        if (container != null && !par1Packet106Transaction.accepted)
    1212        {
    1213            this.addToSendQueue(new Packet106Transaction(par1Packet106Transaction.windowId, par1Packet106Transaction.shortWindowId, true));
    1214        }
    1215    }
    1216
    1217    public void handleWindowItems(Packet104WindowItems par1Packet104WindowItems)
    1218    {
    1219        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1220
    1221        if (par1Packet104WindowItems.windowId == 0)
    1222        {
    1223            entityclientplayermp.inventoryContainer.putStacksInSlots(par1Packet104WindowItems.itemStack);
    1224        }
    1225        else if (par1Packet104WindowItems.windowId == entityclientplayermp.openContainer.windowId)
    1226        {
    1227            entityclientplayermp.openContainer.putStacksInSlots(par1Packet104WindowItems.itemStack);
    1228        }
    1229    }
    1230
    1231    /**
    1232     * Updates Client side signs
    1233     */
    1234    public void handleUpdateSign(Packet130UpdateSign par1Packet130UpdateSign)
    1235    {
    1236        boolean flag = false;
    1237
    1238        if (this.mc.theWorld.blockExists(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition))
    1239        {
    1240            TileEntity tileentity = this.mc.theWorld.getBlockTileEntity(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition);
    1241
    1242            if (tileentity instanceof TileEntitySign)
    1243            {
    1244                TileEntitySign tileentitysign = (TileEntitySign)tileentity;
    1245
    1246                if (tileentitysign.isEditable())
    1247                {
    1248                    for (int i = 0; i < 4; ++i)
    1249                    {
    1250                        tileentitysign.signText[i] = par1Packet130UpdateSign.signLines[i];
    1251                    }
    1252
    1253                    tileentitysign.onInventoryChanged();
    1254                }
    1255
    1256                flag = true;
    1257            }
    1258        }
    1259
    1260        if (!flag && this.mc.thePlayer != null)
    1261        {
    1262            this.mc.thePlayer.sendChatToPlayer("Unable to locate sign at " + par1Packet130UpdateSign.xPosition + ", " + par1Packet130UpdateSign.yPosition + ", " + par1Packet130UpdateSign.zPosition);
    1263        }
    1264    }
    1265
    1266    public void handleTileEntityData(Packet132TileEntityData par1Packet132TileEntityData)
    1267    {
    1268        if (this.mc.theWorld.blockExists(par1Packet132TileEntityData.xPosition, par1Packet132TileEntityData.yPosition, par1Packet132TileEntityData.zPosition))
    1269        {
    1270            TileEntity tileentity = this.mc.theWorld.getBlockTileEntity(par1Packet132TileEntityData.xPosition, par1Packet132TileEntityData.yPosition, par1Packet132TileEntityData.zPosition);
    1271
    1272            if (tileentity != null)
    1273            {
    1274                if (par1Packet132TileEntityData.actionType == 1 && tileentity instanceof TileEntityMobSpawner)
    1275                {
    1276                    tileentity.readFromNBT(par1Packet132TileEntityData.customParam1);
    1277                }
    1278                else if (par1Packet132TileEntityData.actionType == 2 && tileentity instanceof TileEntityCommandBlock)
    1279                {
    1280                    tileentity.readFromNBT(par1Packet132TileEntityData.customParam1);
    1281                }
    1282                else if (par1Packet132TileEntityData.actionType == 3 && tileentity instanceof TileEntityBeacon)
    1283                {
    1284                    tileentity.readFromNBT(par1Packet132TileEntityData.customParam1);
    1285                }
    1286                else if (par1Packet132TileEntityData.actionType == 4 && tileentity instanceof TileEntitySkull)
    1287                {
    1288                    tileentity.readFromNBT(par1Packet132TileEntityData.customParam1);
    1289                }
    1290                else
    1291                {
    1292                    tileentity.onDataPacket(netManager,  par1Packet132TileEntityData);
    1293                }
    1294            }
    1295        }
    1296    }
    1297
    1298    public void handleUpdateProgressbar(Packet105UpdateProgressbar par1Packet105UpdateProgressbar)
    1299    {
    1300        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1301        this.unexpectedPacket(par1Packet105UpdateProgressbar);
    1302
    1303        if (entityclientplayermp.openContainer != null && entityclientplayermp.openContainer.windowId == par1Packet105UpdateProgressbar.windowId)
    1304        {
    1305            entityclientplayermp.openContainer.updateProgressBar(par1Packet105UpdateProgressbar.progressBar, par1Packet105UpdateProgressbar.progressBarValue);
    1306        }
    1307    }
    1308
    1309    public void handlePlayerInventory(Packet5PlayerInventory par1Packet5PlayerInventory)
    1310    {
    1311        Entity entity = this.getEntityByID(par1Packet5PlayerInventory.entityID);
    1312
    1313        if (entity != null)
    1314        {
    1315            entity.setCurrentItemOrArmor(par1Packet5PlayerInventory.slot, par1Packet5PlayerInventory.getItemSlot());
    1316        }
    1317    }
    1318
    1319    public void handleCloseWindow(Packet101CloseWindow par1Packet101CloseWindow)
    1320    {
    1321        this.mc.thePlayer.func_92015_f();
    1322    }
    1323
    1324    public void handleBlockEvent(Packet54PlayNoteBlock par1Packet54PlayNoteBlock)
    1325    {
    1326        this.mc.theWorld.addBlockEvent(par1Packet54PlayNoteBlock.xLocation, par1Packet54PlayNoteBlock.yLocation, par1Packet54PlayNoteBlock.zLocation, par1Packet54PlayNoteBlock.blockId, par1Packet54PlayNoteBlock.instrumentType, par1Packet54PlayNoteBlock.pitch);
    1327    }
    1328
    1329    public void handleBlockDestroy(Packet55BlockDestroy par1Packet55BlockDestroy)
    1330    {
    1331        this.mc.theWorld.destroyBlockInWorldPartially(par1Packet55BlockDestroy.getEntityId(), par1Packet55BlockDestroy.getPosX(), par1Packet55BlockDestroy.getPosY(), par1Packet55BlockDestroy.getPosZ(), par1Packet55BlockDestroy.getDestroyedStage());
    1332    }
    1333
    1334    public void handleMapChunks(Packet56MapChunks par1Packet56MapChunks)
    1335    {
    1336        for (int i = 0; i < par1Packet56MapChunks.getNumberOfChunkInPacket(); ++i)
    1337        {
    1338            int j = par1Packet56MapChunks.getChunkPosX(i);
    1339            int k = par1Packet56MapChunks.getChunkPosZ(i);
    1340            this.worldClient.doPreChunk(j, k, true);
    1341            this.worldClient.invalidateBlockReceiveRegion(j << 4, 0, k << 4, (j << 4) + 15, 256, (k << 4) + 15);
    1342            Chunk chunk = this.worldClient.getChunkFromChunkCoords(j, k);
    1343
    1344            if (chunk == null)
    1345            {
    1346                this.worldClient.doPreChunk(j, k, true);
    1347                chunk = this.worldClient.getChunkFromChunkCoords(j, k);
    1348            }
    1349
    1350            if (chunk != null)
    1351            {
    1352                chunk.fillChunk(par1Packet56MapChunks.getChunkCompressedData(i), par1Packet56MapChunks.field_73590_a[i], par1Packet56MapChunks.field_73588_b[i], true);
    1353                this.worldClient.markBlockRangeForRenderUpdate(j << 4, 0, k << 4, (j << 4) + 15, 256, (k << 4) + 15);
    1354
    1355                if (!(this.worldClient.provider instanceof WorldProviderSurface))
    1356                {
    1357                    chunk.resetRelightChecks();
    1358                }
    1359            }
    1360        }
    1361    }
    1362
    1363    /**
    1364     * If this returns false, all packets will be queued for the main thread to handle, even if they would otherwise be
    1365     * processed asynchronously. Used to avoid processing packets on the client before the world has been downloaded
    1366     * (which happens on the main thread)
    1367     */
    1368    public boolean canProcessPacketsAsync()
    1369    {
    1370        return this.mc != null && this.mc.theWorld != null && this.mc.thePlayer != null && this.worldClient != null;
    1371    }
    1372
    1373    public void handleGameEvent(Packet70GameEvent par1Packet70GameEvent)
    1374    {
    1375        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1376        int i = par1Packet70GameEvent.eventType;
    1377        int j = par1Packet70GameEvent.gameMode;
    1378
    1379        if (i >= 0 && i < Packet70GameEvent.clientMessage.length && Packet70GameEvent.clientMessage[i] != null)
    1380        {
    1381            entityclientplayermp.addChatMessage(Packet70GameEvent.clientMessage[i]);
    1382        }
    1383
    1384        if (i == 1)
    1385        {
    1386            this.worldClient.getWorldInfo().setRaining(true);
    1387            this.worldClient.setRainStrength(0.0F);
    1388        }
    1389        else if (i == 2)
    1390        {
    1391            this.worldClient.getWorldInfo().setRaining(false);
    1392            this.worldClient.setRainStrength(1.0F);
    1393        }
    1394        else if (i == 3)
    1395        {
    1396            this.mc.playerController.setGameType(EnumGameType.getByID(j));
    1397        }
    1398        else if (i == 4)
    1399        {
    1400            this.mc.displayGuiScreen(new GuiWinGame());
    1401        }
    1402        else if (i == 5)
    1403        {
    1404            GameSettings gamesettings = this.mc.gameSettings;
    1405
    1406            if (j == 0)
    1407            {
    1408                this.mc.displayGuiScreen(new GuiScreenDemo());
    1409            }
    1410            else if (j == 101)
    1411            {
    1412                this.mc.ingameGUI.getChatGUI().addTranslatedMessage("demo.help.movement", new Object[] {Keyboard.getKeyName(gamesettings.keyBindForward.keyCode), Keyboard.getKeyName(gamesettings.keyBindLeft.keyCode), Keyboard.getKeyName(gamesettings.keyBindBack.keyCode), Keyboard.getKeyName(gamesettings.keyBindRight.keyCode)});
    1413            }
    1414            else if (j == 102)
    1415            {
    1416                this.mc.ingameGUI.getChatGUI().addTranslatedMessage("demo.help.jump", new Object[] {Keyboard.getKeyName(gamesettings.keyBindJump.keyCode)});
    1417            }
    1418            else if (j == 103)
    1419            {
    1420                this.mc.ingameGUI.getChatGUI().addTranslatedMessage("demo.help.inventory", new Object[] {Keyboard.getKeyName(gamesettings.keyBindInventory.keyCode)});
    1421            }
    1422        }
    1423        else if (i == 6)
    1424        {
    1425            this.worldClient.playSound(entityclientplayermp.posX, entityclientplayermp.posY + (double)entityclientplayermp.getEyeHeight(), entityclientplayermp.posZ, "random.successful_hit", 0.18F, 0.45F, false);
    1426        }
    1427    }
    1428
    1429    /**
    1430     * Contains logic for handling packets containing arbitrary unique item data. Currently this is only for maps.
    1431     */
    1432    public void handleMapData(Packet131MapData par1Packet131MapData)
    1433    {
    1434        FMLNetworkHandler.handlePacket131Packet(this, par1Packet131MapData);
    1435    }
    1436
    1437    public void fmlPacket131Callback(Packet131MapData par1Packet131MapData)
    1438    {
    1439        if (par1Packet131MapData.itemID == Item.map.itemID)
    1440        {
    1441            ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).updateMPMapData(par1Packet131MapData.itemData);
    1442        }
    1443        else
    1444        {
    1445            this.mc.getLogAgent().logWarning("Unknown itemid: " + par1Packet131MapData.uniqueID);
    1446        }
    1447    }
    1448
    1449    public void handleDoorChange(Packet61DoorChange par1Packet61DoorChange)
    1450    {
    1451        if (par1Packet61DoorChange.getRelativeVolumeDisabled())
    1452        {
    1453            this.mc.theWorld.func_82739_e(par1Packet61DoorChange.sfxID, par1Packet61DoorChange.posX, par1Packet61DoorChange.posY, par1Packet61DoorChange.posZ, par1Packet61DoorChange.auxData);
    1454        }
    1455        else
    1456        {
    1457            this.mc.theWorld.playAuxSFX(par1Packet61DoorChange.sfxID, par1Packet61DoorChange.posX, par1Packet61DoorChange.posY, par1Packet61DoorChange.posZ, par1Packet61DoorChange.auxData);
    1458        }
    1459    }
    1460
    1461    /**
    1462     * Increment player statistics
    1463     */
    1464    public void handleStatistic(Packet200Statistic par1Packet200Statistic)
    1465    {
    1466        this.mc.thePlayer.incrementStat(StatList.getOneShotStat(par1Packet200Statistic.statisticId), par1Packet200Statistic.amount);
    1467    }
    1468
    1469    /**
    1470     * Handle an entity effect packet.
    1471     */
    1472    public void handleEntityEffect(Packet41EntityEffect par1Packet41EntityEffect)
    1473    {
    1474        Entity entity = this.getEntityByID(par1Packet41EntityEffect.entityId);
    1475
    1476        if (entity instanceof EntityLiving)
    1477        {
    1478            PotionEffect potioneffect = new PotionEffect(par1Packet41EntityEffect.effectId, par1Packet41EntityEffect.duration, par1Packet41EntityEffect.effectAmplifier);
    1479            potioneffect.setPotionDurationMax(par1Packet41EntityEffect.isDurationMax());
    1480            ((EntityLiving)entity).addPotionEffect(potioneffect);
    1481        }
    1482    }
    1483
    1484    /**
    1485     * Handle a remove entity effect packet.
    1486     */
    1487    public void handleRemoveEntityEffect(Packet42RemoveEntityEffect par1Packet42RemoveEntityEffect)
    1488    {
    1489        Entity entity = this.getEntityByID(par1Packet42RemoveEntityEffect.entityId);
    1490
    1491        if (entity instanceof EntityLiving)
    1492        {
    1493            ((EntityLiving)entity).removePotionEffectClient(par1Packet42RemoveEntityEffect.effectId);
    1494        }
    1495    }
    1496
    1497    /**
    1498     * determine if it is a server handler
    1499     */
    1500    public boolean isServerHandler()
    1501    {
    1502        return false;
    1503    }
    1504
    1505    /**
    1506     * Handle a player information packet.
    1507     */
    1508    public void handlePlayerInfo(Packet201PlayerInfo par1Packet201PlayerInfo)
    1509    {
    1510        GuiPlayerInfo guiplayerinfo = (GuiPlayerInfo)this.playerInfoMap.get(par1Packet201PlayerInfo.playerName);
    1511
    1512        if (guiplayerinfo == null && par1Packet201PlayerInfo.isConnected)
    1513        {
    1514            guiplayerinfo = new GuiPlayerInfo(par1Packet201PlayerInfo.playerName);
    1515            this.playerInfoMap.put(par1Packet201PlayerInfo.playerName, guiplayerinfo);
    1516            this.playerInfoList.add(guiplayerinfo);
    1517        }
    1518
    1519        if (guiplayerinfo != null && !par1Packet201PlayerInfo.isConnected)
    1520        {
    1521            this.playerInfoMap.remove(par1Packet201PlayerInfo.playerName);
    1522            this.playerInfoList.remove(guiplayerinfo);
    1523        }
    1524
    1525        if (par1Packet201PlayerInfo.isConnected && guiplayerinfo != null)
    1526        {
    1527            guiplayerinfo.responseTime = par1Packet201PlayerInfo.ping;
    1528        }
    1529    }
    1530
    1531    /**
    1532     * Handle a keep alive packet.
    1533     */
    1534    public void handleKeepAlive(Packet0KeepAlive par1Packet0KeepAlive)
    1535    {
    1536        this.addToSendQueue(new Packet0KeepAlive(par1Packet0KeepAlive.randomId));
    1537    }
    1538
    1539    /**
    1540     * Handle a player abilities packet.
    1541     */
    1542    public void handlePlayerAbilities(Packet202PlayerAbilities par1Packet202PlayerAbilities)
    1543    {
    1544        EntityClientPlayerMP entityclientplayermp = this.mc.thePlayer;
    1545        entityclientplayermp.capabilities.isFlying = par1Packet202PlayerAbilities.getFlying();
    1546        entityclientplayermp.capabilities.isCreativeMode = par1Packet202PlayerAbilities.isCreativeMode();
    1547        entityclientplayermp.capabilities.disableDamage = par1Packet202PlayerAbilities.getDisableDamage();
    1548        entityclientplayermp.capabilities.allowFlying = par1Packet202PlayerAbilities.getAllowFlying();
    1549        entityclientplayermp.capabilities.setFlySpeed(par1Packet202PlayerAbilities.getFlySpeed());
    1550        entityclientplayermp.capabilities.setPlayerWalkSpeed(par1Packet202PlayerAbilities.getWalkSpeed());
    1551    }
    1552
    1553    public void handleAutoComplete(Packet203AutoComplete par1Packet203AutoComplete)
    1554    {
    1555        String[] astring = par1Packet203AutoComplete.getText().split("\u0000");
    1556
    1557        if (this.mc.currentScreen instanceof GuiChat)
    1558        {
    1559            GuiChat guichat = (GuiChat)this.mc.currentScreen;
    1560            guichat.func_73894_a(astring);
    1561        }
    1562    }
    1563
    1564    public void handleLevelSound(Packet62LevelSound par1Packet62LevelSound)
    1565    {
    1566        this.mc.theWorld.playSound(par1Packet62LevelSound.getEffectX(), par1Packet62LevelSound.getEffectY(), par1Packet62LevelSound.getEffectZ(), par1Packet62LevelSound.getSoundName(), par1Packet62LevelSound.getVolume(), par1Packet62LevelSound.getPitch(), false);
    1567    }
    1568
    1569    public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload)
    1570    {
    1571        FMLNetworkHandler.handlePacket250Packet(par1Packet250CustomPayload, netManager, this);
    1572    }
    1573
    1574    public void handleVanilla250Packet(Packet250CustomPayload par1Packet250CustomPayload)
    1575    {
    1576        if ("MC|TPack".equals(par1Packet250CustomPayload.channel))
    1577        {
    1578            String[] astring = (new String(par1Packet250CustomPayload.data)).split("\u0000");
    1579            String s = astring[0];
    1580
    1581            if (astring[1].equals("16"))
    1582            {
    1583                if (this.mc.texturePackList.getAcceptsTextures())
    1584                {
    1585                    this.mc.texturePackList.requestDownloadOfTexture(s);
    1586                }
    1587                else if (this.mc.texturePackList.func_77300_f())
    1588                {
    1589                    this.mc.displayGuiScreen(new GuiYesNo(new NetClientWebTextures(this, s), StringTranslate.getInstance().translateKey("multiplayer.texturePrompt.line1"), StringTranslate.getInstance().translateKey("multiplayer.texturePrompt.line2"), 0));
    1590                }
    1591            }
    1592        }
    1593        else if ("MC|TrList".equals(par1Packet250CustomPayload.channel))
    1594        {
    1595            DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1596
    1597            try
    1598            {
    1599                int i = datainputstream.readInt();
    1600                GuiScreen guiscreen = this.mc.currentScreen;
    1601
    1602                if (guiscreen != null && guiscreen instanceof GuiMerchant && i == this.mc.thePlayer.openContainer.windowId)
    1603                {
    1604                    IMerchant imerchant = ((GuiMerchant)guiscreen).getIMerchant();
    1605                    MerchantRecipeList merchantrecipelist = MerchantRecipeList.readRecipiesFromStream(datainputstream);
    1606                    imerchant.setRecipes(merchantrecipelist);
    1607                }
    1608            }
    1609            catch (IOException ioexception)
    1610            {
    1611                ioexception.printStackTrace();
    1612            }
    1613        }
    1614    }
    1615
    1616    /**
    1617     * Handle a set objective packet.
    1618     */
    1619    public void handleSetObjective(Packet206SetObjective par1Packet206SetObjective)
    1620    {
    1621        Scoreboard scoreboard = this.worldClient.getScoreboard();
    1622        ScoreObjective scoreobjective;
    1623
    1624        if (par1Packet206SetObjective.change == 0)
    1625        {
    1626            scoreobjective = scoreboard.func_96535_a(par1Packet206SetObjective.objectiveName, ScoreObjectiveCriteria.field_96641_b);
    1627            scoreobjective.setDisplayName(par1Packet206SetObjective.objectiveDisplayName);
    1628        }
    1629        else
    1630        {
    1631            scoreobjective = scoreboard.getObjective(par1Packet206SetObjective.objectiveName);
    1632
    1633            if (par1Packet206SetObjective.change == 1)
    1634            {
    1635                scoreboard.func_96519_k(scoreobjective);
    1636            }
    1637            else if (par1Packet206SetObjective.change == 2)
    1638            {
    1639                scoreobjective.setDisplayName(par1Packet206SetObjective.objectiveDisplayName);
    1640            }
    1641        }
    1642    }
    1643
    1644    /**
    1645     * Handle a set score packet.
    1646     */
    1647    public void handleSetScore(Packet207SetScore par1Packet207SetScore)
    1648    {
    1649        Scoreboard scoreboard = this.worldClient.getScoreboard();
    1650        ScoreObjective scoreobjective = scoreboard.getObjective(par1Packet207SetScore.scoreName);
    1651
    1652        if (par1Packet207SetScore.updateOrRemove == 0)
    1653        {
    1654            Score score = scoreboard.func_96529_a(par1Packet207SetScore.itemName, scoreobjective);
    1655            score.func_96647_c(par1Packet207SetScore.value);
    1656        }
    1657        else if (par1Packet207SetScore.updateOrRemove == 1)
    1658        {
    1659            scoreboard.func_96515_c(par1Packet207SetScore.itemName);
    1660        }
    1661    }
    1662
    1663    /**
    1664     * Handle a set display objective packet.
    1665     */
    1666    public void handleSetDisplayObjective(Packet208SetDisplayObjective par1Packet208SetDisplayObjective)
    1667    {
    1668        Scoreboard scoreboard = this.worldClient.getScoreboard();
    1669
    1670        if (par1Packet208SetDisplayObjective.scoreName.length() == 0)
    1671        {
    1672            scoreboard.func_96530_a(par1Packet208SetDisplayObjective.scoreboardPosition, (ScoreObjective)null);
    1673        }
    1674        else
    1675        {
    1676            ScoreObjective scoreobjective = scoreboard.getObjective(par1Packet208SetDisplayObjective.scoreName);
    1677            scoreboard.func_96530_a(par1Packet208SetDisplayObjective.scoreboardPosition, scoreobjective);
    1678        }
    1679    }
    1680
    1681    /**
    1682     * Handle a set player team packet.
    1683     */
    1684    public void handleSetPlayerTeam(Packet209SetPlayerTeam par1Packet209SetPlayerTeam)
    1685    {
    1686        Scoreboard scoreboard = this.worldClient.getScoreboard();
    1687        ScorePlayerTeam scoreplayerteam;
    1688
    1689        if (par1Packet209SetPlayerTeam.mode == 0)
    1690        {
    1691            scoreplayerteam = scoreboard.func_96527_f(par1Packet209SetPlayerTeam.teamName);
    1692        }
    1693        else
    1694        {
    1695            scoreplayerteam = scoreboard.func_96508_e(par1Packet209SetPlayerTeam.teamName);
    1696        }
    1697
    1698        if (par1Packet209SetPlayerTeam.mode == 0 || par1Packet209SetPlayerTeam.mode == 2)
    1699        {
    1700            scoreplayerteam.func_96664_a(par1Packet209SetPlayerTeam.teamDisplayName);
    1701            scoreplayerteam.func_96666_b(par1Packet209SetPlayerTeam.teamPrefix);
    1702            scoreplayerteam.func_96662_c(par1Packet209SetPlayerTeam.teamSuffix);
    1703            scoreplayerteam.func_98298_a(par1Packet209SetPlayerTeam.friendlyFire);
    1704        }
    1705
    1706        Iterator iterator;
    1707        String s;
    1708
    1709        if (par1Packet209SetPlayerTeam.mode == 0 || par1Packet209SetPlayerTeam.mode == 3)
    1710        {
    1711            iterator = par1Packet209SetPlayerTeam.playerNames.iterator();
    1712
    1713            while (iterator.hasNext())
    1714            {
    1715                s = (String)iterator.next();
    1716                scoreboard.func_96521_a(s, scoreplayerteam);
    1717            }
    1718        }
    1719
    1720        if (par1Packet209SetPlayerTeam.mode == 4)
    1721        {
    1722            iterator = par1Packet209SetPlayerTeam.playerNames.iterator();
    1723
    1724            while (iterator.hasNext())
    1725            {
    1726                s = (String)iterator.next();
    1727                scoreboard.func_96512_b(s, scoreplayerteam);
    1728            }
    1729        }
    1730
    1731        if (par1Packet209SetPlayerTeam.mode == 1)
    1732        {
    1733            scoreboard.func_96511_d(scoreplayerteam);
    1734        }
    1735    }
    1736
    1737    /**
    1738     * Handle a world particles packet.
    1739     */
    1740    public void handleWorldParticles(Packet63WorldParticles par1Packet63WorldParticles)
    1741    {
    1742        for (int i = 0; i < par1Packet63WorldParticles.getQuantity(); ++i)
    1743        {
    1744            double d0 = this.rand.nextGaussian() * (double)par1Packet63WorldParticles.getOffsetX();
    1745            double d1 = this.rand.nextGaussian() * (double)par1Packet63WorldParticles.getOffsetY();
    1746            double d2 = this.rand.nextGaussian() * (double)par1Packet63WorldParticles.getOffsetZ();
    1747            double d3 = this.rand.nextGaussian() * (double)par1Packet63WorldParticles.getSpeed();
    1748            double d4 = this.rand.nextGaussian() * (double)par1Packet63WorldParticles.getSpeed();
    1749            double d5 = this.rand.nextGaussian() * (double)par1Packet63WorldParticles.getSpeed();
    1750            this.worldClient.spawnParticle(par1Packet63WorldParticles.getParticleName(), par1Packet63WorldParticles.getPositionX() + d0, par1Packet63WorldParticles.getPositionY() + d1, par1Packet63WorldParticles.getPositionZ() + d2, d3, d4, d5);
    1751        }
    1752    }
    1753
    1754    /**
    1755     * Return the NetworkManager instance used by this NetClientHandler
    1756     */
    1757    public INetworkManager getNetManager()
    1758    {
    1759        return this.netManager;
    1760    }
    1761
    1762    @Override
    1763    public EntityPlayer getPlayer()
    1764    {
    1765        return mc.thePlayer;
    1766    }
    1767
    1768    public static void setConnectionCompatibilityLevel(byte connectionCompatibilityLevel)
    1769    {
    1770        NetClientHandler.connectionCompatibilityLevel = connectionCompatibilityLevel;
    1771    }
    1772
    1773    public static byte getConnectionCompatibilityLevel()
    1774    {
    1775        return connectionCompatibilityLevel;
    1776    }
    1777}