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

Hello, I am trying to make a simple Keybind toggle that toggles a HUD gui. But I cannot seem to figure out how to make the keyUp and keyDown methods toggle. All the GUI is doing is running a loop checking to see if keyPressed is true. If keyPressed is true then it doesnt show it. But I want it to toggle, so I don't want to press it and then release it and the GUI toggle on and then off. I want it to be like the F3 menu ( on how it toggles ). Could any of you experienced folk help me a little?

 

package ws.mods.wsessentials;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.EnumSet;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

public class KeyBindings extends KeyHandler {

public wsEssentials ws;

private EnumSet tickTypes = EnumSet.of(TickType.CLIENT);
public static boolean keyPressed = false;
public static boolean keyReleased = true;

public KeyBindings(KeyBinding[] keyBindings, boolean[] repeatings){
	super(keyBindings, repeatings);
}

@Override
public String getLabel(){
	return "F";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat){
	if (keyPressed == false){
		keyPressed = true;
	} else {
		keyPressed = false;
	}
	keyReleased = false;
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd){
	if (keyPressed == true){
		keyReleased = true;
	} else {
		keyReleased = true;
	}
}

@Override
public EnumSet<TickType> ticks(){
	return tickTypes;
}

}

Don't use those booleans, and disable the repeatings for your key.

Use the keyDown method only.

In it,

 

if(tickend)
{
if(hasOpenedGui)
{
//close gui
hasOpenedGui=false;
}
else
{
//open gui
hasOpenedGui=true;
}
} 

That is, if you have an HUD. If it is a gui (extends GuiScreen), you can use Minecraft.getMinecraft().currentScreen to check.

  • Author

Don't use those booleans, and disable the repeatings for your key.

Use the keyDown method only.

In it,

 

if(tickend)
{
if(hasOpenedGui)
{
//close gui
hasOpenedGui=false;
}
else
{
//open gui
hasOpenedGui=true;
}
} 

That is, if you have an HUD. If it is a gui (extends GuiScreen), you can use Minecraft.getMinecraft().currentScreen to check.

Wow, I don't know why I didn't think of that before. Thank you very much! :) The GUI is just a simple GUI that extends Gui, but this seems to work brilliantly for it. Thank you. :)

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.