001 package net.minecraft.network.packet; 002 003 import cpw.mods.fml.relauncher.Side; 004 import cpw.mods.fml.relauncher.SideOnly; 005 import java.io.DataInputStream; 006 import java.io.DataOutputStream; 007 import java.io.IOException; 008 import net.minecraft.item.ItemStack; 009 010 public class Packet15Place extends Packet 011 { 012 private int xPosition; 013 private int yPosition; 014 private int zPosition; 015 016 /** The offset to use for block/item placement. */ 017 private int direction; 018 private ItemStack itemStack; 019 020 /** The offset from xPosition where the actual click took place */ 021 private float xOffset; 022 023 /** The offset from yPosition where the actual click took place */ 024 private float yOffset; 025 026 /** The offset from zPosition where the actual click took place */ 027 private float zOffset; 028 029 public Packet15Place() {} 030 031 @SideOnly(Side.CLIENT) 032 public Packet15Place(int par1, int par2, int par3, int par4, ItemStack par5ItemStack, float par6, float par7, float par8) 033 { 034 this.xPosition = par1; 035 this.yPosition = par2; 036 this.zPosition = par3; 037 this.direction = par4; 038 this.itemStack = par5ItemStack; 039 this.xOffset = par6; 040 this.yOffset = par7; 041 this.zOffset = par8; 042 } 043 044 /** 045 * Abstract. Reads the raw packet data from the data stream. 046 */ 047 public void readPacketData(DataInputStream par1DataInputStream) throws IOException 048 { 049 this.xPosition = par1DataInputStream.readInt(); 050 this.yPosition = par1DataInputStream.read(); 051 this.zPosition = par1DataInputStream.readInt(); 052 this.direction = par1DataInputStream.read(); 053 this.itemStack = readItemStack(par1DataInputStream); 054 this.xOffset = (float)par1DataInputStream.read() / 16.0F; 055 this.yOffset = (float)par1DataInputStream.read() / 16.0F; 056 this.zOffset = (float)par1DataInputStream.read() / 16.0F; 057 } 058 059 /** 060 * Abstract. Writes the raw packet data to the data stream. 061 */ 062 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException 063 { 064 par1DataOutputStream.writeInt(this.xPosition); 065 par1DataOutputStream.write(this.yPosition); 066 par1DataOutputStream.writeInt(this.zPosition); 067 par1DataOutputStream.write(this.direction); 068 writeItemStack(this.itemStack, par1DataOutputStream); 069 par1DataOutputStream.write((int)(this.xOffset * 16.0F)); 070 par1DataOutputStream.write((int)(this.yOffset * 16.0F)); 071 par1DataOutputStream.write((int)(this.zOffset * 16.0F)); 072 } 073 074 /** 075 * Passes this Packet on to the NetHandler for processing. 076 */ 077 public void processPacket(NetHandler par1NetHandler) 078 { 079 par1NetHandler.handlePlace(this); 080 } 081 082 /** 083 * Abstract. Return the size of the packet (not counting the header). 084 */ 085 public int getPacketSize() 086 { 087 return 19; 088 } 089 090 public int getXPosition() 091 { 092 return this.xPosition; 093 } 094 095 public int getYPosition() 096 { 097 return this.yPosition; 098 } 099 100 public int getZPosition() 101 { 102 return this.zPosition; 103 } 104 105 public int getDirection() 106 { 107 return this.direction; 108 } 109 110 public ItemStack getItemStack() 111 { 112 return this.itemStack; 113 } 114 115 /** 116 * Returns the offset from xPosition where the actual click took place 117 */ 118 public float getXOffset() 119 { 120 return this.xOffset; 121 } 122 123 /** 124 * Returns the offset from yPosition where the actual click took place 125 */ 126 public float getYOffset() 127 { 128 return this.yOffset; 129 } 130 131 /** 132 * Returns the offset from zPosition where the actual click took place 133 */ 134 public float getZOffset() 135 { 136 return this.zOffset; 137 } 138 }