package com.yolp900.itsjustacharm.common.network; import com.yolp900.itsjustacharm.ItsJustaCharm; import com.yolp900.itsjustacharm.reference.LibSounds; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fml.common.network.ByteBufUtils; public class MessageSound extends MessageBase<MessageSound> { private LibSounds sound; private double x, y, z; private double volume, pitch; private boolean distanceDelay; private SoundTypes type; public MessageSound() { } public MessageSound(LibSounds sound, double x, double y, double z, double volume, double pitch) { setParams(sound, x, y, z, volume, pitch); this.type = SoundTypes.Player; } public MessageSound(LibSounds sound, double x, double y, double z, double volume, double pitch, boolean distanceDelay) { setParams(sound, x, y, z, volume, pitch); this.distanceDelay = distanceDelay; this.type = SoundTypes.Position; } private void setParams(LibSounds sound, double x, double y, double z, double volume, double pitch) { this.sound = sound; this.x = x; this.y = y; this.z = z; this.volume = volume; this.pitch = pitch; } @Override public void handleClientSide(MessageSound message, EntityPlayer player) { LibSounds sound = message.sound; double x = message.x; double y = message.y; double z = message.z; double volume = message.volume; double pitch = message.pitch; SoundTypes type = message.type; if (type == SoundTypes.Player) { ItsJustaCharm.proxy.playSound(sound, player.worldObj, player, x, y, z, volume, pitch); //player.playSound(SoundHandler.getSoundEvent(sound).getSoundEvent(), (float)volume, (float)pitch); } else if (type == SoundTypes.Position) { boolean distanceDelay = message.distanceDelay; ItsJustaCharm.proxy.playSound(sound, player.worldObj, x, y, z, volume, pitch, distanceDelay); } } @Override public void handleServerSide(MessageSound message, EntityPlayer player) { } @Override public void fromBytes(ByteBuf buf) { this.sound = LibSounds.valueOf(ByteBufUtils.readUTF8String(buf)); this.x = buf.readDouble(); this.y = buf.readDouble(); this.z = buf.readDouble(); this.volume = buf.readDouble(); this.pitch = buf.readDouble(); this.distanceDelay = buf.readBoolean(); this.type = SoundTypes.valueOf(ByteBufUtils.readUTF8String(buf)); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, sound.toString()); buf.writeDouble(x); buf.writeDouble(y); buf.writeDouble(z); buf.writeDouble(volume); buf.writeDouble(pitch); buf.writeBoolean(distanceDelay); ByteBufUtils.writeUTF8String(buf, type.toString()); } private enum SoundTypes { Player, Position } }