Search in sources :

Example 1 with PositionedSoundRecord

use of net.minecraft.client.audio.PositionedSoundRecord in project ForestryMC by ForestryMC.

the class SoundUtil method playSoundEvent.

@SideOnly(Side.CLIENT)
public static void playSoundEvent(SoundEvent soundIn, float pitchIn) {
    Minecraft minecraft = Minecraft.getMinecraft();
    SoundHandler soundHandler = minecraft.getSoundHandler();
    PositionedSoundRecord sound = PositionedSoundRecord.getMasterRecord(soundIn, pitchIn);
    soundHandler.playSound(sound);
}
Also used : PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) SoundHandler(net.minecraft.client.audio.SoundHandler) Minecraft(net.minecraft.client.Minecraft) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with PositionedSoundRecord

use of net.minecraft.client.audio.PositionedSoundRecord in project Galacticraft by micdoodle8.

the class EventHandlerGC method onSoundPlayed.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onSoundPlayed(PlaySoundEvent event) {
    // The event.result starts off equal to event.sound, but could have been altered or set to null by another mod
    if (event.result == null) {
        return;
    }
    EntityPlayerSP player = FMLClientHandler.instance().getClient().thePlayer;
    if (player != null && player.worldObj != null && player.worldObj.provider instanceof IGalacticraftWorldProvider && event != null) {
        // Only modify standard game sounds, not music
        if (event.result.getAttenuationType() != ISound.AttenuationType.NONE) {
            PlayerGearData gearData = ClientProxyCore.playerItemData.get(PlayerUtil.getName(player));
            float x = event.result.getXPosF();
            float y = event.result.getYPosF();
            float z = event.result.getZPosF();
            if (gearData == null || gearData.getFrequencyModule() == -1) {
                // If the player doesn't have a frequency module, and the player isn't in an oxygenated environment
                // Note: this is a very simplistic approach, and nowhere near realistic, but required for performance reasons
                AxisAlignedBB bb = AxisAlignedBB.fromBounds(x - 0.0015D, y - 0.0015D, z - 0.0015D, x + 0.0015D, y + 0.0015D, z + 0.0015D);
                boolean playerInAtmosphere = OxygenUtil.isAABBInBreathableAirBlock(player);
                boolean soundInAtmosphere = OxygenUtil.isAABBInBreathableAirBlock(player.worldObj, bb);
                if ((!playerInAtmosphere || !soundInAtmosphere)) {
                    float volume = event.result.getVolume();
                    // First check for duplicate firing of PlaySoundEvent17 on this handler's own playing of a reduced volume sound (see below)
                    for (int i = 0; i < this.soundPlayList.size(); i++) {
                        SoundPlayEntry entry = this.soundPlayList.get(i);
                        if (entry.name.equals(event.name) && entry.x == x && entry.y == y && entry.z == z && entry.volume == volume) {
                            this.soundPlayList.remove(i);
                            return;
                        }
                    }
                    // If it's not a duplicate: play the same sound but at reduced volume
                    float newVolume = volume / Math.max(0.01F, ((IGalacticraftWorldProvider) player.worldObj.provider).getSoundVolReductionAmount());
                    this.soundPlayList.add(new SoundPlayEntry(event.name, x, y, z, newVolume));
                    ISound newSound = new PositionedSoundRecord(event.result.getSoundLocation(), newVolume, event.result.getPitch(), x, y, z);
                    event.manager.playSound(newSound);
                    event.result = null;
                    return;
                }
            }
        }
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) PlayerGearData(micdoodle8.mods.galacticraft.core.wrappers.PlayerGearData) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with PositionedSoundRecord

use of net.minecraft.client.audio.PositionedSoundRecord in project Galacticraft by micdoodle8.

the class PlayerClient method onLivingUpdatePost.

@Override
public void onLivingUpdatePost(EntityPlayerSP player) {
    GCPlayerStatsClient stats = GCPlayerStatsClient.get(player);
    boolean ridingThirdPersonEntity = player.ridingEntity instanceof ICameraZoomEntity && ((ICameraZoomEntity) player.ridingEntity).defaultThirdPerson();
    if (stats.getPlatformControlled() || player.worldObj.provider instanceof IZeroGDimension) {
        stats.getFreefallHandler().postVanillaMotion(player);
        if (stats.isInFreefall() || ridingThirdPersonEntity) {
            this.cancelLimbSwing(player);
        } else {
            if (stats.isInFreefallLast() && this.downMot2 < -0.008D) {
                stats.setLandingTicks(5 - (int) (Math.min(this.downMot2, stats.getDownMotionLast()) * 40));
                if (stats.getLandingTicks() > stats.getMaxLandingticks()) {
                    if (stats.getLandingTicks() > stats.getMaxLandingticks() + 4) {
                        stats.getFreefallHandler().pjumpticks = stats.getLandingTicks() - stats.getMaxLandingticks() - 5;
                    }
                    stats.setLandingTicks(stats.getMaxLandingticks());
                }
                float dYmax = 0.3F * stats.getLandingTicks() / stats.getMaxLandingticks();
                float factor = 1F;
                for (int i = 0; i <= stats.getLandingTicks(); i++) {
                    stats.getLandingYOffset()[i] = dYmax * MathHelper.sin(i * 3.1415926F / stats.getLandingTicks()) * factor;
                    factor *= 0.97F;
                }
            }
        }
        if (stats.getLandingTicks() > 0) {
            stats.setLandingTicks(stats.getLandingTicks() - 1);
            player.limbSwing *= 0.8F;
            player.limbSwingAmount = 0F;
        }
    } else {
        stats.setInFreefall(false);
        if (ridingThirdPersonEntity) {
            this.cancelLimbSwing(player);
        }
    }
    if (ridingThirdPersonEntity && !stats.isLastRidingCameraZoomEntity()) {
        if (!ConfigManagerCore.disableVehicleCameraChanges)
            FMLClientHandler.instance().getClient().gameSettings.thirdPersonView = 1;
    }
    if (player.ridingEntity instanceof ICameraZoomEntity) {
        if (!ConfigManagerCore.disableVehicleCameraChanges) {
            stats.setLastZoomed(true);
            TickHandlerClient.zoom(((ICameraZoomEntity) player.ridingEntity).getCameraZoom());
        }
    } else if (stats.isLastZoomed()) {
        if (!ConfigManagerCore.disableVehicleCameraChanges) {
            stats.setLastZoomed(false);
            TickHandlerClient.zoom(4.0F);
        }
    }
    stats.setLastRidingCameraZoomEntity(ridingThirdPersonEntity);
    if (stats.isUsingParachute()) {
        player.fallDistance = 0.0F;
    }
    PlayerGearData gearData = GalacticraftCore.proxy.getGearData(player);
    stats.setUsingParachute(false);
    if (gearData != null) {
        stats.setUsingParachute(gearData.getParachute() != null);
        if (!GalacticraftCore.isHeightConflictingModInstalled) {
            if (gearData.getMask() != GCPlayerHandler.GEAR_NOT_PRESENT) {
                player.height = 1.9375F;
            } else {
                player.height = 1.8F;
            }
            AxisAlignedBB bounds = player.getEntityBoundingBox();
            player.setEntityBoundingBox(new AxisAlignedBB(bounds.minX, bounds.minY, bounds.minZ, bounds.maxX, bounds.minY + (double) player.height, bounds.maxZ));
        }
    }
    if (stats.isUsingParachute() && player.onGround) {
        stats.setUsingParachute(false);
        stats.setLastUsingParachute(false);
        FMLClientHandler.instance().getClient().gameSettings.thirdPersonView = stats.getThirdPersonView();
    }
    if (!stats.isLastUsingParachute() && stats.isUsingParachute()) {
        FMLClientHandler.instance().getClient().getSoundHandler().playSound(new PositionedSoundRecord(new ResourceLocation(Constants.TEXTURE_PREFIX + "player.parachute"), 0.95F + player.getRNG().nextFloat() * 0.1F, 1.0F, (float) player.posX, (float) player.posY, (float) player.posZ));
    }
    stats.setLastUsingParachute(stats.isUsingParachute());
    stats.setLastOnGround(player.onGround);
}
Also used : PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) ICameraZoomEntity(micdoodle8.mods.galacticraft.api.entity.ICameraZoomEntity) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension) PlayerGearData(micdoodle8.mods.galacticraft.core.wrappers.PlayerGearData)

Example 4 with PositionedSoundRecord

use of net.minecraft.client.audio.PositionedSoundRecord in project BetterRain by OreCruncher.

the class PlayerSoundEffectHandler method soundEvent.

/*
	 * Intercept the sound events and patch up the rain sound. If the rain
	 * experience is to be Vanilla let it just roll on through.
	 */
@SubscribeEvent
public void soundEvent(final PlaySoundEvent event) {
    if (event.sound == null)
        return;
    if ((ModOptions.alwaysOverrideSound || !StormProperties.doVanilla()) && replaceRainSound(event.name)) {
        final ISound sound = event.sound;
        event.result = new PositionedSoundRecord(StormProperties.getCurrentStormSound(), StormProperties.getCurrentVolume(), sound.getPitch(), sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
        return;
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

PositionedSoundRecord (net.minecraft.client.audio.PositionedSoundRecord)4 PlayerGearData (micdoodle8.mods.galacticraft.core.wrappers.PlayerGearData)2 ISound (net.minecraft.client.audio.ISound)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 ICameraZoomEntity (micdoodle8.mods.galacticraft.api.entity.ICameraZoomEntity)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)1 Minecraft (net.minecraft.client.Minecraft)1 SoundHandler (net.minecraft.client.audio.SoundHandler)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1