Sounds volume and pitch are now configurable in the new sounds.yml file

This commit is contained in:
nossr50
2019-01-12 19:08:54 -08:00
parent 6927712a9d
commit 85fd0a79bc
22 changed files with 251 additions and 45 deletions

View File

@ -8,6 +8,8 @@ import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -131,7 +133,7 @@ public final class ChimaeraWing {
mcMMOPlayer.setTeleportCommenceLocation(null);
if (Config.getInstance().getChimaeraSoundEnabled()) {
player.playSound(location, Sound.ENTITY_BAT_TAKEOFF, Misc.BAT_VOLUME, Misc.BAT_PITCH);
SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING);
}
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));

View File

@ -5,6 +5,8 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import com.google.common.collect.ImmutableList;
import org.bukkit.*;
import org.bukkit.FireworkEffect.Type;
@ -357,7 +359,7 @@ public final class HolidayManager {
public void levelUpApril(Player player, FakeSkillType fakeSkillType) {
int levelTotal = Misc.getRandom().nextInt(1 + UserManager.getPlayer(player).getSkillLevel(PrimarySkill.MINING)) + 1;
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH);
SoundManager.sendSound(player, player.getLocation(), SoundType.LEVEL_UP);
player.sendMessage(ChatColor.YELLOW + StringUtils.getCapitalized(fakeSkillType.toString()) + " skill increased by 1. Total (" + levelTotal + ")");
ParticleEffectUtils.fireworkParticleShower(player, ALL_COLORS.get(Misc.getRandom().nextInt(ALL_COLORS.size())));
}

View File

@ -31,7 +31,7 @@ public final class Misc {
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
// Sound Pitches & Volumes from CB
public static final float ANVIL_USE_PITCH = 0.3F; // Not in CB directly, I went off the place sound values
/* public static final float ANVIL_USE_PITCH = 0.3F; // Not in CB directly, I went off the place sound values
public static final float ANVIL_USE_VOLUME = 1.0F * Config.getInstance().getMasterVolume(); // Not in CB directly, I went off the place sound values
public static final float FIZZ_VOLUME = 0.5F * Config.getInstance().getMasterVolume();
public static final float POP_VOLUME = 0.2F * Config.getInstance().getMasterVolume();
@ -39,24 +39,12 @@ public final class Misc {
public static final float BAT_PITCH = 0.6F;
public static final float GHAST_VOLUME = 1.0F * Config.getInstance().getMasterVolume();
public static final float LEVELUP_PITCH = 0.5F; // Reduced to differentiate between vanilla level-up
public static final float LEVELUP_VOLUME = 0.75F * Config.getInstance().getMasterVolume(); // Use max volume always
public static final float LEVELUP_VOLUME = 0.75F * Config.getInstance().getMasterVolume(); // Use max volume always*/
public static final Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
private Misc() {};
public static float getFizzPitch() {
return 2.6F + (getRandom().nextFloat() - getRandom().nextFloat()) * 0.8F;
}
public static float getPopPitch() {
return ((getRandom().nextFloat() - getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F;
}
public static float getGhastPitch() {
return (getRandom().nextFloat() - getRandom().nextFloat()) * 0.2F + 1.0F;
}
public static boolean isNPCEntity(Entity entity) {
return (entity == null || entity.hasMetadata("NPC") || entity instanceof NPC || entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
}

View File

@ -0,0 +1,81 @@
package com.gmail.nossr50.util.sounds;
import com.gmail.nossr50.config.SoundConfig;
import com.gmail.nossr50.util.Misc;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class SoundManager {
/**
* Sends a sound to the player
* @param soundType the type of sound
*/
public static void sendSound(Player player, Location location, SoundType soundType)
{
player.playSound(location, getSound(soundType), getVolume(soundType), getPitch(soundType));
}
public static void worldSendSound(World world, Location location, SoundType soundType)
{
world.playSound(location, getSound(soundType), getVolume(soundType), getPitch(soundType));
}
/**
* All volume is multiplied by the master volume to get its final value
* @param soundType target soundtype
* @return the volume for this soundtype
*/
private static float getVolume(SoundType soundType)
{
return SoundConfig.getInstance().getVolume(soundType) * SoundConfig.getInstance().getMasterVolume();
}
private static float getPitch(SoundType soundType)
{
if(soundType == SoundType.FIZZ)
return getFizzPitch();
else if (soundType == SoundType.POP)
return getPopPitch();
else if (soundType == SoundType.KRAKEN)
return getKrakenPitch();
else
return SoundConfig.getInstance().getPitch(soundType);
}
private static Sound getSound(SoundType soundType)
{
switch(soundType)
{
case ANVIL:
return Sound.BLOCK_ANVIL_PLACE;
case ITEM_BREAK:
return Sound.ENTITY_ITEM_BREAK;
case POP:
return Sound.ENTITY_ITEM_PICKUP;
case KRAKEN:
return Sound.ENTITY_GHAST_SCREAM;
case CHIMAERA_WING:
return Sound.ENTITY_BAT_TAKEOFF;
case LEVEL_UP:
return Sound.ENTITY_PLAYER_LEVELUP;
case FIZZ:
return Sound.BLOCK_FIRE_EXTINGUISH;
default:
return null;
}
}
public static float getFizzPitch() {
return 2.6F + (Misc.getRandom().nextFloat() - Misc.getRandom().nextFloat()) * 0.8F;
}
public static float getPopPitch() {
return ((Misc.getRandom().nextFloat() - Misc.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F;
}
public static float getKrakenPitch() {
return (Misc.getRandom().nextFloat() - Misc.getRandom().nextFloat()) * 0.2F + 1.0F;
}
}

View File

@ -0,0 +1,23 @@
package com.gmail.nossr50.util.sounds;
public enum SoundType {
ANVIL,
LEVEL_UP,
FIZZ,
ITEM_BREAK,
POP,
KRAKEN,
CHIMAERA_WING;
public boolean usesCustomPitch()
{
switch(this){
case POP:
case FIZZ:
case KRAKEN:
return true;
default:
return false;
}
}
}