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

I just made a TickHandler and registered it. Not sure if detecting a key press is supposed to be placed inside a TickHandler, hopefully it's the right way.

 

My TickHandler:

 

 

package deathman12e3.legendaryutilities;

import java.util.EnumSet;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class TickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{

	if(Keyboard.isKeyDown(Keyboard.KEY_R))
	{

		System.out.println("HIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");

	}

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{



}

@Override
public EnumSet<TickType> ticks()
{

	return null;

}

@Override
public String getLabel()
{

	return null;

}

}

 

 

 

My problem is that it never prints anything.

Kain

you can also make a class that extends KeyHandler and regsiter that class, will probably be easier

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Is there an easier way to detect a key press? Packet Handlers and all those seem like a lot of work just to detect when a key is pressed.

Kain

why would you need a packet handler ? its a key press

 

example:

import java.util.EnumSet;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

public class HBKeyHandler extends KeyHandler {

public HBKeyHandler() {
	super(new KeyBinding[]{new KeyBinding("configure health bar", Keyboard.KEY_C)}, new boolean[]{false});
}

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

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
		boolean tickEnd, boolean isRepeat) {
	if(Minecraft.getMinecraft().inGameHasFocus){
		Minecraft.getMinecraft().thePlayer.openGui(MainMod.instance, 0, Minecraft.getMinecraft().theWorld, 0, 0, 0);
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

}

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

}

also, your TickHandler is not working because you are not returning null in "public EnumSet<TickType> ticks()"

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Nah, I'll just stick with a TickHandler. I think I'll need it later in a little bit.

 

And what do you mean by my TickHandler is not returning null in "public EnumSet<TickType> ticks()"?

Kain

Nah, I'll just stick with a TickHandler. I think I'll need it later in a little bit.

*hydroflame goes suspicisous mode.... hmmmm*

 

anyway

hum you are returning null

 

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

and you should be returning something :

@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.PLAYER);
}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Small little question, do you happen to know where the Minecraft stores it's key bindings? I'm trying to get what key is used in the binding for the inventory.

Kain

yeah in Minecraft.gameSettings.keyBindings

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Sorry if I keep bothering you, but is there a iskeyPress method? There's only a isKeyDown method in Keyboard.

Kain

well if you were using a keyhandler you wouldnt have to worry about that, but no there isnt

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Ok, I just made my KeyHandler. I'll just set a boolean to toggle when the key is down and up.

Kain

  • Author

Also, what's this?

 

	if(Minecraft.getMinecraft().inGameHasFocus){
		Minecraft.getMinecraft().thePlayer.openGui(mod_LegendaryUtilities.instance, 0, Minecraft.getMinecraft().theWorld, 0, 0, 0);
	}

Kain

code to open a gui

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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.