Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

aight, so I created a GUI, with sliders.

works all fine and all, sliders work and such

but, when I close out of the gui, and then go back in, all the slider values reset like if they were never changed.

Can anyone help me?

 

Here's my code

import java.awt.Color;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.config.GuiSlider;
import us.loki.legit.config.Configuration;
import us.loki.legit.config.Property;
import us.loki.legit.cosmetics.GuiCosmetics;

public class GuiWings extends GuiScreen {
    
    public static boolean wings = true;
    public static boolean winter = true;
    private GuiScreen parentScreen;
    int var3 = this.height / 4 + 48;
    private GuiButton Wings; 
    private GuiButton Winter; 
    public static GuiSlider slider;
    public static GuiSlider red;
    public static GuiSlider green;
    public static GuiSlider blue;
    private static int test;
    
    
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
    {
     this.drawDefaultBackground();
     this.drawCenteredString(this.fontRendererObj, "Wings", this.width / 2, 10, 16777215);
     //this.drawCenteredString(this.fontRendererObj, "Settings won't save in GUI", this.width / 2, 40, 16777215);
     super.drawScreen(mouseX, mouseY, partialTicks);
     }
    public void initGui() {
        this.refreshButtons();
        super.initGui();
        
    }
    private void refreshButtons(){
        this.buttonList.clear();
        this.Wings = (new GuiButton(2, this.width / 2 - 100, var3 + 110, I18n.format("Wings: ")));
        this.buttonList.add(this.Wings);
        this.Winter = (new GuiButton(3, this.width / 2 - 100, var3 + 140, I18n.format("Winter Wings: ")));
        this.buttonList.add(this.Winter);
        this.buttonList.add(slider = new GuiSlider(21, width/2-100, 25, 200, 20, "Size: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(red = new GuiSlider(22, width/2-100, 60, 200, 20, "Red: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(green = new GuiSlider(23, width/2-100, 95, 200, 20, "Green: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(blue = new GuiSlider(24, width/2-100, 130, 200, 20, "Blue: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(new GuiButton(5, width / 2 - 100, var3 + 170, I18n.format("Done", new Object[0])));
       
    }
    protected void actionPerformed(GuiButton button) throws IOException {
        if (button.id == 2) {
            if (wings==true){
                wings=false;
            }else if (wings==false){
                wings=true;
            }
        }
        if (button.id == 3) {
            if (winter==true){
                winter=false;
            }else if (winter==false){
                winter=true;
            }
        }
        if(button.id == 21) {
            slider.setValue(slider.sliderValue);
        }

    if (button.id == 5) {
        this.mc.displayGuiScreen(new GuiCosmetics());
    }
    this.updateButtons();
    }
    private void updateButtons()
    {
        this.Wings.displayString = wings ? "Wings: Disabled" : (wings ? "Wings:" : "Wings: Enabled");
        this.Winter.displayString = winter ? "Winter Wings: Disabled" : (winter ? " Winter Wings:" : "Winter Wings: Enabled");
    }
    

}

import java.awt.Color;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.config.GuiSlider;
import us.loki.legit.config.Configuration;
import us.loki.legit.config.Property;
import us.loki.legit.cosmetics.GuiCosmetics;

public class GuiWings extends GuiScreen {
    
    public static boolean wings = true;
    public static boolean winter = true;
    private GuiScreen parentScreen;
    int var3 = this.height / 4 + 48;
    private GuiButton Wings; 
    private GuiButton Winter; 
    public static GuiSlider slider;
    public static GuiSlider red;
    public static GuiSlider green;
    public static GuiSlider blue;
    private static int test;
    
    
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
    {
     this.drawDefaultBackground();
     this.drawCenteredString(this.fontRendererObj, "Wings", this.width / 2, 10, 16777215);
     //this.drawCenteredString(this.fontRendererObj, "Settings won't save in GUI", this.width / 2, 40, 16777215);
     super.drawScreen(mouseX, mouseY, partialTicks);
     }
    public void initGui() {
        this.refreshButtons();
        super.initGui();
        
    }
    private void refreshButtons(){
        this.buttonList.clear();
        this.Wings = (new GuiButton(2, this.width / 2 - 100, var3 + 110, I18n.format("Wings: ")));
        this.buttonList.add(this.Wings);
        this.Winter = (new GuiButton(3, this.width / 2 - 100, var3 + 140, I18n.format("Winter Wings: ")));
        this.buttonList.add(this.Winter);
        this.buttonList.add(slider = new GuiSlider(21, width/2-100, 25, 200, 20, "Size: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(red = new GuiSlider(22, width/2-100, 60, 200, 20, "Red: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(green = new GuiSlider(23, width/2-100, 95, 200, 20, "Green: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(blue = new GuiSlider(24, width/2-100, 130, 200, 20, "Blue: ", " %", 0, 100, 50, true, true));
        this.buttonList.add(new GuiButton(5, width / 2 - 100, var3 + 170, I18n.format("Done", new Object[0])));
       
    }
    protected void actionPerformed(GuiButton button) throws IOException {
        if (button.id == 2) {
            if (wings==true){
                wings=false;
            }else if (wings==false){
                wings=true;
            }
        }
        if (button.id == 3) {
            if (winter==true){
                winter=false;
            }else if (winter==false){
                winter=true;
            }
        }
        if(button.id == 21) {
            slider.updateSlider();
        }

    if (button.id == 5) {
        this.mc.displayGuiScreen(new GuiCosmetics());
    }
    this.updateButtons();
    }
    private void updateButtons()
    {
        this.Wings.displayString = wings ? "Wings: Disabled" : (wings ? "Wings:" : "Wings: Enabled");
        this.Winter.displayString = winter ? "Winter Wings: Disabled" : (winter ? " Winter Wings:" : "Winter Wings: Enabled");
    }
    

}

Edited by $ober

GUIs don't store data. You need to store the data somewhere else.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
9 hours ago, Draco18s said:

GUIs don't store data. You need to store the data somewhere else.

oh

 

thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.