001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package net.tridentsdk.server.effect.sound;
018
019import net.tridentsdk.base.Position;
020import net.tridentsdk.effect.sound.SoundEffect;
021import net.tridentsdk.effect.sound.SoundEffectType;
022import net.tridentsdk.server.effect.TridentRemoteEffect;
023import net.tridentsdk.server.netty.packet.OutPacket;
024import net.tridentsdk.server.packets.play.out.PacketPlayOutSoundEffect;
025import net.tridentsdk.util.Vector;
026import net.tridentsdk.world.World;
027
028/**
029 * Represents a sound effect
030 *
031 * @author The TridentSDK Team
032 */
033public class TridentSoundEffect extends TridentRemoteEffect<SoundEffectType> implements SoundEffect {
034    private PacketPlayOutSoundEffect packet = new PacketPlayOutSoundEffect();
035
036    public TridentSoundEffect(World world, SoundEffectType type){
037        packet.set("loc", new Position(world, 0, 0, 0));
038        packet.set("sound", type);
039        packet.set("pitch", 63);
040        packet.set("volume", 1f);
041    }
042
043    @Override
044    public SoundEffectType type(){
045        return packet.sound();
046    }
047
048    @Override
049    public void setType(SoundEffectType type){
050        packet.set("sound", type);
051    }
052
053    @Override
054    public void setPosition(Vector vector){
055        packet.location().setX(vector.x() * 8);
056        packet.location().setY(vector.y() * 8);
057        packet.location().setZ(vector.z() * 8);
058    }
059
060    @Override
061    public void setVolume(float volume){
062        packet.set("volume", volume);
063    }
064
065    @Override
066    public void setPitch(int pitch){
067        packet.set("pitch", pitch);
068    }
069
070    @Override
071    public float volume(){
072        return packet.volume();
073    }
074
075    @Override
076    public int pitch(){
077        return packet.pitch();
078    }
079
080    @Override
081    public OutPacket getPacket(){
082        return packet;
083    }
084}