| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.network.Packet;
|
| 5 | import net.minecraft.network.PacketBuffer;
|
| 6 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 7 | import net.minecraft.util.MathHelper;
|
| 8 | import org.apache.commons.lang3.Validate;
|
| 9 |
|
| 10 | public class S29PacketSoundEffect implements Packet<INetHandlerPlayClient>
|
| 11 | {
|
| 12 | private String soundName;
|
| 13 | private int posX;
|
| 14 | private int posY = Integer.MAX_VALUE;
|
| 15 | private int posZ;
|
| 16 | private float soundVolume;
|
| 17 | private int soundPitch;
|
| 18 |
|
| 19 | public S29PacketSoundEffect()
|
| 20 | {
|
| 21 | }
|
| 22 |
|
| 23 | public S29PacketSoundEffect(String soundNameIn, double soundX, double soundY, double soundZ, float volume, float pitch)
|
| 24 | {
|
| 25 | Validate.notNull(soundNameIn, "name", new Object[0]);
|
| 26 | this.soundName = soundNameIn;
|
| 27 | this.posX = (int)(soundX * 8.0D);
|
| 28 | this.posY = (int)(soundY * 8.0D);
|
| 29 | this.posZ = (int)(soundZ * 8.0D);
|
| 30 | this.soundVolume = volume;
|
| 31 | this.soundPitch = (int)(pitch * 63.0F);
|
| 32 | pitch = MathHelper.clamp_float(pitch, 0.0F, 255.0F);
|
| 33 | }
|
| 34 |
|
| 35 | /**
|
| 36 | * Reads the raw packet data from the data stream.
|
| 37 | */
|
| 38 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 39 | {
|
| 40 | this.soundName = buf.readStringFromBuffer(256);
|
| 41 | this.posX = buf.readInt();
|
| 42 | this.posY = buf.readInt();
|
| 43 | this.posZ = buf.readInt();
|
| 44 | this.soundVolume = buf.readFloat();
|
| 45 | this.soundPitch = buf.readUnsignedByte();
|
| 46 | }
|
| 47 |
|
| 48 | /**
|
| 49 | * Writes the raw packet data to the data stream.
|
| 50 | */
|
| 51 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 52 | {
|
| 53 | buf.writeString(this.soundName);
|
| 54 | buf.writeInt(this.posX);
|
| 55 | buf.writeInt(this.posY);
|
| 56 | buf.writeInt(this.posZ);
|
| 57 | buf.writeFloat(this.soundVolume);
|
| 58 | buf.writeByte(this.soundPitch);
|
| 59 | }
|
| 60 |
|
| 61 | public String getSoundName()
|
| 62 | {
|
| 63 | return this.soundName;
|
| 64 | }
|
| 65 |
|
| 66 | public double getX()
|
| 67 | {
|
| 68 | return (double)((float)this.posX / 8.0F);
|
| 69 | }
|
| 70 |
|
| 71 | public double getY()
|
| 72 | {
|
| 73 | return (double)((float)this.posY / 8.0F);
|
| 74 | }
|
| 75 |
|
| 76 | public double getZ()
|
| 77 | {
|
| 78 | return (double)((float)this.posZ / 8.0F);
|
| 79 | }
|
| 80 |
|
| 81 | public float getVolume()
|
| 82 | {
|
| 83 | return this.soundVolume;
|
| 84 | }
|
| 85 |
|
| 86 | public float getPitch()
|
| 87 | {
|
| 88 | return (float)this.soundPitch / 63.0F;
|
| 89 | }
|
| 90 |
|
| 91 | /**
|
| 92 | * Passes this Packet on to the NetHandler for processing.
|
| 93 | */
|
| 94 | public void processPacket(INetHandlerPlayClient handler)
|
| 95 | {
|
| 96 | handler.handleSoundEffect(this);
|
| 97 | }
|
| 98 | }
|
| 99 |
|