2VeryIcey
2VeryIcey

Reputation: 13

Modifying a Static Integer Based Upon The Value Of A Different Varible

I Am Coding Something For Minecraft...And Am Trying To Change The Location Of Certain Text Based Off The GUI Scale...My Question Relates To Changing The X Position For The Text Based Off The Games Gui Scale...My Code Is:

public int scale = Wrapper.mc.gameSettings.guiScale;
public static int XScale = 865;{
if(scale == 0 ){
        int XScale = 405;
    }else if(scale == 1 ){
        int XScale = 1835;
    }else if(scale == 2){
        int XScale = 865;
    }else if(scale == 3){
        int XScale = 565;
    }
}

My Issue Is That No Matter What My GUI Scale Is, The XScale Variable Doesn't Seem To Change, And It Needs to Be Static Because When It's Not Static The Individual Things Being Rendered Want It To Be Static...So I Make Them Not Static...And Then The Render Class Wants Them To Be Static...Get The Idea?

---EDIT--- I Have Tried What @AntonH Said, To No Avail...The Outcome Hasn't Changed...Should I Put It Inside A Loop? The New Code Is:

public int scale = Wrapper.mc.gameSettings.guiScale;
public static int XScale = 865;{
if(scale == 0 ){
        GUIIngameHook.XScale = 405;
    }else if(scale == 1 ){
        GUIIngameHook.XScale = 1835;
    }else if(scale == 2){
        GUIIngameHook.XScale = 865;
    }else if(scale == 3){
        GUIIngameHook.XScale = 565;
    }
}

---ENTIRE SCRIPT--- Not Sure How Helpful This Will Be...But It Should Provide Context..

package me.zach.frostwave.UI;

public class GUIIngameHook {
public static void StartHud(){
    renderClientName();
    renderCoords();
    renderFPS();
    renderMods();
    renderArrayList();
    renderModLine();
}
public int scale = Wrapper.mc.gameSettings.guiScale;
public static int XScale = 865;{
if(scale == 0 ){
        GUIIngameHook.XScale = 405;
    }else if(scale == 1 ){
        GUIIngameHook.XScale = 1835;
    }else if(scale == 2){
        GUIIngameHook.XScale = 865;
    }else if(scale == 3){
        GUIIngameHook.XScale = 565;
    }
}


public static void renderClientName() {
    Wrapper.fr.drawString("Frost Wave [MCV: 1.10, V: 0.05A]", 5, 5,  0x0011FF);
    FrostWave.Frostwave.getGuiManager().renderPinned();
    FrostWave.Frostwave.getGuiManager().update();
}

public static void renderFPS() {
    Wrapper.fr.drawStringWithShadow("[FPS:" + Wrapper.mc.getDebugFPS() + "]", 5, 15,   0x7AA7FF);
    FrostWave.Frostwave.getGuiManager().renderPinned();
    FrostWave.Frostwave.getGuiManager().update();
}

public static void renderCoords() {
    Wrapper.fr.drawStringWithShadow("[Coords: X: " + (int) Wrapper.mc.thePlayer.posX + " Y: " + (int) Wrapper.mc.thePlayer.posY + " Z: " + (int) Wrapper.mc.thePlayer.posZ + "]" , 5, 25, 0x10F0DA);
    FrostWave.Frostwave.getGuiManager().renderPinned();
    FrostWave.Frostwave.getGuiManager().update();
}
public static void renderMods() {
    Wrapper.fr.drawString(" [Active Mods]" , XScale, 5, 0x5A47FF);
    FrostWave.Frostwave.getGuiManager().renderPinned();
    FrostWave.Frostwave.getGuiManager().update();
}
public static void renderModLine() {
    Wrapper.fr.drawString("-------------" , XScale, 11, 0x5A47FF);
    FrostWave.Frostwave.getGuiManager().renderPinned();
    FrostWave.Frostwave.getGuiManager().update();
}

public static void renderArrayList() {
    int yCount = 17;
    for(Module m : FrostWave.manager.activeModules){
        m.onRender();

        if(m.getState() && !m.isCategory(Category.GUI)){
            Wrapper.fr.drawString(m.getName(), XScale, yCount, m.getColor());
            yCount = yCount + 10;
        }
    }
}

}

Upvotes: 0

Views: 40

Answers (1)

MeBigFatGuy
MeBigFatGuy

Reputation: 28588

so you are using an instance initializer. is that really what you wanted? Given that this variable is static that would seem to be a mistake. maybe you want to do

static {
    if(scale == 0 ){
        XScale = 405;
    }else if(scale == 1 ){
        XScale = 1835;
    }else if(scale == 2){
        XScale = 865;
    }else if(scale == 3){
        XScale = 565;
    }
}

Upvotes: 1

Related Questions