Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeybindHandler Error #2

Open
SkelletonX opened this issue Apr 16, 2018 · 1 comment
Open

KeybindHandler Error #2

SkelletonX opened this issue Apr 16, 2018 · 1 comment

Comments

@SkelletonX
Copy link

my KeybindHandler.java
`package com.skelletonx.MacroSK.handler;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;

import org.lwjgl.input.Keyboard;

import com.skelletonx.MacroSK.util.LogHelper;

public class KeybindHandler
{
/** Storing an instance of Minecraft in a local variable saves having to get it every time */
private final Minecraft mc;

/** Key descriptions; use a language file to localize the description later */
private static final String[] desc = {"key.tut_inventory.desc"};

/** Default key values */
private static final int[] keyValues = {Keyboard.KEY_P};

/** Make this public or provide a getter if you'll need access to the key bindings from elsewhere */
public static final KeyBinding[] keys = new KeyBinding[desc.length];

public KeybindHandler(Minecraft mc) {
	this.mc = mc;
	for (int i = 0; i < desc.length; ++i) {
		keys[i] = new KeyBinding(desc[i], keyValues[i], StatCollector.translateToLocal("key.tutorial.label"));
		ClientRegistry.registerKeyBinding(keys[i]);
		LogHelper.info("KeybindHandler Register OK");
	}
}

/**
 * KeyInputEvent is in the FML package, so we must register to the FML event bus
 */
@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
	LogHelper.info("KeyInputEvent");
	// checking inGameHasFocus prevents your keys from firing when the player is typing a chat message
	// NOTE that the KeyInputEvent will NOT be posted when a gui screen such as the inventory is open
	// so we cannot close an inventory screen from here; that should be done in the GUI itself
	if (mc.inGameHasFocus) {
		if (keys[0].isKeyDown()) {
			LogHelper.info("TESTE");
		}
	}
}

}`

my ClientProxy.java:
`package com.skelletonx.MacroSK.proxy;

import com.skelletonx.MacroSK.handler.KeybindHandler;

import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;

public class ClientProxy extends CommonProxy{

private final Minecraft mc = Minecraft.getMinecraft();

@Override
public void preInit() {
	MinecraftForge.EVENT_BUS.register(new KeybindHandler(mc));
}

}
My Main Class:package com.skelletonx.MacroSK;

import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import com.skelletonx.MacroSK.handler.KeybindHandler;
import com.skelletonx.MacroSK.proxy.*;
import com.skelletonx.MacroSK.util.LogHelper;

@mod(modid = MacroSK.MODID, version = MacroSK.VERSION)
public class MacroSK
{

public static final String MODID = "MacroSK";
public static final String VERSION = "1.0";
public static final String COMMON_PROXY ="com.skelletonx.MacroSK.proxy.CommonProxy";
public static final String CLIENT_PROXY ="com.skelletonx.MacroSK.proxy.ClientProxy";

@SidedProxy(clientSide=CLIENT_PROXY, serverSide=COMMON_PROXY)
public static CommonProxy proxy;

@Mod.EventHandler
public void PreInit(FMLPreInitializationEvent event) {
	LogHelper.info("pre-initialization");
	proxy.preInit();
	
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
    proxy.registerClient();
    proxy.globalRegister();
}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
	
}

}
`When I press Key_P, nothing happens

@SkelletonX
Copy link
Author

using 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant