base mod created
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElytraSound extends MovingSound
|
||||
{
|
||||
private final EntityPlayerSP player;
|
||||
private int time;
|
||||
|
||||
public ElytraSound(EntityPlayerSP p_i47113_1_)
|
||||
{
|
||||
super(SoundEvents.ITEM_ELYTRA_FLYING, SoundCategory.PLAYERS);
|
||||
this.player = p_i47113_1_;
|
||||
this.repeat = true;
|
||||
this.repeatDelay = 0;
|
||||
this.volume = 0.1F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like the old updateEntity(), except more generic.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
++this.time;
|
||||
|
||||
if (!this.player.isDead && (this.time <= 20 || this.player.isElytraFlying()))
|
||||
{
|
||||
this.xPosF = (float)this.player.posX;
|
||||
this.yPosF = (float)this.player.posY;
|
||||
this.zPosF = (float)this.player.posZ;
|
||||
float f = MathHelper.sqrt(this.player.motionX * this.player.motionX + this.player.motionZ * this.player.motionZ + this.player.motionY * this.player.motionY);
|
||||
float f1 = f / 2.0F;
|
||||
|
||||
if ((double)f >= 0.01D)
|
||||
{
|
||||
this.volume = MathHelper.clamp(f1 * f1, 0.0F, 1.0F);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.volume = 0.0F;
|
||||
}
|
||||
|
||||
if (this.time < 20)
|
||||
{
|
||||
this.volume = 0.0F;
|
||||
}
|
||||
else if (this.time < 40)
|
||||
{
|
||||
this.volume = (float)((double)this.volume * ((double)(this.time - 20) / 20.0D));
|
||||
}
|
||||
|
||||
float f2 = 0.8F;
|
||||
|
||||
if (this.volume > 0.8F)
|
||||
{
|
||||
this.pitch = 1.0F + (this.volume - 0.8F);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pitch = 1.0F;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.donePlaying = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.entity.monster.EntityGuardian;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuardianSound extends MovingSound
|
||||
{
|
||||
private final EntityGuardian guardian;
|
||||
|
||||
public GuardianSound(EntityGuardian guardian)
|
||||
{
|
||||
super(SoundEvents.ENTITY_GUARDIAN_ATTACK, SoundCategory.HOSTILE);
|
||||
this.guardian = guardian;
|
||||
this.attenuationType = ISound.AttenuationType.NONE;
|
||||
this.repeat = true;
|
||||
this.repeatDelay = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like the old updateEntity(), except more generic.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
if (!this.guardian.isDead && this.guardian.hasTargetedEntity())
|
||||
{
|
||||
this.xPosF = (float)this.guardian.posX;
|
||||
this.yPosF = (float)this.guardian.posY;
|
||||
this.zPosF = (float)this.guardian.posZ;
|
||||
float f = this.guardian.getAttackAnimationScale(0.0F);
|
||||
this.volume = 0.0F + 1.0F * f * f;
|
||||
this.pitch = 0.7F + 0.5F * f;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.donePlaying = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ISound
|
||||
{
|
||||
ResourceLocation getSoundLocation();
|
||||
|
||||
@Nullable
|
||||
SoundEventAccessor createAccessor(SoundHandler handler);
|
||||
|
||||
Sound getSound();
|
||||
|
||||
SoundCategory getCategory();
|
||||
|
||||
boolean canRepeat();
|
||||
|
||||
int getRepeatDelay();
|
||||
|
||||
float getVolume();
|
||||
|
||||
float getPitch();
|
||||
|
||||
float getXPosF();
|
||||
|
||||
float getYPosF();
|
||||
|
||||
float getZPosF();
|
||||
|
||||
ISound.AttenuationType getAttenuationType();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum AttenuationType
|
||||
{
|
||||
NONE(0),
|
||||
LINEAR(2);
|
||||
|
||||
private final int type;
|
||||
|
||||
private AttenuationType(int typeIn)
|
||||
{
|
||||
this.type = typeIn;
|
||||
}
|
||||
|
||||
public int getTypeInt()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ISoundEventAccessor<T>
|
||||
{
|
||||
int getWeight();
|
||||
|
||||
T cloneEntry();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ISoundEventListener
|
||||
{
|
||||
void soundPlay(ISound soundIn, SoundEventAccessor accessor);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ITickableSound extends ISound, ITickable
|
||||
{
|
||||
boolean isDonePlaying();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class MovingSound extends PositionedSound implements ITickableSound
|
||||
{
|
||||
protected boolean donePlaying;
|
||||
|
||||
protected MovingSound(SoundEvent soundIn, SoundCategory categoryIn)
|
||||
{
|
||||
super(soundIn, categoryIn);
|
||||
}
|
||||
|
||||
public boolean isDonePlaying()
|
||||
{
|
||||
return this.donePlaying;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class MovingSoundMinecart extends MovingSound
|
||||
{
|
||||
private final EntityMinecart minecart;
|
||||
private float distance = 0.0F;
|
||||
|
||||
public MovingSoundMinecart(EntityMinecart minecartIn)
|
||||
{
|
||||
super(SoundEvents.ENTITY_MINECART_RIDING, SoundCategory.NEUTRAL);
|
||||
this.minecart = minecartIn;
|
||||
this.repeat = true;
|
||||
this.repeatDelay = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like the old updateEntity(), except more generic.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
if (this.minecart.isDead)
|
||||
{
|
||||
this.donePlaying = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.xPosF = (float)this.minecart.posX;
|
||||
this.yPosF = (float)this.minecart.posY;
|
||||
this.zPosF = (float)this.minecart.posZ;
|
||||
float f = MathHelper.sqrt(this.minecart.motionX * this.minecart.motionX + this.minecart.motionZ * this.minecart.motionZ);
|
||||
|
||||
if ((double)f >= 0.01D)
|
||||
{
|
||||
this.distance = MathHelper.clamp(this.distance + 0.0025F, 0.0F, 1.0F);
|
||||
this.volume = 0.0F + MathHelper.clamp(f, 0.0F, 0.5F) * 0.7F;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.distance = 0.0F;
|
||||
this.volume = 0.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class MovingSoundMinecartRiding extends MovingSound
|
||||
{
|
||||
private final EntityPlayer player;
|
||||
private final EntityMinecart minecart;
|
||||
|
||||
public MovingSoundMinecartRiding(EntityPlayer playerRiding, EntityMinecart minecart)
|
||||
{
|
||||
super(SoundEvents.ENTITY_MINECART_INSIDE, SoundCategory.NEUTRAL);
|
||||
this.player = playerRiding;
|
||||
this.minecart = minecart;
|
||||
this.attenuationType = ISound.AttenuationType.NONE;
|
||||
this.repeat = true;
|
||||
this.repeatDelay = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like the old updateEntity(), except more generic.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
if (!this.minecart.isDead && this.player.isRiding() && this.player.getRidingEntity() == this.minecart)
|
||||
{
|
||||
float f = MathHelper.sqrt(this.minecart.motionX * this.minecart.motionX + this.minecart.motionZ * this.minecart.motionZ);
|
||||
|
||||
if ((double)f >= 0.01D)
|
||||
{
|
||||
this.volume = 0.0F + MathHelper.clamp(f, 0.0F, 1.0F) * 0.75F;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.volume = 0.0F;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.donePlaying = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class MusicTicker implements ITickable
|
||||
{
|
||||
private final Random rand = new Random();
|
||||
private final Minecraft mc;
|
||||
private ISound currentMusic;
|
||||
private int timeUntilNextMusic = 100;
|
||||
|
||||
public MusicTicker(Minecraft mcIn)
|
||||
{
|
||||
this.mc = mcIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like the old updateEntity(), except more generic.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
MusicTicker.MusicType musicticker$musictype = this.mc.getAmbientMusicType();
|
||||
|
||||
if (this.currentMusic != null)
|
||||
{
|
||||
if (!musicticker$musictype.getMusicLocation().getSoundName().equals(this.currentMusic.getSoundLocation()))
|
||||
{
|
||||
this.mc.getSoundHandler().stopSound(this.currentMusic);
|
||||
this.timeUntilNextMusic = MathHelper.getInt(this.rand, 0, musicticker$musictype.getMinDelay() / 2);
|
||||
}
|
||||
|
||||
if (!this.mc.getSoundHandler().isSoundPlaying(this.currentMusic))
|
||||
{
|
||||
this.currentMusic = null;
|
||||
this.timeUntilNextMusic = Math.min(MathHelper.getInt(this.rand, musicticker$musictype.getMinDelay(), musicticker$musictype.getMaxDelay()), this.timeUntilNextMusic);
|
||||
}
|
||||
}
|
||||
|
||||
this.timeUntilNextMusic = Math.min(this.timeUntilNextMusic, musicticker$musictype.getMaxDelay());
|
||||
|
||||
if (this.currentMusic == null && this.timeUntilNextMusic-- <= 0)
|
||||
{
|
||||
this.playMusic(musicticker$musictype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a music track for the maximum allowable period of time
|
||||
*/
|
||||
public void playMusic(MusicTicker.MusicType requestedMusicType)
|
||||
{
|
||||
this.currentMusic = PositionedSoundRecord.getMusicRecord(requestedMusicType.getMusicLocation());
|
||||
this.mc.getSoundHandler().playSound(this.currentMusic);
|
||||
this.timeUntilNextMusic = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum MusicType
|
||||
{
|
||||
MENU(SoundEvents.MUSIC_MENU, 20, 600),
|
||||
GAME(SoundEvents.MUSIC_GAME, 12000, 24000),
|
||||
CREATIVE(SoundEvents.MUSIC_CREATIVE, 1200, 3600),
|
||||
CREDITS(SoundEvents.MUSIC_CREDITS, 0, 0),
|
||||
NETHER(SoundEvents.MUSIC_NETHER, 1200, 3600),
|
||||
END_BOSS(SoundEvents.MUSIC_DRAGON, 0, 0),
|
||||
END(SoundEvents.MUSIC_END, 6000, 24000);
|
||||
|
||||
private final SoundEvent musicLocation;
|
||||
private final int minDelay;
|
||||
private final int maxDelay;
|
||||
|
||||
private MusicType(SoundEvent musicLocationIn, int minDelayIn, int maxDelayIn)
|
||||
{
|
||||
this.musicLocation = musicLocationIn;
|
||||
this.minDelay = minDelayIn;
|
||||
this.maxDelay = maxDelayIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link SoundEvent} containing the current music track's location
|
||||
*/
|
||||
public SoundEvent getMusicLocation()
|
||||
{
|
||||
return this.musicLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum delay between playing music of this type.
|
||||
*/
|
||||
public int getMinDelay()
|
||||
{
|
||||
return this.minDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum delay between playing music of this type.
|
||||
*/
|
||||
public int getMaxDelay()
|
||||
{
|
||||
return this.maxDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class PositionedSound implements ISound
|
||||
{
|
||||
protected Sound sound;
|
||||
@Nullable
|
||||
private SoundEventAccessor soundEvent;
|
||||
protected SoundCategory category;
|
||||
protected ResourceLocation positionedSoundLocation;
|
||||
protected float volume;
|
||||
protected float pitch;
|
||||
protected float xPosF;
|
||||
protected float yPosF;
|
||||
protected float zPosF;
|
||||
protected boolean repeat;
|
||||
/** The number of ticks between repeating the sound */
|
||||
protected int repeatDelay;
|
||||
protected ISound.AttenuationType attenuationType;
|
||||
|
||||
protected PositionedSound(SoundEvent soundIn, SoundCategory categoryIn)
|
||||
{
|
||||
this(soundIn.getSoundName(), categoryIn);
|
||||
}
|
||||
|
||||
protected PositionedSound(ResourceLocation soundId, SoundCategory categoryIn)
|
||||
{
|
||||
this.volume = 1.0F;
|
||||
this.pitch = 1.0F;
|
||||
this.attenuationType = ISound.AttenuationType.LINEAR;
|
||||
this.positionedSoundLocation = soundId;
|
||||
this.category = categoryIn;
|
||||
}
|
||||
|
||||
public ResourceLocation getSoundLocation()
|
||||
{
|
||||
return this.positionedSoundLocation;
|
||||
}
|
||||
|
||||
public SoundEventAccessor createAccessor(SoundHandler handler)
|
||||
{
|
||||
this.soundEvent = handler.getAccessor(this.positionedSoundLocation);
|
||||
|
||||
if (this.soundEvent == null)
|
||||
{
|
||||
this.sound = SoundHandler.MISSING_SOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sound = this.soundEvent.cloneEntry();
|
||||
}
|
||||
|
||||
return this.soundEvent;
|
||||
}
|
||||
|
||||
public Sound getSound()
|
||||
{
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public SoundCategory getCategory()
|
||||
{
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public boolean canRepeat()
|
||||
{
|
||||
return this.repeat;
|
||||
}
|
||||
|
||||
public int getRepeatDelay()
|
||||
{
|
||||
return this.repeatDelay;
|
||||
}
|
||||
|
||||
public float getVolume()
|
||||
{
|
||||
return this.volume * this.sound.getVolume();
|
||||
}
|
||||
|
||||
public float getPitch()
|
||||
{
|
||||
return this.pitch * this.sound.getPitch();
|
||||
}
|
||||
|
||||
public float getXPosF()
|
||||
{
|
||||
return this.xPosF;
|
||||
}
|
||||
|
||||
public float getYPosF()
|
||||
{
|
||||
return this.yPosF;
|
||||
}
|
||||
|
||||
public float getZPosF()
|
||||
{
|
||||
return this.zPosF;
|
||||
}
|
||||
|
||||
public ISound.AttenuationType getAttenuationType()
|
||||
{
|
||||
return this.attenuationType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class PositionedSoundRecord extends PositionedSound
|
||||
{
|
||||
public PositionedSoundRecord(SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, BlockPos pos)
|
||||
{
|
||||
this(soundIn, categoryIn, volumeIn, pitchIn, (float)pos.getX() + 0.5F, (float)pos.getY() + 0.5F, (float)pos.getZ() + 0.5F);
|
||||
}
|
||||
|
||||
public static PositionedSoundRecord getMasterRecord(SoundEvent soundIn, float pitchIn)
|
||||
{
|
||||
return getRecord(soundIn, pitchIn, 0.25F);
|
||||
}
|
||||
|
||||
public static PositionedSoundRecord getRecord(SoundEvent soundIn, float pitchIn, float volumeIn)
|
||||
{
|
||||
return new PositionedSoundRecord(soundIn, SoundCategory.MASTER, volumeIn, pitchIn, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static PositionedSoundRecord getMusicRecord(SoundEvent soundIn)
|
||||
{
|
||||
return new PositionedSoundRecord(soundIn, SoundCategory.MUSIC, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static PositionedSoundRecord getRecordSoundRecord(SoundEvent soundIn, float xIn, float yIn, float zIn)
|
||||
{
|
||||
return new PositionedSoundRecord(soundIn, SoundCategory.RECORDS, 4.0F, 1.0F, false, 0, ISound.AttenuationType.LINEAR, xIn, yIn, zIn);
|
||||
}
|
||||
|
||||
public PositionedSoundRecord(SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, float xIn, float yIn, float zIn)
|
||||
{
|
||||
this(soundIn, categoryIn, volumeIn, pitchIn, false, 0, ISound.AttenuationType.LINEAR, xIn, yIn, zIn);
|
||||
}
|
||||
|
||||
private PositionedSoundRecord(SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, boolean repeatIn, int repeatDelayIn, ISound.AttenuationType attenuationTypeIn, float xIn, float yIn, float zIn)
|
||||
{
|
||||
this(soundIn.getSoundName(), categoryIn, volumeIn, pitchIn, repeatIn, repeatDelayIn, attenuationTypeIn, xIn, yIn, zIn);
|
||||
}
|
||||
|
||||
public PositionedSoundRecord(ResourceLocation soundId, SoundCategory categoryIn, float volumeIn, float pitchIn, boolean repeatIn, int repeatDelayIn, ISound.AttenuationType attenuationTypeIn, float xIn, float yIn, float zIn)
|
||||
{
|
||||
super(soundId, categoryIn);
|
||||
this.volume = volumeIn;
|
||||
this.pitch = pitchIn;
|
||||
this.xPosF = xIn;
|
||||
this.yPosF = yIn;
|
||||
this.zPosF = zIn;
|
||||
this.repeat = repeatIn;
|
||||
this.repeatDelay = repeatDelayIn;
|
||||
this.attenuationType = attenuationTypeIn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class Sound implements ISoundEventAccessor<Sound>
|
||||
{
|
||||
private final ResourceLocation name;
|
||||
private final float volume;
|
||||
private final float pitch;
|
||||
private final int weight;
|
||||
private final Sound.Type type;
|
||||
private final boolean streaming;
|
||||
|
||||
public Sound(String nameIn, float volumeIn, float pitchIn, int weightIn, Sound.Type typeIn, boolean p_i46526_6_)
|
||||
{
|
||||
this.name = new ResourceLocation(nameIn);
|
||||
this.volume = volumeIn;
|
||||
this.pitch = pitchIn;
|
||||
this.weight = weightIn;
|
||||
this.type = typeIn;
|
||||
this.streaming = p_i46526_6_;
|
||||
}
|
||||
|
||||
public ResourceLocation getSoundLocation()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ResourceLocation getSoundAsOggLocation()
|
||||
{
|
||||
return new ResourceLocation(this.name.getResourceDomain(), "sounds/" + this.name.getResourcePath() + ".ogg");
|
||||
}
|
||||
|
||||
public float getVolume()
|
||||
{
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float getPitch()
|
||||
{
|
||||
return this.pitch;
|
||||
}
|
||||
|
||||
public int getWeight()
|
||||
{
|
||||
return this.weight;
|
||||
}
|
||||
|
||||
public Sound cloneEntry()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public Sound.Type getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isStreaming()
|
||||
{
|
||||
return this.streaming;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum Type
|
||||
{
|
||||
FILE("file"),
|
||||
SOUND_EVENT("event");
|
||||
|
||||
private final String name;
|
||||
|
||||
private Type(String nameIn)
|
||||
{
|
||||
this.name = nameIn;
|
||||
}
|
||||
|
||||
public static Sound.Type getByName(String nameIn)
|
||||
{
|
||||
for (Sound.Type sound$type : values())
|
||||
{
|
||||
if (sound$type.name.equals(nameIn))
|
||||
{
|
||||
return sound$type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundEventAccessor implements ISoundEventAccessor<Sound>
|
||||
{
|
||||
private final List<ISoundEventAccessor<Sound>> accessorList = Lists.<ISoundEventAccessor<Sound>>newArrayList();
|
||||
private final Random rnd = new Random();
|
||||
private final ResourceLocation location;
|
||||
private final ITextComponent subtitle;
|
||||
|
||||
public SoundEventAccessor(ResourceLocation locationIn, @Nullable String subtitleIn)
|
||||
{
|
||||
this.location = locationIn;
|
||||
this.subtitle = subtitleIn == null ? null : new TextComponentTranslation(subtitleIn, new Object[0]);
|
||||
}
|
||||
|
||||
public int getWeight()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (ISoundEventAccessor<Sound> isoundeventaccessor : this.accessorList)
|
||||
{
|
||||
i += isoundeventaccessor.getWeight();
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public Sound cloneEntry()
|
||||
{
|
||||
int i = this.getWeight();
|
||||
|
||||
if (!this.accessorList.isEmpty() && i != 0)
|
||||
{
|
||||
int j = this.rnd.nextInt(i);
|
||||
|
||||
for (ISoundEventAccessor<Sound> isoundeventaccessor : this.accessorList)
|
||||
{
|
||||
j -= isoundeventaccessor.getWeight();
|
||||
|
||||
if (j < 0)
|
||||
{
|
||||
return isoundeventaccessor.cloneEntry();
|
||||
}
|
||||
}
|
||||
|
||||
return SoundHandler.MISSING_SOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SoundHandler.MISSING_SOUND;
|
||||
}
|
||||
}
|
||||
|
||||
public void addSound(ISoundEventAccessor<Sound> p_188715_1_)
|
||||
{
|
||||
this.accessorList.add(p_188715_1_);
|
||||
}
|
||||
|
||||
public ResourceLocation getLocation()
|
||||
{
|
||||
return this.location;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ITextComponent getSubtitle()
|
||||
{
|
||||
return this.subtitle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.Closeable;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundHandler implements IResourceManagerReloadListener, ITickable
|
||||
{
|
||||
public static final Sound MISSING_SOUND = new Sound("meta:missing_sound", 1.0F, 1.0F, 1, Sound.Type.FILE, false);
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Gson GSON = (new GsonBuilder()).registerTypeHierarchyAdapter(ITextComponent.class, new ITextComponent.Serializer()).registerTypeAdapter(SoundList.class, new SoundListSerializer()).create();
|
||||
private static final ParameterizedType TYPE = new ParameterizedType()
|
||||
{
|
||||
public Type[] getActualTypeArguments()
|
||||
{
|
||||
return new Type[] {String.class, SoundList.class};
|
||||
}
|
||||
public Type getRawType()
|
||||
{
|
||||
return Map.class;
|
||||
}
|
||||
public Type getOwnerType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
};
|
||||
private final SoundRegistry soundRegistry = new SoundRegistry();
|
||||
private final SoundManager sndManager;
|
||||
private final IResourceManager mcResourceManager;
|
||||
|
||||
public SoundHandler(IResourceManager manager, GameSettings gameSettingsIn)
|
||||
{
|
||||
this.mcResourceManager = manager;
|
||||
this.sndManager = new SoundManager(this, gameSettingsIn);
|
||||
}
|
||||
|
||||
public void onResourceManagerReload(IResourceManager resourceManager)
|
||||
{
|
||||
this.soundRegistry.clearMap();
|
||||
|
||||
java.util.List<net.minecraft.util.Tuple<ResourceLocation, SoundList>> resources = new java.util.LinkedList<>();
|
||||
for (String s : resourceManager.getResourceDomains())
|
||||
{
|
||||
try
|
||||
{
|
||||
for (IResource iresource : resourceManager.getAllResources(new ResourceLocation(s, "sounds.json")))
|
||||
{
|
||||
try
|
||||
{
|
||||
Map<String, SoundList> map = this.getSoundMap(iresource.getInputStream());
|
||||
|
||||
for (Entry<String, SoundList> entry : map.entrySet())
|
||||
{
|
||||
resources.add(new net.minecraft.util.Tuple<>(new ResourceLocation(s, entry.getKey()), entry.getValue()));
|
||||
}
|
||||
}
|
||||
catch (RuntimeException runtimeexception)
|
||||
{
|
||||
LOGGER.warn("Invalid sounds.json", (Throwable)runtimeexception);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException var11)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
net.minecraftforge.fml.common.ProgressManager.ProgressBar resourcesBar = net.minecraftforge.fml.common.ProgressManager.push("Loading sounds", resources.size());
|
||||
resources.forEach(entry ->
|
||||
{
|
||||
resourcesBar.step(entry.getFirst().toString());
|
||||
try
|
||||
{
|
||||
this.loadSoundResource(entry.getFirst(), entry.getSecond());
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
LOGGER.warn("Invalid sounds.json", e);
|
||||
}
|
||||
});
|
||||
net.minecraftforge.fml.common.ProgressManager.pop(resourcesBar);
|
||||
for (ResourceLocation resourcelocation : this.soundRegistry.getKeys())
|
||||
{
|
||||
SoundEventAccessor soundeventaccessor = (SoundEventAccessor)this.soundRegistry.getObject(resourcelocation);
|
||||
|
||||
if (soundeventaccessor.getSubtitle() instanceof TextComponentTranslation)
|
||||
{
|
||||
String s1 = ((TextComponentTranslation)soundeventaccessor.getSubtitle()).getKey();
|
||||
|
||||
if (!I18n.hasKey(s1))
|
||||
{
|
||||
LOGGER.debug("Missing subtitle {} for event: {}", s1, resourcelocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ResourceLocation resourcelocation1 : this.soundRegistry.getKeys())
|
||||
{
|
||||
if (SoundEvent.REGISTRY.getObject(resourcelocation1) == null)
|
||||
{
|
||||
LOGGER.debug("Not having sound event for: {}", (Object)resourcelocation1);
|
||||
}
|
||||
}
|
||||
|
||||
this.sndManager.reloadSoundSystem();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Map<String, SoundList> getSoundMap(InputStream stream)
|
||||
{
|
||||
Map map;
|
||||
|
||||
try
|
||||
{
|
||||
map = (Map)JsonUtils.fromJson(GSON, new InputStreamReader(stream, StandardCharsets.UTF_8), TYPE);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(stream);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private void loadSoundResource(ResourceLocation location, SoundList sounds)
|
||||
{
|
||||
SoundEventAccessor soundeventaccessor = (SoundEventAccessor)this.soundRegistry.getObject(location);
|
||||
boolean flag = soundeventaccessor == null;
|
||||
|
||||
if (flag || sounds.canReplaceExisting())
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
LOGGER.debug("Replaced sound event location {}", (Object)location);
|
||||
}
|
||||
|
||||
soundeventaccessor = new SoundEventAccessor(location, sounds.getSubtitle());
|
||||
this.soundRegistry.add(soundeventaccessor);
|
||||
}
|
||||
|
||||
for (final Sound sound : sounds.getSounds())
|
||||
{
|
||||
final ResourceLocation resourcelocation = sound.getSoundLocation();
|
||||
ISoundEventAccessor<Sound> isoundeventaccessor;
|
||||
|
||||
switch (sound.getType())
|
||||
{
|
||||
case FILE:
|
||||
|
||||
if (!this.validateSoundResource(sound, location))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
isoundeventaccessor = sound;
|
||||
break;
|
||||
case SOUND_EVENT:
|
||||
isoundeventaccessor = new ISoundEventAccessor<Sound>()
|
||||
{
|
||||
public int getWeight()
|
||||
{
|
||||
SoundEventAccessor soundeventaccessor1 = (SoundEventAccessor)SoundHandler.this.soundRegistry.getObject(resourcelocation);
|
||||
return soundeventaccessor1 == null ? 0 : soundeventaccessor1.getWeight();
|
||||
}
|
||||
public Sound cloneEntry()
|
||||
{
|
||||
SoundEventAccessor soundeventaccessor1 = (SoundEventAccessor)SoundHandler.this.soundRegistry.getObject(resourcelocation);
|
||||
|
||||
if (soundeventaccessor1 == null)
|
||||
{
|
||||
return SoundHandler.MISSING_SOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sound sound1 = soundeventaccessor1.cloneEntry();
|
||||
return new Sound(sound1.getSoundLocation().toString(), sound1.getVolume() * sound.getVolume(), sound1.getPitch() * sound.getPitch(), sound.getWeight(), Sound.Type.FILE, sound1.isStreaming() || sound.isStreaming());
|
||||
}
|
||||
}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown SoundEventRegistration type: " + sound.getType());
|
||||
}
|
||||
|
||||
soundeventaccessor.addSound(isoundeventaccessor);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateSoundResource(Sound p_184401_1_, ResourceLocation p_184401_2_)
|
||||
{
|
||||
ResourceLocation resourcelocation = p_184401_1_.getSoundAsOggLocation();
|
||||
IResource iresource = null;
|
||||
boolean flag;
|
||||
|
||||
try
|
||||
{
|
||||
iresource = this.mcResourceManager.getResource(resourcelocation);
|
||||
iresource.getInputStream();
|
||||
return true;
|
||||
}
|
||||
catch (FileNotFoundException var11)
|
||||
{
|
||||
LOGGER.warn("File {} does not exist, cannot add it to event {}", resourcelocation, p_184401_2_);
|
||||
flag = false;
|
||||
}
|
||||
catch (IOException ioexception)
|
||||
{
|
||||
LOGGER.warn("Could not load sound file {}, cannot add it to event {}", resourcelocation, p_184401_2_, ioexception);
|
||||
flag = false;
|
||||
return flag;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Closeable)iresource);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public SoundEventAccessor getAccessor(ResourceLocation location)
|
||||
{
|
||||
return (SoundEventAccessor)this.soundRegistry.getObject(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a sound
|
||||
*/
|
||||
public void playSound(ISound sound)
|
||||
{
|
||||
this.sndManager.playSound(sound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound in n ticks
|
||||
*/
|
||||
public void playDelayedSound(ISound sound, int delay)
|
||||
{
|
||||
this.sndManager.playDelayedSound(sound, delay);
|
||||
}
|
||||
|
||||
public void setListener(EntityPlayer player, float p_147691_2_)
|
||||
{
|
||||
this.sndManager.setListener(player, p_147691_2_);
|
||||
}
|
||||
|
||||
public void setListener(net.minecraft.entity.Entity entity, float partialTicks)
|
||||
{
|
||||
this.sndManager.setListener(entity, partialTicks);
|
||||
}
|
||||
|
||||
public void pauseSounds()
|
||||
{
|
||||
this.sndManager.pauseAllSounds();
|
||||
}
|
||||
|
||||
public void stopSounds()
|
||||
{
|
||||
this.sndManager.stopAllSounds();
|
||||
}
|
||||
|
||||
public void unloadSounds()
|
||||
{
|
||||
this.sndManager.unloadSoundSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Like the old updateEntity(), except more generic.
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
this.sndManager.updateAllSounds();
|
||||
}
|
||||
|
||||
public void resumeSounds()
|
||||
{
|
||||
this.sndManager.resumeAllSounds();
|
||||
}
|
||||
|
||||
public void setSoundLevel(SoundCategory category, float volume)
|
||||
{
|
||||
if (category == SoundCategory.MASTER && volume <= 0.0F)
|
||||
{
|
||||
this.stopSounds();
|
||||
}
|
||||
|
||||
this.sndManager.setVolume(category, volume);
|
||||
}
|
||||
|
||||
public void stopSound(ISound soundIn)
|
||||
{
|
||||
this.sndManager.stopSound(soundIn);
|
||||
}
|
||||
|
||||
public boolean isSoundPlaying(ISound sound)
|
||||
{
|
||||
return this.sndManager.isSoundPlaying(sound);
|
||||
}
|
||||
|
||||
public void addListener(ISoundEventListener listener)
|
||||
{
|
||||
this.sndManager.addListener(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ISoundEventListener listener)
|
||||
{
|
||||
this.sndManager.removeListener(listener);
|
||||
}
|
||||
|
||||
public void stop(String p_189520_1_, SoundCategory p_189520_2_)
|
||||
{
|
||||
this.sndManager.stop(p_189520_1_, p_189520_2_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundList
|
||||
{
|
||||
private final List<Sound> sounds;
|
||||
/** if true it will override all the sounds from the resourcepacks loaded before */
|
||||
private final boolean replaceExisting;
|
||||
private final String subtitle;
|
||||
|
||||
public SoundList(List<Sound> soundsIn, boolean replceIn, String subtitleIn)
|
||||
{
|
||||
this.sounds = soundsIn;
|
||||
this.replaceExisting = replceIn;
|
||||
this.subtitle = subtitleIn;
|
||||
}
|
||||
|
||||
public List<Sound> getSounds()
|
||||
{
|
||||
return this.sounds;
|
||||
}
|
||||
|
||||
public boolean canReplaceExisting()
|
||||
{
|
||||
return this.replaceExisting;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getSubtitle()
|
||||
{
|
||||
return this.subtitle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundListSerializer implements JsonDeserializer<SoundList>
|
||||
{
|
||||
public SoundList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
||||
{
|
||||
JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "entry");
|
||||
boolean flag = JsonUtils.getBoolean(jsonobject, "replace", false);
|
||||
String s = JsonUtils.getString(jsonobject, "subtitle", (String)null);
|
||||
List<Sound> list = this.deserializeSounds(jsonobject);
|
||||
return new SoundList(list, flag, s);
|
||||
}
|
||||
|
||||
private List<Sound> deserializeSounds(JsonObject object)
|
||||
{
|
||||
List<Sound> list = Lists.<Sound>newArrayList();
|
||||
|
||||
if (object.has("sounds"))
|
||||
{
|
||||
JsonArray jsonarray = JsonUtils.getJsonArray(object, "sounds");
|
||||
|
||||
for (int i = 0; i < jsonarray.size(); ++i)
|
||||
{
|
||||
JsonElement jsonelement = jsonarray.get(i);
|
||||
|
||||
if (JsonUtils.isString(jsonelement))
|
||||
{
|
||||
String s = JsonUtils.getString(jsonelement, "sound");
|
||||
list.add(new Sound(s, 1.0F, 1.0F, 1, Sound.Type.FILE, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.add(this.deserializeSound(JsonUtils.getJsonObject(jsonelement, "sound")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private Sound deserializeSound(JsonObject object)
|
||||
{
|
||||
String s = JsonUtils.getString(object, "name");
|
||||
Sound.Type sound$type = this.deserializeType(object, Sound.Type.FILE);
|
||||
float f = JsonUtils.getFloat(object, "volume", 1.0F);
|
||||
Validate.isTrue(f > 0.0F, "Invalid volume");
|
||||
float f1 = JsonUtils.getFloat(object, "pitch", 1.0F);
|
||||
Validate.isTrue(f1 > 0.0F, "Invalid pitch");
|
||||
int i = JsonUtils.getInt(object, "weight", 1);
|
||||
Validate.isTrue(i > 0, "Invalid weight");
|
||||
boolean flag = JsonUtils.getBoolean(object, "stream", false);
|
||||
return new Sound(s, f, f1, i, sound$type, flag);
|
||||
}
|
||||
|
||||
private Sound.Type deserializeType(JsonObject object, Sound.Type defaultValue)
|
||||
{
|
||||
Sound.Type sound$type = defaultValue;
|
||||
|
||||
if (object.has("type"))
|
||||
{
|
||||
sound$type = Sound.Type.getByName(JsonUtils.getString(object, "type"));
|
||||
Validate.notNull(sound$type, "Invalid type");
|
||||
}
|
||||
|
||||
return sound$type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,645 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.netty.util.internal.ThreadLocalRandom;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
import paulscode.sound.SoundSystem;
|
||||
import paulscode.sound.SoundSystemConfig;
|
||||
import paulscode.sound.SoundSystemException;
|
||||
import paulscode.sound.SoundSystemLogger;
|
||||
import paulscode.sound.Source;
|
||||
import paulscode.sound.codecs.CodecJOrbis;
|
||||
import paulscode.sound.libraries.LibraryLWJGLOpenAL;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundManager
|
||||
{
|
||||
/** The marker used for logging */
|
||||
private static final Marker LOG_MARKER = MarkerManager.getMarker("SOUNDS");
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Set<ResourceLocation> UNABLE_TO_PLAY = Sets.<ResourceLocation>newHashSet();
|
||||
/** A reference to the sound handler. */
|
||||
public final SoundHandler sndHandler;
|
||||
/** Reference to the GameSettings object. */
|
||||
private final GameSettings options;
|
||||
/** A reference to the sound system. */
|
||||
private SoundManager.SoundSystemStarterThread sndSystem;
|
||||
/** Set to true when the SoundManager has been initialised. */
|
||||
private boolean loaded;
|
||||
/** A counter for how long the sound manager has been running */
|
||||
private int playTime;
|
||||
/** Identifiers of all currently playing sounds. Type: HashBiMap<String, ISound> */
|
||||
private final Map<String, ISound> playingSounds = HashBiMap.<String, ISound>create();
|
||||
/** Inverse map of currently playing sounds, automatically mirroring changes in original map */
|
||||
private final Map<ISound, String> invPlayingSounds;
|
||||
private final Multimap<SoundCategory, String> categorySounds;
|
||||
/** A subset of playingSounds, this contains only ITickableSounds */
|
||||
private final List<ITickableSound> tickableSounds;
|
||||
/** Contains sounds to play in n ticks. Type: HashMap<ISound, Integer> */
|
||||
private final Map<ISound, Integer> delayedSounds;
|
||||
/** The future time in which to stop this sound. Type: HashMap<String, Integer> */
|
||||
private final Map<String, Integer> playingSoundsStopTime;
|
||||
private final List<ISoundEventListener> listeners;
|
||||
private final List<String> pausedChannels;
|
||||
|
||||
public SoundManager(SoundHandler p_i45119_1_, GameSettings p_i45119_2_)
|
||||
{
|
||||
this.invPlayingSounds = ((BiMap)this.playingSounds).inverse();
|
||||
this.categorySounds = HashMultimap.<SoundCategory, String>create();
|
||||
this.tickableSounds = Lists.<ITickableSound>newArrayList();
|
||||
this.delayedSounds = Maps.<ISound, Integer>newHashMap();
|
||||
this.playingSoundsStopTime = Maps.<String, Integer>newHashMap();
|
||||
this.listeners = Lists.<ISoundEventListener>newArrayList();
|
||||
this.pausedChannels = Lists.<String>newArrayList();
|
||||
this.sndHandler = p_i45119_1_;
|
||||
this.options = p_i45119_2_;
|
||||
|
||||
try
|
||||
{
|
||||
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
|
||||
SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);
|
||||
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.SoundSetupEvent(this));
|
||||
}
|
||||
catch (SoundSystemException soundsystemexception)
|
||||
{
|
||||
LOGGER.error(LOG_MARKER, "Error linking with the LibraryJavaSound plug-in", (Throwable)soundsystemexception);
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadSoundSystem()
|
||||
{
|
||||
UNABLE_TO_PLAY.clear();
|
||||
|
||||
for (SoundEvent soundevent : SoundEvent.REGISTRY)
|
||||
{
|
||||
ResourceLocation resourcelocation = soundevent.getSoundName();
|
||||
|
||||
if (this.sndHandler.getAccessor(resourcelocation) == null)
|
||||
{
|
||||
LOGGER.warn("Missing sound for event: {}", SoundEvent.REGISTRY.getNameForObject(soundevent));
|
||||
UNABLE_TO_PLAY.add(resourcelocation);
|
||||
}
|
||||
}
|
||||
|
||||
this.unloadSoundSystem();
|
||||
this.loadSoundSystem();
|
||||
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.SoundLoadEvent(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to add the paulscode library and the relevant codecs. If it fails, the master volume will be set to zero.
|
||||
*/
|
||||
private synchronized void loadSoundSystem()
|
||||
{
|
||||
if (!this.loaded)
|
||||
{
|
||||
try
|
||||
{
|
||||
(new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
SoundSystemConfig.setLogger(new SoundSystemLogger()
|
||||
{
|
||||
public void message(String p_message_1_, int p_message_2_)
|
||||
{
|
||||
if (!p_message_1_.isEmpty())
|
||||
{
|
||||
SoundManager.LOGGER.info(p_message_1_);
|
||||
}
|
||||
}
|
||||
public void importantMessage(String p_importantMessage_1_, int p_importantMessage_2_)
|
||||
{
|
||||
if (!p_importantMessage_1_.isEmpty())
|
||||
{
|
||||
SoundManager.LOGGER.warn(p_importantMessage_1_);
|
||||
}
|
||||
}
|
||||
public void errorMessage(String p_errorMessage_1_, String p_errorMessage_2_, int p_errorMessage_3_)
|
||||
{
|
||||
if (!p_errorMessage_2_.isEmpty())
|
||||
{
|
||||
SoundManager.LOGGER.error("Error in class '{}'", (Object)p_errorMessage_1_);
|
||||
SoundManager.LOGGER.error(p_errorMessage_2_);
|
||||
}
|
||||
}
|
||||
});
|
||||
SoundManager.this.sndSystem = SoundManager.this.new SoundSystemStarterThread();
|
||||
SoundManager.this.loaded = true;
|
||||
SoundManager.this.sndSystem.setMasterVolume(SoundManager.this.options.getSoundLevel(SoundCategory.MASTER));
|
||||
SoundManager.LOGGER.info(SoundManager.LOG_MARKER, "Sound engine started");
|
||||
}
|
||||
}, "Sound Library Loader")).start();
|
||||
}
|
||||
catch (RuntimeException runtimeexception)
|
||||
{
|
||||
LOGGER.error(LOG_MARKER, "Error starting SoundSystem. Turning off sounds & music", (Throwable)runtimeexception);
|
||||
this.options.setSoundLevel(SoundCategory.MASTER, 0.0F);
|
||||
this.options.saveOptions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float getVolume(SoundCategory category)
|
||||
{
|
||||
return category != null && category != SoundCategory.MASTER ? this.options.getSoundLevel(category) : 1.0F;
|
||||
}
|
||||
|
||||
public void setVolume(SoundCategory category, float volume)
|
||||
{
|
||||
if (this.loaded)
|
||||
{
|
||||
if (category == SoundCategory.MASTER)
|
||||
{
|
||||
this.sndSystem.setMasterVolume(volume);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : this.categorySounds.get(category))
|
||||
{
|
||||
ISound isound = this.playingSounds.get(s);
|
||||
float f = this.getClampedVolume(isound);
|
||||
|
||||
if (f <= 0.0F)
|
||||
{
|
||||
this.stopSound(isound);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sndSystem.setVolume(s, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the Sound System
|
||||
*/
|
||||
public void unloadSoundSystem()
|
||||
{
|
||||
if (this.loaded)
|
||||
{
|
||||
this.stopAllSounds();
|
||||
this.sndSystem.cleanup();
|
||||
this.loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops all currently playing sounds
|
||||
*/
|
||||
public void stopAllSounds()
|
||||
{
|
||||
if (this.loaded)
|
||||
{
|
||||
for (String s : this.playingSounds.keySet())
|
||||
{
|
||||
this.sndSystem.stop(s);
|
||||
}
|
||||
|
||||
this.pausedChannels.clear(); //Forge: MC-35856 Fixed paused sounds repeating when switching worlds
|
||||
this.playingSounds.clear();
|
||||
this.delayedSounds.clear();
|
||||
this.tickableSounds.clear();
|
||||
this.categorySounds.clear();
|
||||
this.playingSoundsStopTime.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(ISoundEventListener listener)
|
||||
{
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ISoundEventListener listener)
|
||||
{
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void updateAllSounds()
|
||||
{
|
||||
++this.playTime;
|
||||
|
||||
for (ITickableSound itickablesound : this.tickableSounds)
|
||||
{
|
||||
itickablesound.update();
|
||||
|
||||
if (itickablesound.isDonePlaying())
|
||||
{
|
||||
this.stopSound(itickablesound);
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = this.invPlayingSounds.get(itickablesound);
|
||||
this.sndSystem.setVolume(s, this.getClampedVolume(itickablesound));
|
||||
this.sndSystem.setPitch(s, this.getClampedPitch(itickablesound));
|
||||
this.sndSystem.setPosition(s, itickablesound.getXPosF(), itickablesound.getYPosF(), itickablesound.getZPosF());
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Entry<String, ISound>> iterator = this.playingSounds.entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Entry<String, ISound> entry = (Entry)iterator.next();
|
||||
String s1 = entry.getKey();
|
||||
ISound isound = entry.getValue();
|
||||
|
||||
if (!this.sndSystem.playing(s1))
|
||||
{
|
||||
int i = ((Integer)this.playingSoundsStopTime.get(s1)).intValue();
|
||||
|
||||
if (i <= this.playTime)
|
||||
{
|
||||
int j = isound.getRepeatDelay();
|
||||
|
||||
if (isound.canRepeat() && j > 0)
|
||||
{
|
||||
this.delayedSounds.put(isound, Integer.valueOf(this.playTime + j));
|
||||
}
|
||||
|
||||
iterator.remove();
|
||||
LOGGER.debug(LOG_MARKER, "Removed channel {} because it's not playing anymore", (Object)s1);
|
||||
this.sndSystem.removeSource(s1);
|
||||
this.playingSoundsStopTime.remove(s1);
|
||||
|
||||
try
|
||||
{
|
||||
this.categorySounds.remove(isound.getCategory(), s1);
|
||||
}
|
||||
catch (RuntimeException var8)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (isound instanceof ITickableSound)
|
||||
{
|
||||
this.tickableSounds.remove(isound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Entry<ISound, Integer>> iterator1 = this.delayedSounds.entrySet().iterator();
|
||||
|
||||
while (iterator1.hasNext())
|
||||
{
|
||||
Entry<ISound, Integer> entry1 = (Entry)iterator1.next();
|
||||
|
||||
if (this.playTime >= ((Integer)entry1.getValue()).intValue())
|
||||
{
|
||||
ISound isound1 = entry1.getKey();
|
||||
|
||||
if (isound1 instanceof ITickableSound)
|
||||
{
|
||||
((ITickableSound)isound1).update();
|
||||
}
|
||||
|
||||
this.playSound(isound1);
|
||||
iterator1.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the sound is playing or still within time
|
||||
*/
|
||||
public boolean isSoundPlaying(ISound sound)
|
||||
{
|
||||
if (!this.loaded)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = this.invPlayingSounds.get(sound);
|
||||
|
||||
if (s == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.sndSystem.playing(s) || this.playingSoundsStopTime.containsKey(s) && ((Integer)this.playingSoundsStopTime.get(s)).intValue() <= this.playTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopSound(ISound sound)
|
||||
{
|
||||
if (this.loaded)
|
||||
{
|
||||
String s = this.invPlayingSounds.get(sound);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
this.sndSystem.stop(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playSound(ISound p_sound)
|
||||
{
|
||||
if (this.loaded)
|
||||
{
|
||||
p_sound = net.minecraftforge.client.ForgeHooksClient.playSound(this, p_sound);
|
||||
if (p_sound == null) return;
|
||||
|
||||
SoundEventAccessor soundeventaccessor = p_sound.createAccessor(this.sndHandler);
|
||||
ResourceLocation resourcelocation = p_sound.getSoundLocation();
|
||||
|
||||
if (soundeventaccessor == null)
|
||||
{
|
||||
if (UNABLE_TO_PLAY.add(resourcelocation))
|
||||
{
|
||||
LOGGER.warn(LOG_MARKER, "Unable to play unknown soundEvent: {}", (Object)resourcelocation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.listeners.isEmpty())
|
||||
{
|
||||
for (ISoundEventListener isoundeventlistener : this.listeners)
|
||||
{
|
||||
isoundeventlistener.soundPlay(p_sound, soundeventaccessor);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.sndSystem.getMasterVolume() <= 0.0F)
|
||||
{
|
||||
LOGGER.debug(LOG_MARKER, "Skipped playing soundEvent: {}, master volume was zero", (Object)resourcelocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
Sound sound = p_sound.getSound();
|
||||
|
||||
if (sound == SoundHandler.MISSING_SOUND)
|
||||
{
|
||||
if (UNABLE_TO_PLAY.add(resourcelocation))
|
||||
{
|
||||
LOGGER.warn(LOG_MARKER, "Unable to play empty soundEvent: {}", (Object)resourcelocation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float f3 = p_sound.getVolume();
|
||||
float f = 16.0F;
|
||||
|
||||
if (f3 > 1.0F)
|
||||
{
|
||||
f *= f3;
|
||||
}
|
||||
|
||||
SoundCategory soundcategory = p_sound.getCategory();
|
||||
float f1 = this.getClampedVolume(p_sound);
|
||||
float f2 = this.getClampedPitch(p_sound);
|
||||
|
||||
if (f1 == 0.0F)
|
||||
{
|
||||
LOGGER.debug(LOG_MARKER, "Skipped playing sound {}, volume was zero.", (Object)sound.getSoundLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = p_sound.canRepeat() && p_sound.getRepeatDelay() == 0;
|
||||
String s = MathHelper.getRandomUUID(ThreadLocalRandom.current()).toString();
|
||||
ResourceLocation resourcelocation1 = sound.getSoundAsOggLocation();
|
||||
|
||||
if (sound.isStreaming())
|
||||
{
|
||||
this.sndSystem.newStreamingSource(false, s, getURLForSoundResource(resourcelocation1), resourcelocation1.toString(), flag, p_sound.getXPosF(), p_sound.getYPosF(), p_sound.getZPosF(), p_sound.getAttenuationType().getTypeInt(), f);
|
||||
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.PlayStreamingSourceEvent(this, p_sound, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sndSystem.newSource(false, s, getURLForSoundResource(resourcelocation1), resourcelocation1.toString(), flag, p_sound.getXPosF(), p_sound.getYPosF(), p_sound.getZPosF(), p_sound.getAttenuationType().getTypeInt(), f);
|
||||
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.PlaySoundSourceEvent(this, p_sound, s));
|
||||
}
|
||||
|
||||
LOGGER.debug(LOG_MARKER, "Playing sound {} for event {} as channel {}", sound.getSoundLocation(), resourcelocation, s);
|
||||
this.sndSystem.setPitch(s, f2);
|
||||
this.sndSystem.setVolume(s, f1);
|
||||
this.sndSystem.play(s);
|
||||
this.playingSoundsStopTime.put(s, Integer.valueOf(this.playTime + 20));
|
||||
this.playingSounds.put(s, p_sound);
|
||||
this.categorySounds.put(soundcategory, s);
|
||||
|
||||
if (p_sound instanceof ITickableSound)
|
||||
{
|
||||
this.tickableSounds.add((ITickableSound)p_sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float getClampedPitch(ISound soundIn)
|
||||
{
|
||||
return MathHelper.clamp(soundIn.getPitch(), 0.5F, 2.0F);
|
||||
}
|
||||
|
||||
private float getClampedVolume(ISound soundIn)
|
||||
{
|
||||
return MathHelper.clamp(soundIn.getVolume() * this.getVolume(soundIn.getCategory()), 0.0F, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses all currently playing sounds
|
||||
*/
|
||||
public void pauseAllSounds()
|
||||
{
|
||||
for (Entry<String, ISound> entry : this.playingSounds.entrySet())
|
||||
{
|
||||
String s = entry.getKey();
|
||||
boolean flag = this.isSoundPlaying(entry.getValue());
|
||||
|
||||
if (flag)
|
||||
{
|
||||
LOGGER.debug(LOG_MARKER, "Pausing channel {}", (Object)s);
|
||||
this.sndSystem.pause(s);
|
||||
this.pausedChannels.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes playing all currently playing sounds (after pauseAllSounds)
|
||||
*/
|
||||
public void resumeAllSounds()
|
||||
{
|
||||
for (String s : this.pausedChannels)
|
||||
{
|
||||
LOGGER.debug(LOG_MARKER, "Resuming channel {}", (Object)s);
|
||||
this.sndSystem.play(s);
|
||||
}
|
||||
|
||||
this.pausedChannels.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a sound to play in n tick
|
||||
*/
|
||||
public void playDelayedSound(ISound sound, int delay)
|
||||
{
|
||||
this.delayedSounds.put(sound, Integer.valueOf(this.playTime + delay));
|
||||
}
|
||||
|
||||
private static URL getURLForSoundResource(final ResourceLocation p_148612_0_)
|
||||
{
|
||||
String s = String.format("%s:%s:%s", "mcsounddomain", p_148612_0_.getResourceDomain(), p_148612_0_.getResourcePath());
|
||||
URLStreamHandler urlstreamhandler = new URLStreamHandler()
|
||||
{
|
||||
protected URLConnection openConnection(URL p_openConnection_1_)
|
||||
{
|
||||
return new URLConnection(p_openConnection_1_)
|
||||
{
|
||||
public void connect() throws IOException
|
||||
{
|
||||
}
|
||||
public InputStream getInputStream() throws IOException
|
||||
{
|
||||
return Minecraft.getMinecraft().getResourceManager().getResource(p_148612_0_).getInputStream();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
return new URL((URL)null, s, urlstreamhandler);
|
||||
}
|
||||
catch (MalformedURLException var4)
|
||||
{
|
||||
throw new Error("TODO: Sanely handle url exception! :D");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the listener of sounds
|
||||
*/
|
||||
public void setListener(EntityPlayer player, float p_148615_2_)
|
||||
{
|
||||
setListener((net.minecraft.entity.Entity) player, p_148615_2_);
|
||||
}
|
||||
|
||||
public void setListener(net.minecraft.entity.Entity player, float p_148615_2_)
|
||||
{
|
||||
if (this.loaded && player != null)
|
||||
{
|
||||
float f = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * p_148615_2_;
|
||||
float f1 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * p_148615_2_;
|
||||
double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)p_148615_2_;
|
||||
double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)p_148615_2_ + (double)player.getEyeHeight();
|
||||
double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)p_148615_2_;
|
||||
float f2 = MathHelper.cos((f1 + 90.0F) * 0.017453292F);
|
||||
float f3 = MathHelper.sin((f1 + 90.0F) * 0.017453292F);
|
||||
float f4 = MathHelper.cos(-f * 0.017453292F);
|
||||
float f5 = MathHelper.sin(-f * 0.017453292F);
|
||||
float f6 = MathHelper.cos((-f + 90.0F) * 0.017453292F);
|
||||
float f7 = MathHelper.sin((-f + 90.0F) * 0.017453292F);
|
||||
float f8 = f2 * f4;
|
||||
float f9 = f3 * f4;
|
||||
float f10 = f2 * f6;
|
||||
float f11 = f3 * f6;
|
||||
this.sndSystem.setListenerPosition((float)d0, (float)d1, (float)d2);
|
||||
this.sndSystem.setListenerOrientation(f8, f5, f9, f10, f7, f11);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(String p_189567_1_, SoundCategory p_189567_2_)
|
||||
{
|
||||
if (p_189567_2_ != null)
|
||||
{
|
||||
for (String s : this.categorySounds.get(p_189567_2_))
|
||||
{
|
||||
ISound isound = this.playingSounds.get(s);
|
||||
|
||||
if (p_189567_1_.isEmpty())
|
||||
{
|
||||
this.stopSound(isound);
|
||||
}
|
||||
else if (isound.getSoundLocation().equals(new ResourceLocation(p_189567_1_)))
|
||||
{
|
||||
this.stopSound(isound);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (p_189567_1_.isEmpty())
|
||||
{
|
||||
this.stopAllSounds();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ISound isound1 : this.playingSounds.values())
|
||||
{
|
||||
if (isound1.getSoundLocation().equals(new ResourceLocation(p_189567_1_)))
|
||||
{
|
||||
this.stopSound(isound1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
class SoundSystemStarterThread extends SoundSystem
|
||||
{
|
||||
private SoundSystemStarterThread()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean playing(String p_playing_1_)
|
||||
{
|
||||
synchronized (SoundSystemConfig.THREAD_SYNC)
|
||||
{
|
||||
if (this.soundLibrary == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Source source = (Source)this.soundLibrary.getSources().get(p_playing_1_);
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return source.playing() || source.paused() || source.preLoad;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.RegistrySimple;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SoundRegistry extends RegistrySimple<ResourceLocation, SoundEventAccessor>
|
||||
{
|
||||
/** Contains all registered sound */
|
||||
private Map<ResourceLocation, SoundEventAccessor> soundRegistry;
|
||||
|
||||
/**
|
||||
* Creates the Map we will use to map keys to their registered values.
|
||||
*/
|
||||
protected Map<ResourceLocation, SoundEventAccessor> createUnderlyingMap()
|
||||
{
|
||||
this.soundRegistry = Maps.<ResourceLocation, SoundEventAccessor>newHashMap();
|
||||
return this.soundRegistry;
|
||||
}
|
||||
|
||||
public void add(SoundEventAccessor accessor)
|
||||
{
|
||||
this.putObject(accessor.getLocation(), accessor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the underlying sound map (Called on resource manager reload)
|
||||
*/
|
||||
public void clearMap()
|
||||
{
|
||||
this.soundRegistry.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraft.client.audio;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
Reference in New Issue
Block a user