From d1e292ca25b7987bc4ddf334205238d75f7f29b7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Dec 2018 13:17:31 +0800 Subject: from aei but like jei now --- .gitignore | 26 ++ build.gradle | 50 ++++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54413 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++ gradlew.bat | 84 +++++++ settings.gradle | 2 + src/main/java/me/shedaniel/ClientListener.java | 66 ++++++ src/main/java/me/shedaniel/Core.java | 33 +++ src/main/java/me/shedaniel/api/IAEIPlugin.java | 9 + .../java/me/shedaniel/api/IDisplayCategory.java | 27 +++ src/main/java/me/shedaniel/api/IDisplayHelper.java | 7 + src/main/java/me/shedaniel/api/IDrawable.java | 10 + src/main/java/me/shedaniel/api/IRecipe.java | 15 ++ src/main/java/me/shedaniel/api/IRecipeManager.java | 20 ++ .../java/me/shedaniel/api/TriBooleanProducer.java | 8 + .../java/me/shedaniel/gui/AEIRenderHelper.java | 235 ++++++++++++++++++ src/main/java/me/shedaniel/gui/Drawable.java | 33 +++ src/main/java/me/shedaniel/gui/GuiItemList.java | 264 +++++++++++++++++++++ .../java/me/shedaniel/gui/RecipeContainer.java | 13 + src/main/java/me/shedaniel/gui/RecipeGui.java | 218 +++++++++++++++++ src/main/java/me/shedaniel/gui/widget/AEISlot.java | 181 ++++++++++++++ src/main/java/me/shedaniel/gui/widget/Button.java | 72 ++++++ src/main/java/me/shedaniel/gui/widget/Control.java | 96 ++++++++ .../java/me/shedaniel/gui/widget/IFocusable.java | 10 + src/main/java/me/shedaniel/gui/widget/TextBox.java | 71 ++++++ .../java/me/shedaniel/gui/widget/WidgetArrow.java | 38 +++ .../java/me/shedaniel/impl/AEIRecipeManager.java | 157 ++++++++++++ .../java/me/shedaniel/library/KeyBindManager.java | 58 +++++ src/main/java/me/shedaniel/library/Sink.java | 6 + .../shedaniel/listenerdefinitions/CharInput.java | 9 + .../shedaniel/listenerdefinitions/DoneLoading.java | 8 + .../listenerdefinitions/DrawContainer.java | 10 + .../listenerdefinitions/GuiCickListener.java | 8 + .../shedaniel/listenerdefinitions/GuiKeyDown.java | 9 + .../listenerdefinitions/IMixinGuiContainer.java | 14 ++ .../listenerdefinitions/MinecraftResize.java | 8 + .../listenerdefinitions/MouseScrollListener.java | 5 + .../listenerdefinitions/PreLoadOptions.java | 9 + .../listenerdefinitions/RecipeLoadListener.java | 7 + .../shedaniel/listeners/DrawContainerListener.java | 60 +++++ .../java/me/shedaniel/listeners/InitListener.java | 22 ++ .../me/shedaniel/listeners/ResizeListener.java | 14 ++ .../java/me/shedaniel/mixins/MixinDoneLoading.java | 22 ++ .../me/shedaniel/mixins/MixinGuiContainer.java | 98 ++++++++ .../mixins/MixinGuiContainerCreative.java | 93 ++++++++ .../me/shedaniel/mixins/MixinKeyboardListener.java | 27 +++ .../me/shedaniel/mixins/MixinMinecraftResize.java | 23 ++ .../me/shedaniel/mixins/MixinRecipeManager.java | 26 ++ .../java/me/shedaniel/mixins/SettingsMixin.java | 44 ++++ .../java/me/shedaniel/network/CheatPacket.java | 45 ++++ .../java/me/shedaniel/network/DeletePacket.java | 32 +++ .../java/me/shedaniel/plugin/VanillaPlugin.java | 43 ++++ .../plugin/crafting/VanillaCraftingCategory.java | 106 +++++++++ .../plugin/crafting/VanillaCraftingRecipe.java | 16 ++ .../crafting/VanillaShapedCraftingRecipe.java | 55 +++++ .../crafting/VanillaShapelessCraftingRecipe.java | 57 +++++ .../plugin/furnace/VanillaFurnaceCategory.java | 83 +++++++ .../plugin/furnace/VanillaFurnaceRecipe.java | 42 ++++ .../assets/almostenoughitems/.modassetroot | 0 .../assets/almostenoughitems/lang/en_us.json | 8 + .../assets/almostenoughitems/lang/fr_fr.json | 8 + .../textures/gui/recipecontainer.png | Bin 0 -> 3577 bytes src/main/resources/mixins.roughlyenoughitems.json | 18 ++ src/main/resources/pack.mcmeta | 6 + src/main/resources/riftmod.json | 26 ++ 66 files changed, 3048 insertions(+) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100755 src/main/java/me/shedaniel/ClientListener.java create mode 100755 src/main/java/me/shedaniel/Core.java create mode 100755 src/main/java/me/shedaniel/api/IAEIPlugin.java create mode 100755 src/main/java/me/shedaniel/api/IDisplayCategory.java create mode 100755 src/main/java/me/shedaniel/api/IDisplayHelper.java create mode 100755 src/main/java/me/shedaniel/api/IDrawable.java create mode 100755 src/main/java/me/shedaniel/api/IRecipe.java create mode 100755 src/main/java/me/shedaniel/api/IRecipeManager.java create mode 100755 src/main/java/me/shedaniel/api/TriBooleanProducer.java create mode 100755 src/main/java/me/shedaniel/gui/AEIRenderHelper.java create mode 100755 src/main/java/me/shedaniel/gui/Drawable.java create mode 100755 src/main/java/me/shedaniel/gui/GuiItemList.java create mode 100755 src/main/java/me/shedaniel/gui/RecipeContainer.java create mode 100755 src/main/java/me/shedaniel/gui/RecipeGui.java create mode 100755 src/main/java/me/shedaniel/gui/widget/AEISlot.java create mode 100755 src/main/java/me/shedaniel/gui/widget/Button.java create mode 100755 src/main/java/me/shedaniel/gui/widget/Control.java create mode 100755 src/main/java/me/shedaniel/gui/widget/IFocusable.java create mode 100755 src/main/java/me/shedaniel/gui/widget/TextBox.java create mode 100755 src/main/java/me/shedaniel/gui/widget/WidgetArrow.java create mode 100755 src/main/java/me/shedaniel/impl/AEIRecipeManager.java create mode 100755 src/main/java/me/shedaniel/library/KeyBindManager.java create mode 100755 src/main/java/me/shedaniel/library/Sink.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/CharInput.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/DoneLoading.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/DrawContainer.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiCickListener.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiKeyDown.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/IMixinGuiContainer.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/MinecraftResize.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/MouseScrollListener.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/PreLoadOptions.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/RecipeLoadListener.java create mode 100755 src/main/java/me/shedaniel/listeners/DrawContainerListener.java create mode 100755 src/main/java/me/shedaniel/listeners/InitListener.java create mode 100755 src/main/java/me/shedaniel/listeners/ResizeListener.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinDoneLoading.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinGuiContainer.java create mode 100644 src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinKeyboardListener.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinMinecraftResize.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinRecipeManager.java create mode 100755 src/main/java/me/shedaniel/mixins/SettingsMixin.java create mode 100755 src/main/java/me/shedaniel/network/CheatPacket.java create mode 100755 src/main/java/me/shedaniel/network/DeletePacket.java create mode 100755 src/main/java/me/shedaniel/plugin/VanillaPlugin.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingRecipe.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaShapedCraftingRecipe.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaShapelessCraftingRecipe.java create mode 100755 src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java create mode 100755 src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java create mode 100755 src/main/resources/assets/almostenoughitems/.modassetroot create mode 100755 src/main/resources/assets/almostenoughitems/lang/en_us.json create mode 100755 src/main/resources/assets/almostenoughitems/lang/fr_fr.json create mode 100755 src/main/resources/assets/almostenoughitems/textures/gui/recipecontainer.png create mode 100644 src/main/resources/mixins.roughlyenoughitems.json create mode 100644 src/main/resources/pack.mcmeta create mode 100644 src/main/resources/riftmod.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..92af0487c --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Compiled nonsense that does not belong in *source* control +/build +/bin +/.gradle +/minecraft +/out +/run +/classes + +# IDE nonsense that could go in source control but really shouldn't +.classpath +.project +.metadata +.settings +*.launch +*.iml +.idea +*.ipr +*.iws + +# Sekrit files +private.properties + +# Files from bad operating systems :^) +Thumbs.db +.DS_Store diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..e9f44d88a --- /dev/null +++ b/build.gradle @@ -0,0 +1,50 @@ +buildscript { + repositories { + jcenter() + maven { url 'https://www.jitpack.io' } + maven { url 'http://repo.spongepowered.org/maven' } + maven { url 'http://files.minecraftforge.net/maven' } + } + dependencies { + classpath 'com.github.Chocohead:ForgeGradle:moderniser-SNAPSHOT' + classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' + } +} + +apply plugin: 'net.minecraftforge.gradle.tweaker-client' +apply plugin: 'org.spongepowered.mixin' +apply plugin: 'java' + +group 'me.shedaniel' +version '1.0b-SNAPSHOT' +archivesBaseName = 'RoughlyEnoughItems' + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +repositories { + mavenCentral() + maven { url 'https://www.dimdev.org/maven/' } + maven { url 'https://repo.spongepowered.org/maven/' } + maven { url 'https://www.jitpack.io' } + maven { url "http://repo.strezz.org/artifactory/list/Strezz-Central" } +} + + + +mixin { + defaultObfuscationEnv notch + add sourceSets.main, 'mixins.roughlyenoughitems.refmap.json' +} + +minecraft { + version = '1.13.2' + mappings = 'snapshot_20181130' + runDir = 'run' + tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderClientTweaker' +} + +dependencies { + implementation 'com.github.Chocohead:Rift:f76cf44d887d290782590c99770876393c924333:dev' + implementation 'com.google.code.gson:gson:2.8.5' +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..1948b9074 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..acb49a1b1 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Dec 21 19:34:34 HKT 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 000000000..cccdd3d51 --- /dev/null +++ b/gradlew @@ -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" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..e95643d6a --- /dev/null +++ b/gradlew.bat @@ -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 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..cc5cba83c --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'RoughlyEnoughItems' + diff --git a/src/main/java/me/shedaniel/ClientListener.java b/src/main/java/me/shedaniel/ClientListener.java new file mode 100755 index 000000000..9d52addd5 --- /dev/null +++ b/src/main/java/me/shedaniel/ClientListener.java @@ -0,0 +1,66 @@ +package me.shedaniel; + +import me.shedaniel.api.IAEIPlugin; +import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.DoneLoading; +import me.shedaniel.listenerdefinitions.RecipeLoadListener; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.registry.IRegistry; + +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + +public class ClientListener implements DoneLoading, RecipeLoadListener { + public static KeyBinding recipeKeybind; + public static KeyBinding hideKeybind; + public static KeyBinding useKeybind; + + private List plugins; + public static List stackList; + + @Override + public void onDoneLoading() { + + plugins = new ArrayList<>(); + stackList = new ArrayList<>(); + + recipeKeybind = KeyBindManager.createKeybinding("key.aei.recipe", KeyEvent.VK_R, "key.aei.category", AEIRenderHelper::recipeKeybind); + hideKeybind = KeyBindManager.createKeybinding("key.aei.hide", KeyEvent.VK_O, "key.aei.category", AEIRenderHelper::hideKeybind); + useKeybind = KeyBindManager.createKeybinding("key.aei.use", KeyEvent.VK_U, "key.aei.category", AEIRenderHelper::useKeybind); + + buildItemList(); + } + + private void buildItemList() { + if (!IRegistry.ITEM.isEmpty()) { + IRegistry.ITEM.forEach(item -> processItem((Item) item)); + } + + } + + private void processItem(Item item) { + NonNullList items = NonNullList.create(); + try { + item.fillItemGroup(item.getGroup(), items); + items.forEach(stackList::add); + } catch (NullPointerException e) { + if (item == Items.ENCHANTED_BOOK) { + item.fillItemGroup(ItemGroup.TOOLS, items); + items.forEach(stackList::add); + } + } + } + + @Override + public void recipesLoaded(net.minecraft.item.crafting.RecipeManager recipeManager) { + AEIRecipeManager.instance().RecipesLoaded(recipeManager); + } +} diff --git a/src/main/java/me/shedaniel/Core.java b/src/main/java/me/shedaniel/Core.java new file mode 100755 index 000000000..61f985db1 --- /dev/null +++ b/src/main/java/me/shedaniel/Core.java @@ -0,0 +1,33 @@ +package me.shedaniel; + +import me.shedaniel.network.CheatPacket; +import me.shedaniel.network.DeletePacket; +import net.minecraft.network.EnumPacketDirection; +import org.dimdev.rift.listener.PacketAdder; + +/** + * Created by James on 7/27/2018. + */ +public class Core implements PacketAdder { + @Override + public void registerHandshakingPackets(PacketRegistrationReceiver receiver) { + } + + @Override + public void registerPlayPackets(PacketRegistrationReceiver receiver) { + receiver.registerPacket(EnumPacketDirection.SERVERBOUND, CheatPacket.class); + receiver.registerPacket(EnumPacketDirection.SERVERBOUND, DeletePacket.class); + } + + @Override + public void registerStatusPackets(PacketRegistrationReceiver receiver) { + + } + + @Override + public void registerLoginPackets(PacketRegistrationReceiver receiver) { + + } + + +} diff --git a/src/main/java/me/shedaniel/api/IAEIPlugin.java b/src/main/java/me/shedaniel/api/IAEIPlugin.java new file mode 100755 index 000000000..9f5b5da6e --- /dev/null +++ b/src/main/java/me/shedaniel/api/IAEIPlugin.java @@ -0,0 +1,9 @@ +package me.shedaniel.api; + +/** + * Created by James on 7/27/2018. + */ +public interface IAEIPlugin { + + public void register(); +} diff --git a/src/main/java/me/shedaniel/api/IDisplayCategory.java b/src/main/java/me/shedaniel/api/IDisplayCategory.java new file mode 100755 index 000000000..f5cb02a4d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDisplayCategory.java @@ -0,0 +1,27 @@ +package me.shedaniel.api; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; + +import java.util.List; + +/** + * Created by James on 8/7/2018. + */ +public interface IDisplayCategory { + public String getId(); + + public String getDisplayName(); + + public void addRecipe(T recipe); + + public void resetRecipes(); + + public List setupDisplay(int number); + + public boolean canDisplay(T recipe); + + public void drawExtras(); + + public void addWidget(List controls, int number); +} diff --git a/src/main/java/me/shedaniel/api/IDisplayHelper.java b/src/main/java/me/shedaniel/api/IDisplayHelper.java new file mode 100755 index 000000000..6f230d3b5 --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDisplayHelper.java @@ -0,0 +1,7 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/7/2018. + */ +public interface IDisplayHelper { +} diff --git a/src/main/java/me/shedaniel/api/IDrawable.java b/src/main/java/me/shedaniel/api/IDrawable.java new file mode 100755 index 000000000..102b7e1c5 --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDrawable.java @@ -0,0 +1,10 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/7/2018. + */ +public interface IDrawable { + public void draw(); + + public boolean isHighlighted(); +} diff --git a/src/main/java/me/shedaniel/api/IRecipe.java b/src/main/java/me/shedaniel/api/IRecipe.java new file mode 100755 index 000000000..6359c351a --- /dev/null +++ b/src/main/java/me/shedaniel/api/IRecipe.java @@ -0,0 +1,15 @@ +package me.shedaniel.api; + +import java.util.List; + +/** + * Created by James on 7/27/2018. + */ +public interface IRecipe { + + public String getId(); + + public List getOutput(); + + public List> getInput(); +} diff --git a/src/main/java/me/shedaniel/api/IRecipeManager.java b/src/main/java/me/shedaniel/api/IRecipeManager.java new file mode 100755 index 000000000..355a1cd4d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IRecipeManager.java @@ -0,0 +1,20 @@ +package me.shedaniel.api; + +import net.minecraft.item.ItemStack; + +import java.util.List; +import java.util.Map; + +/** + * Created by James on 8/5/2018. + */ +public interface IRecipeManager { + + public void addRecipe(String id, IRecipe recipe); + + public void addRecipe(String id, List recipes); + + public void addDisplayAdapter(IDisplayCategory adapter); + + public Map> getRecipesFor(ItemStack stack); +} diff --git a/src/main/java/me/shedaniel/api/TriBooleanProducer.java b/src/main/java/me/shedaniel/api/TriBooleanProducer.java new file mode 100755 index 000000000..0925fee75 --- /dev/null +++ b/src/main/java/me/shedaniel/api/TriBooleanProducer.java @@ -0,0 +1,8 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/4/2018. + */ +public interface TriBooleanProducer { + public boolean accept(int first, int second, int third); +} diff --git a/src/main/java/me/shedaniel/gui/AEIRenderHelper.java b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java new file mode 100755 index 000000000..3ffbc7d82 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java @@ -0,0 +1,235 @@ +package me.shedaniel.gui; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.IFocusable; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.item.ItemStack; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +/** + * Created by James on 7/28/2018. + */ +public class AEIRenderHelper { + static Point mouseLoc; + static public GuiItemList aeiGui; + static GuiContainer overlayedGui; + static List tooltipsToRender = new ArrayList<>(); + + public static void setMouseLoc(int x, int y) { + mouseLoc = new Point(x, y); + } + + static public IFocusable focusedControl; + + public static Point getMouseLoc() { + return mouseLoc; + } + + public static MainWindow getResolution() { + + return Minecraft.getInstance().mainWindow; + } + + public static void drawAEI(GuiContainer overlayedGui) { + AEIRenderHelper.overlayedGui = overlayedGui; + if (aeiGui == null) { + aeiGui = new GuiItemList(overlayedGui); + } + aeiGui.draw(); + renderTooltips(); + } + + public static void resize() { + if (aeiGui != null) { + aeiGui.resize(); + } + if (overlayedGui instanceof RecipeGui) { + overlayedGui.onResize(Minecraft.getInstance(), 0, 0); + } + } + + public static ItemRenderer getItemRender() { + return Minecraft.getInstance().getItemRenderer(); + } + + public static FontRenderer getFontRenderer() { + return Minecraft.getInstance().fontRenderer; + } + + public static GuiContainer getOverlayedGui() { + if (overlayedGui instanceof GuiContainer) + return overlayedGui; + return null; + } + + public static void addToolTip(List text, int x, int y) { + tooltipsToRender.add(new TooltipData(text, x, y)); + } + + + private static void renderTooltips() { + GlStateManager.pushMatrix(); + GlStateManager.enableLighting(); + for(TooltipData tooltipData : tooltipsToRender) { + getOverlayedGui().drawHoveringText(tooltipData.text, tooltipData.x, tooltipData.y); + } + GlStateManager.disableLighting(); + tooltipsToRender.clear(); + GlStateManager.popMatrix(); + + } + + public static boolean mouseClick(int x, int y, int button) { + if (aeiGui.visible) { + for(Control control : aeiGui.controls) { + if (control.isHighlighted() && control.isEnabled() && control.onClick != null) { + if (focusedControl != null) + focusedControl.setFocused(false); + if (control instanceof IFocusable) { + focusedControl = (IFocusable) control; + ((IFocusable) control).setFocused(true); + } + return control.onClick.apply(button); + } + } + if (focusedControl != null) { + focusedControl.setFocused(false); + focusedControl = null; + } + } + if (overlayedGui instanceof RecipeGui) { + List controls = ((RecipeGui) overlayedGui).controls; + Optional ctrl = controls.stream().filter(Control::isHighlighted).filter(Control::isEnabled).findFirst(); + if (ctrl.isPresent()) { + try { + return ctrl.get().onClick.apply(button); + } catch (Exception e) { + } + } + } + return false; + } + + public static boolean keyDown(int typedChar, int keyCode, int unknown) { + boolean handled = false; + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.onKeyDown != null) { + handled = control.onKeyDown.accept(typedChar, keyCode, unknown); + } + if (control.charPressed != null) + if (typedChar == 256) { + ((IFocusable) control).setFocused(false); + focusedControl = null; + } + handled = true; + } + if (!handled) { + return KeyBindManager.processGuiKeybinds(typedChar); + } + return handled; + } + + public static boolean charInput(long num, int keyCode, int unknown) { + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.charPressed != null) { + int numChars = Character.charCount(keyCode); + if (num == numChars) + control.charPressed.accept((char) keyCode, unknown); + else { + char[] chars = Character.toChars(keyCode); + for(int x = 0; x < chars.length; x++) { + control.charPressed.accept(chars[x], unknown); + } + } + return true; + } + } + return false; + } + + public static boolean mouseScrolled(double direction) { + if (!aeiGui.visible) + return false; + if (direction > 0 && aeiGui.buttonLeft.isEnabled()) + aeiGui.buttonLeft.onClick.apply(0); + else if (direction < 0 && aeiGui.buttonRight.isEnabled()) + aeiGui.buttonRight.onClick.apply(0); + return true; + } + + private static class TooltipData { + + private final List text; + private final int x; + private final int y; + + public TooltipData(List text, int x, int y) { + this.text = text; + this.x = x; + this.y = y; + } + } + + public static void updateSearch() { + aeiGui.updateView(); + } + + public static void tick() { + if (aeiGui != null && Minecraft.getInstance().currentScreen == overlayedGui) + aeiGui.tick(); + } + + public static void recipeKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayRecipesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayRecipesFor(stack); + } + + } + + public static void useKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayUsesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayUsesFor(stack); + } + + } + + public static void hideKeybind() { + if (Minecraft.getInstance().currentScreen == overlayedGui && aeiGui != null) { + aeiGui.visible = !aeiGui.visible; + } + } +} diff --git a/src/main/java/me/shedaniel/gui/Drawable.java b/src/main/java/me/shedaniel/gui/Drawable.java new file mode 100755 index 000000000..8fffc17af --- /dev/null +++ b/src/main/java/me/shedaniel/gui/Drawable.java @@ -0,0 +1,33 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDrawable; +import me.shedaniel.gui.widget.Control; + +import java.awt.*; + +/** + * Created by James on 7/28/2018. + */ +public abstract class Drawable implements IDrawable { + protected Rectangle rect; + + public Drawable(int x, int y, int width, int height) { + rect = new Rectangle(x, y, width, height); + } + + public Drawable(Rectangle rect) { + this.rect = rect; + } + + public abstract void draw(); + + public boolean isHighlighted() { + Point mousePoint = AEIRenderHelper.getMouseLoc(); + if (rect.contains(mousePoint.x, mousePoint.y)) { + if (this instanceof Control) + AEIRenderHelper.aeiGui.setLastHovered((Control) this); + return true; + } + return false; + } +} diff --git a/src/main/java/me/shedaniel/gui/GuiItemList.java b/src/main/java/me/shedaniel/gui/GuiItemList.java new file mode 100755 index 000000000..80666f2cb --- /dev/null +++ b/src/main/java/me/shedaniel/gui/GuiItemList.java @@ -0,0 +1,264 @@ +package me.shedaniel.gui; + +import me.shedaniel.ClientListener; +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Button; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.TextBox; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.registry.IRegistry; +import net.minecraft.util.text.TextComponentTranslation; + +import java.awt.*; +import java.util.ArrayList; + +public class GuiItemList extends Drawable { + + public static final int FOOTERSIZE = 44; + private GuiContainer overlayedGui; + private static int page = 0; + private ArrayList displaySlots; + protected ArrayList controls; + private boolean needsResize = false; + Button buttonLeft; + Button buttonRight; + Button buttonCheating; + TextBox searchBox; + private ArrayList view; + private Control lastHovered; + protected boolean visible = true; + private int oldGuiLeft = 0; + private boolean cheatMode = false; + + public GuiItemList(GuiContainer overlayedGui) { + super(calculateRect(overlayedGui)); + displaySlots = new ArrayList<>(); + controls = new ArrayList<>(); + this.overlayedGui = overlayedGui; + view = new ArrayList<>(); + resize(); + } + + public boolean canCheat() { + EntityPlayer player = Minecraft.getInstance().player; + if (cheatMode) { + if (!player.hasPermissionLevel(1)) { + cheatClicked(0); + return false; + } + return true; + } + return false; + } + + private static Rectangle calculateRect(GuiContainer overlayedGui) { + MainWindow res = AEIRenderHelper.getResolution(); + int startX = (((IMixinGuiContainer) overlayedGui).getGuiLeft() + ((IMixinGuiContainer) overlayedGui).getXSize()) + 10; + int width = res.getScaledWidth() - startX; + return new Rectangle(startX, 0, width, res.getScaledHeight()); + } + + protected void resize() { + MainWindow res = AEIRenderHelper.getResolution(); + + if (overlayedGui != Minecraft.getInstance().currentScreen) { + if (Minecraft.getInstance().currentScreen instanceof GuiContainer) { + overlayedGui = (GuiContainer) Minecraft.getInstance().currentScreen; + + } else { + needsResize = true; + return; + } + } + oldGuiLeft = ((IMixinGuiContainer) overlayedGui).getGuiLeft(); + rect = calculateRect(overlayedGui); + page = 0; + buttonLeft = new Button(rect.x, rect.y + 3, 16, 20, "<"); + buttonLeft.onClick = this::btnLeftClicked; + buttonRight = new Button(rect.x + rect.width - 18, rect.y + 3, 16, 20, ">"); + buttonRight.onClick = this::btnRightClicked; + controls.clear(); + controls.add(buttonLeft); + controls.add(buttonRight); + String savedText = ""; + if (searchBox != null) { + savedText = searchBox.getText(); + } + searchBox = new TextBox(rect.x, rect.height - 31, rect.width - 4, 18); + searchBox.setText(savedText); + controls.add(searchBox); + buttonCheating = new Button(5, 5, 45, 20, getCheatModeText()); + buttonCheating.onClick = this::cheatClicked; + controls.add(buttonCheating); + calculateSlots(); + updateView(); + fillSlots(); + controls.addAll(displaySlots); + } + + private void fillSlots() { + page = MathHelper.clamp(page, 0, (int) Math.floor(view.size() / displaySlots.size())); + int firstSlot = page * displaySlots.size(); + for(int i = 0; i < displaySlots.size(); i++) { + if (firstSlot + i < view.size() && firstSlot + i >= 0) { + displaySlots.get(i).setStack(view.get(firstSlot + i)); + } else { + displaySlots.get(i).setStack(ItemStack.EMPTY); + } + } + } + + private void calculateSlots() { + int x = rect.x; + int y = rect.y + 20; + MainWindow res = AEIRenderHelper.getResolution(); + displaySlots.clear(); + int xOffset = 4; + int yOffset = 4; + while (true) { + AEISlot slot = new AEISlot(x + xOffset, y + yOffset); + slot.setCheatable(true); + xOffset += 18; + displaySlots.add(slot); + if (x + xOffset + 18 > res.getScaledWidth()) { + xOffset = 4; + yOffset += 18; + } + if (y + yOffset + 9 + FOOTERSIZE > rect.height) { + break; + } + } + } + + @Override + public void draw() { + if (!visible) + return; + if (needsResize == true) + resize(); + if (oldGuiLeft != ((IMixinGuiContainer) overlayedGui).getGuiLeft()) + resize(); + GlStateManager.pushMatrix(); + updateButtons(); + controls.forEach(Control::draw); + String header = String.format("%s/%s", page + 1, ((int) Math.floor(view.size() / displaySlots.size())) + 1); + Minecraft.getInstance().fontRenderer.drawStringWithShadow(header, rect.x + (rect.width / 2) - (Minecraft.getInstance().fontRenderer.getStringWidth(header) / 2), rect.y + 10, -1); + GlStateManager.popMatrix(); + } + + private void updateButtons() { + if (page == 0) + buttonLeft.setEnabled(false); + else + buttonLeft.setEnabled(true); + if (displaySlots.size() + displaySlots.size() * page >= view.size()) + buttonRight.setEnabled(false); + else + buttonRight.setEnabled(true); + } + + + public boolean btnRightClicked(int button) { + if (button == 0) { + page++; + fillSlots(); + return true; + } + return false; + } + + public boolean btnLeftClicked(int button) { + if (button == 0) { + page--; + fillSlots(); + return true; + } + return false; + } + + public boolean cheatClicked(int button) { + if (button == 0) { + cheatMode = !cheatMode; + + buttonCheating.setString(getCheatModeText()); + return true; + } + return false; + } + + private String getCheatModeText() { + if (cheatMode) { + TextComponentTranslation cheat = new TextComponentTranslation("text.aei.cheat", new Object[]{null}); + return cheat.getFormattedText(); + } + TextComponentTranslation noCheat = new TextComponentTranslation("text.aei.nocheat", new Object[]{null}); + return noCheat.getFormattedText(); + } + + protected void updateView() { + String searchText = searchBox.getText(); + String modText = null; + if (searchText.contains("@")) { + int nextBreak = searchText.indexOf(' ', searchText.indexOf('@')); + if (nextBreak == 0 || nextBreak == -1) + nextBreak = searchText.length(); + modText = searchText.substring(searchText.indexOf('@'), nextBreak); + searchText = searchText.replace(modText, "").trim(); + modText = modText.replace("@", "").toLowerCase(); + } + + view.clear(); + if (searchText.equals("") || searchText == null) { + for(ItemStack stack : ClientListener.stackList) { + if (modText != null) { + if (getMod(stack).contains(modText)) { + view.add(stack); + } + } else { + view.add(stack); + } + } + } else { + for(ItemStack stack : ClientListener.stackList) { + if (stack.getItem().getName().getString().toLowerCase().contains(searchText)) + if (modText != null) { + if (getMod(stack).contains(modText)) { + view.add(stack); + } + } else { + view.add(stack); + } + } + } + page = 0; + fillSlots(); + } + + public void tick() { + controls.forEach(f -> f.tick()); + } + + public void setLastHovered(Control ctrl) { + lastHovered = ctrl; + } + + public Control getLastHovered() { + return lastHovered; + } + + private String getMod(ItemStack stack) { + if (stack != null && !stack.isEmpty()) { + ResourceLocation location = IRegistry.ITEM.getKey(stack.getItem()); + return location.getNamespace(); + } + return ""; + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeContainer.java b/src/main/java/me/shedaniel/gui/RecipeContainer.java new file mode 100755 index 000000000..f8605a45c --- /dev/null +++ b/src/main/java/me/shedaniel/gui/RecipeContainer.java @@ -0,0 +1,13 @@ +package me.shedaniel.gui; + + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; + +public class RecipeContainer extends Container { + + @Override + public boolean canInteractWith(EntityPlayer entityPlayer) { + return true; + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java new file mode 100755 index 000000000..6cdd9542a --- /dev/null +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -0,0 +1,218 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.api.IRecipe; +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Button; +import me.shedaniel.gui.widget.Control; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.inventory.Container; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class RecipeGui extends GuiContainer { + private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private final MainWindow mainWindow; + private final Container container; + private final GuiScreen prevScreen; + private final Map> recipes; + private int guiWidth = 176; + private int guiHeight = 222; + ArrayList categories = new ArrayList<>(); + private int categoryPointer = 0; + private int recipePointer = 0; + private List slots; + private int cycleCounter = 0; + private int[] itemPointer; + List controls = new LinkedList<>(); + + public RecipeGui(Container p_i1072_1_, GuiScreen prevScreen, Map> recipes) { + super(new RecipeContainer()); + this.container = p_i1072_1_; + this.prevScreen = prevScreen; + this.recipes = recipes; + this.mc = Minecraft.getInstance(); + this.itemRender = mc.getItemRenderer(); + this.fontRenderer = mc.fontRenderer; + this.mainWindow = Minecraft.getInstance().mainWindow; + + setupCategories(); + } + + private void setupCategories() { + categories.addAll(recipes.keySet()); + updateRecipe(); + } + + + @Override + public void render(int mouseX, int mouseY, float partialTicks) { + super.render(mouseX, mouseY, partialTicks); + int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + drawCenteredString(this.fontRenderer, categories.get(categoryPointer).getDisplayName(), guiLeft + guiWidth / 2, y + 11, -1); + drawCenteredString(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), guiLeft + guiWidth / 2, y + 34, -1); + controls.forEach(Control::draw); + } + + private int getCurrentPage() { + return recipePointer / 2; + } + + @Override + public void tick() { + super.tick(); + slots.forEach(AEISlot::tick); + controls.forEach(Control::tick); + } + + + @Override + public void onResize(Minecraft p_onResize_1_, int p_onResize_2_, int p_onResize_3_) { + super.onResize(p_onResize_1_, p_onResize_2_, p_onResize_3_); + updateRecipe(); + } + + private void updateRecipe() { + IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer); + categories.get(categoryPointer).resetRecipes(); + categories.get(categoryPointer).addRecipe(recipe); + slots = categories.get(categoryPointer).setupDisplay(0); + if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + IRecipe recipe2 = recipes.get(categories.get(categoryPointer)).get(recipePointer + 1); + categories.get(categoryPointer).addRecipe(recipe2); + slots.addAll(categories.get(categoryPointer).setupDisplay(1)); + } + + guiLeft = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); + guiTop = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + + for(AEISlot slot : slots) { + slot.move(guiLeft, guiTop); + } + + Button btnCategoryLeft = new Button(guiLeft + 10, guiTop + 5, 15, 20, "<"); + Button btnCategoryRight = new Button(guiLeft + guiWidth - 25, guiTop + 5, 15, 20, ">"); + btnCategoryRight.onClick = this::btnCategoryRight; + btnCategoryLeft.onClick = this::btnCategoryLeft; + + Button btnRecipeLeft = new Button(guiLeft + 10, guiTop + 28, 15, 20, "<"); + Button btnRecipeRight = new Button(guiLeft + guiWidth - 25, guiTop + 28, 15, 20, ">"); + btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0); + btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages()); + btnRecipeRight.onClick = this::btnRecipeRight; + btnRecipeLeft.onClick = this::btnRecipeLeft; + + controls.clear(); + controls.add(btnCategoryLeft); + controls.add(btnCategoryRight); + if (categories.size() <= 2) { + btnCategoryLeft.setEnabled(false); + btnCategoryRight.setEnabled(false); + } + + controls.add(btnRecipeLeft); + controls.add(btnRecipeRight); + + itemPointer = new int[9]; + for(int i = 0; i < itemPointer.length; i++) { + itemPointer[i] = 0; + } + + List newControls = new LinkedList<>(); + categories.get(categoryPointer).addWidget(newControls, 0); + if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + categories.get(categoryPointer).addWidget(newControls, 1); + } + newControls.forEach(f -> f.move(guiLeft, guiTop)); + controls.addAll(newControls); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) { + drawDefaultBackground(); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + + int lvt_4_1_ = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); + int lvt_5_1_ = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + + this.drawTexturedModalRect(lvt_4_1_, lvt_5_1_, 0, 0, this.guiWidth, this.guiHeight); + slots.forEach(AEISlot::draw); + } + + + @Override + protected void initGui() { + super.initGui(); + } + + @Override + public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { + if (p_keyPressed_1_ == 259 && prevScreen != null && AEIRenderHelper.focusedControl == null) { + Minecraft.getInstance().displayGuiScreen(prevScreen); + return true; + } + + return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + } + + private boolean btnCategoryLeft(int button) { + recipePointer = 0; + categoryPointer--; + if (categoryPointer < 0) { + categoryPointer = categories.size() - 1; + } + updateRecipe(); + return true; + } + + private boolean btnCategoryRight(int button) { + recipePointer = 0; + categoryPointer++; + if (categoryPointer >= categories.size()) { + categoryPointer = 0; + } + updateRecipe(); + return true; + } + + private boolean btnRecipeLeft(int button) { + recipePointer -= 2; + if (recipePointer < 0) { + recipePointer = (getTotalPages() - 1) * 2; + } + updateRecipe(); + return true; + } + + private boolean btnRecipeRight(int button) { + recipePointer += 2; + if (recipePointer >= recipes.get(categories.get(categoryPointer)).size()) { + recipePointer = 0; + } + updateRecipe(); + return true; + } + + private int riseDoublesToInt(double i) { + return (int) (i + (i % 1 == 0 ? 0 : 1)); + } + + private int getTotalPages() { + return MathHelper.clamp(riseDoublesToInt(recipes.get(categories.get(categoryPointer)).size() / 2), 1, Integer.MAX_VALUE); + } +} diff --git a/src/main/java/me/shedaniel/gui/widget/AEISlot.java b/src/main/java/me/shedaniel/gui/widget/AEISlot.java new file mode 100755 index 000000000..bc3569699 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/AEISlot.java @@ -0,0 +1,181 @@ +package me.shedaniel.gui.widget; + +import com.google.common.collect.Lists; +import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import me.shedaniel.network.CheatPacket; +import me.shedaniel.network.DeletePacket; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; + +import java.awt.*; +import java.util.LinkedList; +import java.util.List; + +/** + * Created by James on 7/28/2018. + */ +public class AEISlot extends Control { + private static final ResourceLocation RECIPE_GUI = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private boolean cheatable = false; + private List itemList = new LinkedList<>(); + private int itemListPointer = 0; + private long displayCounter = 0; + + public boolean isDrawBackground() { + return drawBackground; + } + + private String extraTooltip; + + + @Override + public void tick() { + if (itemList.size() > 1) { + displayCounter++; + if (displayCounter % 10 == 0) + if (itemListPointer + 1 >= itemList.size()) + itemListPointer = 0; + else itemListPointer++; + } + } + + public void setStackList(List newItemList) { + itemList = newItemList; + itemListPointer = 0; + displayCounter = 0; + } + + public void setExtraTooltip(String toolTip) { + extraTooltip = toolTip; + } + + public void setDrawBackground(boolean drawBackground) { + this.drawBackground = drawBackground; + } + + private boolean drawBackground = false; + private Point backgroundUV = new Point(0, 222); + + public AEISlot(int x, int y) { + super(x, y, 18, 18); + this.onClick = this::onClick; + } + + public ItemStack getStack() { + if (itemList.isEmpty()) { + return ItemStack.EMPTY; + } + return itemList.get(itemListPointer); + } + + public void setStack(ItemStack stack) { + itemList.clear(); + if (stack != null) + itemList.add(stack); + itemListPointer = 0; + } + + @Override + public void draw() { + if (drawBackground) { + Minecraft.getInstance().getTextureManager().bindTexture(RECIPE_GUI); + drawTexturedModalRect(rect.x - 1, rect.y - 1, backgroundUV.x, backgroundUV.y, rect.width, rect.height); + } + if (getStack().isEmpty()) + return; + RenderHelper.enableGUIStandardItemLighting(); + + drawStack(rect.x, rect.y); + if (isHighlighted()) + drawTooltip(); + } + + private void drawTooltip() { + List toolTip = getTooltip(); + toolTip.add("ยง9" + getMod()); + Point mouse = AEIRenderHelper.getMouseLoc(); + AEIRenderHelper.addToolTip(toolTip, mouse.x, mouse.y); + } + + private boolean onClick(int button) { + EntityPlayer player = Minecraft.getInstance().player; + if (AEIRenderHelper.aeiGui.canCheat() && !(player.inventory.getItemStack().isEmpty())) { + //Delete the itemstack. + Minecraft.getInstance().getConnection().sendPacket(new DeletePacket()); + return true; + } + if (!player.inventory.getItemStack().isEmpty()) { + return false; + } + + if (AEIRenderHelper.aeiGui.canCheat() && this.cheatable) { + if (getStack() != null && !getStack().isEmpty()) { + ItemStack cheatedStack = getStack().copy(); + if (button == 0) + cheatedStack.setCount(1); + if (button == 1) { + cheatedStack.setCount(cheatedStack.getMaxStackSize()); + } + Minecraft.getInstance().getConnection().sendPacket(new CheatPacket(cheatedStack)); + return true; + } + } else { + AEIRenderHelper.recipeKeybind(); + } + return false; + } + + + private void drawStack(int x, int y) { + GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + AEIRenderHelper.getItemRender().zLevel = 200.0F; + AEIRenderHelper.getItemRender().renderItemAndEffectIntoGUI(getStack(), x, y); + assert gui != null; + if (((IMixinGuiContainer) gui).getDraggedStack().isEmpty()) + AEIRenderHelper.getItemRender().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, getStack(), x, y - 0, ""); + else + AEIRenderHelper.getItemRender().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, getStack(), x, y - 8, ""); + AEIRenderHelper.getItemRender().zLevel = 0.0F; + } + + public String getMod() { + if (!getStack().isEmpty()) { + ResourceLocation location = IRegistry.ITEM.getKey(getStack().getItem()); + assert location != null; + return location.getNamespace(); + } + return ""; + } + + private List getTooltip() { + Minecraft mc = Minecraft.getInstance(); + GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + List toolTip = Lists.newArrayList(); + if (gui != null) { + toolTip = gui.getItemToolTip(getStack()); + } else { + toolTip.add(getStack().getDisplayName().getFormattedText()); + } + if (extraTooltip != null) { + toolTip.add(extraTooltip); + } + + return toolTip; + } + + public boolean isCheatable() { + return cheatable; + } + + public void setCheatable(boolean cheatable) { + this.cheatable = cheatable; + } + + +} diff --git a/src/main/java/me/shedaniel/gui/widget/Button.java b/src/main/java/me/shedaniel/gui/widget/Button.java new file mode 100755 index 000000000..3cb68a2ba --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/Button.java @@ -0,0 +1,72 @@ +package me.shedaniel.gui.widget; + +import me.shedaniel.gui.AEIRenderHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; + +import java.awt.*; + +/** + * Created by James on 7/29/2018. + */ +public class Button extends Control { + private String buttonText; + protected static final ResourceLocation BUTTON_TEXTURES = new ResourceLocation("textures/gui/widgets.png"); + + + public Button(int x, int y, int width, int height, String buttonText) { + super(x, y, width, height); + this.buttonText = buttonText; + } + + public Button(Rectangle rect, String buttonText) { + super(rect); + this.buttonText = buttonText; + } + + public void setString(String text) { + buttonText = text; + } + + + @Override + public void draw() { + GlStateManager.pushMatrix(); + GlStateManager.disableLighting(); + GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + Minecraft lvt_4_1_ = Minecraft.getInstance(); + FontRenderer lvt_5_1_ = lvt_4_1_.fontRenderer; + lvt_4_1_.getTextureManager().bindTexture(BUTTON_TEXTURES); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + int hoverState = (byte) 0; + if (this.isEnabled()) { + if (!this.isHighlighted()) + hoverState = (byte) 1; + else + hoverState = (byte) 2; + } + + GlStateManager.enableBlend(); + GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + gui.drawTexturedModalRect(rect.x, rect.y, 0, 46 + hoverState * 20, rect.width / 2, rect.height); + gui.drawTexturedModalRect(rect.x + rect.width / 2, rect.y, 200 - rect.width / 2, 46 + hoverState * 20, rect.width / 2, rect.height); + //this.mouseDragged(lvt_4_1_, p_194828_1_, p_194828_2_); + int lvt_7_1_ = 14737632; +// if(!this.enabled) { +// lvt_7_1_ = 10526880; +// } else if(this.hovered) { +// lvt_7_1_ = 16777120; +// } + + + gui.drawCenteredString(lvt_5_1_, this.buttonText, rect.x + rect.width / 2, rect.y + (rec