Advertisement
Guest User

Packet24MobSpawn

a guest
Sep 2nd, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.17 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.util.List;
  7.  
  8. public class Packet24MobSpawn extends Packet {
  9.     /** The entity ID. */
  10.     public int entityId;
  11.  
  12.     /** The type of mob. */
  13.     public int type;
  14.  
  15.     /** The X position of the entity. */
  16.     public int xPosition;
  17.  
  18.     /** The Y position of the entity. */
  19.     public int yPosition;
  20.  
  21.     /** The Z position of the entity. */
  22.     public int zPosition;
  23.     public int velocityX;
  24.     public int velocityY;
  25.     public int velocityZ;
  26.  
  27.     /** The yaw of the entity. */
  28.     public byte yaw;
  29.  
  30.     /** The pitch of the entity. */
  31.     public byte pitch;
  32.  
  33.     /** The yaw of the entity's head. */
  34.     public byte headYaw;
  35.  
  36.     /** Indexed metadata for Mob, terminated by 0x7F */
  37.     private DataWatcher metaData;
  38.     private List metadata;
  39.  
  40.     public Packet24MobSpawn() {
  41.     }
  42.  
  43.     public Packet24MobSpawn(EntityLiving par1EntityLiving) {
  44.         this.entityId = par1EntityLiving.entityId;
  45.         this.type = (byte) EntityList.getEntityID(par1EntityLiving) & 255;
  46.         this.xPosition = par1EntityLiving.myEntitySize
  47.                 .multiplyBy32AndRound(par1EntityLiving.posX);
  48.         this.yPosition = MathHelper.floor_double(par1EntityLiving.posY * 32.0D);
  49.         this.zPosition = par1EntityLiving.myEntitySize
  50.                 .multiplyBy32AndRound(par1EntityLiving.posZ);
  51.         this.yaw = (byte) ((int) (par1EntityLiving.rotationYaw * 256.0F / 360.0F));
  52.         this.pitch = (byte) ((int) (par1EntityLiving.rotationPitch * 256.0F / 360.0F));
  53.         this.headYaw = (byte) ((int) (par1EntityLiving.rotationYawHead * 256.0F / 360.0F));
  54.         double var2 = 3.9D;
  55.         double var4 = par1EntityLiving.motionX;
  56.         double var6 = par1EntityLiving.motionY;
  57.         double var8 = par1EntityLiving.motionZ;
  58.  
  59.         if (var4 < -var2) {
  60.             var4 = -var2;
  61.         }
  62.  
  63.         if (var6 < -var2) {
  64.             var6 = -var2;
  65.         }
  66.  
  67.         if (var8 < -var2) {
  68.             var8 = -var2;
  69.         }
  70.  
  71.         if (var4 > var2) {
  72.             var4 = var2;
  73.         }
  74.  
  75.         if (var6 > var2) {
  76.             var6 = var2;
  77.         }
  78.  
  79.         if (var8 > var2) {
  80.             var8 = var2;
  81.         }
  82.  
  83.         this.velocityX = (int) (var4 * 8000.0D);
  84.         this.velocityY = (int) (var6 * 8000.0D);
  85.         this.velocityZ = (int) (var8 * 8000.0D);
  86.         this.metaData = par1EntityLiving.getDataWatcher();
  87.     }
  88.  
  89.     /**
  90.      * Abstract. Reads the raw packet data from the data stream.
  91.      */
  92.     public void readPacketData(DataInputStream par1DataInputStream)
  93.             throws IOException {
  94.         this.entityId = par1DataInputStream.readInt();
  95.         this.type = par1DataInputStream.readByte() & 255;
  96.         this.xPosition = par1DataInputStream.readInt();
  97.         this.yPosition = par1DataInputStream.readInt();
  98.         this.zPosition = par1DataInputStream.readInt();
  99.         this.yaw = par1DataInputStream.readByte();
  100.         this.pitch = par1DataInputStream.readByte();
  101.         this.headYaw = par1DataInputStream.readByte();
  102.         this.velocityX = par1DataInputStream.readShort();
  103.         this.velocityY = par1DataInputStream.readShort();
  104.         this.velocityZ = par1DataInputStream.readShort();
  105.         this.metadata = DataWatcher.readWatchableObjects(par1DataInputStream);
  106.     }
  107.  
  108.     /**
  109.      * Abstract. Writes the raw packet data to the data stream.
  110.      */
  111.     public void writePacketData(DataOutputStream par1DataOutputStream)
  112.             throws IOException {
  113.         par1DataOutputStream.writeInt(this.entityId);
  114.         par1DataOutputStream.writeByte(this.type & 255);
  115.         par1DataOutputStream.writeInt(this.xPosition);
  116.         par1DataOutputStream.writeInt(this.yPosition);
  117.         par1DataOutputStream.writeInt(this.zPosition);
  118.         par1DataOutputStream.writeByte(this.yaw);
  119.         par1DataOutputStream.writeByte(this.pitch);
  120.         par1DataOutputStream.writeByte(this.headYaw);
  121.         par1DataOutputStream.writeShort(this.velocityX);
  122.         par1DataOutputStream.writeShort(this.velocityY);
  123.         par1DataOutputStream.writeShort(this.velocityZ);
  124.         this.metaData.writeWatchableObjects(par1DataOutputStream);
  125.     }
  126.  
  127.     /**
  128.      * Passes this Packet on to the NetHandler for processing.
  129.      */
  130.     public void processPacket(NetHandler par1NetHandler) {
  131.         par1NetHandler.handleMobSpawn(this);
  132.     }
  133.  
  134.     /**
  135.      * Abstract. Return the size of the packet (not counting the header).
  136.      */
  137.     public int getPacketSize() {
  138.         return 26;
  139.     }
  140.  
  141.     public List getMetadata() {
  142.         if (this.metadata == null) {
  143.             this.metadata = this.metaData.func_75685_c();
  144.         }
  145.  
  146.         return this.metadata;
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement