| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.entity.DataWatcher;
|
| 6 | import net.minecraft.entity.EntityList;
|
| 7 | import net.minecraft.entity.EntityLivingBase;
|
| 8 | import net.minecraft.network.Packet;
|
| 9 | import net.minecraft.network.PacketBuffer;
|
| 10 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 11 | import net.minecraft.util.MathHelper;
|
| 12 |
|
| 13 | public class S0FPacketSpawnMob implements Packet<INetHandlerPlayClient>
|
| 14 | {
|
| 15 | private int entityId;
|
| 16 | private int type;
|
| 17 | private int x;
|
| 18 | private int y;
|
| 19 | private int z;
|
| 20 | private int velocityX;
|
| 21 | private int velocityY;
|
| 22 | private int velocityZ;
|
| 23 | private byte yaw;
|
| 24 | private byte pitch;
|
| 25 | private byte headPitch;
|
| 26 | private DataWatcher field_149043_l;
|
| 27 | private List<DataWatcher.WatchableObject> watcher;
|
| 28 |
|
| 29 | public S0FPacketSpawnMob()
|
| 30 | {
|
| 31 | }
|
| 32 |
|
| 33 | public S0FPacketSpawnMob(EntityLivingBase entityIn)
|
| 34 | {
|
| 35 | this.entityId = entityIn.getEntityId();
|
| 36 | this.type = (byte)EntityList.getEntityID(entityIn);
|
| 37 | this.x = MathHelper.floor_double(entityIn.posX * 32.0D);
|
| 38 | this.y = MathHelper.floor_double(entityIn.posY * 32.0D);
|
| 39 | this.z = MathHelper.floor_double(entityIn.posZ * 32.0D);
|
| 40 | this.yaw = (byte)((int)(entityIn.rotationYaw * 256.0F / 360.0F));
|
| 41 | this.pitch = (byte)((int)(entityIn.rotationPitch * 256.0F / 360.0F));
|
| 42 | this.headPitch = (byte)((int)(entityIn.rotationYawHead * 256.0F / 360.0F));
|
| 43 | double d0 = 3.9D;
|
| 44 | double d1 = entityIn.motionX;
|
| 45 | double d2 = entityIn.motionY;
|
| 46 | double d3 = entityIn.motionZ;
|
| 47 |
|
| 48 | if (d1 < -d0)
|
| 49 | {
|
| 50 | d1 = -d0;
|
| 51 | }
|
| 52 |
|
| 53 | if (d2 < -d0)
|
| 54 | {
|
| 55 | d2 = -d0;
|
| 56 | }
|
| 57 |
|
| 58 | if (d3 < -d0)
|
| 59 | {
|
| 60 | d3 = -d0;
|
| 61 | }
|
| 62 |
|
| 63 | if (d1 > d0)
|
| 64 | {
|
| 65 | d1 = d0;
|
| 66 | }
|
| 67 |
|
| 68 | if (d2 > d0)
|
| 69 | {
|
| 70 | d2 = d0;
|
| 71 | }
|
| 72 |
|
| 73 | if (d3 > d0)
|
| 74 | {
|
| 75 | d3 = d0;
|
| 76 | }
|
| 77 |
|
| 78 | this.velocityX = (int)(d1 * 8000.0D);
|
| 79 | this.velocityY = (int)(d2 * 8000.0D);
|
| 80 | this.velocityZ = (int)(d3 * 8000.0D);
|
| 81 | this.field_149043_l = entityIn.getDataWatcher();
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * Reads the raw packet data from the data stream.
|
| 86 | */
|
| 87 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 88 | {
|
| 89 | this.entityId = buf.readVarIntFromBuffer();
|
| 90 | this.type = buf.readByte() & 255;
|
| 91 | this.x = buf.readInt();
|
| 92 | this.y = buf.readInt();
|
| 93 | this.z = buf.readInt();
|
| 94 | this.yaw = buf.readByte();
|
| 95 | this.pitch = buf.readByte();
|
| 96 | this.headPitch = buf.readByte();
|
| 97 | this.velocityX = buf.readShort();
|
| 98 | this.velocityY = buf.readShort();
|
| 99 | this.velocityZ = buf.readShort();
|
| 100 | this.watcher = DataWatcher.readWatchedListFromPacketBuffer(buf);
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Writes the raw packet data to the data stream.
|
| 105 | */
|
| 106 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 107 | {
|
| 108 | buf.writeVarIntToBuffer(this.entityId);
|
| 109 | buf.writeByte(this.type & 255);
|
| 110 | buf.writeInt(this.x);
|
| 111 | buf.writeInt(this.y);
|
| 112 | buf.writeInt(this.z);
|
| 113 | buf.writeByte(this.yaw);
|
| 114 | buf.writeByte(this.pitch);
|
| 115 | buf.writeByte(this.headPitch);
|
| 116 | buf.writeShort(this.velocityX);
|
| 117 | buf.writeShort(this.velocityY);
|
| 118 | buf.writeShort(this.velocityZ);
|
| 119 | this.field_149043_l.writeTo(buf);
|
| 120 | }
|
| 121 |
|
| 122 | /**
|
| 123 | * Passes this Packet on to the NetHandler for processing.
|
| 124 | */
|
| 125 | public void processPacket(INetHandlerPlayClient handler)
|
| 126 | {
|
| 127 | handler.handleSpawnMob(this);
|
| 128 | }
|
| 129 |
|
| 130 | public List<DataWatcher.WatchableObject> func_149027_c()
|
| 131 | {
|
| 132 | if (this.watcher == null)
|
| 133 | {
|
| 134 | this.watcher = this.field_149043_l.getAllWatched();
|
| 135 | }
|
| 136 |
|
| 137 | return this.watcher;
|
| 138 | }
|
| 139 |
|
| 140 | public int getEntityID()
|
| 141 | {
|
| 142 | return this.entityId;
|
| 143 | }
|
| 144 |
|
| 145 | public int getEntityType()
|
| 146 | {
|
| 147 | return this.type;
|
| 148 | }
|
| 149 |
|
| 150 | public int getX()
|
| 151 | {
|
| 152 | return this.x;
|
| 153 | }
|
| 154 |
|
| 155 | public int getY()
|
| 156 | {
|
| 157 | return this.y;
|
| 158 | }
|
| 159 |
|
| 160 | public int getZ()
|
| 161 | {
|
| 162 | return this.z;
|
| 163 | }
|
| 164 |
|
| 165 | public int getVelocityX()
|
| 166 | {
|
| 167 | return this.velocityX;
|
| 168 | }
|
| 169 |
|
| 170 | public int getVelocityY()
|
| 171 | {
|
| 172 | return this.velocityY;
|
| 173 | }
|
| 174 |
|
| 175 | public int getVelocityZ()
|
| 176 | {
|
| 177 | return this.velocityZ;
|
| 178 | }
|
| 179 |
|
| 180 | public byte getYaw()
|
| 181 | {
|
| 182 | return this.yaw;
|
| 183 | }
|
| 184 |
|
| 185 | public byte getPitch()
|
| 186 | {
|
| 187 | return this.pitch;
|
| 188 | }
|
| 189 |
|
| 190 | public byte getHeadPitch()
|
| 191 | {
|
| 192 | return this.headPitch;
|
| 193 | }
|
| 194 | }
|
| 195 |
|