简体   繁体   English

根据不同变量的值修改静态整数

[英]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: 我正在为Minecraft编写一些代码...并且正试图根据GUI比例更改某些文本的位置...我的问题与基于游戏Gui比例更改文本的X位置有关...我的代码是:

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? 我的问题是我的GUI缩放比例没有问题,XScale变量似乎没有变化,它需要是静态的,因为当它不是静态的时,正在渲染的各个对象都希望它是静态的...所以我使它们成为静态的不是静态的...然后Render类希望它们是静态的...明白了吗?

---EDIT--- I Have Tried What @AntonH Said, To No Avail...The Outcome Hasn't Changed...Should I Put It Inside A Loop? ---编辑---我尝试了@AntonH说的话,一无所获...结果没有改变...我应该将其放入循环中吗? 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;
        }
    }
}

} }

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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM