我的 tabgui 不工作我按上下键但仍然没有?

my tabgui is not working im pressing up and down but still nothing?

我正在按向下键和向上键,但没有任何反应。

视频:https://www.youtube.com/watch?v=8F9KuHkb5_U&t=1384s

代码:

package sonikhack.render;

public class TabGUI extends Module{
    
    public int currentTab, moduleIndex;
    public boolean expanded;
    
    public TabGUI() {
        super("TabGUI", Keyboard.KEY_NONE, Category.RENDER);
        toggled = true;
    }
    
   public void onEvent(Event e) {
       if(e instanceof EventRenderGUI) {
           FontRenderer fr = mc.fontRendererObj;
           
           Gui.drawRect(5, 30.5, 70, 30 + Module.Category.values().length * 16 + 1.5, 0x90000000);
           Gui.drawRect(7, 33 + currentTab * 16, 7 + 61, 33 + currentTab * 16 + 12, 0xff0099ff);
           
           int count = 0;
           for(Category c : Module.Category.values()) {
               fr.drawStringWithShadow(c.name, 11, 35 + count*16, -1);
               
               count++;
           }
           
           List<Module> modules = Client.getModulesByCategory(Module.Category.values()[currentTab]);
           
           Gui.drawRect(70, 30.5, 70 + 70, 30 + modules.size() * 16 + 4, 0x90000000);
           Gui.drawRect(72, 33 + moduleIndex * 16, 57 + 70, 33 + moduleIndex * 16 + 12, 0xff0099ff);
           
           count = 0;
           for(Module m : modules) {
               fr.drawStringWithShadow(m.name, 73, 36 + count*16, -1);
               
               count++;
           }
           
           if(e instanceof EventKey) {
               int code = ((EventKey)e).code;
               
               if(code == Keyboard.KEY_UP) {
                   if(currentTab <= 0) {
                       currentTab = Module.Category.values().length - 1;
                   }else
                       currentTab--;
               }
               
               if(code == Keyboard.KEY_DOWN) {
                 if(currentTab >= Module.Category.values().length - 1) {
                       currentTab = 0;
                   }else         
                       currentTab++;
               }
       }
   }
    
   }

EventRenderGUI:

package sonikhack.events.listerners;

import sonikhack.events.Event;

public class EventRenderGUI extends Event<EventRenderGUI> {

}

事件键:

package sonikhack.events.listerners;

import sonikhack.events.Event;

public class EventKey extends Event<EventKey> {
    
    public int code;
    
    public EventKey(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}

您需要将 e instanceof EventKey if 语句移到 e instanceof EventRenderGUI if 语句之外。

只要您正确挂钩了事件,这就应该有效:

if (e instanceof EventRenderGUI) {
    FontRenderer fr = mc.fontRendererObj;

    Gui.drawRect(5, 30.5, 70, 30 + Module.Category.values().length * 16 + 1.5, 0x90000000);
    Gui.drawRect(7, 33 + currentTab * 16, 7 + 61, 33 + currentTab * 16 + 12, 0xff0099ff);

    int count = 0;
    for (Category c: Module.Category.values()) {
        fr.drawStringWithShadow(c.name, 11, 35 + count * 16, -1);

        count++;
    }

    List < Module > modules = Client.getModulesByCategory(Module.Category.values()[currentTab]);

    Gui.drawRect(70, 30.5, 70 + 70, 30 + modules.size() * 16 + 4, 0x90000000);
    Gui.drawRect(72, 33 + moduleIndex * 16, 57 + 70, 33 + moduleIndex * 16 + 12, 0xff0099ff);

    count = 0;
    for (Module m: modules) {
        fr.drawStringWithShadow(m.name, 73, 36 + count * 16, -1);

        count++;
    }
}

if (e instanceof EventKey) {
    int code = ((EventKey) e).code;

    if (code == Keyboard.KEY_UP) {
        if (currentTab <= 0) {
            currentTab = Module.Category.values().length - 1;
        } else currentTab--;
    }
    if (code == Keyboard.KEY_DOWN) {
        if (currentTab >= Module.Category.values().length - 1) {
            currentTab = 0;
        } else
            currentTab++;
    }
}