quick and dirty port to 1.16.4

This commit is contained in:
2022-02-03 10:41:28 +01:00
parent 85a4934066
commit 97a89ab403
33 changed files with 611 additions and 889 deletions
+5
View File
@@ -0,0 +1,5 @@
# Disable autocrlf on generated files, they always generate with LF
# Add any extra files or paths here to make git stop saying they
# are changed when only line endings change.
src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf
+23 -15
View File
@@ -1,17 +1,25 @@
.idea/ # eclipse
.gradle/ bin
build/ *.launch
classes/ .settings
eclipse/ .metadata
gradle/
out/
**/*.iml
*.txt
*.gradle
gradlew
gradlew.bat
.classpath .classpath
.metadata/
.project .project
.settings/
bin/ # idea
out
*.ipr
*.iws
*.iml
.idea
# gradle
build
.gradle
# other
eclipse
run
# Files from Forge MDK
forge*changelog.txt
+151
View File
@@ -0,0 +1,151 @@
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
version = '1.0.2'
group = 'de.skate702.craftingkeys' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'craftingkeys'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20201028-1.16.3'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
examplemod {
source sourceSets.main
}
}
}
}
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.16.4-35.1.37'
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// These dependencies get remapped to your current MCP mappings
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"Specification-Title": "examplemod",
"Specification-Vendor": "examplemodsareus",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"examplemodsareus",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
}
}
repositories {
maven {
url "file:///${project.projectDir}/mcmodsrepo"
}
}
}
+4
View File
@@ -0,0 +1,4 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
Vendored
+172
View File
@@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
Vendored
+84
View File
@@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@@ -1,33 +1,16 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraft.client.gui.screen.EnchantmentScreen;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.inventory.*;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import de.skate702.craftingkeys.config.Config;
import de.skate702.craftingkeys.config.GuiConfig;
import de.skate702.craftingkeys.config.GuiConfigHandler;
import de.skate702.craftingkeys.config.KeyBindings;
import de.skate702.craftingkeys.manager.*; import de.skate702.craftingkeys.manager.*;
import de.skate702.craftingkeys.proxies.CraftingKeysProxy; import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import de.skate702.craftingkeys.util.Util; import de.skate702.craftingkeys.util.Util;
import net.minecraft.client.gui.GuiEnchantment;
import net.minecraft.client.gui.GuiMerchant;
import net.minecraft.client.gui.GuiRepair;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.*;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
/** /**
@@ -36,7 +19,7 @@ import net.minecraftforge.common.MinecraftForge;
* *
* @author skate702 * @author skate702
*/ */
@Mod(modid = CraftingKeys.MODID, name = CraftingKeys.NAME, version = CraftingKeys.VERSION) @Mod(CraftingKeys.MODID)
public class CraftingKeys { public class CraftingKeys {
public static final String MODID = "craftingkeys"; public static final String MODID = "craftingkeys";
@@ -46,152 +29,73 @@ public class CraftingKeys {
/** /**
* Current Instance of CraftingKeys. * Current Instance of CraftingKeys.
*/ */
@SuppressWarnings("WeakerAccess")
@Instance(value = MODID)
public static CraftingKeys instance; public static CraftingKeys instance;
/** public CraftingKeys() {
* Current Proxy (Common or Client) instance = this;
*/
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy",
serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
public static CraftingKeysProxy proxy;
/**
* This method will be executed before Init.
*
* @param event Input Event from FML
*/
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Logger.info("preInit(e)", "Loading Config now.");
Config.loadConfig(event);
Logger.info("preInit(e)", "Finished loading Config.");
}
/**
* This method will be executed while loading.
*
* @param event Input Event from FML
*/
@EventHandler
public void load(FMLInitializationEvent event) {
// Registering
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiConfigHandler());
KeyBindings.init();
Logger.info("load(e)", "Registered Mod."); Logger.info("load(e)", "Registered Mod.");
} }
/** public static CraftingKeysProxy proxy = new CraftingKeysProxy();
* This method will be executed after Init.
*
* @param event Input Event from FML
*/
@SuppressWarnings("EmptyMethod")
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
@SuppressWarnings("UnusedParameters")
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (KeyBindings.openGuiBinding.isPressed()) {
Logger.info("onKeyInput(e)", "Open Crafting Keys Config Gui.");
Util.client.player.openGui(instance, GuiConfig.GuiID, Util.client.world,
((int) Util.client.player.posX), (int) Util.client.player.posY,
(int) Util.client.player.posZ);
}
}
/**
* This method will be executed when the Config is changed. Update!
*
* @param eventArgs Input event from FML
*/
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
if (eventArgs.getModID().equals(MODID)) {
Config.syncConfig();
Logger.info("onConfigChanged(e)", "Changed config.");
}
}
/**
* This method listens on GUIs open. Just to test my own gui!
*
* @param event Some Forge input event
*/
@SuppressWarnings({"EmptyMethod", "UnusedParameters"})
@SubscribeEvent
public void onGuiOpened(GuiOpenEvent event) {
//if (event.gui instanceof GuiMainMenu) {
//event.gui = new GuiConfig(); // (Only for testing)
//}
}
/** /**
* This method will be executed every Ingame Tick. * This method will be executed every Ingame Tick.
* *
* @param tick This is a tick. What did you think about it? * @param tick This is a tick. What did you think about it?
*/ */
@SuppressWarnings("UnusedParameters")
@SubscribeEvent @SubscribeEvent
public void onTick(TickEvent.ClientTickEvent tick) { public void onTick(TickEvent.ClientTickEvent tick) {
GuiScreen currentScreen = Util.client.currentScreen; Screen currentScreen = Util.client.currentScreen;
if (currentScreen != null) { if (currentScreen != null) {
if (currentScreen instanceof GuiCrafting) { if (currentScreen instanceof CraftingScreen) {
ContainerManager con = CraftingManager.getInstance( ContainerManager con = CraftingManager.getInstance(
((GuiCrafting) currentScreen).inventorySlots); ((CraftingScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiInventory) { } else if (currentScreen instanceof InventoryScreen) {
ContainerManager con = InventoryManager.getInstance( ContainerManager con = InventoryManager.getInstance(
((GuiInventory) currentScreen).inventorySlots); ((InventoryScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiMerchant) { } else if (currentScreen instanceof MerchantScreen) {
ContainerManager con = VillagerManager.getInstance( ContainerManager con = VillagerManager.getInstance(
((GuiMerchant) currentScreen).inventorySlots); ((MerchantScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiFurnace) { } else if (currentScreen instanceof FurnaceScreen) {
ContainerManager con = FurnaceManager.getInstance( ContainerManager con = FurnaceManager.getInstance(
((GuiFurnace) currentScreen).inventorySlots); ((FurnaceScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiDispenser) { } else if (currentScreen instanceof DispenserScreen) {
ContainerManager con = DispenserManager.getInstance( ContainerManager con = DispenserManager.getInstance(
((GuiDispenser) currentScreen).inventorySlots); ((DispenserScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiBrewingStand) { } else if (currentScreen instanceof BrewingStandScreen) {
ContainerManager con = BrewingManager.getInstance( ContainerManager con = BrewingManager.getInstance(
((GuiBrewingStand) currentScreen).inventorySlots); ((BrewingStandScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiEnchantment) { } else if (currentScreen instanceof EnchantmentScreen) {
ContainerManager con = EnchantmentManager.getInstance( ContainerManager con = EnchantmentManager.getInstance(
((GuiEnchantment) currentScreen).inventorySlots); ((EnchantmentScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} else if (currentScreen instanceof GuiRepair) { } else if (currentScreen instanceof AnvilScreen) {
ContainerManager con = AnvilManager.getInstance( ContainerManager con = AnvilManager.getInstance(
((GuiRepair) currentScreen).inventorySlots); ((AnvilScreen) currentScreen).getContainer());
con.acceptKey(); con.acceptKey();
} }
@@ -1,170 +1,80 @@
package de.skate702.craftingkeys.config; package de.skate702.craftingkeys.config;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraft.client.Minecraft;
import de.skate702.craftingkeys.CraftingKeys; import net.minecraft.client.util.InputMappings;
import de.skate702.craftingkeys.util.Logger;
import net.minecraftforge.common.config.Configuration; import java.awt.event.KeyEvent;
import net.minecraftforge.common.config.Property;
import org.lwjgl.input.Keyboard;
/** /**
* Configuration Management for Keys, etc. * Configuration Management for Keys, etc.
*/ */
public class Config { public class Config {
/**
* Defines the config string for the keys-category.
*/
private static final String categoryKeys = "keys";
/**
* Defines the config string for the other-category.
*/
private static final String categoryOther = "other";
/**
* Standard Return Key if there is a problem reading the config.
*/
private static final int retDefKey = -1;
/** /**
* Defines all 11 Keys you can use with Crafting Keys. * Defines all 11 Keys you can use with Crafting Keys.
*/ */
static Property keyTopLeft, keyTopCenter, keyTopRight, private static int keyTopLeft = KeyEvent.VK_Q;
keyCenterLeft, keyCenterCenter, keyCenterRight, private static int keyTopCenter = KeyEvent.VK_W;
keyLowerLeft, keyLowerCenter, keyLowerRight, private static int keyTopRight = KeyEvent.VK_E;
keyStack, keyInteract, keyDrop; private static int keyCenterLeft = KeyEvent.VK_A;
/** private static int keyCenterCenter = KeyEvent.VK_S;
* Provides the Suggested Config File. private static int keyCenterRight = KeyEvent.VK_D;
*/ private static int keyLowerLeft = KeyEvent.VK_Z;
private static Configuration configFile = null; private static int keyLowerCenter = KeyEvent.VK_X;
/** private static int keyLowerRight = KeyEvent.VK_C;
* Defines, if NumPad is always active for crafting. private static int keyStack = Minecraft.getInstance().gameSettings.keyBindSneak.getKey().getKeyCode();
*/ private static int keyInteract = Minecraft.getInstance().gameSettings.keyBindSprint.getKey().getKeyCode();
private static Property enableNumPad; private static final int keyDrop = KeyEvent.VK_SPACE;
public static boolean isKeyDown(int keyCode) {
return InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), keyCode);
}
public static boolean isKeyTopLeftPressed() { public static boolean isKeyTopLeftPressed() {
return Keyboard.isKeyDown(keyTopLeft.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(71); return isKeyDown(keyTopLeft) || isKeyDown(KeyEvent.VK_NUMPAD7);
} }
public static boolean isKeyTopCenterPressed() { public static boolean isKeyTopCenterPressed() {
return Keyboard.isKeyDown(keyTopCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(72); return isKeyDown(keyTopCenter) || isKeyDown(KeyEvent.VK_NUMPAD8);
} }
public static boolean isKeyTopRightPressed() { public static boolean isKeyTopRightPressed() {
return Keyboard.isKeyDown(keyTopRight.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(73); return isKeyDown(keyTopRight) || isKeyDown(KeyEvent.VK_NUMPAD9);
} }
public static boolean isKeyCenterLeftPressed() { public static boolean isKeyCenterLeftPressed() {
return Keyboard.isKeyDown(keyCenterLeft.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(75); return isKeyDown(keyCenterLeft) || isKeyDown(KeyEvent.VK_NUMPAD4);
} }
public static boolean isKeyCenterCenterPressed() { public static boolean isKeyCenterCenterPressed() {
return Keyboard.isKeyDown(keyCenterCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(76); return isKeyDown(keyCenterCenter) || isKeyDown(KeyEvent.VK_NUMPAD5);
} }
public static boolean isKeyCenterRightPressed() { public static boolean isKeyCenterRightPressed() {
return Keyboard.isKeyDown(keyCenterRight.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(77); return isKeyDown(keyCenterRight) || isKeyDown(KeyEvent.VK_NUMPAD6);
} }
public static boolean isKeyLowerLeftPressed() { public static boolean isKeyLowerLeftPressed() {
return Keyboard.isKeyDown(keyLowerLeft.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(79); return isKeyDown(keyLowerLeft) || isKeyDown(KeyEvent.VK_NUMPAD1);
} }
public static boolean isKeyLowerCenterPressed() { public static boolean isKeyLowerCenterPressed() {
return Keyboard.isKeyDown(keyLowerCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(80); return isKeyDown(keyLowerCenter) || isKeyDown(KeyEvent.VK_NUMPAD2);
} }
public static boolean isKeyLowerRightPressed() { public static boolean isKeyLowerRightPressed() {
return Keyboard.isKeyDown(keyLowerRight.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(81); return isKeyDown(keyLowerRight) || isKeyDown(KeyEvent.VK_NUMPAD3);
} }
public static boolean isKeyStackPressed() { public static boolean isKeyStackPressed() {
return Keyboard.isKeyDown(keyStack.getInt(retDefKey)); return isKeyDown(keyStack);
} }
public static boolean isKeyInteractPressed() { public static boolean isKeyInteractPressed() {
return Keyboard.isKeyDown(keyInteract.getInt(retDefKey)); return isKeyDown(keyInteract);
} }
public static boolean isKeyDropPressed() { public static boolean isKeyDropPressed() {
return Keyboard.isKeyDown(keyDrop.getInt(retDefKey)); return isKeyDown(keyDrop);
} }
private static boolean isNumPadEnabled() {
return enableNumPad.getBoolean(true);
}
/**
* Initializes the configFile Files, loads all values (or sets them to default).
*
* @param event PreInitEvent from Main Class
*/
public static void loadConfig(FMLPreInitializationEvent event) {
configFile = new Configuration(event.getSuggestedConfigurationFile(), CraftingKeys.VERSION);
configFile.load();
genComments();
syncConfig();
}
/**
* Syncs and saves the configFile file.
*/
public static void syncConfig() {
if (configFile == null) {
Logger.error("syncConfig()", "Unable to read config file!");
return;
}
syncProperties();
if (configFile.hasChanged())
configFile.save();
}
/**
* Generates comments for easier understanding of the categories.
*/
private static void genComments() {
configFile.addCustomCategoryComment(categoryKeys, "Keyboard codes based on http://minecraft.gamepedia.com/Key_codes");
configFile.addCustomCategoryComment(categoryOther, "Other settings which have effects @ crafting keys");
}
/**
* Loads all properties from the configFile file.
*/
private static void syncProperties() {
// Standard Keys
keyTopLeft = configFile.get(categoryKeys, "keyTopLeft", Keyboard.KEY_Q);
keyTopCenter = configFile.get(categoryKeys, "keyTopCenter", Keyboard.KEY_W);
keyTopRight = configFile.get(categoryKeys, "keyTopRight", Keyboard.KEY_E);
keyCenterLeft = configFile.get(categoryKeys, "keyCenterLeft", Keyboard.KEY_A);
keyCenterCenter = configFile.get(categoryKeys, "keyCenterCenter", Keyboard.KEY_S);
keyCenterRight = configFile.get(categoryKeys, "keyCenterRight", Keyboard.KEY_D);
keyLowerLeft = configFile.get(categoryKeys, "keyLowerLeft", Keyboard.KEY_Y); // German Keyboard Layout
keyLowerCenter = configFile.get(categoryKeys, "keyLowerCenter", Keyboard.KEY_X);
keyLowerRight = configFile.get(categoryKeys, "keyLowerRight", Keyboard.KEY_C);
// Special Keys
keyStack = configFile.get(categoryKeys, "keyStack", Keyboard.KEY_LSHIFT);
keyInteract = configFile.get(categoryKeys, "keyInteract", Keyboard.KEY_LCONTROL);
keyDrop = configFile.get(categoryKeys, "keyDrop", Keyboard.KEY_SPACE);
// Other Settings
enableNumPad = configFile.get(categoryOther, "numPadEnabled", true, "Activates the NumPad for crafting");
}
} }
@@ -1,421 +0,0 @@
package de.skate702.craftingkeys.config;
import de.skate702.craftingkeys.CraftingKeys;
import de.skate702.craftingkeys.util.LanguageLocalizer;
import de.skate702.craftingkeys.util.Logger;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.ArrayList;
public class GuiConfig extends GuiScreen {
public static final int GuiID = 702;
private static final Color pureWhite = new Color(255, 255, 255, 255);
private static final Color lightGray = new Color(128, 128, 128, 255);
private static final Color highlight = new Color(86, 144, 72, 255);
private final int buttonSaveID = 901;
private final int buttonAbortID = 902;
/**
* 0,1,2 = top,
* 3,4,5 = mid,
* 6,7,8 = low,
* 9 = interact,
* 10 = stack,
* 11 = drop
*/
private int[] keyValues = new int[]{};
private int guiBasePosition;
private int guiShowBasePosX;
private int guiShowBasePosY;
private GuiType guiShowType;
private int guiShowState;
private long lastTime = 0;
private long currentTime;
@SuppressWarnings("FieldCanBeLocal")
private ArrayList<GuiButton> configButtons;
private int selectedButtonID = -1;
@Override
public void initGui() {
// Fill vars
int guiBaseOffset = 35;
guiBasePosition = width / 2 - guiBaseOffset;
guiShowBasePosX = width / 2 - 35;
guiShowBasePosY = height / 2 + 25;
guiShowType = GuiType.ANVIL;
guiShowState = 0;
lastTime = Minecraft.getSystemTime();
currentTime = Minecraft.getSystemTime();
// Init Config
initKeyValues();
// Init buttons
addStandardButtons();
addCraftingButtons();
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
//Setting up
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
drawDefaultBackground(); //drawWorldBackground(0);
//Title
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.title"), width / 2, height / 2 - 115, pureWhite.getRGB());
// Info-text and fake line
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.description"), width / 2, height / 2 - 10, pureWhite.getRGB());
drawCenteredString(fontRenderer, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", width / 2, height / 2 + 8, lightGray.getRGB());
// Key Info
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.stack"), guiBasePosition + 130, height / 2 - 96, pureWhite.getRGB());
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.drop"), guiBasePosition + 130, height / 2 - 58, pureWhite.getRGB());
//Draw line to let it look better
drawHorizontalLine(guiBasePosition - 86, guiBasePosition + 85, height / 2 - 20, pureWhite.getRGB());
// Draw Crafting Table
drawCraftingTable();
// Draw info
drawInfo();
//Draw line to let it look better
drawHorizontalLine(guiShowBasePosX - 86, guiShowBasePosX + 85, guiShowBasePosY + 80, lightGray.getRGB());
// Super
super.drawScreen(mouseX, mouseY, partialTicks);
}
private void drawInfo() {
// Insert Gui by selected Type
currentTime = Minecraft.getSystemTime();
int waitingTimeMS = 3000;
if (currentTime - lastTime > waitingTimeMS) {
showNextGui();
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
lastTime = Minecraft.getSystemTime();
}
switch (guiShowType) {
case FURNACE:
genFurnaceInfo();
break;
case BREWINGSTAND:
genBrewingStandInfo();
break;
case DISPENSER:
genDispenserInfo();
break;
case ENCHANTMENT:
genEnchantmentInfo();
break;
case INVENTORY:
genInventoryInfo();
break;
case VILLAGER:
genVillagerInfo();
break;
case ANVIL:
genAnvilInfo();
break;
}
}
@Override
public void actionPerformed(GuiButton button) {
if (button.id == buttonAbortID) {
Logger.info("actionPerformed(b)", "Closing Crafting Keys GUI now!");
mc.player.closeScreen();
} else if (button.id == buttonSaveID) {
save();
Logger.info("actionPerformed(b)", "Saving & closing Crafting Keys GUI now!");
mc.player.closeScreen();
} else if (button.id >= 0 && button.id <= 11) {
if (selectedButtonID == -1) {
selectedButtonID = button.id;
configButtons.get(selectedButtonID).displayString = "...";
}
}
}
private void save() {
Config.keyTopLeft.set(keyValues[0]);
Config.keyTopCenter.set(keyValues[1]);
Config.keyTopRight.set(keyValues[2]);
Config.keyCenterLeft.set(keyValues[3]);
Config.keyCenterCenter.set(keyValues[4]);
Config.keyCenterRight.set(keyValues[5]);
Config.keyLowerLeft.set(keyValues[6]);
Config.keyLowerCenter.set(keyValues[7]);
Config.keyLowerRight.set(keyValues[8]);
Config.keyInteract.set(keyValues[9]);
Config.keyStack.set(keyValues[10]);
Config.keyDrop.set(keyValues[11]);
Config.syncConfig();
}
@Override
public void keyTyped(char character, int keyCode) {
if (keyCode == Keyboard.KEY_ESCAPE) {
if (selectedButtonID != -1) {
selectedButtonID = -1;
drawKeyValues();
} else {
Logger.info("keyTyped(c,i)", "Trying to close inventory with esc.");
try {
super.keyTyped(character, keyCode); // Enable standard gui closing
} catch (Exception ignored) {
// support for newer versions, just do nothing
}
}
} else if (selectedButtonID != -1) {
if (!ArrayUtils.contains(keyValues, keyCode) || keyValues[selectedButtonID] == keyCode) { // No double keys
keyValues[selectedButtonID] = keyCode;
selectedButtonID = -1;
drawKeyValues();
}
}
}
private void drawCraftingTable() {
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/crafting_table.png"));
drawTexturedModalRect(guiBasePosition - 86, height / 2 - 100, 1, 0, 174, 80);
}
private void genFurnaceInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/furnace.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 0, 100, 50, 50);
drawInfoString(1, 63, 21);
drawInfoString(4, 63, 57);
drawInfoString(9, 123, 39);
}
private void genBrewingStandInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/brewing_stand.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 200, 0, 50, 50);
drawInfoString(0, 24, 21);
drawInfoString(4, 86, 63);
drawInfoString(3, 64, 56);
drawInfoString(5, 109, 56);
}
private void genEnchantmentInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/enchanting_table.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 150, 50, 50, 50);
drawInfoString(1, 22, 51);
drawInfoString(2, 42, 51);
}
private void genAnvilInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/anvil.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
drawRect(guiShowBasePosX + -30, guiShowBasePosY + 17, guiShowBasePosX + 83, guiShowBasePosY + 36, Color.black.getRGB());
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 100, 0, 50, 50);
drawInfoString(4, 34, 51);
drawInfoString(5, 83, 51);
drawInfoString(9, 141, 51);
}
private void genVillagerInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/villager.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 100, 100, 50, 50);
drawInfoString(4, 43, 57);
drawInfoString(5, 69, 57);
drawInfoString(9, 126, 58);
}
private void genInventoryInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 0, 0, 50, 50);
drawInfoString(1, 105, 22);
drawInfoString(2, 123, 22);
drawInfoString(4, 105, 40);
drawInfoString(5, 123, 40);
drawInfoString(9, 164, 32);
}
private void genDispenserInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/dispenser.png"));
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 50, 50, 50, 50);
drawInfoString(0, 69, 21);
drawInfoString(1, 87, 21);
drawInfoString(2, 105, 21);
drawInfoString(3, 69, 39);
drawInfoString(4, 87, 39);
drawInfoString(5, 105, 39);
drawInfoString(6, 69, 57);
drawInfoString(7, 87, 57);
drawInfoString(8, 105, 57);
}
private void drawInfoString(int index, int posX, int posY) {
drawCenteredString(fontRenderer, Keyboard.getKeyName(keyValues[index]),
guiShowBasePosX + posX - 86, guiShowBasePosY + posY, highlight.getRGB());
}
private void addStandardButtons() {
// Add control buttons
buttonList.add((new GuiButton(buttonAbortID, width - 53, 3, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.abort"))));
buttonList.add((new GuiButton(buttonSaveID, width - 53, 26, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.save"))));
}
private void addCraftingButtons() {
configButtons = new ArrayList<GuiButton>();
configButtons.add((new GuiButton(0, guiBasePosition - 60, height / 2 - 87, 20, 20, "")));
configButtons.add((new GuiButton(1, guiBasePosition - 41, height / 2 - 87, 20, 20, "")));
configButtons.add((new GuiButton(2, guiBasePosition - 22, height / 2 - 87, 20, 20, "")));
configButtons.add((new GuiButton(3, guiBasePosition - 60, height / 2 - 68, 20, 20, "")));
configButtons.add((new GuiButton(4, guiBasePosition - 41, height / 2 - 68, 20, 20, "")));
configButtons.add((new GuiButton(5, guiBasePosition - 22, height / 2 - 68, 20, 20, "")));
configButtons.add((new GuiButton(6, guiBasePosition - 60, height / 2 - 49, 20, 20, "")));
configButtons.add((new GuiButton(7, guiBasePosition - 41, height / 2 - 49, 20, 20, "")));
configButtons.add((new GuiButton(8, guiBasePosition - 22, height / 2 - 49, 20, 20, "")));
configButtons.add((new GuiButton(9, guiBasePosition + 34, height / 2 - 67, 22, 20, "")));
configButtons.add((new GuiButton(10, guiBasePosition + 105, height / 2 - 84, 50, 20, "")));
configButtons.add((new GuiButton(11, guiBasePosition + 105, height / 2 - 46, 50, 20, "")));
buttonList.addAll(configButtons);
drawKeyValues();
}
private void initKeyValues() {
if (keyValues.length == 0) {
keyValues = new int[]{
Config.keyTopLeft.getInt(), // 0
Config.keyTopCenter.getInt(), // 1
Config.keyTopRight.getInt(), // 2
Config.keyCenterLeft.getInt(), // 3
Config.keyCenterCenter.getInt(), // 4
Config.keyCenterRight.getInt(), // 5
Config.keyLowerLeft.getInt(), // 6
Config.keyLowerCenter.getInt(), // 7
Config.keyLowerRight.getInt(), // 8
Config.keyInteract.getInt(), // 9
Config.keyStack.getInt(), // 10
Config.keyDrop.getInt()}; // 11
}
}
private void drawKeyValues() {
for (int i = 0; i < keyValues.length; i++) {
configButtons.get(i).displayString = Keyboard.getKeyName(keyValues[i]);
}
}
private void showNextGui() {
switch (guiShowState) {
case 0:
guiShowType = GuiType.FURNACE;
break;
case 1:
guiShowType = GuiType.BREWINGSTAND;
break;
case 2:
guiShowType = GuiType.INVENTORY;
break;
case 3:
guiShowType = GuiType.ENCHANTMENT;
break;
case 4:
guiShowType = GuiType.DISPENSER;
break;
case 5:
guiShowType = GuiType.VILLAGER;
break;
case 6:
guiShowType = GuiType.ANVIL;
break;
}
if (guiShowState >= 6) {
guiShowState = 0;
} else {
guiShowState++;
}
}
public enum GuiType {
ANVIL,
FURNACE,
BREWINGSTAND,
ENCHANTMENT,
INVENTORY,
VILLAGER,
DISPENSER
}
}
@@ -1,24 +0,0 @@
package de.skate702.craftingkeys.config;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public class GuiConfigHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == GuiConfig.GuiID) {
return new GuiConfig();
}
return null;
}
}
@@ -1,25 +0,0 @@
package de.skate702.craftingkeys.config;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;
/**
* Provides all Key Bindings and methods to register and check them.
*/
public class KeyBindings {
private static final String category = "craftingkeys.binding.cat";
public static final KeyBinding openGuiBinding = new KeyBinding("craftingkeys.binding.opengui",
Keyboard.KEY_K, category);
/**
* Initializes all key bindings and registers them to the client-side.
*/
public static void init() {
ClientRegistry.registerKeyBinding(openGuiBinding);
}
}
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Anvil GUI Inventory. * Manages a Anvil GUI Inventory.
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Brewing Stand GUI Inventory. * Manages a Brewing Stand GUI Inventory.
@@ -5,15 +5,13 @@ import de.skate702.craftingkeys.config.Config;
import de.skate702.craftingkeys.util.InputUtil; import de.skate702.craftingkeys.util.InputUtil;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import de.skate702.craftingkeys.util.Util; import de.skate702.craftingkeys.util.Util;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.block.Blocks;
import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.gui.screen.inventory.InventoryScreen;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraft.init.Blocks; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Slot;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
/** /**
* Provides all needed methods to handle and manage a gui inventory. Does also provide frames for own implementations. * Provides all needed methods to handle and manage a gui inventory. Does also provide frames for own implementations.
@@ -41,7 +39,7 @@ public abstract class ContainerManager {
public void acceptKey() { public void acceptKey() {
// Get hovered slot and goal slotIndex of pressed key (if pressed) // Get hovered slot and goal slotIndex of pressed key (if pressed)
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition((GuiContainer) Util.client.currentScreen); Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition(Util.client.currentScreen);
int slotIndex = specificKeyToSlotIndex(); int slotIndex = specificKeyToSlotIndex();
// Handle accepted key // Handle accepted key
@@ -163,30 +161,30 @@ public abstract class ContainerManager {
// hotbar-slots are always the last 9 slots of the currently opened inventory // hotbar-slots are always the last 9 slots of the currently opened inventory
int hotbarStartIndex = Util.client.player.openContainer.getInventory().size() - 9 - 1; int hotbarStartIndex = Util.client.player.openContainer.getInventory().size() - 9 - 1;
if (Util.client.currentScreen instanceof GuiInventory) { if (Util.client.currentScreen instanceof InventoryScreen) {
hotbarStartIndex -= 1; hotbarStartIndex -= 1;
} }
int inputdelta; int inputdelta;
KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar; KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar;
if (Keyboard.isKeyDown(hotbar[0].getKeyCode())) { if (Config.isKeyDown(hotbar[0].getKey().getKeyCode())) {
inputdelta = 1; inputdelta = 1;
} else if (Keyboard.isKeyDown(hotbar[1].getKeyCode())) { } else if (Config.isKeyDown(hotbar[1].getKey().getKeyCode())) {
inputdelta = 2; inputdelta = 2;
} else if (Keyboard.isKeyDown(hotbar[2].getKeyCode())) { } else if (Config.isKeyDown(hotbar[2].getKey().getKeyCode())) {
inputdelta = 3; inputdelta = 3;
} else if (Keyboard.isKeyDown(hotbar[3].getKeyCode())) { } else if (Config.isKeyDown(hotbar[3].getKey().getKeyCode())) {
inputdelta = 4; inputdelta = 4;
} else if (Keyboard.isKeyDown(hotbar[4].getKeyCode())) { } else if (Config.isKeyDown(hotbar[4].getKey().getKeyCode())) {
inputdelta = 5; inputdelta = 5;
} else if (Keyboard.isKeyDown(hotbar[5].getKeyCode())) { } else if (Config.isKeyDown(hotbar[5].getKey().getKeyCode())) {
inputdelta = 6; inputdelta = 6;
} else if (Keyboard.isKeyDown(hotbar[6].getKeyCode())) { } else if (Config.isKeyDown(hotbar[6].getKey().getKeyCode())) {
inputdelta = 7; inputdelta = 7;
} else if (Keyboard.isKeyDown(hotbar[7].getKeyCode())) { } else if (Config.isKeyDown(hotbar[7].getKey().getKeyCode())) {
inputdelta = 8; inputdelta = 8;
} else if (Keyboard.isKeyDown(hotbar[8].getKeyCode())) { } else if (Config.isKeyDown(hotbar[8].getKey().getKeyCode())) {
inputdelta = 9; inputdelta = 9;
} else { } else {
return; return;
@@ -209,16 +207,9 @@ public abstract class ContainerManager {
Logger.info("handleNumKey()", "Moved to hotbar slot " + inputdelta + "."); Logger.info("handleNumKey()", "Moved to hotbar slot " + inputdelta + ".");
moveStackToInventory(-1); moveStackToInventory(-1);
// Handle Minecraft handling. Ah...
while (Keyboard.next()) {
Logger.info("handleNumKey()", "The cake is a lie!");
} }
} }
}
/** /**
* Converts the first specific pressed Key to the slot in a given Inventory. * Converts the first specific pressed Key to the slot in a given Inventory.
* Does also accept Interaction (mapped to -101) and drop key (mapped to -102). * Does also accept Interaction (mapped to -101) and drop key (mapped to -102).
@@ -270,7 +261,6 @@ public abstract class ContainerManager {
} else { } else {
return -1; return -1;
} }
} }
/** /**
@@ -288,7 +278,6 @@ public abstract class ContainerManager {
} else { } else {
move(srcIndex, destIndex, source.getCount()); move(srcIndex, destIndex, source.getCount());
} }
} }
/** /**
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Crafting GUI Inventory. * Manages a Crafting GUI Inventory.
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Dispenser GUI Inventory. * Manages a Dispenser GUI Inventory.
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Enchantment Table GUI Inventory. * Manages a Enchantment Table GUI Inventory.
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Furnace GUI Inventory. * Manages a Furnace GUI Inventory.
@@ -1,7 +1,7 @@
package de.skate702.craftingkeys.manager; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Inventory GUI Inventory. * Manages a Inventory GUI Inventory.
@@ -2,7 +2,7 @@ package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
/** /**
* Manages a Villager GUI Inventory. * Manages a Villager GUI Inventory.
@@ -1,21 +0,0 @@
package de.skate702.craftingkeys.proxies;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
/**
* Client Proxy, extending Common Proxy.
*
* @author skate702
*/
public class CraftingKeysClientProxy extends CraftingKeysProxy {
@Override
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
EntityPlayer player) {
controller.windowClick(windowId, slot, rightClick, ClickType.PICKUP, player);
}
}
@@ -1,9 +1,10 @@
package de.skate702.craftingkeys.proxies; package de.skate702.craftingkeys.proxies;
import net.minecraftforge.fml.relauncher.Side; import net.minecraft.client.multiplayer.PlayerController;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.inventory.container.ClickType;
import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/** /**
* The common proxy. * The common proxy.
@@ -22,9 +23,10 @@ public class CraftingKeysProxy {
* @param action 0 * @param action 0
* @param player The current player (from Client) * @param player The current player (from Client)
*/ */
@SideOnly(Side.CLIENT) @OnlyIn(Dist.CLIENT)
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action, public void sendSlotClick(PlayerController controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action,
EntityPlayer player) { PlayerEntity player) {
controller.windowClick(windowId, slot, rightClick, ClickType.PICKUP, player);
} }
@@ -1,9 +1,8 @@
package de.skate702.craftingkeys.util; package de.skate702.craftingkeys.util;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.inventory.Container; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.container.Slot;
import org.lwjgl.input.Mouse;
/** /**
* This class provides methods to interact with the Mouse and key input. * This class provides methods to interact with the Mouse and key input.
@@ -24,70 +23,18 @@ public class InputUtil {
/** /**
* Returns the Slot at the current Mouse Position. [FROM GUICONTAINER] * Returns the Slot at the current Mouse Position. [FROM GUICONTAINER]
* *
* @param guiContainer The (Inventory) Container to work with. * @param screen The (Inventory) Container to work with.
* @return Returns the slot (or null) * @return Returns the slot (or null)
*/ */
public static Slot getSlotAtMousePosition(GuiContainer guiContainer) { public static Slot getSlotAtMousePosition(Screen screen) {
if (guiContainer != null) { if (screen instanceof ContainerScreen) {
Container container = guiContainer.inventorySlots; return ((ContainerScreen) screen).getSlotUnderMouse();
int x = getMouseX(guiContainer);
int y = getMouseY(guiContainer);
for (int k = 0; k < container.inventorySlots.size(); k++) {
Slot slot = (Slot) container.inventorySlots.get(k);
if (getIsMouseOverSlot(guiContainer, slot, x, y)) {
return slot;
}
}
return null;
} else { } else {
Logger.debug("getSlotAtMousePosition(gui)", "guiContainer == null"); Logger.debug("getSlotAtMousePosition(gui)", "guiContainer == null");
return null; return null;
} }
} }
/**
* Returns, if the mouse cursor is over a specified slot [FROM GUICONTAINER]
*
* @param guiContainer the GuiContainer to work with
* @param slot The spcified slot
* @param x The Mouse x-Position
* @param y The Mouse y-Position
* @return True, if the mouse is positioned over this slot. Otherwise false
*/
private static boolean getIsMouseOverSlot(GuiContainer guiContainer, Slot slot, int x, int y) {
if (guiContainer != null) {
// Constants from Minecraft Source Code
x -= (guiContainer.width - 176) / 2;
y -= (guiContainer.height - 166) / 2;
return x >= slot.xPos - 1 && x < slot.xPos + 16 + 1
&& y >= slot.yPos - 1 && y < slot.yPos + 16 + 1;
} else {
return false;
}
}
/**
* Returns a calculated Mouse Position for getSlotAtMousePosition().
*
* @param guiContainer the GuiContainer to work with
* @return The relative Mouse-Position
*/
private static int getMouseX(GuiContainer guiContainer) {
return (Mouse.getEventX() * guiContainer.width) / Util.client.displayWidth;
}
/**
* Returns a calculated Mouse Position for getSlotAtMousePosition().
*
* @param guiContainer the GuiContainer to work with
* @return The relative Mouse-Position
*/
private static int getMouseY(GuiContainer guiContainer) {
return guiContainer.height - (Mouse.getEventY() * guiContainer.height) / Util.client.displayHeight - 1;
}
/** /**
* Returns, if the current KeyValue is the same * Returns, if the current KeyValue is the same
* *
@@ -1,10 +1,9 @@
package de.skate702.craftingkeys.util; package de.skate702.craftingkeys.util;
import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentTranslation;
/** /**
* Provides basic utility methods. For input methods, look at InputUtil. * Provides basic utility methods. For input methods, look at InputUtil.
@@ -14,7 +13,7 @@ public class Util {
/** /**
* Current Instance Client, used for a lot of operations. * Current Instance Client, used for a lot of operations.
*/ */
public static final Minecraft client = FMLClientHandler.instance().getClient(); public static final Minecraft client = Minecraft.getInstance();
/** /**
* Only used by isFirstInWorldTick() * Only used by isFirstInWorldTick()
*/ */
@@ -65,7 +64,7 @@ public class Util {
* @param lang_key key from lang-file * @param lang_key key from lang-file
*/ */
public static void printMessage(String lang_key) { public static void printMessage(String lang_key) {
String translated = (new TextComponentTranslation(lang_key)).getUnformattedComponentText(); String translated = new TranslationTextComponent(lang_key).getUnformattedComponentText();
client.player.sendChatMessage(translated); client.player.sendChatMessage(translated);
} }
+40
View File
@@ -0,0 +1,40 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader = "javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion = "[35,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license = "All rights reserved"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId = "craftingkeys" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version = "${file.jarVersion}" #mandatory
# A display name for the mod
displayName = "Crafting Keys" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="http://craftingkeys.skate702.de" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile = "examplemod.png" #optional
# A text field displayed in the mod UI
credits = "Based on the open-source InvTweaks-Mod. Thanks a lot!" #optional
# A text field displayed in the mod UI
authors = "skate702 (sebinside)" #optional
# The description text for the mod (multi line!) (#mandatory)
description = "Simple better crafting! Crafing Keys enables new inventory key-bindings to speed up your crafting."
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange = "[1.16.4,1.17)"
ordering = "NONE"
side = "CLIENT"
@@ -1,11 +0,0 @@
# Config Stuff
craftingkeys.config.title=Crafting Keys Konfiguration
craftingkeys.config.description=Konfiguriere hier deine Tastenbelegung und klicke dann auf "Speichern".
craftingkeys.config.button.save=Speichern
craftingkeys.config.button.abort=Abbruch
craftingkeys.config.stack=Stapel Taste
craftingkeys.config.drop=Wegwerf Taste
# Key Bindings
craftingkeys.binding.opengui=Konfigurieren-Fenster oeffnen
craftingkeys.binding.cat=Crafting Keys
@@ -0,0 +1,10 @@
{
"craftingkeys.config.title": "Crafting Keys Konfiguration",
"craftingkeys.config.description": "Konfiguriere hier deine Tastenbelegung und klicke dann auf Speichern.",
"craftingkeys.config.button.save": "Speichern",
"craftingkeys.config.button.abort": "Abbruch",
"craftingkeys.config.stack": "Stapel Taste",
"craftingkeys.config.drop": "Wegwerf Taste",
"craftingkeys.binding.opengui": "Konfigurieren-Fenster oeffnen",
"craftingkeys.binding.cat": "Crafting Keys"
}
@@ -1,11 +0,0 @@
# Config Stuff
craftingkeys.config.title=Crafting Keys Config
craftingkeys.config.description=Configure your keys here. Click "Save" when finished!
craftingkeys.config.button.save=Save
craftingkeys.config.button.abort=Abort
craftingkeys.config.stack=Stack key
craftingkeys.config.drop=Drop key
# Key Bindings
craftingkeys.binding.opengui=Open config-gui
craftingkeys.binding.cat=Crafting Keys
@@ -0,0 +1,10 @@
{
"craftingkeys.config.title": "Crafting Keys Config",
"craftingkeys.config.description": "Configure your keys here. Click Save when finished!",
"craftingkeys.config.button.save": "Save",
"craftingkeys.config.button.abort": "Abort",
"craftingkeys.config.stack": "Stack key",
"craftingkeys.config.drop": "Drop key",
"craftingkeys.binding.opengui": "Open config-gui",
"craftingkeys.binding.cat": "Crafting Keys"
}
-12
View File
@@ -1,12 +0,0 @@
[
{
"modid": "craftingkeys",
"name": "Crafting Keys",
"description": "Simple better crafting! Crafing Keys enables new inventory key-bindings to speed up your crafting.",
"version": "1.0.2.1",
"credits": "Based on the open-source InvTweaks-Mod. Thanks a lot!",
"mcversion": "1.7.10 - 1.12.2",
"url": "http://craftingkeys.skate702.de",
"authorList": [ "skate702 (sebinside)" ]
}
]
+7
View File
@@ -0,0 +1,7 @@
{
"pack": {
"description": "examplemod resources",
"pack_format": 6,
"_comment": "A pack_format of 6 requires json lang files and some texture changes from 1.16.2. Note: we require v6 pack meta for all mods."
}
}