    001    package net.minecraft.src;
    002
    003    import java.io.ByteArrayOutputStream;
    004    import java.io.DataInputStream;
    005    import java.io.DataOutputStream;
    006    import java.io.IOException;
    007
    008    public class Packet52MultiBlockChange extends Packet
    009    {
    010        /** Chunk X position. */
    011        public int xPosition;
    012
    013        /** Chunk Z position. */
    014        public int zPosition;
    015
    016        /** The metadata for each block changed. */
    017        public byte[] metadataArray;
    018
    019        /** The size of the arrays. */
    020        public int size;
    021        private static byte[] field_73449_e = new byte[0];
    022
    023        public Packet52MultiBlockChange()
    024        {
    025            this.isChunkDataPacket = true;
    026        }
    027
    028        public Packet52MultiBlockChange(int par1, int par2, short[] par3ArrayOfShort, int par4, World par5World)
    029        {
    030            this.isChunkDataPacket = true;
    031            this.xPosition = par1;
    032            this.zPosition = par2;
    033            this.size = par4;
    034            int var6 = 4 * par4;
    035            Chunk var7 = par5World.getChunkFromChunkCoords(par1, par2);
    036
    037            try
    038            {
    039                if (par4 >= 64)
    040                {
    041                    System.out.println("ChunkTilesUpdatePacket compress " + par4);
    042
    043                    if (field_73449_e.length < var6)
    044                    {
    045                        field_73449_e = new byte[var6];
    046                    }
    047                }
    048                else
    049                {
    050                    ByteArrayOutputStream var8 = new ByteArrayOutputStream(var6);
    051                    DataOutputStream var9 = new DataOutputStream(var8);
    052
    053                    for (int var10 = 0; var10 < par4; ++var10)
    054                    {
    055                        int var11 = par3ArrayOfShort[var10] >> 12 & 15;
    056                        int var12 = par3ArrayOfShort[var10] >> 8 & 15;
    057                        int var13 = par3ArrayOfShort[var10] & 255;
    058                        var9.writeShort(par3ArrayOfShort[var10]);
    059                        var9.writeShort((short)((var7.getBlockID(var11, var13, var12) & 4095) << 4 | var7.getBlockMetadata(var11, var13, var12) & 15));
    060                    }
    061
    062                    this.metadataArray = var8.toByteArray();
    063
    064                    if (this.metadataArray.length != var6)
    065                    {
    066                        throw new RuntimeException("Expected length " + var6 + " doesn\'t match received length " + this.metadataArray.length);
    067                    }
    068                }
    069            }
    070            catch (IOException var14)
    071            {
    072                System.err.println(var14.getMessage());
    073                this.metadataArray = null;
    074            }
    075        }
    076
    077        /**
    078         * Abstract. Reads the raw packet data from the data stream.
    079         */
    080        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    081        {
    082            this.xPosition = par1DataInputStream.readInt();
    083            this.zPosition = par1DataInputStream.readInt();
    084            this.size = par1DataInputStream.readShort() & 65535;
    085            int var2 = par1DataInputStream.readInt();
    086
    087            if (var2 > 0)
    088            {
    089                this.metadataArray = new byte[var2];
    090                par1DataInputStream.readFully(this.metadataArray);
    091            }
    092        }
    093
    094        /**
    095         * Abstract. Writes the raw packet data to the data stream.
    096         */
    097        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    098        {
    099            par1DataOutputStream.writeInt(this.xPosition);
    100            par1DataOutputStream.writeInt(this.zPosition);
    101            par1DataOutputStream.writeShort((short)this.size);
    102
    103            if (this.metadataArray != null)
    104            {
    105                par1DataOutputStream.writeInt(this.metadataArray.length);
    106                par1DataOutputStream.write(this.metadataArray);
    107            }
    108            else
    109            {
    110                par1DataOutputStream.writeInt(0);
    111            }
    112        }
    113
    114        /**
    115         * Passes this Packet on to the NetHandler for processing.
    116         */
    117        public void processPacket(NetHandler par1NetHandler)
    118        {
    119            par1NetHandler.handleMultiBlockChange(this);
    120        }
    121
    122        /**
    123         * Abstract. Return the size of the packet (not counting the header).
    124         */
    125        public int getPacketSize()
    126        {
    127            return 10 + this.size * 4;
    128        }
    129    }