Skip to content

KeybindHandler Error #2

@SkelletonX

Description

@SkelletonX

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions