| 1 | package net.minecraft.network.play.client;
|
| 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.INetHandlerPlayServer;
|
| 8 | import net.minecraft.util.Vec3;
|
| 9 | import net.minecraft.world.World;
|
| 10 |
|
| 11 | public class C02PacketUseEntity implements Packet<INetHandlerPlayServer>
|
| 12 | {
|
| 13 | private int entityId;
|
| 14 | private C02PacketUseEntity.Action action;
|
| 15 | private Vec3 hitVec;
|
| 16 |
|
| 17 | public C02PacketUseEntity()
|
| 18 | {
|
| 19 | }
|
| 20 |
|
| 21 | public C02PacketUseEntity(Entity entity, C02PacketUseEntity.Action action)
|
| 22 | {
|
| 23 | this.entityId = entity.getEntityId();
|
| 24 | this.action = action;
|
| 25 | }
|
| 26 |
|
| 27 | public C02PacketUseEntity(Entity entity, Vec3 hitVec)
|
| 28 | {
|
| 29 | this(entity, C02PacketUseEntity.Action.INTERACT_AT);
|
| 30 | this.hitVec = hitVec;
|
| 31 | }
|
| 32 |
|
| 33 | /**
|
| 34 | * Reads the raw packet data from the data stream.
|
| 35 | */
|
| 36 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 37 | {
|
| 38 | this.entityId = buf.readVarIntFromBuffer();
|
| 39 | this.action = (C02PacketUseEntity.Action)buf.readEnumValue(C02PacketUseEntity.Action.class);
|
| 40 |
|
| 41 | if (this.action == C02PacketUseEntity.Action.INTERACT_AT)
|
| 42 | {
|
| 43 | this.hitVec = new Vec3((double)buf.readFloat(), (double)buf.readFloat(), (double)buf.readFloat());
|
| 44 | }
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Writes the raw packet data to the data stream.
|
| 49 | */
|
| 50 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 51 | {
|
| 52 | buf.writeVarIntToBuffer(this.entityId);
|
| 53 | buf.writeEnumValue(this.action);
|
| 54 |
|
| 55 | if (this.action == C02PacketUseEntity.Action.INTERACT_AT)
|
| 56 | {
|
| 57 | buf.writeFloat((float)this.hitVec.xCoord);
|
| 58 | buf.writeFloat((float)this.hitVec.yCoord);
|
| 59 | buf.writeFloat((float)this.hitVec.zCoord);
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * Passes this Packet on to the NetHandler for processing.
|
| 65 | */
|
| 66 | public void processPacket(INetHandlerPlayServer handler)
|
| 67 | {
|
| 68 | handler.processUseEntity(this);
|
| 69 | }
|
| 70 |
|
| 71 | public Entity getEntityFromWorld(World worldIn)
|
| 72 | {
|
| 73 | return worldIn.getEntityByID(this.entityId);
|
| 74 | }
|
| 75 |
|
| 76 | public C02PacketUseEntity.Action getAction()
|
| 77 | {
|
| 78 | return this.action;
|
| 79 | }
|
| 80 |
|
| 81 | public Vec3 getHitVec()
|
| 82 | {
|
| 83 | return this.hitVec;
|
| 84 | }
|
| 85 |
|
| 86 | public static enum Action
|
| 87 | {
|
| 88 | INTERACT,
|
| 89 | ATTACK,
|
| 90 | INTERACT_AT;
|
| 91 | }
|
| 92 | }
|
| 93 |
|