001package net.minecraft.network.packet; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.io.DataInputStream; 006import java.io.DataOutputStream; 007import java.io.IOException; 008import java.util.ArrayList; 009import java.util.Iterator; 010import java.util.List; 011import net.minecraft.util.Vec3; 012import net.minecraft.world.ChunkPosition; 013 014public class Packet60Explosion extends Packet 015{ 016 public double explosionX; 017 public double explosionY; 018 public double explosionZ; 019 public float explosionSize; 020 public List chunkPositionRecords; 021 022 /** X velocity of the player being pushed by the explosion */ 023 private float playerVelocityX; 024 025 /** Y velocity of the player being pushed by the explosion */ 026 private float playerVelocityY; 027 028 /** Z velocity of the player being pushed by the explosion */ 029 private float playerVelocityZ; 030 031 public Packet60Explosion() {} 032 033 public Packet60Explosion(double par1, double par3, double par5, float par7, List par8List, Vec3 par9Vec3) 034 { 035 this.explosionX = par1; 036 this.explosionY = par3; 037 this.explosionZ = par5; 038 this.explosionSize = par7; 039 this.chunkPositionRecords = new ArrayList(par8List); 040 041 if (par9Vec3 != null) 042 { 043 this.playerVelocityX = (float)par9Vec3.xCoord; 044 this.playerVelocityY = (float)par9Vec3.yCoord; 045 this.playerVelocityZ = (float)par9Vec3.zCoord; 046 } 047 } 048 049 /** 050 * Abstract. Reads the raw packet data from the data stream. 051 */ 052 public void readPacketData(DataInputStream par1DataInputStream) throws IOException 053 { 054 this.explosionX = par1DataInputStream.readDouble(); 055 this.explosionY = par1DataInputStream.readDouble(); 056 this.explosionZ = par1DataInputStream.readDouble(); 057 this.explosionSize = par1DataInputStream.readFloat(); 058 int i = par1DataInputStream.readInt(); 059 this.chunkPositionRecords = new ArrayList(i); 060 int j = (int)this.explosionX; 061 int k = (int)this.explosionY; 062 int l = (int)this.explosionZ; 063 064 for (int i1 = 0; i1 < i; ++i1) 065 { 066 int j1 = par1DataInputStream.readByte() + j; 067 int k1 = par1DataInputStream.readByte() + k; 068 int l1 = par1DataInputStream.readByte() + l; 069 this.chunkPositionRecords.add(new ChunkPosition(j1, k1, l1)); 070 } 071 072 this.playerVelocityX = par1DataInputStream.readFloat(); 073 this.playerVelocityY = par1DataInputStream.readFloat(); 074 this.playerVelocityZ = par1DataInputStream.readFloat(); 075 } 076 077 /** 078 * Abstract. Writes the raw packet data to the data stream. 079 */ 080 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException 081 { 082 par1DataOutputStream.writeDouble(this.explosionX); 083 par1DataOutputStream.writeDouble(this.explosionY); 084 par1DataOutputStream.writeDouble(this.explosionZ); 085 par1DataOutputStream.writeFloat(this.explosionSize); 086 par1DataOutputStream.writeInt(this.chunkPositionRecords.size()); 087 int i = (int)this.explosionX; 088 int j = (int)this.explosionY; 089 int k = (int)this.explosionZ; 090 Iterator iterator = this.chunkPositionRecords.iterator(); 091 092 while (iterator.hasNext()) 093 { 094 ChunkPosition chunkposition = (ChunkPosition)iterator.next(); 095 int l = chunkposition.x - i; 096 int i1 = chunkposition.y - j; 097 int j1 = chunkposition.z - k; 098 par1DataOutputStream.writeByte(l); 099 par1DataOutputStream.writeByte(i1); 100 par1DataOutputStream.writeByte(j1); 101 } 102 103 par1DataOutputStream.writeFloat(this.playerVelocityX); 104 par1DataOutputStream.writeFloat(this.playerVelocityY); 105 par1DataOutputStream.writeFloat(this.playerVelocityZ); 106 } 107 108 /** 109 * Passes this Packet on to the NetHandler for processing. 110 */ 111 public void processPacket(NetHandler par1NetHandler) 112 { 113 par1NetHandler.handleExplosion(this); 114 } 115 116 /** 117 * Abstract. Return the size of the packet (not counting the header). 118 */ 119 public int getPacketSize() 120 { 121 return 32 + this.chunkPositionRecords.size() * 3 + 3; 122 } 123 124 @SideOnly(Side.CLIENT) 125 126 /** 127 * Gets the X velocity of the player being pushed by the explosion. 128 */ 129 public float getPlayerVelocityX() 130 { 131 return this.playerVelocityX; 132 } 133 134 @SideOnly(Side.CLIENT) 135 136 /** 137 * Gets the Y velocity of the player being pushed by the explosion. 138 */ 139 public float getPlayerVelocityY() 140 { 141 return this.playerVelocityY; 142 } 143 144 @SideOnly(Side.CLIENT) 145 146 /** 147 * Gets the Z velocity of the player being pushed by the explosion. 148 */ 149 public float getPlayerVelocityZ() 150 { 151 return this.playerVelocityZ; 152 } 153}