Author SHA1 Message Date
Meduris a8e400f59b upgrade to 1.21.1 neoforge 2026-09-11 23:30:37 +02:00
Meduris 0d4ba2ef6d ignore local maven publishing 2022-07-02 22:39:57 +02:00
Meduris 4e6398d7f1 update a few things the automation could not handle 2022-07-02 22:32:27 +02:00
Meduris c5791690f6 update class names to official mappings 2022-07-02 22:16:49 +02:00
Meduris 95916ca608 update to official mappings gradle 2022-07-02 22:16:03 +02:00
Meduris 5f3a6cbc7d update to official mappings code 2022-07-02 22:16:03 +02:00
Meduris ef02ecf902 update gradle, forgegradle and add plugin for code remapping 2022-07-02 22:14:04 +02:00
Meduris 2f025fbd06 update build environment
fix forge thinking the mod would be required server side
2022-02-03 11:48:27 +01:00
Meduris 97a89ab403 quick and dirty port to 1.16.4 2022-02-03 10:41:28 +01:00
35 changed files with 907 additions and 936 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/* text eol=lf
src/generated/**/*.json text eol=lf
+35 -12
View File
@@ -1,17 +1,40 @@
.idea/ ### Gradle ###
.gradle/ .gradle
build/ build/
classes/ !gradle/wrapper/gradle-wrapper.jar
eclipse/ !**/src/**/build/
gradle/
### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr
out/ out/
**/*.iml !**/src/**/out/
*.txt
*.gradle .run/
gradlew
gradlew.bat ### Eclipse ###
.apt_generated
.classpath .classpath
.metadata/ .eclipse/
.factorypath
.project .project
.settings/ .settings
.springBeans
.sts4-cache
bin/ bin/
!**/src/**/bin/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
### Minecraft Modding ###
run/
!**/src/**/run/
**/src/generated/**/.cache/
repo/
!**/src/**/repo/
+190
View File
@@ -0,0 +1,190 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'net.neoforged.moddev' version '2.0.147'
id 'idea'
}
tasks.named('wrapper', Wrapper).configure {
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
// documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
// file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
// (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
distributionType = Wrapper.DistributionType.BIN
}
version = mod_version
group = mod_group_id
sourceSets.main.resources {
// Include resources generated by data generators.
srcDir('src/generated/resources')
// Exclude common development only resources from finalized outputs
exclude("**/*.bbmodel") // BlockBench project files
exclude("src/generated/**/.cache") // datagen cache files
}
repositories {
// Add here additional repositories if required by some of the dependencies below.
}
base {
archivesName = mod_id
}
// Mojang ships Java 21 to end users in 1.21.1, so mods should target Java 21.
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
neoForge {
// Specify the version of NeoForge to use.
version = project.neo_version
parchment {
mappingsVersion = project.parchment_mappings_version
minecraftVersion = project.parchment_minecraft_version
}
// This line is optional. Access Transformers are automatically detected
// accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
client()
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}
server {
server()
programArgument '--nogui'
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}
// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}
data {
data()
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
// gameDirectory = project.file('run-data')
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
// applies to all the run configs above
configureEach {
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
systemProperty 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
logLevel = org.slf4j.event.Level.DEBUG
}
}
mods {
// define mod <-> source bindings
// these are used to tell the game which sources are for which mod
// multi mod projects should define one per mod
"${mod_id}" {
sourceSet(sourceSets.main)
}
}
}
// Sets up a dependency configuration called 'localRuntime'.
// This configuration should be used instead of 'runtimeOnly' to declare
// a dependency that will be present for runtime testing but that is
// "optional", meaning it will not be pulled by dependents of this mod.
configurations {
runtimeClasspath.extendsFrom localRuntime
}
dependencies {
// Example optional mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation "blank:coolmod-${mc_version}:${coolmod_version}"
// Example mod dependency using a file as dependency
// implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")
// Example project dependency using a sister or child project:
// implementation project(":myproject")
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
neo_version : neo_version,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
]
inputs.properties replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
}
// Include the output of "generateModMetadata" as an input directory for the build
// this works with both building through Gradle and the IDE.
sourceSets.main.resources.srcDir generateModMetadata
// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata
// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
register('mavenJava', MavenPublication) {
from components.java
}
}
repositories {
maven {
url "file://${project.projectDir}/repo"
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
+39
View File
@@ -0,0 +1,39 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
org.gradle.jvmargs=-Xmx1G
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
#read more on this at https://github.com/neoforged/ModDevGradle?tab=readme-ov-file#better-minecraft-parameter-names--javadoc-parchment
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
parchment_minecraft_version=1.21.1
parchment_mappings_version=2024.11.17
# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.21.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21.1]
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.1.219
# The loader version range can only use the major version of FML as bounds
loader_version_range=[1,)
## Mod Properties
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=craftingkeys
# The human-readable display name for the mod.
mod_name=Crafting Keys
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.0.4
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=de.skate702.craftingkeys
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+251
View File
@@ -0,0 +1,251 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# 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 ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH="\\\"\\\""
# 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
if ! command -v java >/dev/null 2>&1
then
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
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
Vendored
+94
View File
@@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@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=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@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="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 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!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+9
View File
@@ -0,0 +1,9 @@
pluginManagement {
repositories {
gradlePluginPortal()
}
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
}
@@ -1,34 +1,27 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraft.client.gui.screens.inventory.EnchantmentScreen;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraft.client.gui.screens.Screen;
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.screens.inventory.AnvilScreen;
import net.minecraft.client.gui.GuiRepair; import net.minecraft.client.gui.screens.inventory.BrewingStandScreen;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.screens.inventory.CraftingScreen;
import net.minecraft.client.gui.inventory.*; import net.minecraft.client.gui.screens.inventory.DispenserScreen;
import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraft.client.gui.screens.inventory.FurnaceScreen;
import net.minecraftforge.common.MinecraftForge; import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.gui.screens.inventory.MerchantScreen;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.common.NeoForge;
/** /**
* The Main Class of the Mod with the important onTick-Method. Some Methods are * The Main Class of the Mod with the important onTick-Method. Some Methods are
@@ -36,162 +29,82 @@ import net.minecraftforge.common.MinecraftForge;
* *
* @author skate702 * @author skate702
*/ */
@Mod(modid = CraftingKeys.MODID, name = CraftingKeys.NAME, version = CraftingKeys.VERSION) @Mod(value = CraftingKeys.MODID, dist = Dist.CLIENT)
public class CraftingKeys { public class CraftingKeys {
public static final String MODID = "craftingkeys"; public static final String MODID = "craftingkeys";
public static final String VERSION = "1.0.2";
public static final String NAME = "Crafting Keys"; public static final String NAME = "Crafting Keys";
/** /**
* 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;
*/ NeoForge.EVENT_BUS.addListener(this::onTick);
@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);
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") public void onTick(ClientTickEvent.Post tick) {
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent tick) {
GuiScreen currentScreen = Util.client.currentScreen; Screen currentScreen = Util.client.screen;
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).getMenu());
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).getMenu());
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).getMenu());
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).getMenu());
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).getMenu());
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).getMenu());
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).getMenu());
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).getMenu());
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 com.mojang.blaze3d.platform.InputConstants;
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().options.keyShift.getKey().getValue();
*/ private static int keyInteract = Minecraft.getInstance().options.keySprint.getKey().getValue();
private static Property enableNumPad; private static final int keyDrop = KeyEvent.VK_SPACE;
public static boolean isKeyDown(int keyCode) {
return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Anvil GUI Inventory. * Manages a Anvil GUI Inventory.
@@ -14,7 +14,7 @@ public class AnvilManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private AnvilManager(Container container) { private AnvilManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -24,7 +24,7 @@ public class AnvilManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static AnvilManager getInstance(Container container) { public static AnvilManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new AnvilManager(container); instance = new AnvilManager(container);
} else { } else {
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Brewing Stand GUI Inventory. * Manages a Brewing Stand GUI Inventory.
@@ -15,7 +15,7 @@ public class BrewingManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private BrewingManager(Container container) { private BrewingManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -25,7 +25,7 @@ public class BrewingManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static BrewingManager getInstance(Container container) { public static BrewingManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new BrewingManager(container); instance = new BrewingManager(container);
} else { } else {
@@ -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.world.level.block.Blocks;
import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.KeyMapping;
import net.minecraft.init.Blocks; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.inventory.Container; import net.minecraft.world.inventory.Slot;
import net.minecraft.inventory.Slot; import net.minecraft.world.item.Item;
import net.minecraft.item.Item; import net.minecraft.world.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.
@@ -23,14 +21,14 @@ public abstract class ContainerManager {
/** /**
* The Container to work with. * The Container to work with.
*/ */
Container container; AbstractContainerMenu container;
/** /**
* Creates a new ContainerManager with the given container. * Creates a new ContainerManager with the given container.
* *
* @param container The container to work with * @param container The container to work with
*/ */
ContainerManager(Container container) { ContainerManager(AbstractContainerMenu container) {
this.container = container; this.container = container;
} }
@@ -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.screen);
int slotIndex = specificKeyToSlotIndex(); int slotIndex = specificKeyToSlotIndex();
// Handle accepted key // Handle accepted key
@@ -63,7 +61,7 @@ public abstract class ContainerManager {
!Util.isHoldingStack()) { // MOVE FROM SLOT !Util.isHoldingStack()) { // MOVE FROM SLOT
Logger.info("acceptKey()", "Key for index " + slotIndex + " pressed."); Logger.info("acceptKey()", "Key for index " + slotIndex + " pressed.");
onSpecificKeyPressed(currentHoveredSlot.slotNumber, slotIndex); onSpecificKeyPressed(currentHoveredSlot.index, slotIndex);
} else if (Util.isHoldingStack()) { // MOVE FROM HAND } else if (Util.isHoldingStack()) { // MOVE FROM HAND
@@ -100,7 +98,7 @@ public abstract class ContainerManager {
// Handles Interaction with items held // Handles Interaction with items held
// Stack up on hand if equal or small enough, else throw held stack away // Stack up on hand if equal or small enough, else throw held stack away
if (Util.isHoldingStack() && getItemStack(getInteractionSlotIndex()) != null && ( if (Util.isHoldingStack() && getItemStack(getInteractionSlotIndex()) != null && (
!Util.getHeldStack().isItemEqual(getItemStack(getInteractionSlotIndex())) !Util.getHeldStack().is(getItemStack(getInteractionSlotIndex()).getItem())
|| Util.getHeldStack().getCount() + getItemStack(getInteractionSlotIndex()).getCount() || Util.getHeldStack().getCount() + getItemStack(getInteractionSlotIndex()).getCount()
> getItemStack(getInteractionSlotIndex()).getMaxStackSize())) { > getItemStack(getInteractionSlotIndex()).getMaxStackSize())) {
moveStackToInventory(-1); moveStackToInventory(-1);
@@ -161,32 +159,32 @@ public abstract class ContainerManager {
void handleNumKey(Slot currentHoveredSlot) { void handleNumKey(Slot currentHoveredSlot) {
// 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.containerMenu.getItems().size() - 9 - 1;
if (Util.client.currentScreen instanceof GuiInventory) { if (Util.client.screen instanceof InventoryScreen) {
hotbarStartIndex -= 1; hotbarStartIndex -= 1;
} }
int inputdelta; int inputdelta;
KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar; KeyMapping[] hotbar = Util.client.options.keyHotbarSlots;
if (Keyboard.isKeyDown(hotbar[0].getKeyCode())) { if (Config.isKeyDown(hotbar[0].getKey().getValue())) {
inputdelta = 1; inputdelta = 1;
} else if (Keyboard.isKeyDown(hotbar[1].getKeyCode())) { } else if (Config.isKeyDown(hotbar[1].getKey().getValue())) {
inputdelta = 2; inputdelta = 2;
} else if (Keyboard.isKeyDown(hotbar[2].getKeyCode())) { } else if (Config.isKeyDown(hotbar[2].getKey().getValue())) {
inputdelta = 3; inputdelta = 3;
} else if (Keyboard.isKeyDown(hotbar[3].getKeyCode())) { } else if (Config.isKeyDown(hotbar[3].getKey().getValue())) {
inputdelta = 4; inputdelta = 4;
} else if (Keyboard.isKeyDown(hotbar[4].getKeyCode())) { } else if (Config.isKeyDown(hotbar[4].getKey().getValue())) {
inputdelta = 5; inputdelta = 5;
} else if (Keyboard.isKeyDown(hotbar[5].getKeyCode())) { } else if (Config.isKeyDown(hotbar[5].getKey().getValue())) {
inputdelta = 6; inputdelta = 6;
} else if (Keyboard.isKeyDown(hotbar[6].getKeyCode())) { } else if (Config.isKeyDown(hotbar[6].getKey().getValue())) {
inputdelta = 7; inputdelta = 7;
} else if (Keyboard.isKeyDown(hotbar[7].getKeyCode())) { } else if (Config.isKeyDown(hotbar[7].getKey().getValue())) {
inputdelta = 8; inputdelta = 8;
} else if (Keyboard.isKeyDown(hotbar[8].getKeyCode())) { } else if (Config.isKeyDown(hotbar[8].getKey().getValue())) {
inputdelta = 9; inputdelta = 9;
} else { } else {
return; return;
@@ -196,7 +194,7 @@ public abstract class ContainerManager {
// if there could not be meant another stack at mouse position. cool logic! // if there could not be meant another stack at mouse position. cool logic!
if (!Util.isHoldingStack()) { if (!Util.isHoldingStack()) {
if (currentHoveredSlot == null || !currentHoveredSlot.getHasStack()) { if (currentHoveredSlot == null || !currentHoveredSlot.hasItem()) {
Logger.info("handleNumKey()", "Trying output to hotbar speedup."); Logger.info("handleNumKey()", "Trying output to hotbar speedup.");
onInteractionKeyPressed(); onInteractionKeyPressed();
} }
@@ -209,14 +207,7 @@ 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!");
}
} }
} }
/** /**
@@ -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());
} }
} }
/** /**
@@ -317,13 +306,13 @@ public abstract class ContainerManager {
int movedAmount = Math.min(amount, sourceSize); int movedAmount = Math.min(amount, sourceSize);
// Clear goal slot (May fail on full inventory!); only available if not holdling // Clear goal slot (May fail on full inventory!); only available if not holdling
if (destination != null && !source.isItemEqual(destination) && srcIndex >= 0) { if (destination != null && !source.is(destination.getItem()) && srcIndex >= 0) {
moveStackToInventory(destIndex); moveStackToInventory(destIndex);
destination = getItemStack(destIndex); destination = getItemStack(destIndex);
} }
// Move some // Move some
if (destination == null || source.isItemEqual(destination)) { if (destination == null || source.is(destination.getItem())) {
if (srcIndex >= 0) { if (srcIndex >= 0) {
leftClick(srcIndex); leftClick(srcIndex);
@@ -353,14 +342,14 @@ public abstract class ContainerManager {
*/ */
ItemStack getItemStack(int index) { ItemStack getItemStack(int index) {
if (index >= 0 && index < container.inventorySlots.size()) { if (index >= 0 && index < container.slots.size()) {
Slot slot = (Slot) (container.inventorySlots.get(index)); Slot slot = (Slot) (container.slots.get(index));
// NEW_1_11 No Null-Stacks anymore. Empty Stacks with air... // NEW_1_11 No Null-Stacks anymore. Empty Stacks with air...
ItemStack returnStack = (slot == null) ? null : slot.getStack(); ItemStack returnStack = (slot == null) ? null : slot.getItem();
if(returnStack.getCount() == 0 && returnStack.getItem() == Item.getItemFromBlock(Blocks.AIR)) { if(returnStack.getCount() == 0 && returnStack.getItem() == Item.byBlock(Blocks.AIR)) {
returnStack = null; returnStack = null;
} }
@@ -436,12 +425,12 @@ public abstract class ContainerManager {
private int calcInventoryDestination(ItemStack stackToMove) { private int calcInventoryDestination(ItemStack stackToMove) {
// First run: Try to find a nice stack to put items on additionally // First run: Try to find a nice stack to put items on additionally
for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) { for (int i = getInventoryStartIndex(); i < container.slots.size(); i++) {
ItemStack potentialGoalStack = getItemStack(i); ItemStack potentialGoalStack = getItemStack(i);
if (potentialGoalStack != null && stackToMove != null) { if (potentialGoalStack != null && stackToMove != null) {
if (potentialGoalStack.isItemEqual(stackToMove)) { if (potentialGoalStack.is(stackToMove.getItem())) {
if (potentialGoalStack.getCount() + stackToMove.getCount() <= stackToMove.getMaxStackSize()) { if (potentialGoalStack.getCount() + stackToMove.getCount() <= stackToMove.getMaxStackSize()) {
return i; return i;
} }
@@ -450,7 +439,7 @@ public abstract class ContainerManager {
} }
// Second run: Find a free slot // Second run: Find a free slot
for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) { for (int i = getInventoryStartIndex(); i < container.slots.size(); i++) {
if (getItemStack(i) == null) { if (getItemStack(i) == null) {
return i; return i;
} }
@@ -504,9 +493,8 @@ public abstract class ContainerManager {
int rightClickData = (rightClick) ? 1 : 0; int rightClickData = (rightClick) ? 1 : 0;
CraftingKeys.proxy.sendSlotClick(Util.client.playerController, container.windowId, index, CraftingKeys.proxy.sendSlotClick(Util.client.gameMode, container.containerId, index,
rightClickData, 0, Util.client.player); rightClickData, 0, Util.client.player);
} }
} }
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Crafting GUI Inventory. * Manages a Crafting GUI Inventory.
@@ -15,7 +15,7 @@ public class CraftingManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private CraftingManager(Container container) { private CraftingManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -25,7 +25,7 @@ public class CraftingManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static CraftingManager getInstance(Container container) { public static CraftingManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new CraftingManager(container); instance = new CraftingManager(container);
} else { } else {
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Dispenser GUI Inventory. * Manages a Dispenser GUI Inventory.
@@ -15,7 +15,7 @@ public class DispenserManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private DispenserManager(Container container) { private DispenserManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -25,7 +25,7 @@ public class DispenserManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static DispenserManager getInstance(Container container) { public static DispenserManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new DispenserManager(container); instance = new DispenserManager(container);
} else { } else {
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Enchantment Table GUI Inventory. * Manages a Enchantment Table GUI Inventory.
@@ -15,7 +15,7 @@ public class EnchantmentManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private EnchantmentManager(Container container) { private EnchantmentManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -25,7 +25,7 @@ public class EnchantmentManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static EnchantmentManager getInstance(Container container) { public static EnchantmentManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new EnchantmentManager(container); instance = new EnchantmentManager(container);
} else { } else {
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Furnace GUI Inventory. * Manages a Furnace GUI Inventory.
@@ -15,7 +15,7 @@ public class FurnaceManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private FurnaceManager(Container container) { private FurnaceManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -25,7 +25,7 @@ public class FurnaceManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static FurnaceManager getInstance(Container container) { public static FurnaceManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new FurnaceManager(container); instance = new FurnaceManager(container);
} else { } else {
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Inventory GUI Inventory. * Manages a Inventory GUI Inventory.
@@ -15,7 +15,7 @@ public class InventoryManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private InventoryManager(Container container) { private InventoryManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -25,7 +25,7 @@ public class InventoryManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static InventoryManager getInstance(Container container) { public static InventoryManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new InventoryManager(container); instance = new InventoryManager(container);
} else { } else {
@@ -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.world.inventory.AbstractContainerMenu;
/** /**
* Manages a Villager GUI Inventory. * Manages a Villager GUI Inventory.
@@ -16,7 +16,7 @@ public class VillagerManager extends ContainerManager {
* *
* @param container The container from a crafting GUI * @param container The container from a crafting GUI
*/ */
private VillagerManager(Container container) { private VillagerManager(AbstractContainerMenu container) {
super(container); super(container);
} }
@@ -26,7 +26,7 @@ public class VillagerManager extends ContainerManager {
* @param container A container from a GUI * @param container A container from a GUI
* @return manager-singleton * @return manager-singleton
*/ */
public static VillagerManager getInstance(Container container) { public static VillagerManager getInstance(AbstractContainerMenu container) {
if (instance == null) { if (instance == null) {
instance = new VillagerManager(container); instance = new VillagerManager(container);
} else { } else {
@@ -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.MultiPlayerGameMode;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraft.world.entity.player.Player;
import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.world.inventory.ClickType;
import net.minecraft.entity.player.EntityPlayer; import net.neoforged.api.distmarker.Dist;
import net.neoforged.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(MultiPlayerGameMode controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action,
EntityPlayer player) { Player player) {
controller.handleInventoryMouseClick(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.screens.Screen;
import net.minecraft.inventory.Container; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.inventory.Slot; import net.minecraft.world.inventory.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 AbstractContainerScreen) {
Container container = guiContainer.inventorySlots; return ((AbstractContainerScreen) 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,6 +1,6 @@
package de.skate702.craftingkeys.util; package de.skate702.craftingkeys.util;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.language.I18n;
public class LanguageLocalizer { public class LanguageLocalizer {
/** /**
@@ -10,6 +10,6 @@ public class LanguageLocalizer {
* @return localized The localized String * @return localized The localized String
*/ */
public static String localize(String unloc) { public static String localize(String unloc) {
return I18n.format(unloc); return I18n.get(unloc);
} }
} }
@@ -1,10 +1,10 @@
package de.skate702.craftingkeys.util; package de.skate702.craftingkeys.util;
import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.world.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 +14,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()
*/ */
@@ -32,7 +32,7 @@ public class Util {
* @return A item stack * @return A item stack
*/ */
public static ItemStack getHeldStack() { public static ItemStack getHeldStack() {
return client.player.inventory.getItemStack(); return ((AbstractContainerScreen<?>)client.screen).getMenu().getCarried();
} }
/** /**
@@ -50,10 +50,10 @@ public class Util {
* @return True, if this is the first tick * @return True, if this is the first tick
*/ */
public static boolean isFirstInWorldTick() { public static boolean isFirstInWorldTick() {
if (firstInWorldTick && client.world != null) { if (firstInWorldTick && client.level != null) {
firstInWorldTick = false; firstInWorldTick = false;
return true; return true;
} else if (client.world == null) { } else if (client.level == null) {
firstInWorldTick = true; firstInWorldTick = true;
} }
return false; return false;
@@ -65,8 +65,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(); client.player.displayClientMessage(Component.translatable(lang_key), false);
client.player.sendChatMessage(translated);
} }
} }
@@ -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)" ]
}
]
+6
View File
@@ -0,0 +1,6 @@
{
"pack": {
"description": "craftingkeys resources",
"pack_format": 6
}
}
@@ -0,0 +1,93 @@
# This is an example neoforge.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 FML version. This is currently 2.
loaderVersion="${loader_version_range}" #mandatory
# 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="${mod_license}"
# 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="${mod_id}" #mandatory
# The version number of the mod
version="${mod_version}" #mandatory
# A display name for the mod
displayName="${mod_name}" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://docs.neoforged.net/docs/misc/updatechecker/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="https://github.com/sebinside/CraftingKeys" #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
# The authors of the mod, displayed in the mod UI (optional)
authors="skate702 (sebinside), Meduris"
# 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.
'''
# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
#[[mixins]]
#config="${mod_id}.mixins.json"
# The [[accessTransformers]] block allows you to declare where your AT file is.
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg
#[[accessTransformers]]
#file="META-INF/accesstransformer.cfg"
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.${mod_id}]] #optional
# the modid of the dependency
modId="neoforge" #mandatory
# The type of the dependency. Can be one of "required", "optional", "incompatible" or "discouraged" (case insensitive).
# 'required' requires the mod to exist, 'optional' does not
# 'incompatible' will prevent the game from loading when the mod exists, and 'discouraged' will show a warning
type="required" #mandatory
# Optional field describing why the dependency is required or why it is incompatible
# reason="..."
# The version range of the dependency
versionRange="[${neo_version},)" #mandatory
# An ordering relationship for the dependency.
# BEFORE - This mod is loaded BEFORE the dependency
# AFTER - This mod is loaded AFTER the dependency
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.${mod_id}]]
modId="minecraft"
type="required"
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="${minecraft_version_range}"
ordering="NONE"
side="BOTH"
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
# stop your mod loading on the server for example.
#[features.${mod_id}]
#openGLVersion="[3.2,)"