Search code examples
javaminecraftminecraft-forgeminecraft-fabric

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


I'm pressing the down key and up key and its not doing anything.

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

Code:

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> {

}

EventKey:

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

Solution

  • You need to move the e instanceof EventKey if statement outside of the e instanceof EventRenderGUI if statement.

    This should work as long as you have your events hooked correctly:

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