| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.entity.EntityLivingBase;
|
| 5 | import net.minecraft.network.Packet;
|
| 6 | import net.minecraft.network.PacketBuffer;
|
| 7 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 8 | import net.minecraft.util.CombatTracker;
|
| 9 |
|
| 10 | public class S42PacketCombatEvent implements Packet<INetHandlerPlayClient>
|
| 11 | {
|
| 12 | public S42PacketCombatEvent.Event eventType;
|
| 13 | public int field_179774_b;
|
| 14 | public int field_179775_c;
|
| 15 | public int field_179772_d;
|
| 16 | public String deathMessage;
|
| 17 |
|
| 18 | public S42PacketCombatEvent()
|
| 19 | {
|
| 20 | }
|
| 21 |
|
| 22 | @SuppressWarnings("incomplete-switch")
|
| 23 | public S42PacketCombatEvent(CombatTracker combatTrackerIn, S42PacketCombatEvent.Event combatEventType)
|
| 24 | {
|
| 25 | this.eventType = combatEventType;
|
| 26 | EntityLivingBase entitylivingbase = combatTrackerIn.func_94550_c();
|
| 27 |
|
| 28 | switch (combatEventType)
|
| 29 | {
|
| 30 | case END_COMBAT:
|
| 31 | this.field_179772_d = combatTrackerIn.func_180134_f();
|
| 32 | this.field_179775_c = entitylivingbase == null ? -1 : entitylivingbase.getEntityId();
|
| 33 | break;
|
| 34 |
|
| 35 | case ENTITY_DIED:
|
| 36 | this.field_179774_b = combatTrackerIn.getFighter().getEntityId();
|
| 37 | this.field_179775_c = entitylivingbase == null ? -1 : entitylivingbase.getEntityId();
|
| 38 | this.deathMessage = combatTrackerIn.getDeathMessage().getUnformattedText();
|
| 39 | }
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Reads the raw packet data from the data stream.
|
| 44 | */
|
| 45 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 46 | {
|
| 47 | this.eventType = (S42PacketCombatEvent.Event)buf.readEnumValue(S42PacketCombatEvent.Event.class);
|
| 48 |
|
| 49 | if (this.eventType == S42PacketCombatEvent.Event.END_COMBAT)
|
| 50 | {
|
| 51 | this.field_179772_d = buf.readVarIntFromBuffer();
|
| 52 | this.field_179775_c = buf.readInt();
|
| 53 | }
|
| 54 | else if (this.eventType == S42PacketCombatEvent.Event.ENTITY_DIED)
|
| 55 | {
|
| 56 | this.field_179774_b = buf.readVarIntFromBuffer();
|
| 57 | this.field_179775_c = buf.readInt();
|
| 58 | this.deathMessage = buf.readStringFromBuffer(32767);
|
| 59 | }
|
| 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.writeEnumValue(this.eventType);
|
| 68 |
|
| 69 | if (this.eventType == S42PacketCombatEvent.Event.END_COMBAT)
|
| 70 | {
|
| 71 | buf.writeVarIntToBuffer(this.field_179772_d);
|
| 72 | buf.writeInt(this.field_179775_c);
|
| 73 | }
|
| 74 | else if (this.eventType == S42PacketCombatEvent.Event.ENTITY_DIED)
|
| 75 | {
|
| 76 | buf.writeVarIntToBuffer(this.field_179774_b);
|
| 77 | buf.writeInt(this.field_179775_c);
|
| 78 | buf.writeString(this.deathMessage);
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Passes this Packet on to the NetHandler for processing.
|
| 84 | */
|
| 85 | public void processPacket(INetHandlerPlayClient handler)
|
| 86 | {
|
| 87 | handler.handleCombatEvent(this);
|
| 88 | }
|
| 89 |
|
| 90 | public static enum Event
|
| 91 | {
|
| 92 | ENTER_COMBAT,
|
| 93 | END_COMBAT,
|
| 94 | ENTITY_DIED;
|
| 95 | }
|
| 96 | }
|
| 97 |
|