Search in sources :

Example 1 with SoundCategory

use of net.minecraft.util.SoundCategory in project DynamicSurroundings by OreCruncher.

the class MinecraftConfigHandler method onConfigSave.

@SubscribeEvent
public static void onConfigSave(@Nonnull final PresetEvent.Save event) {
    final PresetData data = event.getModData(MINECRAFT);
    final GameSettings settings = Minecraft.getMinecraft().gameSettings;
    for (final Options option : GameSettings.Options.values()) {
        final String theName = option.getTranslation();
        switch(option) {
            case INVERT_MOUSE:
                data.setBoolean(theName, settings.invertMouse);
                break;
            case SENSITIVITY:
                data.setDouble(theName, settings.mouseSensitivity);
                break;
            case FOV:
                data.setDouble(theName, settings.fovSetting);
                break;
            case GAMMA:
                data.setDouble(theName, settings.gammaSetting);
                break;
            case SATURATION:
                data.setDouble(theName, settings.saturation);
                break;
            case RENDER_DISTANCE:
                data.setInt(theName, settings.renderDistanceChunks);
                break;
            case VIEW_BOBBING:
                data.setBoolean(theName, settings.viewBobbing);
                break;
            case ANAGLYPH:
                data.setBoolean(theName, settings.anaglyph);
                break;
            case FRAMERATE_LIMIT:
                data.setInt(theName, settings.limitFramerate);
                break;
            case FBO_ENABLE:
                data.setBoolean(theName, settings.fboEnable);
                break;
            case CHAT_COLOR:
                data.setBoolean(theName, settings.chatColours);
                break;
            case CHAT_LINKS:
                data.setBoolean(theName, settings.chatLinks);
                break;
            case CHAT_OPACITY:
                data.setDouble(theName, settings.chatOpacity);
                break;
            case CHAT_LINKS_PROMPT:
                data.setBoolean(theName, settings.chatLinksPrompt);
                break;
            case SNOOPER_ENABLED:
                data.setBoolean(theName, settings.snooperEnabled);
                break;
            case USE_FULLSCREEN:
                data.setBoolean(theName, settings.fullScreen);
                break;
            case ENABLE_VSYNC:
                data.setBoolean(theName, settings.enableVsync);
                break;
            case USE_VBO:
                data.setBoolean(theName, settings.useVbo);
                break;
            case TOUCHSCREEN:
                data.setBoolean(theName, settings.touchscreen);
                break;
            case CHAT_SCALE:
                data.setDouble(theName, settings.chatScale);
                break;
            case CHAT_WIDTH:
                data.setDouble(theName, settings.chatWidth);
                break;
            case CHAT_HEIGHT_FOCUSED:
                data.setDouble(theName, settings.chatHeightFocused);
                break;
            case CHAT_HEIGHT_UNFOCUSED:
                data.setDouble(theName, settings.chatHeightUnfocused);
                break;
            case MIPMAP_LEVELS:
                data.setInt(theName, settings.mipmapLevels);
                break;
            case FORCE_UNICODE_FONT:
                data.setBoolean(theName, settings.forceUnicodeFont);
                break;
            case REDUCED_DEBUG_INFO:
                data.setBoolean(theName, settings.reducedDebugInfo);
                break;
            case ENTITY_SHADOWS:
                data.setBoolean(theName, settings.entityShadows);
                break;
            case ENABLE_WEAK_ATTACKS:
                data.setBoolean(theName, settings.enableWeakAttacks);
                break;
            case SHOW_SUBTITLES:
                data.setBoolean(theName, settings.showSubtitles);
                break;
            case REALMS_NOTIFICATIONS:
                data.setBoolean(theName, settings.realmsNotifications);
                break;
            case AUTO_JUMP:
                data.setBoolean(theName, settings.autoJump);
                break;
            case RENDER_CLOUDS:
                data.setInt(theName, settings.clouds);
                break;
            case GRAPHICS:
                data.setBoolean(theName, settings.fancyGraphics);
                break;
            case AMBIENT_OCCLUSION:
                data.setInt(theName, settings.ambientOcclusion);
                break;
            case GUI_SCALE:
                data.setInt(theName, settings.guiScale);
                break;
            case PARTICLES:
                data.setInt(theName, settings.particleSetting);
                break;
            case CHAT_VISIBILITY:
                data.setInt(theName, settings.chatVisibility.ordinal());
                break;
            case MAIN_HAND:
                data.setString(theName, settings.mainHand.name());
                break;
            case ATTACK_INDICATOR:
                data.setInt(theName, settings.attackIndicator);
                break;
            default:
        }
    }
    // Not to forget sounds...
    for (final SoundCategory cat : SoundCategory.values()) data.setDouble(SOUND_PREFIX + cat.getName(), settings.getSoundLevel(cat));
    // ...and keybindings
    for (final KeyBinding keybinding : settings.keyBindings) {
        final String id = KEYBIND_PREFIX + keybinding.getKeyDescription();
        String val = Integer.toString(keybinding.getKeyCode());
        if (keybinding.getKeyModifier() != KeyModifier.NONE)
            val += ":" + keybinding.getKeyModifier();
        data.setString(id, val);
    }
}
Also used : Options(net.minecraft.client.settings.GameSettings.Options) KeyBinding(net.minecraft.client.settings.KeyBinding) SoundCategory(net.minecraft.util.SoundCategory) PresetData(org.blockartistry.Presets.api.PresetData) GameSettings(net.minecraft.client.settings.GameSettings) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with SoundCategory

use of net.minecraft.util.SoundCategory in project DynamicSurroundings by OreCruncher.

the class MinecraftConfigHandler method onConfigLoad.

@SubscribeEvent
public static void onConfigLoad(@Nonnull final PresetEvent.Load event) {
    final PresetData data = event.getModData(MINECRAFT);
    if (data != null) {
        final GameSettings settings = Minecraft.getMinecraft().gameSettings;
        boolean refreshChat = false;
        boolean refreshMipmaps = false;
        boolean refreshRenderDistance = false;
        boolean refreshRenderers = false;
        boolean refreshUnicodeFlag = false;
        boolean refreshResources = false;
        boolean refreshVsync = false;
        for (final Entry<String, String> e : data.getEntries()) {
            if (e.getKey().startsWith(SOUND_PREFIX)) {
                final String catName = e.getKey().replace(SOUND_PREFIX, "");
                final SoundCategory sc = SoundCategory.getByName(catName);
                if (sc != null) {
                    settings.setSoundLevel(sc, (float) Double.parseDouble(e.getValue()));
                } else {
                    Presets.log().warn("Unknown sound category: %s", catName);
                }
            } else if (e.getKey().startsWith(KEYBIND_PREFIX)) {
                boolean found = false;
                final String keyName = e.getKey().replace(KEYBIND_PREFIX, "");
                for (final KeyBinding binding : settings.keyBindings) {
                    if (keyName.equals(binding.getKeyDescription())) {
                        final String[] parts = StringUtils.split(e.getValue(), ':');
                        final int keyCode = Integer.parseInt(parts[0]);
                        final KeyModifier modifier = parts.length == 1 ? KeyModifier.NONE : KeyModifier.valueFromString(parts[1]);
                        binding.setKeyModifierAndCode(modifier, keyCode);
                        found = true;
                        break;
                    }
                }
                if (!found)
                    Presets.log().warn("Unknown keybinding found: %s", keyName);
            } else {
                final String theName = e.getKey();
                final Options option = getOptionByName(theName);
                if (option != null) {
                    switch(option) {
                        case INVERT_MOUSE:
                            settings.invertMouse = data.getBoolean(theName, settings.invertMouse);
                            break;
                        case SENSITIVITY:
                            settings.mouseSensitivity = (float) data.getDouble(theName, settings.mouseSensitivity);
                            break;
                        case FOV:
                            settings.fovSetting = (float) data.getDouble(theName, settings.fovSetting);
                            break;
                        case GAMMA:
                            settings.gammaSetting = (float) data.getDouble(theName, settings.gammaSetting);
                            break;
                        case SATURATION:
                            settings.saturation = (float) data.getDouble(theName, settings.saturation);
                            break;
                        case RENDER_DISTANCE:
                            final int rd = data.getInt(theName, settings.renderDistanceChunks);
                            if (settings.renderDistanceChunks != rd) {
                                settings.renderDistanceChunks = rd;
                                refreshRenderDistance = true;
                            }
                            break;
                        case VIEW_BOBBING:
                            settings.viewBobbing = data.getBoolean(theName, settings.viewBobbing);
                            break;
                        case ANAGLYPH:
                            final boolean anal = data.getBoolean(theName, settings.anaglyph);
                            if (settings.anaglyph != anal) {
                                settings.anaglyph = anal;
                                refreshResources = true;
                            }
                            break;
                        case FRAMERATE_LIMIT:
                            settings.limitFramerate = data.getInt(theName, settings.limitFramerate);
                            break;
                        case FBO_ENABLE:
                            settings.fboEnable = data.getBoolean(theName, settings.fboEnable);
                            break;
                        case CHAT_COLOR:
                            settings.chatColours = data.getBoolean(theName, settings.chatColours);
                            refreshChat = true;
                            break;
                        case CHAT_LINKS:
                            settings.chatLinks = data.getBoolean(theName, settings.chatLinks);
                            refreshChat = true;
                            break;
                        case CHAT_OPACITY:
                            settings.chatOpacity = (float) data.getDouble(theName, settings.chatOpacity);
                            refreshChat = true;
                            break;
                        case CHAT_LINKS_PROMPT:
                            settings.chatLinksPrompt = data.getBoolean(theName, settings.chatLinksPrompt);
                            refreshChat = true;
                            break;
                        case SNOOPER_ENABLED:
                            settings.snooperEnabled = data.getBoolean(theName, settings.snooperEnabled);
                            break;
                        case USE_FULLSCREEN:
                            settings.fullScreen = data.getBoolean(theName, settings.fullScreen);
                            break;
                        case ENABLE_VSYNC:
                            final boolean vsync = data.getBoolean(theName, settings.enableVsync);
                            if (settings.enableVsync != vsync) {
                                settings.enableVsync = vsync;
                                refreshVsync = true;
                            }
                            break;
                        case USE_VBO:
                            final boolean vbo = data.getBoolean(theName, settings.useVbo);
                            if (settings.useVbo != vbo) {
                                settings.useVbo = vbo;
                                refreshRenderers = true;
                            }
                            break;
                        case TOUCHSCREEN:
                            settings.touchscreen = data.getBoolean(theName, settings.touchscreen);
                            break;
                        case CHAT_SCALE:
                            settings.chatScale = (float) data.getDouble(theName, settings.chatScale);
                            refreshChat = true;
                            break;
                        case CHAT_WIDTH:
                            settings.chatWidth = (float) data.getDouble(theName, settings.chatWidth);
                            refreshChat = true;
                            break;
                        case CHAT_HEIGHT_FOCUSED:
                            settings.chatHeightFocused = (float) data.getDouble(theName, settings.chatHeightFocused);
                            refreshChat = true;
                            break;
                        case CHAT_HEIGHT_UNFOCUSED:
                            settings.chatHeightUnfocused = (float) data.getDouble(theName, settings.chatHeightUnfocused);
                            refreshChat = true;
                            break;
                        case MIPMAP_LEVELS:
                            final int mips = data.getInt(theName, settings.mipmapLevels);
                            if (settings.mipmapLevels != mips) {
                                settings.mipmapLevels = mips;
                                refreshMipmaps = true;
                            }
                            break;
                        case FORCE_UNICODE_FONT:
                            final boolean force = data.getBoolean(theName, settings.forceUnicodeFont);
                            if (settings.forceUnicodeFont != force) {
                                settings.forceUnicodeFont = force;
                                refreshUnicodeFlag = true;
                            }
                            break;
                        case REDUCED_DEBUG_INFO:
                            settings.reducedDebugInfo = data.getBoolean(theName, settings.reducedDebugInfo);
                            break;
                        case ENTITY_SHADOWS:
                            settings.entityShadows = data.getBoolean(theName, settings.entityShadows);
                            break;
                        case ENABLE_WEAK_ATTACKS:
                            settings.enableWeakAttacks = data.getBoolean(theName, settings.enableWeakAttacks);
                            break;
                        case SHOW_SUBTITLES:
                            settings.showSubtitles = data.getBoolean(theName, settings.showSubtitles);
                            break;
                        case REALMS_NOTIFICATIONS:
                            settings.realmsNotifications = data.getBoolean(theName, settings.realmsNotifications);
                            break;
                        case AUTO_JUMP:
                            settings.autoJump = data.getBoolean(theName, settings.autoJump);
                            break;
                        case RENDER_CLOUDS:
                            settings.clouds = data.getInt(theName, settings.clouds);
                            break;
                        case GRAPHICS:
                            final boolean fancy = data.getBoolean(theName, settings.fancyGraphics);
                            if (settings.fancyGraphics != fancy) {
                                settings.fancyGraphics = fancy;
                                refreshRenderers = true;
                            }
                            break;
                        case AMBIENT_OCCLUSION:
                            final int occlusion = data.getInt(theName, settings.ambientOcclusion);
                            if (settings.ambientOcclusion != occlusion) {
                                settings.ambientOcclusion = occlusion;
                                refreshRenderers = true;
                            }
                            break;
                        case GUI_SCALE:
                            settings.guiScale = data.getInt(theName, settings.guiScale);
                            break;
                        case PARTICLES:
                            settings.particleSetting = data.getInt(theName, settings.particleSetting);
                            break;
                        case CHAT_VISIBILITY:
                            settings.chatVisibility = EnumChatVisibility.getEnumChatVisibility(data.getInt(theName, settings.chatVisibility.ordinal()));
                            break;
                        case MAIN_HAND:
                            settings.mainHand = EnumHandSide.valueOf(data.getString(theName, settings.mainHand.name()));
                            break;
                        case ATTACK_INDICATOR:
                            settings.attackIndicator = data.getInt(theName, settings.attackIndicator);
                            break;
                        default:
                    }
                } else {
                    Presets.log().warn("Unknown option value: %s", theName);
                }
            }
        }
        settings.saveOptions();
        // Tickle the various modules of Minecraft to get the update
        // settings since we bypassed the get/set of GameSettings.
        final Minecraft mc = Minecraft.getMinecraft();
        if (refreshChat)
            mc.ingameGUI.getChatGUI().refreshChat();
        if (refreshMipmaps) {
            mc.getTextureMapBlocks().setMipmapLevels(settings.mipmapLevels);
            mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
            mc.getTextureMapBlocks().setBlurMipmapDirect(false, settings.mipmapLevels > 0);
            refreshResources = true;
        }
        if (refreshRenderDistance)
            mc.renderGlobal.setDisplayListEntitiesDirty();
        if (refreshRenderers)
            mc.renderGlobal.loadRenderers();
        if (refreshUnicodeFlag)
            mc.fontRenderer.setUnicodeFlag(mc.getLanguageManager().isCurrentLocaleUnicode() || settings.forceUnicodeFont);
        if (refreshResources)
            mc.refreshResources();
        if (refreshVsync)
            Display.setVSyncEnabled(settings.enableVsync);
        if (settings.fullScreen != mc.isFullScreen())
            mc.toggleFullscreen();
    }
}
Also used : KeyBinding(net.minecraft.client.settings.KeyBinding) Options(net.minecraft.client.settings.GameSettings.Options) SoundCategory(net.minecraft.util.SoundCategory) PresetData(org.blockartistry.Presets.api.PresetData) KeyModifier(net.minecraftforge.client.settings.KeyModifier) GameSettings(net.minecraft.client.settings.GameSettings) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with SoundCategory

use of net.minecraft.util.SoundCategory in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class ClientEventHandler method musicControl.

@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;
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) SoundCategory(net.minecraft.util.SoundCategory) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with SoundCategory

use of net.minecraft.util.SoundCategory in project Railcraft by Railcraft.

the class PacketMovingSound method readData.

@Override
@SideOnly(Side.CLIENT)
public void readData(RailcraftInputStream data) throws IOException {
    Entity entity = Minecraft.getMinecraft().world.getEntityByID(data.readInt());
    SoundCategory category = data.readEnum(SoundCategory.values());
    SoundEvent event = new SoundEvent(new ResourceLocation(data.readUTF()));
    SoundHelper.MovingSoundType type = data.readEnum(SoundHelper.MovingSoundType.values());
    NBTTagCompound nbt = data.readNBT();
    if (!(entity instanceof EntityMinecart))
        return;
    type.handle(event, category, (EntityMinecart) entity, nbt);
}
Also used : Entity(net.minecraft.entity.Entity) SoundEvent(net.minecraft.util.SoundEvent) SoundCategory(net.minecraft.util.SoundCategory) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SoundHelper(mods.railcraft.common.util.sounds.SoundHelper) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

SoundCategory (net.minecraft.util.SoundCategory)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 GameSettings (net.minecraft.client.settings.GameSettings)2 Options (net.minecraft.client.settings.GameSettings.Options)2 KeyBinding (net.minecraft.client.settings.KeyBinding)2 PresetData (org.blockartistry.Presets.api.PresetData)2 SoundHelper (mods.railcraft.common.util.sounds.SoundHelper)1 Minecraft (net.minecraft.client.Minecraft)1 ISound (net.minecraft.client.audio.ISound)1 Entity (net.minecraft.entity.Entity)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SoundEvent (net.minecraft.util.SoundEvent)1 KeyModifier (net.minecraftforge.client.settings.KeyModifier)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1