| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.entity.Entity;
|
| 5 | import net.minecraft.network.Packet;
|
| 6 | import net.minecraft.network.PacketBuffer;
|
| 7 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 8 |
|
| 9 | public class S12PacketEntityVelocity implements Packet<INetHandlerPlayClient>
|
| 10 | {
|
| 11 | private int entityID;
|
| 12 | private int motionX;
|
| 13 | private int motionY;
|
| 14 | private int motionZ;
|
| 15 |
|
| 16 | public S12PacketEntityVelocity()
|
| 17 | {
|
| 18 | }
|
| 19 |
|
| 20 | public S12PacketEntityVelocity(Entity entityIn)
|
| 21 | {
|
| 22 | this(entityIn.getEntityId(), entityIn.motionX, entityIn.motionY, entityIn.motionZ);
|
| 23 | }
|
| 24 |
|
| 25 | public S12PacketEntityVelocity(int entityIDIn, double motionXIn, double motionYIn, double motionZIn)
|
| 26 | {
|
| 27 | this.entityID = entityIDIn;
|
| 28 | double d0 = 3.9D;
|
| 29 |
|
| 30 | if (motionXIn < -d0)
|
| 31 | {
|
| 32 | motionXIn = -d0;
|
| 33 | }
|
| 34 |
|
| 35 | if (motionYIn < -d0)
|
| 36 | {
|
| 37 | motionYIn = -d0;
|
| 38 | }
|
| 39 |
|
| 40 | if (motionZIn < -d0)
|
| 41 | {
|
| 42 | motionZIn = -d0;
|
| 43 | }
|
| 44 |
|
| 45 | if (motionXIn > d0)
|
| 46 | {
|
| 47 | motionXIn = d0;
|
| 48 | }
|
| 49 |
|
| 50 | if (motionYIn > d0)
|
| 51 | {
|
| 52 | motionYIn = d0;
|
| 53 | }
|
| 54 |
|
| 55 | if (motionZIn > d0)
|
| 56 | {
|
| 57 | motionZIn = d0;
|
| 58 | }
|
| 59 |
|
| 60 | this.motionX = (int)(motionXIn * 8000.0D);
|
| 61 | this.motionY = (int)(motionYIn * 8000.0D);
|
| 62 | this.motionZ = (int)(motionZIn * 8000.0D);
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Reads the raw packet data from the data stream.
|
| 67 | */
|
| 68 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 69 | {
|
| 70 | this.entityID = buf.readVarIntFromBuffer();
|
| 71 | this.motionX = buf.readShort();
|
| 72 | this.motionY = buf.readShort();
|
| 73 | this.motionZ = buf.readShort();
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * Writes the raw packet data to the data stream.
|
| 78 | */
|
| 79 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 80 | {
|
| 81 | buf.writeVarIntToBuffer(this.entityID);
|
| 82 | buf.writeShort(this.motionX);
|
| 83 | buf.writeShort(this.motionY);
|
| 84 | buf.writeShort(this.motionZ);
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Passes this Packet on to the NetHandler for processing.
|
| 89 | */
|
| 90 | public void processPacket(INetHandlerPlayClient handler)
|
| 91 | {
|
| 92 | handler.handleEntityVelocity(this);
|
| 93 | }
|
| 94 |
|
| 95 | public int getEntityID()
|
| 96 | {
|
| 97 | return this.entityID;
|
| 98 | }
|
| 99 |
|
| 100 | public int getMotionX()
|
| 101 | {
|
| 102 | return this.motionX;
|
| 103 | }
|
| 104 |
|
| 105 | public int getMotionY()
|
| 106 | {
|
| 107 | return this.motionY;
|
| 108 | }
|
| 109 |
|
| 110 | public int getMotionZ()
|
| 111 | {
|
| 112 | return this.motionZ;
|
| 113 | }
|
| 114 | }
|
| 115 |
|