| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import java.util.List;
|
| 5 | import java.util.UUID;
|
| 6 | import net.minecraft.entity.DataWatcher;
|
| 7 | import net.minecraft.entity.player.EntityPlayer;
|
| 8 | import net.minecraft.item.Item;
|
| 9 | import net.minecraft.item.ItemStack;
|
| 10 | import net.minecraft.network.Packet;
|
| 11 | import net.minecraft.network.PacketBuffer;
|
| 12 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 13 | import net.minecraft.util.MathHelper;
|
| 14 |
|
| 15 | public class S0CPacketSpawnPlayer implements Packet<INetHandlerPlayClient>
|
| 16 | {
|
| 17 | private int entityId;
|
| 18 | private UUID playerId;
|
| 19 | private int x;
|
| 20 | private int y;
|
| 21 | private int z;
|
| 22 | private byte yaw;
|
| 23 | private byte pitch;
|
| 24 | private int currentItem;
|
| 25 | private DataWatcher watcher;
|
| 26 | private List<DataWatcher.WatchableObject> field_148958_j;
|
| 27 |
|
| 28 | public S0CPacketSpawnPlayer()
|
| 29 | {
|
| 30 | }
|
| 31 |
|
| 32 | public S0CPacketSpawnPlayer(EntityPlayer player)
|
| 33 | {
|
| 34 | this.entityId = player.getEntityId();
|
| 35 | this.playerId = player.getGameProfile().getId();
|
| 36 | this.x = MathHelper.floor_double(player.posX * 32.0D);
|
| 37 | this.y = MathHelper.floor_double(player.posY * 32.0D);
|
| 38 | this.z = MathHelper.floor_double(player.posZ * 32.0D);
|
| 39 | this.yaw = (byte)((int)(player.rotationYaw * 256.0F / 360.0F));
|
| 40 | this.pitch = (byte)((int)(player.rotationPitch * 256.0F / 360.0F));
|
| 41 | ItemStack itemstack = player.inventory.getCurrentItem();
|
| 42 | this.currentItem = itemstack == null ? 0 : Item.getIdFromItem(itemstack.getItem());
|
| 43 | this.watcher = player.getDataWatcher();
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Reads the raw packet data from the data stream.
|
| 48 | */
|
| 49 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 50 | {
|
| 51 | this.entityId = buf.readVarIntFromBuffer();
|
| 52 | this.playerId = buf.readUuid();
|
| 53 | this.x = buf.readInt();
|
| 54 | this.y = buf.readInt();
|
| 55 | this.z = buf.readInt();
|
| 56 | this.yaw = buf.readByte();
|
| 57 | this.pitch = buf.readByte();
|
| 58 | this.currentItem = buf.readShort();
|
| 59 | this.field_148958_j = DataWatcher.readWatchedListFromPacketBuffer(buf);
|
| 60 | }
|
| 61 |
|
| 62 | /**
|
| 63 | * Writes the raw packet data to the data stream.
|
| 64 | */
|
| 65 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 66 | {
|
| 67 | buf.writeVarIntToBuffer(this.entityId);
|
| 68 | buf.writeUuid(this.playerId);
|
| 69 | buf.writeInt(this.x);
|
| 70 | buf.writeInt(this.y);
|
| 71 | buf.writeInt(this.z);
|
| 72 | buf.writeByte(this.yaw);
|
| 73 | buf.writeByte(this.pitch);
|
| 74 | buf.writeShort(this.currentItem);
|
| 75 | this.watcher.writeTo(buf);
|
| 76 | }
|
| 77 |
|
| 78 | /**
|
| 79 | * Passes this Packet on to the NetHandler for processing.
|
| 80 | */
|
| 81 | public void processPacket(INetHandlerPlayClient handler)
|
| 82 | {
|
| 83 | handler.handleSpawnPlayer(this);
|
| 84 | }
|
| 85 |
|
| 86 | public List<DataWatcher.WatchableObject> func_148944_c()
|
| 87 | {
|
| 88 | if (this.field_148958_j == null)
|
| 89 | {
|
| 90 | this.field_148958_j = this.watcher.getAllWatched();
|
| 91 | }
|
| 92 |
|
| 93 | return this.field_148958_j;
|
| 94 | }
|
| 95 |
|
| 96 | public int getEntityID()
|
| 97 | {
|
| 98 | return this.entityId;
|
| 99 | }
|
| 100 |
|
| 101 | public UUID getPlayer()
|
| 102 | {
|
| 103 | return this.playerId;
|
| 104 | }
|
| 105 |
|
| 106 | public int getX()
|
| 107 | {
|
| 108 | return this.x;
|
| 109 | }
|
| 110 |
|
| 111 | public int getY()
|
| 112 | {
|
| 113 | return this.y;
|
| 114 | }
|
| 115 |
|
| 116 | public int getZ()
|
| 117 | {
|
| 118 | return this.z;
|
| 119 | }
|
| 120 |
|
| 121 | public byte getYaw()
|
| 122 | {
|
| 123 | return this.yaw;
|
| 124 | }
|
| 125 |
|
| 126 | public byte getPitch()
|
| 127 | {
|
| 128 | return this.pitch;
|
| 129 | }
|
| 130 |
|
| 131 | public int getCurrentItemID()
|
| 132 | {
|
| 133 | return this.currentItem;
|
| 134 | }
|
| 135 | }
|
| 136 |
|