001 package net.minecraft.network.packet; 002 003 import java.io.DataInputStream; 004 import java.io.DataOutputStream; 005 import java.io.IOException; 006 import net.minecraft.entity.Entity; 007 008 public class Packet28EntityVelocity extends Packet 009 { 010 public int entityId; 011 public int motionX; 012 public int motionY; 013 public int motionZ; 014 015 public Packet28EntityVelocity() {} 016 017 public Packet28EntityVelocity(Entity par1Entity) 018 { 019 this(par1Entity.entityId, par1Entity.motionX, par1Entity.motionY, par1Entity.motionZ); 020 } 021 022 public Packet28EntityVelocity(int par1, double par2, double par4, double par6) 023 { 024 this.entityId = par1; 025 double var8 = 3.9D; 026 027 if (par2 < -var8) 028 { 029 par2 = -var8; 030 } 031 032 if (par4 < -var8) 033 { 034 par4 = -var8; 035 } 036 037 if (par6 < -var8) 038 { 039 par6 = -var8; 040 } 041 042 if (par2 > var8) 043 { 044 par2 = var8; 045 } 046 047 if (par4 > var8) 048 { 049 par4 = var8; 050 } 051 052 if (par6 > var8) 053 { 054 par6 = var8; 055 } 056 057 this.motionX = (int)(par2 * 8000.0D); 058 this.motionY = (int)(par4 * 8000.0D); 059 this.motionZ = (int)(par6 * 8000.0D); 060 } 061 062 /** 063 * Abstract. Reads the raw packet data from the data stream. 064 */ 065 public void readPacketData(DataInputStream par1DataInputStream) throws IOException 066 { 067 this.entityId = par1DataInputStream.readInt(); 068 this.motionX = par1DataInputStream.readShort(); 069 this.motionY = par1DataInputStream.readShort(); 070 this.motionZ = par1DataInputStream.readShort(); 071 } 072 073 /** 074 * Abstract. Writes the raw packet data to the data stream. 075 */ 076 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException 077 { 078 par1DataOutputStream.writeInt(this.entityId); 079 par1DataOutputStream.writeShort(this.motionX); 080 par1DataOutputStream.writeShort(this.motionY); 081 par1DataOutputStream.writeShort(this.motionZ); 082 } 083 084 /** 085 * Passes this Packet on to the NetHandler for processing. 086 */ 087 public void processPacket(NetHandler par1NetHandler) 088 { 089 par1NetHandler.handleEntityVelocity(this); 090 } 091 092 /** 093 * Abstract. Return the size of the packet (not counting the header). 094 */ 095 public int getPacketSize() 096 { 097 return 10; 098 } 099 100 /** 101 * only false for the abstract Packet class, all real packets return true 102 */ 103 public boolean isRealPacket() 104 { 105 return true; 106 } 107 108 /** 109 * eg return packet30entity.entityId == entityId; WARNING : will throw if you compare a packet to a different packet 110 * class 111 */ 112 public boolean containsSameEntityIDAs(Packet par1Packet) 113 { 114 Packet28EntityVelocity var2 = (Packet28EntityVelocity)par1Packet; 115 return var2.entityId == this.entityId; 116 } 117 }