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);
}
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();
});
}
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();
});
}
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));
}
Aggregations