Search in sources :

Example 11 with GameSettings

use of net.minecraft.client.settings.GameSettings in project Galacticraft by micdoodle8.

the class TextureSpecial method addFrame.

public void addFrame(int[] data, int width, int height) {
    GameSettings settings = Minecraft.getMinecraft().gameSettings;
    BufferedImage[] images = new BufferedImage[settings.mipmapLevels + 1];
    images[0] = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    images[0].setRGB(0, 0, width, height, data, 0, width);
    loadSprite(images, null);
}
Also used : GameSettings(net.minecraft.client.settings.GameSettings) BufferedImage(java.awt.image.BufferedImage)

Example 12 with GameSettings

use of net.minecraft.client.settings.GameSettings in project DynamicSurroundings by OreCruncher.

the class BiomeFogColorCalculator method calculate.

@Override
@Nonnull
public Color calculate(@Nonnull final EntityViewRenderEvent.FogColors event) {
    final EntityLivingBase player = EnvironState.getPlayer();
    final World world = EnvironState.getWorld();
    final IBlockAccessEx provider = ClientChunkCache.INSTANCE;
    final int playerX = MathStuff.floor(player.posX);
    final int playerZ = MathStuff.floor(player.posZ);
    // ForgeHooksClient.getSkyBlendColour()
    final GameSettings settings = Minecraft.getMinecraft().gameSettings;
    final int[] ranges = ForgeModContainer.blendRanges;
    int distance = 6;
    if (settings.fancyGraphics && ranges.length > 0) {
        distance = ranges[MathStuff.clamp(settings.renderDistanceChunks, 0, ranges.length - 1)];
    }
    final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(0, 0, 0);
    this.doScan |= this.posX != playerX || this.posZ != playerZ;
    if (this.doScan) {
        this.doScan = false;
        this.posX = playerX;
        this.posZ = playerZ;
        this.biomeFogColor = new Color(0, 0, 0);
        this.weightBiomeFog = 0;
        for (int x = -distance; x <= distance; ++x) {
            for (int z = -distance; z <= distance; ++z) {
                pos.setPos(playerX + x, 0, playerZ + z);
                // If the chunk is not available doScan will be set true. This will force
                // another scan on the next tick.
                this.doScan = this.doScan | !provider.isAvailable(pos);
                final BiomeInfo biome = ClientRegistry.BIOME.get(provider.getBiome(pos));
                final Color color;
                // Fetch the color we are dealing with.
                if (biome.getHasDust()) {
                    color = biome.getDustColor();
                } else if (biome.getHasFog()) {
                    color = biome.getFogColor();
                } else {
                    color = null;
                }
                if (color != null) {
                    this.biomeFogColor.add(color);
                    this.weightBiomeFog += 1F;
                }
            }
        }
    }
    // If we have nothing then just return whatever Vanilla wanted
    if (this.weightBiomeFog == 0 || distance == 0)
        return super.calculate(event);
    // WorldProvider.getFogColor() - need to calculate the scale based
    // on sunlight and stuff.
    final float partialTicks = (float) event.getRenderPartialTicks();
    final float celestialAngle = world.getCelestialAngle(partialTicks);
    final float baseScale = MathStuff.clamp(MathStuff.cos(celestialAngle * MathStuff.PI_F * 2.0F) * 2.0F + 0.5F, 0, 1);
    double rScale = baseScale * 0.94F + 0.06F;
    double gScale = baseScale * 0.94F + 0.06F;
    double bScale = baseScale * 0.91F + 0.09F;
    // EntityRenderer.updateFogColor() - adjust the scale further
    // based on rain and thunder.
    final float rainStrength = Weather.getIntensityLevel();
    if (rainStrength > 0) {
        rScale *= 1 - rainStrength * 0.5f;
        gScale *= 1 - rainStrength * 0.5f;
        bScale *= 1 - rainStrength * 0.4f;
    }
    final float thunderStrength = Weather.getThunderStrength();
    if (thunderStrength > 0) {
        rScale *= 1 - thunderStrength * 0.5f;
        gScale *= 1 - thunderStrength * 0.5f;
        bScale *= 1 - thunderStrength * 0.5f;
    }
    // Normalize the blended color components based on the biome weight.
    // The components contain a summation of all the fog components
    // in the area around the player.
    final Color fogColor = new Color(this.biomeFogColor);
    fogColor.scale(// 
    (float) (rScale / this.weightBiomeFog), // 
    (float) (gScale / this.weightBiomeFog), // 
    (float) (bScale / this.weightBiomeFog));
    final Color processedColor = applyPlayerEffects(world, player, fogColor, partialTicks);
    final double weightMixed = (distance * 2 + 1) * (distance * 2 + 1);
    final double weightDefault = weightMixed - this.weightBiomeFog;
    final Color vanillaColor = super.calculate(event);
    processedColor.scale((float) this.weightBiomeFog);
    vanillaColor.scale((float) weightDefault);
    return processedColor.add(vanillaColor).scale((float) (1 / weightMixed));
}
Also used : Color(org.blockartistry.lib.Color) BiomeInfo(org.blockartistry.DynSurround.registry.BiomeInfo) World(net.minecraft.world.World) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) GameSettings(net.minecraft.client.settings.GameSettings) Nonnull(javax.annotation.Nonnull)

Example 13 with GameSettings

use of net.minecraft.client.settings.GameSettings 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 14 with GameSettings

use of net.minecraft.client.settings.GameSettings in project malmo by Microsoft.

the class MalmoModClient method init.

public void init(FMLInitializationEvent event) {
    // Register for various events:
    MinecraftForge.EVENT_BUS.register(this);
    GameSettings settings = Minecraft.getMinecraft().gameSettings;
    TextureHelper.hookIntoRenderPipeline();
    setUpExtraKeys(settings);
    this.stateMachine = new ClientStateMachine(ClientState.WAITING_FOR_MOD_READY, this);
    this.originalMouseHelper = Minecraft.getMinecraft().mouseHelper;
    this.mouseHook = new MouseHook();
    this.mouseHook.isOverriding = true;
    Minecraft.getMinecraft().mouseHelper = this.mouseHook;
    setInputType(InputType.AI);
}
Also used : GameSettings(net.minecraft.client.settings.GameSettings)

Example 15 with GameSettings

use of net.minecraft.client.settings.GameSettings in project malmo by Microsoft.

the class CommandForKey method install.

@Override
public void install(MissionInit missionInit) {
    // Attempt to find the keybinding that matches the description we were given,
    // and replace it with our own KeyHook object:
    GameSettings settings = Minecraft.getMinecraft().gameSettings;
    boolean createdHook = false;
    // GameSettings contains both a field for each KeyBinding (eg keyBindAttack), and an array of KeyBindings with a pointer to
    // each field. We want to make sure we replace both pointers, otherwise Minecraft will end up using our object for some things, and
    // the original object for others.
    // So we need to use reflection to replace the field:
    Field[] fields = GameSettings.class.getFields();
    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];
        if (f.getType() == KeyBinding.class) {
            KeyBinding kb;
            try {
                kb = (KeyBinding) (f.get(settings));
                if (kb != null && kb.getKeyDescription().equals(this.keyDescription)) {
                    this.originalBinding = kb;
                    this.keyHook = create(this.originalBinding);
                    createdHook = true;
                    f.set(settings, this.keyHook);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    // And then we replace the pointer in the array:
    for (int i = 0; i < settings.keyBindings.length; i++) {
        if (settings.keyBindings[i].getKeyDescription().equals(this.keyDescription)) {
            this.originalBindingIndex = i;
            if (!createdHook) {
                this.originalBinding = settings.keyBindings[i];
                this.keyHook = create(this.originalBinding);
                createdHook = true;
            }
            settings.keyBindings[i] = this.keyHook;
        }
    }
    // And possibly in the hotbar array too:
    for (int i = 0; i < settings.keyBindsHotbar.length; i++) {
        if (settings.keyBindsHotbar[i].getKeyDescription().equals(this.keyDescription)) {
            this.originalBindingIndex = i;
            if (!createdHook) {
                this.originalBinding = settings.keyBindsHotbar[i];
                this.keyHook = create(this.originalBinding);
                createdHook = true;
            }
            settings.keyBindsHotbar[i] = this.keyHook;
        }
    }
    // Newer versions of MC have changed the way they map from key value to KeyBinding, so we
    // *also* need to fiddle with the static KeyBinding HASH map:
    Field[] kbfields = KeyBinding.class.getDeclaredFields();
    for (Field f : kbfields) {
        if (f.getType() == KeyBindingMap.class) {
            net.minecraftforge.client.settings.KeyBindingMap kbp;
            try {
                f.setAccessible(true);
                kbp = (KeyBindingMap) (f.get(null));
                // just need to remove the original one.
                while (kbp.lookupAll(this.keyHook.getKeyCode()).size() > 1) kbp.removeKey(this.originalBinding);
                return;
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) KeyBinding(net.minecraft.client.settings.KeyBinding) GameSettings(net.minecraft.client.settings.GameSettings) KeyBindingMap(net.minecraftforge.client.settings.KeyBindingMap)

Aggregations

GameSettings (net.minecraft.client.settings.GameSettings)17 KeyBinding (net.minecraft.client.settings.KeyBinding)5 BlockPos (net.minecraft.util.math.BlockPos)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 ClientConfiguration (com.almuradev.almura.core.client.config.ClientConfiguration)2 PanoramicMainMenu (com.almuradev.almura.feature.menu.main.PanoramicMainMenu)2 BufferedImage (java.awt.image.BufferedImage)2 Options (net.minecraft.client.settings.GameSettings.Options)2 SoundCategory (net.minecraft.util.SoundCategory)2 Biome (net.minecraft.world.biome.Biome)2 PresetData (org.blockartistry.Presets.api.PresetData)2 BOPBiome (biomesoplenty.common.biome.BOPBiome)1 ResourcePackRepositoryAccessor (com.almuradev.almura.asm.mixin.accessors.client.resources.ResourcePackRepositoryAccessor)1 GeneralCategory (com.almuradev.almura.core.client.config.category.GeneralCategory)1 SimpleIngameMenu (com.almuradev.almura.feature.menu.game.SimpleIngameMenu)1 DisconnectedGui (com.almuradev.almura.feature.menu.main.DisconnectedGui)1 ApplyTexturePackConfirmGui (com.almuradev.almura.feature.speed.client.gui.ApplyTexturePackConfirmGui)1 Field (java.lang.reflect.Field)1 Nonnull (javax.annotation.Nonnull)1 ClientProxy (me.desht.pneumaticcraft.proxy.ClientProxy)1