Search in sources :

Example 1 with SoundCategory

use of org.spongepowered.api.effect.sound.SoundCategory in project SpongeCommon by SpongePowered.

the class MixinWorldServer method playSound.

@Override
public void playSound(SoundType sound, SoundCategory category, Vector3d position, double volume, double pitch, double minVolume) {
    SoundEvent event;
    try {
        // Check if the event is registered (ie has an integer ID)
        event = SoundEvents.getRegisteredSoundEvent(sound.getId());
    } catch (IllegalStateException e) {
        // Otherwise send it as a custom sound
        this.playCustomSound(null, position.getX(), position.getY(), position.getZ(), sound.getId(), (net.minecraft.util.SoundCategory) (Object) category, (float) Math.max(minVolume, volume), (float) pitch);
        return;
    }
    this.playSound(null, position.getX(), position.getY(), position.getZ(), event, (net.minecraft.util.SoundCategory) (Object) category, (float) Math.max(minVolume, volume), (float) pitch);
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory)

Example 2 with SoundCategory

use of org.spongepowered.api.effect.sound.SoundCategory in project LanternServer by LanternPowered.

the class CommandStopSound method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.player(Text.of("player")), GenericArguments.optional(GenericArguments.catalogedElement(Text.of("category"), SoundCategory.class)), GenericArguments.optional(GenericArguments.catalogedElement(Text.of("sound"), SoundType.class))).executor((src, args) -> {
        SoundCategory category = args.<SoundCategory>getOne("category").orElse(null);
        String type = args.<SoundType>getOne("sound").map(CatalogType::getId).orElse(null);
        LanternPlayer player = args.<LanternPlayer>getOne("player").get();
        player.getConnection().send(new MessagePlayOutStopSounds(type, category));
        return CommandResult.success();
    });
}
Also used : SoundType(org.spongepowered.api.effect.sound.SoundType) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 3 with SoundCategory

use of org.spongepowered.api.effect.sound.SoundCategory in project LanternServer by LanternPowered.

the class CommandPlaySound method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.catalogedElement(Text.of("sound"), SoundType.class), GenericArguments.catalogedElement(Text.of("category"), SoundCategory.class), GenericArguments.player(Text.of("player")), GenericArguments.optional(GenericArguments2.targetedVector3d(Text.of("position"))), GenericArguments.optional(GenericArguments2.doubleNum(Text.of("volume")), 1.0), GenericArguments.optional(GenericArguments2.doubleNum(Text.of("pitch"), 1.0)), GenericArguments.optional(GenericArguments2.doubleNum(Text.of("minimum-volume"), 0.0))).executor((src, args) -> {
        SoundType soundType = args.<SoundType>getOne("sound").get();
        SoundCategory soundCategory = args.<SoundCategory>getOne("category").get();
        LanternPlayer player = args.<LanternPlayer>getOne("player").get();
        double volume = GenericMath.clamp(args.<Double>getOne("volume").orElse(1.0), 0.0, Double.MAX_VALUE);
        // Volume greater then 1 will increase the distance the sound can be heared
        double soundDistance = volume <= 1.0 ? 16.0 : volume * 16.0;
        double pitch = GenericMath.clamp(args.<Double>getOne("pitch").orElse(1.0), 0.5, 2.0);
        double minVolume = GenericMath.clamp(args.<Double>getOne("minimum-volume").orElse(0.0), 0.0, 1.0);
        Vector3d playerPos = player.getPosition();
        Vector3d position = args.<Vector3d>getOne("position").orElse(playerPos);
        // is a minimum volume specified
        if (minVolume > 0.0 && playerPos != position && position.distanceSquared(playerPos) > soundDistance * soundDistance) {
            position = position.sub(playerPos).normalize().mul(FOUR_VECTOR).add(playerPos);
            volume = minVolume;
        }
        player.playSound(soundType, soundCategory, position, volume, pitch);
        return CommandResult.success();
    });
}
Also used : SoundType(org.spongepowered.api.effect.sound.SoundType) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) Vector3d(com.flowpowered.math.vector.Vector3d) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 4 with SoundCategory

use of org.spongepowered.api.effect.sound.SoundCategory in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method playSound.

@Override
public void playSound(SoundType sound, SoundCategory category, Vector3d position, double volume, double pitch, double minVolume) {
    SoundEvent event;
    try {
        // Check if the event is registered (ie has an integer ID)
        event = SoundEvents.getRegisteredSoundEvent(sound.getId());
    } catch (IllegalStateException e) {
        // Otherwise send it as a custom sound
        this.connection.sendPacket(new SPacketCustomSound(sound.getId(), (net.minecraft.util.SoundCategory) (Object) category, position.getX(), position.getY(), position.getZ(), (float) Math.max(minVolume, volume), (float) pitch));
        return;
    }
    this.connection.sendPacket(new SPacketSoundEffect(event, (net.minecraft.util.SoundCategory) (Object) category, position.getX(), position.getY(), position.getZ(), (float) Math.max(minVolume, volume), (float) pitch));
}
Also used : SPacketSoundEffect(net.minecraft.network.play.server.SPacketSoundEffect) SoundEvent(net.minecraft.util.SoundEvent) SPacketCustomSound(net.minecraft.network.play.server.SPacketCustomSound) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) IInteractionObject(net.minecraft.world.IInteractionObject)

Aggregations

SoundCategory (org.spongepowered.api.effect.sound.SoundCategory)4 SoundEvent (net.minecraft.util.SoundEvent)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 SoundType (org.spongepowered.api.effect.sound.SoundType)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 SPacketCustomSound (net.minecraft.network.play.server.SPacketCustomSound)1 SPacketSoundEffect (net.minecraft.network.play.server.SPacketSoundEffect)1 IInteractionObject (net.minecraft.world.IInteractionObject)1 MessagePlayOutStopSounds (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds)1