| 1 | package net.minecraft.network.play.client;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.item.ItemStack;
|
| 5 | import net.minecraft.network.Packet;
|
| 6 | import net.minecraft.network.PacketBuffer;
|
| 7 | import net.minecraft.network.play.INetHandlerPlayServer;
|
| 8 | import net.minecraft.util.BlockPos;
|
| 9 |
|
| 10 | public class C08PacketPlayerBlockPlacement implements Packet<INetHandlerPlayServer>
|
| 11 | {
|
| 12 | private static final BlockPos field_179726_a = new BlockPos(-1, -1, -1);
|
| 13 | private BlockPos position;
|
| 14 | private int placedBlockDirection;
|
| 15 | private ItemStack stack;
|
| 16 | private float facingX;
|
| 17 | private float facingY;
|
| 18 | private float facingZ;
|
| 19 |
|
| 20 | public C08PacketPlayerBlockPlacement()
|
| 21 | {
|
| 22 | }
|
| 23 |
|
| 24 | public C08PacketPlayerBlockPlacement(ItemStack stackIn)
|
| 25 | {
|
| 26 | this(field_179726_a, 255, stackIn, 0.0F, 0.0F, 0.0F);
|
| 27 | }
|
| 28 |
|
| 29 | public C08PacketPlayerBlockPlacement(BlockPos positionIn, int placedBlockDirectionIn, ItemStack stackIn, float facingXIn, float facingYIn, float facingZIn)
|
| 30 | {
|
| 31 | this.position = positionIn;
|
| 32 | this.placedBlockDirection = placedBlockDirectionIn;
|
| 33 | this.stack = stackIn != null ? stackIn.copy() : null;
|
| 34 | this.facingX = facingXIn;
|
| 35 | this.facingY = facingYIn;
|
| 36 | this.facingZ = facingZIn;
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Reads the raw packet data from the data stream.
|
| 41 | */
|
| 42 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 43 | {
|
| 44 | this.position = buf.readBlockPos();
|
| 45 | this.placedBlockDirection = buf.readUnsignedByte();
|
| 46 | this.stack = buf.readItemStackFromBuffer();
|
| 47 | this.facingX = (float)buf.readUnsignedByte() / 16.0F;
|
| 48 | this.facingY = (float)buf.readUnsignedByte() / 16.0F;
|
| 49 | this.facingZ = (float)buf.readUnsignedByte() / 16.0F;
|
| 50 | }
|
| 51 |
|
| 52 | /**
|
| 53 | * Writes the raw packet data to the data stream.
|
| 54 | */
|
| 55 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 56 | {
|
| 57 | buf.writeBlockPos(this.position);
|
| 58 | buf.writeByte(this.placedBlockDirection);
|
| 59 | buf.writeItemStackToBuffer(this.stack);
|
| 60 | buf.writeByte((int)(this.facingX * 16.0F));
|
| 61 | buf.writeByte((int)(this.facingY * 16.0F));
|
| 62 | buf.writeByte((int)(this.facingZ * 16.0F));
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Passes this Packet on to the NetHandler for processing.
|
| 67 | */
|
| 68 | public void processPacket(INetHandlerPlayServer handler)
|
| 69 | {
|
| 70 | handler.processPlayerBlockPlacement(this);
|
| 71 | }
|
| 72 |
|
| 73 | public BlockPos getPosition()
|
| 74 | {
|
| 75 | return this.position;
|
| 76 | }
|
| 77 |
|
| 78 | public int getPlacedBlockDirection()
|
| 79 | {
|
| 80 | return this.placedBlockDirection;
|
| 81 | }
|
| 82 |
|
| 83 | public ItemStack getStack()
|
| 84 | {
|
| 85 | return this.stack;
|
| 86 | }
|
| 87 |
|
| 88 | /**
|
| 89 | * Returns the offset from xPosition where the actual click took place.
|
| 90 | */
|
| 91 | public float getPlacedBlockOffsetX()
|
| 92 | {
|
| 93 | return this.facingX;
|
| 94 | }
|
| 95 |
|
| 96 | /**
|
| 97 | * Returns the offset from yPosition where the actual click took place.
|
| 98 | */
|
| 99 | public float getPlacedBlockOffsetY()
|
| 100 | {
|
| 101 | return this.facingY;
|
| 102 | }
|
| 103 |
|
| 104 | /**
|
| 105 | * Returns the offset from zPosition where the actual click took place.
|
| 106 | */
|
| 107 | public float getPlacedBlockOffsetZ()
|
| 108 | {
|
| 109 | return this.facingZ;
|
| 110 | }
|
| 111 | }
|
| 112 |
|