public void playRecord(String recordName, BlockPos blockPosIn) { ISound isound = (ISound)this.mapSoundPositions.get(blockPosIn); if (isound != null) { this.mc.getSoundHandler().stopSound(isound); this.mapSoundPositions.remove(blockPosIn); } if (recordName != null) { ItemRecord itemrecord = ItemRecord.getRecord(recordName); if (itemrecord != null) { this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordNameLocal()); } PositionedSoundRecord positionedsoundrecord = PositionedSoundRecord.create(new ResourceLocation(recordName), (float)blockPosIn.getX(), (float)blockPosIn.getY(), (float)blockPosIn.getZ()); this.mapSoundPositions.put(blockPosIn, positionedsoundrecord); this.mc.getSoundHandler().playSound(positionedsoundrecord); } }
public void playRecord(@Nullable SoundEvent soundIn, BlockPos pos) { ISound isound = (ISound)this.mapSoundPositions.get(pos); if (isound != null) { this.mc.getSoundHandler().stopSound(isound); this.mapSoundPositions.remove(pos); } if (soundIn != null) { ItemRecord itemrecord = ItemRecord.getBySound(soundIn); if (itemrecord != null) { this.mc.ingameGUI.setRecordPlayingMessage(itemrecord.getRecordNameLocal()); } PositionedSoundRecord positionedsoundrecord = PositionedSoundRecord.getRecordSoundRecord(soundIn, (float)pos.getX(), (float)pos.getY(), (float)pos.getZ()); this.mapSoundPositions.put(pos, positionedsoundrecord); this.mc.getSoundHandler().playSound(positionedsoundrecord); } }
public void soundPlay(ISound soundIn, SoundEventAccessor accessor) { if (accessor.getSubtitle() != null) { String s = accessor.getSubtitle().getFormattedText(); if (!this.subtitles.isEmpty()) { for (GuiSubtitleOverlay.Subtitle guisubtitleoverlay$subtitle : this.subtitles) { if (guisubtitleoverlay$subtitle.getString().equals(s)) { guisubtitleoverlay$subtitle.refresh(new Vec3d((double)soundIn.getXPosF(), (double)soundIn.getYPosF(), (double)soundIn.getZPosF())); return; } } } this.subtitles.add(new GuiSubtitleOverlay.Subtitle(s, new Vec3d((double)soundIn.getXPosF(), (double)soundIn.getYPosF(), (double)soundIn.getZPosF()))); } }
@SubscribeEvent public void playSound(PlaySoundEvent event){ World world = CrystalMod.proxy.getClientWorld(); if(world == null)return; ISound sound = event.getSound(); //if(sound instanceof ITickableSound)return; AxisAlignedBB bb = new AxisAlignedBB(sound.getXPosF(), sound.getYPosF(), sound.getZPosF(), sound.getXPosF(), sound.getYPosF(), sound.getZPosF()).expand(16, 16, 16); List<TileSoundMuffler> mufflers = BlockUtil.searchBoxForTiles(world, bb, TileSoundMuffler.class, null); for(TileSoundMuffler muffler : mufflers){ if(muffler.isSoundInList(sound.getSoundLocation())){ if(muffler.getVolume() <= 0.0f){ event.setResultSound(null); } else { event.setResultSound(new WrappedSound(event.getSound(), muffler.getVolume())); } break; } } }
@SubscribeEvent public void onMusicControl(PlaySoundEvent event) { ISound sound = event.getSound(); SoundCategory category = sound.getCategory(); if (category == SoundCategory.MUSIC) { if (this.mc.thePlayer != null && this.mc.thePlayer.dimension == AetherConfig.getAetherDimensionID()) { if (!sound.getSoundLocation().toString().contains("aether_legacy") && (this.musicTicker.playingMusic() || !this.musicTicker.playingMusic())) { event.setResultSound(null); return; } } } else if (category == SoundCategory.RECORDS) { this.musicTicker.stopMusic(); this.mc.getSoundHandler().stopSounds(); return; } }
/** Play or prevent sound and subtitle according to settings. * This event catches some entity & all other sounds */ @SubscribeEvent public static void playSound(PlaySoundEvent event) { ISound sound = event.getSound(); SoundCategory category = SoundCategory.categorise(sound); SoundResult result = categoryResults.get(category); if (!result.playSound()) { event.setResultSound(null); } if (result.showSubtitle()) { guiSubtitles.addSubtitle(sound, Minecraft.getMinecraft() .getSoundHandler().getAccessor(event.getSound() .getSoundLocation()), result.getColour()); } }
/** Adds a subtitle to the list in the given colour. */ public void addSubtitle(ISound sound, SoundEventAccessor accessor, int colour) { if (sound != null && accessor.getSubtitle() != null) { String s = accessor.getSubtitle().getFormattedText(); if (!this.subtitles.isEmpty()) { for (Subtitle subtitle : this.subtitles) { if (subtitle.getString().equals(s)) { subtitle.refresh(new Vec3d(sound.getXPosF(), sound.getYPosF(), sound.getZPosF())); return; } } } this.subtitles.add(new Subtitle(s, new Vec3d(sound.getXPosF(), sound.getYPosF(), sound.getZPosF()), colour)); } }
public static ISound PlayMusic (ISound musicIn) { Minecraft mc = Minecraft.getMinecraft(); WorldClient world = mc.world; EntityPlayerSP player = mc.player; if (rand.nextFloat() > 0.5) { return musicIn; } if (world == null) { return musicIn; } else { switch (Biome.getIdForBiome(world.getBiome(player.getPosition()))) { case OCEAN: musicIn = PositionedSoundRecord.getMusicRecord(ModSound.OCEAN); return musicIn; case DEEP_OCEAN: musicIn = PositionedSoundRecord.getMusicRecord(ModSound.OCEAN); return musicIn; default: return musicIn; } } }
public BasicSound(@Nonnull final ResourceLocation soundResource, @Nonnull final SoundCategory cat) { super(soundResource, cat); this.volumeScale = DEFAULT_SCALE; this.volume = 1F; this.pitch = 1F; this.setPosition(0, 0, 0); this.repeat = false; this.repeatDelay = 0; this.attenuationType = ISound.AttenuationType.LINEAR; // Sounds are not routed by default. Need to be turned on // in a derived class or set via setter. this.route = false; super.sound = SoundHandler.MISSING_SOUND; }
@Override public void playSound(@Nonnull final ISound sound) { if (sound != null) { try { if (sound instanceof BasicSound<?>) this.playSound((BasicSound<?>) sound); else if (!ModEnvironment.ActualMusic.isLoaded() || sound.getCategory() != SoundCategory.MUSIC) super.playSound(sound); // Flush - avoid that pesky missing sound issue due to async getSoundSystem().CommandQueue(null); } catch (final Throwable t) { // Stop more weirdness from a crashed sound system } } }
@SubscribeEvent(priority = EventPriority.LOW) public void diagnostics(final DiagnosticEvent.Gather event) { final TObjectIntHashMap<String> counts = new TObjectIntHashMap<String>(); final Iterator<Entry<String, ISound>> iterator = this.playingSounds.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, ISound> entry = iterator.next(); ISound isound = entry.getValue(); counts.adjustOrPutValue(isound.getSound().getSoundLocation().toString(), 1, 1); } final ArrayList<String> results = new ArrayList<String>(); final TObjectIntIterator<String> itr = counts.iterator(); while (itr.hasNext()) { itr.advance(); results.add(String.format(TextFormatting.GOLD + "%s: %d", itr.key(), itr.value())); } Collections.sort(results); event.output.addAll(results); }
@SubscribeEvent public void musicControl(PlaySoundEvent event) { ISound sound = event.getSound(); SoundCategory category = sound.getCategory(); if (category == SoundCategory.MUSIC) { if (!sound.getSoundLocation().toString().contains("kk") && MainConfig.client.sound.EnableCustomMusic) { event.setResultSound(null); return; } if (!sound.getSoundLocation().toString().contains("kk") && this.musicHandler.isPlaying() && MainConfig.client.sound.EnableCustomMusic) { event.setResultSound(null); return; } else { if (MainConfig.client.sound.EnableCustomMusic) { musicHandler.stopSound(sound); } } } else if (category == SoundCategory.RECORDS) { this.musicHandler.stopMusic(); this.mc.getSoundHandler().stopSounds(); return; } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onPlaySound(PlaySoundEvent event) { if (event.getResultSound() == null || event.getResultSound() instanceof ITickableSound || ModCyclic.proxy.getClientWorld() == null) { return; } //long term/repeating/music ISound sound = event.getResultSound(); List<BlockPos> blocks = UtilWorld.findBlocks(ModCyclic.proxy.getClientWorld(), new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF()), this, RADIUS); if (blocks == null || blocks.size() == 0) { return; } try {//WARNING": DO NOT USE getVolume anywhere here it just crashes //we do use it inside the sound class, but the engine callss tat later on, and our factor is tacked in SoundVolumeControlled newSound = new SoundVolumeControlled(sound); //the number of nearby blocks informs how much we muffle the sound by float pct = ((float) VOL_REDUCE_PER_BLOCK) / 100F; newSound.setVolume(pct / blocks.size()); event.setResultSound(newSound); } catch (Exception e) { ModCyclic.logger.error("Error trying to detect volume of sound from 3rd party "); ModCyclic.logger.error(e.getMessage()); e.printStackTrace();//getVolume() in naive Positioned sound event gives NPE } }
/** * Plays the specified record. Arg: recordName, x, y, z */ public void playRecord(String par1Str, int par2, int par3, int par4) { ChunkCoordinates var5 = new ChunkCoordinates(par2, par3, par4); ISound var6 = (ISound)this.mapSoundPositions.get(var5); if (var6 != null) { this.mc.getSoundHandler().func_147683_b(var6); this.mapSoundPositions.remove(var5); } if (par1Str != null) { ItemRecord var7 = ItemRecord.func_150926_b(par1Str); if (var7 != null) { this.mc.ingameGUI.setRecordPlayingMessage(var7.func_150927_i()); } PositionedSoundRecord var8 = PositionedSoundRecord.func_147675_a(new ResourceLocation(par1Str), (float)par2, (float)par3, (float)par4); this.mapSoundPositions.put(var5, var8); this.mc.getSoundHandler().playSound(var8); } }
@SubscribeEvent(priority = EventPriority.LOWEST) public void onSoundEvent(PlaySoundEvent evt) { if (SoundEventsManager.isPlayerWearingGlasses()) { final ISound sound = evt.getResultSound(); if (sound != null) { // NOTE do not remove, otherwise sound.getVolume will throw NPE if (sound.createAccessor(evt.getManager().sndHandler) != null) { final IDrawableIcon icon = icons.getIcon(sound.getSoundLocation()); synchronized (events) { events.add(new SoundEvent(sound, icon, Math.log(sound.getVolume() + 1), sound.getPitch())); } } } } }
public static Tuple<SoundType, Double> getTypeFromSound(String name, ISound sound) { SoundCategory c = sound.getCategory(); if (c != null){ SoundType t = SoundType.getSoundTypeByName(c.getName()); if (t != null){ return new Tuple<>(t, t.weight); } } return new Tuple<>(SoundType.AMBIENT, 0.0); }
public PlaySoundEvent(SoundManager manager, ISound sound) { super(manager); this.sound = sound; this.name = sound.getSoundLocation().getResourcePath(); this.setResultSound(sound); }
public SoundSourceEvent(SoundManager manager, ISound sound, String uuid) { super(manager); this.name = sound.getSoundLocation().getResourcePath(); this.sound = sound; this.uuid = uuid; }
@SideOnly(Side.CLIENT) @Override public void doStuffClient() { if (this.sound_id < 0 || this.sound_id >= this.sounds.length) { return; } Sounds.tryAddSound((ISound)PositionedSoundRecord.func_147675_a(this.sounds[this.sound_id], this.x, this.y, this.z)); }
@SubscribeEvent public void soundMufflerPlay(final PlaySoundEvent17 event) { if (Minecraft.getMinecraft().theWorld != null && ExtraUtils.soundMuffler != null && event.result != null) { final World world = (World)Minecraft.getMinecraft().theWorld; if (event.result instanceof ITickableSound) { return; } final float x = event.result.getXPosF(); final float y = event.result.getYPosF(); final float z = event.result.getZPosF(); for (int dx = (int)Math.floor(x - 8.0f) >> 4; dx <= (int)Math.floor(x + 8.0f) >> 4; ++dx) { for (int dz = (int)Math.floor(z - 8.0f) >> 4; dz <= (int)Math.floor(z + 8.0f) >> 4; ++dz) { for (final TileEntity var19 : (Collection<TileEntity>) world.getChunkFromChunkCoords(dx, dz).chunkTileEntityMap.values()) { if (var19 instanceof TileEntitySoundMuffler) { if (var19.getBlockMetadata() == 1) { continue; } double d = (var19.xCoord + 0.5 - x) * (var19.xCoord + 0.5 - x) + (var19.yCoord + 0.5 - y) * (var19.yCoord + 0.5 - y) + (var19.zCoord + 0.5 - z) * (var19.zCoord + 0.5 - z); if (d > 64.0) { continue; } if (d <= 0.0) { continue; } event.result = (ISound)new SoundMuffled(event.result); d = Math.sqrt(d); if (d != 0.0) { d = 1.0 / d / 8.0; } world.spawnParticle("smoke", (double)x, (double)y, (double)z, (var19.xCoord + 0.5 - x) * d, (var19.yCoord + 0.5 - y) * d, (var19.zCoord + 0.5 - z) * d); } } } } } }
@SideOnly(Side.CLIENT) public static void refresh() { if (XUSoundTileGenerators.instance == null || XUSoundTileGenerators.instance.get() == null) { return; } final XUSoundTileGenerators sound = getInstance(); if (!sound.tiles.isEmpty()) { removeOldValues(); if (!sound.tiles.isEmpty() && Sounds.canAddSound((ISound)sound)) { sound.setDonePlaying(false); sound.volume = 1.0E-7f; Sounds.tryAddSound((ISound)sound); } } }
public static boolean canAddSound(final ISound sound) { if (Sounds.playingSounds == null) { Sounds.playingSounds = ReflectionHelper.findField((Class)SoundManager.class, new String[] { "playingSounds", "field_148629_h" }); Sounds.soundMgr = ReflectionHelper.findField((Class)SoundHandler.class, new String[] { "sndManager", "field_147694_f" }); } try { final SoundManager manager = (SoundManager)Sounds.soundMgr.get(Minecraft.getMinecraft().getSoundHandler()); final Map map = (Map)Sounds.playingSounds.get(manager); return !map.containsValue(sound); } catch (IllegalAccessException e) { return false; } }
public SoundUpdaterRocket(EntityPlayerSP par1EntityPlayerSP, EntityAutoRocket par2Entity) { super(new ResourceLocation(GalacticraftCore.TEXTURE_PREFIX + "shuttle.shuttle")); this.theRocket = par2Entity; this.thePlayer = par1EntityPlayerSP; this.field_147666_i = ISound.AttenuationType.NONE; this.volume = 0.00001F; //If it's zero it won't start playing this.field_147663_c = 0.0F; //pitch this.repeat = true; this.field_147665_h = 0; //repeat delay this.updateSoundLocation(par2Entity); }
public static ISound playSound(SoundManager manager, ISound sound) { SoundEventAccessorComposite accessor = manager.field_148622_c.func_147680_a(sound.func_147650_b()); PlaySoundEvent17 e = new PlaySoundEvent17(manager, sound, (accessor == null ? null : accessor.func_148728_d())); MinecraftForge.EVENT_BUS.post(e); return e.result; }
public SoundSourceEvent(SoundManager manager, ISound sound, String uuid) { super(manager); this.name = sound.func_147650_b().func_110623_a(); this.sound = sound; this.uuid = uuid; }
public PlaySoundEvent17(SoundManager manager, ISound sound, SoundCategory category) { super(manager); this.sound = sound; this.category = category; this.name = sound.func_147650_b().func_110623_a(); this.result = sound; }
public PlaySoundSourceEvent(SoundManager manager, ISound sound, String uuid) { super(manager, sound, uuid); this.name = sound.func_147650_b().func_110623_a(); this.manager = manager; this.x = this.y = this.z = 0; }
public PlayStreamingSourceEvent(SoundManager manager, ISound sound, String uuid) { super(manager, sound, uuid); this.x = this.y = this.z = 0; this.manager = null; this.name = sound.func_147650_b().func_110623_a(); }
@SideOnly(Side.CLIENT) public static ISound getAchievementSound(int number) { SoundEvent sound = number == 1 ? SoundsAether.achievement_bronze : number == 2 ? SoundsAether.achievement_silver : SoundsAether.achievement_gen; return new PositionedSoundRecord(sound.getSoundName(), SoundCategory.PLAYERS, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0, 0, 0); }
@SubscribeEvent public void playSoundEvent (PlaySoundEvent event) { if (event.getSound().getCategory() == SoundCategory.MUSIC && !event.getName().startsWith("music.essential_features")) { ISound result = CustomMusic.PlayMusic(event.getSound()); event.setResultSound(result); } }
private void setStateIf(@Nonnull final ISound sound, @Nonnull final SoundState current, @Nonnull final SoundState state) { if (sound instanceof BasicSound) { final BasicSound<?> s = (BasicSound<?>) sound; if (s.getState() == current) s.setState(state); } }
@Override public void stopSound(@Nonnull final ISound sound) { try { if (sound instanceof BasicSound<?>) { this.stopSound((BasicSound<?>) sound); } else { super.stopSound(sound); } } catch (final Throwable t) { // Stop more weirdness from a crashed sound system } }
@Override public void playDelayedSound(@Nonnull final ISound sound, final int delay) { if (sound != null) { try { if (sound instanceof BasicSound<?>) { this.playDelayedSound((BasicSound<?>) sound, delay); } else { super.playDelayedSound(sound, delay); } } catch (final Throwable t) { // Stop more weirdness from a crashed sound system } } }
@Override public void pauseAllSounds() { for (final ISound s : this.playingSounds.values()) this.setStateIf(s, SoundState.PLAYING, SoundState.PAUSED); super.pauseAllSounds(); }
@Override public void resumeAllSounds() { for (final ISound s : this.playingSounds.values()) this.setStateIf(s, SoundState.PAUSED, SoundState.PLAYING); super.resumeAllSounds(); }
@SubscribeEvent public void onSoundSourceEvent(@Nonnull final SoundSourceEvent event) { final ISound sound = event.getSound(); if (sound instanceof BasicSound<?>) { ((BasicSound<?>) sound).setId(event.getUuid()); } }