Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xkball committed Jul 2, 2023
1 parent b6a07ec commit 86d9c54
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.0'
version = '1.1'
group = 'com.xkball.key_command' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'modid'
archivesBaseName = 'KeyCommand'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xkball/key_command/KeyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Mod(modid = KeyCommand.MODID, name = KeyCommand.NAME, version = KeyCommand.VERSION)
public class KeyCommand
{
public static final String MODID = "assets/key_command";
public static final String MODID = "key_command";
public static final String NAME = "Key Command";
public static final String VERSION = "1.0";

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/xkball/key_command/client/KeyBind.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.xkball.key_command.client;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class KeyBind {

final String command;
final int keyDefault;

@SideOnly(Side.CLIENT)
KeyBinding real_key;

public KeyBind(String command, int keyDefault) {
this.command = command;
this.keyDefault = keyDefault;
}

@SideOnly(Side.CLIENT)
public KeyBinding getReal_key() {
return real_key;
}

@SideOnly(Side.CLIENT)
public void setReal_key(KeyBinding real_key) {
this.real_key = real_key;
}
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/com/xkball/key_command/client/KeyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.client.settings.KeyModifier;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,20 +21,24 @@ public class KeyManager {
public static List<KeyBind> keys = new ArrayList<>();

public static void init(){
for(KeyBind key : keys){
if(key.keyDefault != 0){
KeyBinding real_key = new KeyBinding("key.command."+key.command,
KeyConflictContext.IN_GAME,
KeyModifier.NONE,
key.keyDefault,
"key.category.key_command");
key.setReal_key(real_key);
ClientRegistry.registerKeyBinding(real_key);
if(FMLCommonHandler.instance().getSide() == Side.CLIENT){
for(KeyBind key : keys){
if(key.keyDefault != 0){
KeyBinding real_key = new KeyBinding("key.command."+key.command,
KeyConflictContext.IN_GAME,
KeyModifier.NONE,
key.keyDefault,
"key.category.key_command");
key.setReal_key(real_key);
ClientRegistry.registerKeyBinding(real_key);

}

}

}

}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void onKeyPressed(InputEvent.KeyInputEvent event) {
for(KeyBind key : keys){
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"modid": "examplemod",
"name": "Example Mod",
"description": "Example placeholder mod.",
"modid": "key_command",
"name": "Key Command",
"description": "bind key with command.",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "",
"url": "https://github.com/xkball/key_command",
"updateUrl": "",
"authorList": ["ExampleDude"],
"credits": "The Forge and FML guys, for making this example",
"authorList": ["xkball"],
"credits": "xkball",
"logoFile": "",
"screenshots": [],
"dependencies": []
Expand Down

0 comments on commit 86d9c54

Please sign in to comment.