From de97f55968d183cc7d76aad87e3b27d382bfdbc9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 31 May 2020 01:59:47 +1000 Subject: 1.5 --- .gitignore | 22 + build.gradle | 121 ++ gradle.properties | 1 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 52271 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++ gradlew.bat | 90 ++ .../notenoughupdates/AllowEmptyHTMLTag.java | 74 + .../notenoughupdates/CustomRenderItem.java | 167 ++ .../moulberry/notenoughupdates/GuiItemRecipe.java | 80 + .../moulberry/notenoughupdates/GuiItemUsages.java | 165 ++ .../moulberry/notenoughupdates/GuiTextures.java | 47 + .../github/moulberry/notenoughupdates/NEUIO.java | 100 ++ .../moulberry/notenoughupdates/NEUManager.java | 1119 +++++++++++++ .../moulberry/notenoughupdates/NEUOverlay.java | 1704 ++++++++++++++++++++ .../notenoughupdates/NotEnoughUpdates.java | 584 +++++++ .../notenoughupdates/RequestFocusListener.java | 63 + .../github/moulberry/notenoughupdates/Utils.java | 431 +++++ .../notenoughupdates/infopanes/DevInfoPane.java | 106 ++ .../infopanes/FlipperInfoPane.java | 111 ++ .../notenoughupdates/infopanes/HTMLInfoPane.java | 316 ++++ .../notenoughupdates/infopanes/InfoPane.java | 44 + .../notenoughupdates/infopanes/QOLInfoPane.java | 344 ++++ .../infopanes/ScrollableInfoPane.java | 34 + .../infopanes/SettingsInfoPane.java | 259 +++ .../notenoughupdates/infopanes/TextInfoPane.java | 61 + .../notenoughupdates/itemeditor/GuiElement.java | 15 + .../itemeditor/GuiElementButton.java | 35 + .../itemeditor/GuiElementText.java | 42 + .../itemeditor/GuiElementTextField.java | 453 ++++++ .../notenoughupdates/itemeditor/NEUItemEditor.java | 429 +++++ .../notenoughupdates/mixins/MixinItemStack.java | 20 + .../notenoughupdates/options/Options.java | 203 +++ .../notenoughupdates/util/HTMLParagraphView.java | 30 + .../notenoughupdates/util/HtmlImageGenerator.java | 125 ++ .../notenoughupdates/util/HypixelApi.java | 68 + .../notenoughupdates/util/LargeHTMLEditorKit.java | 132 ++ .../notenoughupdates/util/LerpingFloat.java | 68 + .../notenoughupdates/util/LerpingInteger.java | 68 + .../util/SynchronousHTMLEditorKit.java | 36 + .../moulberry/notenoughupdates/util/TexLoc.java | 50 + .../assets/notenoughupdates/ascending_overlay.png | Bin 0 -> 1497 bytes .../resources/assets/notenoughupdates/close.png | Bin 0 -> 2350 bytes .../assets/notenoughupdates/descending_overlay.png | Bin 0 -> 1513 bytes .../resources/assets/notenoughupdates/help.png | Bin 0 -> 3500 bytes .../assets/notenoughupdates/item_edit.png | Bin 0 -> 11387 bytes .../assets/notenoughupdates/item_mask.png | Bin 0 -> 856 bytes .../notenoughupdates/item_pane_tab_arrow.png | Bin 0 -> 7532 bytes .../resources/assets/notenoughupdates/logo.png | Bin 0 -> 21782 bytes .../resources/assets/notenoughupdates/logo_bg.png | Bin 0 -> 21390 bytes .../resources/assets/notenoughupdates/logo_fg.png | Bin 0 -> 5823 bytes .../resources/assets/notenoughupdates/next.png | Bin 0 -> 3912 bytes .../resources/assets/notenoughupdates/next.xcf | Bin 0 -> 8805 bytes src/main/resources/assets/notenoughupdates/off.png | Bin 0 -> 1302 bytes src/main/resources/assets/notenoughupdates/on.png | Bin 0 -> 1311 bytes .../assets/notenoughupdates/order_alphabetical.png | Bin 0 -> 1862 bytes .../notenoughupdates/order_alphabetical_active.png | Bin 0 -> 1819 bytes .../assets/notenoughupdates/order_rarity.png | Bin 0 -> 1808 bytes .../notenoughupdates/order_rarity_active.png | Bin 0 -> 1953 bytes .../resources/assets/notenoughupdates/prev.png | Bin 0 -> 4508 bytes .../resources/assets/notenoughupdates/prev.xcf | Bin 0 -> 8371 bytes .../assets/notenoughupdates/prev_unhovered.png | Bin 0 -> 4553 bytes .../assets/notenoughupdates/rightarrow.png | Bin 0 -> 1212 bytes .../assets/notenoughupdates/rightarrow_overlay.png | Bin 0 -> 1112 bytes .../resources/assets/notenoughupdates/settings.png | Bin 0 -> 3962 bytes .../assets/notenoughupdates/sort_accessory.png | Bin 0 -> 1885 bytes .../notenoughupdates/sort_accessory_active.png | Bin 0 -> 1871 bytes .../resources/assets/notenoughupdates/sort_all.png | Bin 0 -> 1817 bytes .../assets/notenoughupdates/sort_all_active.png | Bin 0 -> 1850 bytes .../assets/notenoughupdates/sort_armor.png | Bin 0 -> 1792 bytes .../assets/notenoughupdates/sort_armor_active.png | Bin 0 -> 1921 bytes .../resources/assets/notenoughupdates/sort_mob.png | Bin 0 -> 1800 bytes .../assets/notenoughupdates/sort_mob_active.png | Bin 0 -> 1815 bytes .../resources/assets/notenoughupdates/sort_pet.png | Bin 0 -> 1902 bytes .../assets/notenoughupdates/sort_pet_active.png | Bin 0 -> 1932 bytes .../assets/notenoughupdates/sort_weapon.png | Bin 0 -> 749 bytes .../assets/notenoughupdates/sort_weapon_active.png | Bin 0 -> 1869 bytes .../assets/notenoughupdates/wkhtmltox.zip | Bin 0 -> 31902481 bytes src/main/resources/mcmod.info | 16 + src/main/resources/mixins.notenoughupdates.json | 8 + 80 files changed, 8011 insertions(+) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/RequestFocusListener.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/Utils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/QOLInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/ScrollableInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/TextInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElement.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementButton.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementText.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/Options.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/HTMLParagraphView.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/HtmlImageGenerator.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/LargeHTMLEditorKit.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/LerpingFloat.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/LerpingInteger.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/SynchronousHTMLEditorKit.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/TexLoc.java create mode 100644 src/main/resources/assets/notenoughupdates/ascending_overlay.png create mode 100644 src/main/resources/assets/notenoughupdates/close.png create mode 100644 src/main/resources/assets/notenoughupdates/descending_overlay.png create mode 100644 src/main/resources/assets/notenoughupdates/help.png create mode 100644 src/main/resources/assets/notenoughupdates/item_edit.png create mode 100644 src/main/resources/assets/notenoughupdates/item_mask.png create mode 100644 src/main/resources/assets/notenoughupdates/item_pane_tab_arrow.png create mode 100644 src/main/resources/assets/notenoughupdates/logo.png create mode 100644 src/main/resources/assets/notenoughupdates/logo_bg.png create mode 100644 src/main/resources/assets/notenoughupdates/logo_fg.png create mode 100644 src/main/resources/assets/notenoughupdates/next.png create mode 100644 src/main/resources/assets/notenoughupdates/next.xcf create mode 100644 src/main/resources/assets/notenoughupdates/off.png create mode 100644 src/main/resources/assets/notenoughupdates/on.png create mode 100644 src/main/resources/assets/notenoughupdates/order_alphabetical.png create mode 100644 src/main/resources/assets/notenoughupdates/order_alphabetical_active.png create mode 100644 src/main/resources/assets/notenoughupdates/order_rarity.png create mode 100644 src/main/resources/assets/notenoughupdates/order_rarity_active.png create mode 100644 src/main/resources/assets/notenoughupdates/prev.png create mode 100644 src/main/resources/assets/notenoughupdates/prev.xcf create mode 100644 src/main/resources/assets/notenoughupdates/prev_unhovered.png create mode 100644 src/main/resources/assets/notenoughupdates/rightarrow.png create mode 100644 src/main/resources/assets/notenoughupdates/rightarrow_overlay.png create mode 100644 src/main/resources/assets/notenoughupdates/settings.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_accessory.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_accessory_active.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_all.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_all_active.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_armor.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_armor_active.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_mob.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_mob_active.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_pet.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_pet_active.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_weapon.png create mode 100644 src/main/resources/assets/notenoughupdates/sort_weapon_active.png create mode 100644 src/main/resources/assets/notenoughupdates/wkhtmltox.zip create mode 100644 src/main/resources/mcmod.info create mode 100644 src/main/resources/mixins.notenoughupdates.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2c770e09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# eclipse +bin +*.launch +.settings +.metadata +.classpath +.project + +# idea +out +*.ipr +*.iws +*.iml +.idea + +# gradle +build +.gradle + +# other +eclipse +run diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..29128fba --- /dev/null +++ b/build.gradle @@ -0,0 +1,121 @@ +buildscript { + repositories { + jcenter() + maven { url = "https://files.minecraftforge.net/maven" } + maven { url = "https://repo.spongepowered.org/maven" } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' + classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' + classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4' + } +} + +apply plugin: 'java' +apply plugin: 'net.minecraftforge.gradle.forge' +apply plugin: 'org.spongepowered.mixin' +apply plugin: 'com.github.johnrengelman.shadow' + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +version = "1.0" +group= "io.github.moulberry" +archivesBaseName = "NotEnoughUpdates" +String modid = "notenoughupdates" +String mixinClassifier = "dep" + +minecraft { + version = "1.8.9-11.15.1.2318-1.8.9" + runDir = "run" + mappings = "stable_20" +} + +repositories { + jcenter() + maven { url 'https://repo.spongepowered.org/maven/' } +} + +dependencies { + compile('org.spongepowered:mixin:0.7.11-SNAPSHOT') + compile('org.kohsuke:github-api:1.108') + compile('com.fasterxml.jackson.core:jackson-core:2.10.2') + compile('info.bliki.wiki:bliki-core:3.1.0') +} + +mixin { + add sourceSets.main, "mixins.${modid}.refmap.json" +} + +jar { + manifest.attributes( + 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker', + 'MixinConfigs': "mixins.${modid}.json", + 'FMLCorePluginContainsFMLMod': true, + "ForceLoadAsMod": true + ) +} + +shadowJar { + dependencies { + include(dependency('org.kohsuke:github-api:1.108')) + include(dependency('org.spongepowered:mixin:0.7.11-SNAPSHOT')) + + include(dependency('commons-io:commons-io')) + include(dependency('org.apache.commons:commons-lang3')) + include(dependency('com.fasterxml.jackson.core:jackson-databind:2.10.2')) + include(dependency('com.fasterxml.jackson.core:jackson-annotations:2.10.2')) + include(dependency('com.fasterxml.jackson.core:jackson-core:2.10.2')) + + include(dependency('info.bliki.wiki:bliki-core:3.1.0')) + include(dependency('org.slf4j:slf4j-api:1.7.18')) + include(dependency('org.luaj:luaj-jse:3.0.1')) + } + + relocate 'com.fasterxml.jackson', 'neu.com.fasterxml.jackson' + relocate 'org.slf4j', 'neu.org.slf4j' + + exclude 'module-info.class' + exclude 'dummyThing' + exclude 'LICENSE.txt' + + classifier = mixinClassifier +} + +reobf { + shadowJar { + mappingType = 'SEARGE' + } +} + + +task runClientFix { + doLast { + String fileName = "${archivesBaseName}-${version}-${mixinClassifier}.jar" + ant.move file: "${buildDir}/libs/${fileName}", tofile: "${projectDir}/run/mods/${fileName}" + ant.delete file: "${buildDir}/libs/${archivesBaseName}-${version}.jar" + } +} + +runClient { + standardInput = System.in +} + +build.dependsOn(shadowJar) +runClient.dependsOn(build) +runClient.dependsOn(runClientFix) + +processResources +{ + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version':project.version, 'mcversion':project.minecraft.version + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..4687f10d --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx2G diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..30d399d8 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 00000000..671daab2 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Sep 14 12:28:28 PDT 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 00000000..91a7e269 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# 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 +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# 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\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +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" ] ; 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"` + + # 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 + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..8a0b282a --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@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 + +@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= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@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 Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_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=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +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/src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java b/src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java new file mode 100644 index 00000000..3cf5ef31 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java @@ -0,0 +1,74 @@ +package io.github.moulberry.notenoughupdates; + +import info.bliki.htmlcleaner.TagNode; +import info.bliki.wiki.filter.ITextConverter; +import info.bliki.wiki.model.IWikiModel; +import info.bliki.wiki.tags.HTMLTag; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class AllowEmptyHTMLTag extends HTMLTag { + public AllowEmptyHTMLTag(String name) { + super(name); + } + + public void renderHTML(ITextConverter converter, Appendable buf, IWikiModel model) throws IOException { + boolean newLinesAfterTag = false; + boolean newLinesAfterChildren = false; + TagNode node = this; + String name = node.getName(); + List children = node.getChildren(); + + if (NEW_LINES) { + switch (name) { + case "div": + case "p": + case "li": + case "td": + buf.append('\n'); + break; + case "table": + case "ul": + case "ol": + case "th": + case "tr": + buf.append('\n'); + newLinesAfterTag = true; + newLinesAfterChildren = true; + break; + case "pre": + buf.append('\n'); + newLinesAfterTag = false; + newLinesAfterChildren = true; + break; + case "blockquote": + newLinesAfterChildren = true; + break; + } + } + buf.append('<'); + buf.append(name); + + Map tagAtttributes = node.getAttributes(); + + appendAttributes(buf, tagAtttributes); + + if (children.size() == 0) { + buf.append(" />"); + } else { + buf.append('>'); + if (newLinesAfterTag) { + buf.append('\n'); + } + converter.nodesToText(children, buf, model); + if (newLinesAfterChildren) { + buf.append('\n'); + } + buf.append("'); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java new file mode 100644 index 00000000..bf194e33 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java @@ -0,0 +1,167 @@ +package io.github.moulberry.notenoughupdates; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Vec3i; + +import java.lang.reflect.Method; +import java.util.List; + +public class CustomRenderItem { + + public static void renderItemIntoGUI(RenderItem renderItem, ItemStack stack, int x, int y, boolean effect) { + IBakedModel ibakedmodel = renderItem.getItemModelMesher().getItemModel(stack); + GlStateManager.pushMatrix(); + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false, false); + GlStateManager.enableRescaleNormal(); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(516, 0.1F); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + setupGuiTransform(x, y, ibakedmodel.isGui3d()); + ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel, ItemCameraTransforms.TransformType.GUI); + renderItem(renderItem, stack, ibakedmodel, effect); + GlStateManager.disableAlpha(); + GlStateManager.disableRescaleNormal(); + GlStateManager.disableLighting(); + GlStateManager.popMatrix(); + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap(); + } + + private static void setupGuiTransform(int xPosition, int yPosition, boolean isGui3d) { + GlStateManager.translate((float)xPosition, (float)yPosition, 0); + GlStateManager.translate(8.0F, 8.0F, 0.0F); + GlStateManager.scale(1.0F, 1.0F, -1.0F); + GlStateManager.scale(0.5F, 0.5F, 0.5F); + + if (isGui3d) { + GlStateManager.scale(40.0F, 40.0F, 40.0F); + GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.enableLighting(); + } else { + GlStateManager.scale(64.0F, 64.0F, 64.0F); + GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.disableLighting(); + } + } + + public static void renderItem(RenderItem renderItem, ItemStack stack, IBakedModel model, boolean effect) { + if (stack != null) { + GlStateManager.pushMatrix(); + GlStateManager.scale(0.5F, 0.5F, 0.5F); + + if (model.isBuiltInRenderer()) { + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.translate(-0.5F, -0.5F, -0.5F); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.enableRescaleNormal(); + TileEntityItemStackRenderer.instance.renderByItem(stack); + } else { + GlStateManager.translate(-0.5F, -0.5F, -0.5F); + Class[] paramsRM = new Class[]{IBakedModel.class, ItemStack.class}; + Method renderModelMethod = Utils.getMethod(RenderItem.class, paramsRM, + "renderModel", "func_175036_a"); + if(renderModelMethod != null) { + renderModelMethod.setAccessible(true); + try { + renderModelMethod.invoke(renderItem, model, stack); + } catch(Exception e) {} + } + + if (stack.hasEffect() && effect) { + Class[] paramsRE = new Class[]{IBakedModel.class}; + Method renderEffectMethod = Utils.getMethod(RenderItem.class, paramsRE, + "renderEffect", "func_180451_a"); + if(renderEffectMethod != null) { + renderEffectMethod.setAccessible(true); + try { + renderEffectMethod.invoke(renderItem, model); + } catch(Exception e) {} + } + } + } + + GlStateManager.popMatrix(); + } + } + + /*private static void renderModel(IBakedModel model, ItemStack stack) + { + renderModel(model, -1, stack); + } + + private static void renderModel(IBakedModel model, int color) + { + renderModel(model, color, (ItemStack)null); + } + + private static void renderModel(IBakedModel model, int color, ItemStack stack) + { + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.ITEM); + + for (EnumFacing enumfacing : EnumFacing.values()) + { + renderQuads(worldrenderer, model.getFaceQuads(enumfacing), color, stack); + } + + renderQuads(worldrenderer, model.getGeneralQuads(), color, stack); + tessellator.draw(); + } + + private static void putQuadNormal(WorldRenderer renderer, BakedQuad quad) + { + Vec3i vec3i = quad.getFace().getDirectionVec(); + renderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ()); + } + + private static void renderQuad(WorldRenderer renderer, BakedQuad quad, int color) + { + renderer.addVertexData(quad.getVertexData()); + renderer.putColor4(color); + putQuadNormal(renderer, quad); + } + + private static void renderQuads(WorldRenderer renderer, List quads, int color, ItemStack stack) + { + boolean flag = color == -1 && stack != null; + int i = 0; + + for (int j = quads.size(); i < j; ++i) + { + BakedQuad bakedquad = (BakedQuad)quads.get(i); + int k = color; + + if (flag && bakedquad.hasTintIndex()) + { + k = stack.getItem().getColorFromItemStack(stack, bakedquad.getTintIndex()); + + if (EntityRenderer.anaglyphEnable) + { + k = TextureUtil.anaglyphColor(k); + } + + k = k | -16777216; + } + + net.minecraftforge.client.model.pipeline.LightUtil.renderQuadColor(renderer, bakedquad, k); + } + }*/ + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java new file mode 100644 index 00000000..6916372b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java @@ -0,0 +1,80 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.gson.JsonObject; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiCrafting; +import net.minecraft.client.resources.I18n; +import net.minecraft.inventory.ContainerWorkbench; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class GuiItemRecipe extends GuiCrafting { + + private ItemStack[] craftMatrix; + private String text; + private String craftText = ""; + private NEUManager manager; + + public GuiItemRecipe(ItemStack[] craftMatrix, JsonObject result, String text, NEUManager manager) { + super(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld); + this.craftMatrix = craftMatrix; + this.text = text; + this.manager = manager; + + ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; + for(int i=0; i= 1 && slotId <= 9) { + click = craftMatrix[slotId-1]; + } else if(slotId == 0) { + ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; + click = cw.craftResult.getStackInSlot(0); + } + if(click != null) { + if(clickedButton == 0) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(click), ""); + } else if(clickedButton == 1) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(click), ""); + } + } + } + + /*public void handleMouseInput() throws IOException { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int height = scaledresolution.getScaledHeight(); + + int mouseX = Mouse.getX() / scaledresolution.getScaleFactor(); + int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor(); + if(mouseY > this.guiTop + this.ySize - 94 || mouseY < this.guiTop || + mouseX < this.guiLeft || mouseX > this.guiLeft+this.xSize) { + //Potentially allow mouse input in the future. For now this is still broken. + //super.handleMouseInput(); + } + }*/ + + public void onCraftMatrixChanged(IInventory inventoryIn){} +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java new file mode 100644 index 00000000..ceb4e5d4 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java @@ -0,0 +1,165 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.util.TexLoc; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiCrafting; +import net.minecraft.client.resources.I18n; +import net.minecraft.inventory.ContainerWorkbench; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.io.IOException; +import java.util.List; + +public class GuiItemUsages extends GuiCrafting { + private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); + + private List craftMatrices; + private List results; + private int currentIndex = 0; + + private String text; + private String craftText = ""; + private String collectionText = ""; + private NEUManager manager; + + private TexLoc left = new TexLoc(0, 0, Keyboard.KEY_N); + private TexLoc right = new TexLoc(0, 0, Keyboard.KEY_M); + + public GuiItemUsages(List craftMatrices, List results, String text, NEUManager manager) { + super(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld); + + this.craftMatrices = craftMatrices; + this.results = results; + this.text = text; + this.manager = manager; + + setIndex(0); + } + + private void setIndex(int index) { + if(index < 0 || index >= craftMatrices.size()) { + return; + } else { + currentIndex = index; + + ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; + for(int i=0; i + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + leftSelected = true; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + rightSelected = true; + } + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); + //Left arrow + Utils.drawTexturedRect(110, 63, 7, 11, 34/256f, 48/256f, + 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); + //Right arrow + Utils.drawTexturedRect(147, 63, 7, 11, 10/256f, 24/256f, + 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + + String str = (currentIndex+1)+"/"+craftMatrices.size(); + Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, 132, 69, + false, 24, Color.BLACK.getRGB()); + + + Utils.drawStringCenteredScaledMaxWidth(craftText, fontRendererObj, 132, 25, + false, 75, 4210752); + + + Utils.drawStringScaledMaxWidth(t, fontRendererObj, 28, 6, t.contains("\u00a7"), xSize-38, 4210752); + this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); + } + + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + } + + @Override + public void handleKeyboardInput() throws IOException { + super.handleKeyboardInput(); //TODO: r and u + left.handleKeyboardInput(); + right.handleKeyboardInput(); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; + + int buttonWidth = 7; + int buttonHeight = 11; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + setIndex(currentIndex-1); + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + setIndex(currentIndex+1); + } + } + } + + protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { + ItemStack click = null; + if(slotId >= 1 && slotId <= 9) { + click = craftMatrices.get(currentIndex)[slotId-1]; + } else if(slotId == 0) { + ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; + click = cw.craftResult.getStackInSlot(0); + } + if(click != null) { + if(clickedButton == 0) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(click), ""); + } else if(clickedButton == 1) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(click), ""); + } + } + } + + /*public void handleMouseInput() throws IOException { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int height = scaledresolution.getScaledHeight(); + + int mouseX = Mouse.getX() / scaledresolution.getScaleFactor(); + int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor(); + if(mouseY > this.guiTop + this.ySize - 94 || mouseY < this.guiTop || + mouseX < this.guiLeft || mouseX > this.guiLeft+this.xSize) { + //Potentially allow mouse input in the future. For now this is still broken. + //super.handleMouseInput(); + } + }*/ + + public void onCraftMatrixChanged(IInventory inventoryIn){} +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java new file mode 100644 index 00000000..48db19a5 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java @@ -0,0 +1,47 @@ +package io.github.moulberry.notenoughupdates; + +import net.minecraft.util.ResourceLocation; + +public class GuiTextures { + + private GuiTextures() {} //Not instantiable. Use import static to access class members. + + public static final ResourceLocation itemPaneTabArrow = new ResourceLocation("notenoughupdates:item_pane_tab_arrow.png"); + //public static final ResourceLocation prev = new ResourceLocation("notenoughupdates:prev.png"); + //public static final ResourceLocation next = new ResourceLocation("notenoughupdates:next.png"); + public static final ResourceLocation rightarrow_overlay = new ResourceLocation("notenoughupdates:rightarrow_overlay.png"); + public static final ResourceLocation rightarrow = new ResourceLocation("notenoughupdates:rightarrow.png"); + public static final ResourceLocation item_edit = new ResourceLocation("notenoughupdates:item_edit.png"); + public static final ResourceLocation close = new ResourceLocation("notenoughupdates:close.png"); + public static final ResourceLocation settings = new ResourceLocation("notenoughupdates:settings.png"); + public static final ResourceLocation off = new ResourceLocation("notenoughupdates:off.png"); + public static final ResourceLocation on = new ResourceLocation("notenoughupdates:on.png"); + public static final ResourceLocation help = new ResourceLocation("notenoughupdates:help.png"); + + public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); + + public static final ResourceLocation logo = new ResourceLocation("notenoughupdates:logo.png"); + public static final ResourceLocation logo_fg = new ResourceLocation("notenoughupdates:logo_fg.png"); + public static final ResourceLocation logo_bg = new ResourceLocation("notenoughupdates:logo_bg.png"); + + public static final ResourceLocation sort_all = new ResourceLocation("notenoughupdates:sort_all.png"); + public static final ResourceLocation sort_mob = new ResourceLocation("notenoughupdates:sort_mob.png"); + public static final ResourceLocation sort_pet = new ResourceLocation("notenoughupdates:sort_pet.png"); + public static final ResourceLocation sort_tool = new ResourceLocation("notenoughupdates:sort_weapon.png"); + public static final ResourceLocation sort_armor = new ResourceLocation("notenoughupdates:sort_armor.png"); + public static final ResourceLocation sort_accessory = new ResourceLocation("notenoughupdates:sort_accessory.png"); + public static final ResourceLocation sort_all_active = new ResourceLocation("notenoughupdates:sort_all_active.png"); + public static final ResourceLocation sort_mob_active = new ResourceLocation("notenoughupdates:sort_mob_active.png"); + public static final ResourceLocation sort_pet_active = new ResourceLocation("notenoughupdates:sort_pet_active.png"); + public static final ResourceLocation sort_tool_active = new ResourceLocation("notenoughupdates:sort_weapon_active.png"); + public static final ResourceLocation sort_armor_active = new ResourceLocation("notenoughupdates:sort_armor_active.png"); + public static final ResourceLocation sort_accessory_active = new ResourceLocation("notenoughupdates:sort_accessory_active.png"); + + public static final ResourceLocation order_alphabetical = new ResourceLocation("notenoughupdates:order_alphabetical.png"); + public static final ResourceLocation order_rarity = new ResourceLocation("notenoughupdates:order_rarity.png"); + public static final ResourceLocation order_alphabetical_active = new ResourceLocation("notenoughupdates:order_alphabetical_active.png"); + public static final ResourceLocation order_rarity_active = new ResourceLocation("notenoughupdates:order_rarity_active.png"); + public static final ResourceLocation ascending_overlay = new ResourceLocation("notenoughupdates:ascending_overlay.png"); + public static final ResourceLocation descending_overlay = new ResourceLocation("notenoughupdates:descending_overlay.png"); + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java new file mode 100644 index 00000000..a89bd1dc --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java @@ -0,0 +1,100 @@ +package io.github.moulberry.notenoughupdates; + +import org.kohsuke.github.*; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class NEUIO { + + private final String accessToken; + + public NEUIO(String accessToken) { + this.accessToken = accessToken; + } + + /** + * Creates a new branch, commits to it with a single file change and submits a pull request from the new branch + * back to the master branch. + */ + public boolean createNewRequest(String newBranchName, String prTitle, String prBody, String filename, String content) { + try { + GitHub github = new GitHubBuilder().withOAuthToken(accessToken).build(); + System.out.println("Getting repo"); + + //https://github.com/Moulberry/NotEnoughUpdates-REPO + GHRepository repo = github.getRepositoryById("247692460"); + + System.out.println("Getting last commit"); + String lastCommitSha = repo.getRef("heads/master").getObject().getSha(); + System.out.println("Last master commit sha: " + lastCommitSha); + + String lastTreeSha = repo.getCommit(lastCommitSha).getTree().getSha(); + + GHTreeBuilder tb = repo.createTree(); + tb.baseTree(lastTreeSha); + tb.add(filename, content, false); + GHTree tree = tb.create(); + System.out.println("Created new tree: " + tree.getSha()); + + GHCommitBuilder cb = repo.createCommit(); + cb.message(prTitle); + cb.tree(tree.getSha()); + cb.parent(lastCommitSha); + GHCommit commit = cb.create(); + System.out.println("Created commit: " + commit.getSHA1()); + + repo.createRef("refs/heads/"+newBranchName, commit.getSHA1()); + System.out.println("Set new branch head to commit."); + + repo.createPullRequest(prTitle, newBranchName, "master", prBody); + return true; + } catch(IOException e) { + e.printStackTrace(); + return false; + } + } + + /** + * @param oldShas Map from filename (eg. BOW.json) to the sha in the local repository + * @return Map from filename to the new shas + */ + public Map getChangedItems(Map oldShas) { + HashMap changedFiles = new HashMap<>(); + try { + GitHub github = new GitHubBuilder().withOAuthToken(accessToken).build(); + GHRepository repo = github.getRepositoryById("247692460"); + + for(GHContent content : repo.getDirectoryContent("items")) { + String oldSha = oldShas.get(content.getName()); + if(!content.getSha().equals(oldSha)) { + changedFiles.put(content.getName(), content.getSha()); + } + } + } catch(IOException e) { + return null; + } + return changedFiles; + } + + /** + * Takes set of filename (eg. BOW.json) and returns map from that filename to the individual download link. + */ + public Map getItemsDownload(Set filename) { + HashMap downloadUrls = new HashMap<>(); + try { + GitHub github = new GitHubBuilder().withOAuthToken(accessToken).build(); + GHRepository repo = github.getRepositoryById("247692460"); + + for(GHContent content : repo.getDirectoryContent("items")) { + if(filename.contains(content.getName())) { + downloadUrls.put(content.getName(), content.getDownloadUrl()); + } + } + } catch(IOException e) { } + return downloadUrls; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java new file mode 100644 index 00000000..08939cca --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -0,0 +1,1119 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.common.io.CharSource; +import com.google.gson.*; +import io.github.moulberry.notenoughupdates.options.Options; +import io.github.moulberry.notenoughupdates.util.HypixelApi; +import javafx.scene.control.Alert; +import net.minecraft.client.Minecraft; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.*; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.Display; + +import javax.swing.*; +import java.io.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.text.NumberFormat; +import java.util.*; +import java.util.zip.GZIPInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class NEUManager { + + private final NotEnoughUpdates neu; + public final NEUIO neuio; + public final Gson gson; + + private TreeMap itemMap = new TreeMap<>(); + + private TreeMap> tagWordMap = new TreeMap<>(); + private TreeMap>> titleWordMap = new TreeMap<>(); + private TreeMap>> loreWordMap = new TreeMap<>(); + + public String viewItemAttemptID = null; + public long viewItemAttemptTime = 0; + + public String currentProfile = ""; + public final HypixelApi hypixelApi = new HypixelApi(); + + private ResourceLocation wkZip = new ResourceLocation("notenoughupdates:wkhtmltox.zip"); + private Map itemstackCache = new HashMap<>(); + + private static final String AUCTIONS_PRICE_URL = "https://moulberry.github.io/files/auc_avg_jsons/average_3day.json.gz"; + private JsonObject auctionPricesJson = null; + private long auctionLastUpdate = 0; + + private HashMap craftCost = new HashMap<>(); + + private HashMap> usagesMap = new HashMap<>(); + + public File configLocation; + private File itemsLocation; + private File itemShaLocation; + private JsonObject itemShaConfig; + private File configFile; + public Options config; + + public NEUManager(NotEnoughUpdates neu, NEUIO neuio, File configLocation) { + this.neu = neu; + this.configLocation = configLocation; + this.neuio = neuio; + + GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting(); + gsonBuilder.registerTypeAdapter(Options.Option.class, Options.createSerializer()); + gsonBuilder.registerTypeAdapter(Options.Option.class, Options.createDeserializer()); + gson = gsonBuilder.create(); + + this.configFile = new File(configLocation, "config.json"); + try { + configFile.createNewFile(); + config = Options.loadFromFile(gson, configFile); + } catch(Exception e) { + config = new Options(); + } + + this.itemsLocation = new File(configLocation, "items"); + itemsLocation.mkdir(); + + this.itemShaLocation = new File(configLocation, "itemSha.json"); + try { + itemShaLocation.createNewFile(); + itemShaConfig = getJsonFromFile(itemShaLocation); + if(itemShaConfig == null) itemShaConfig = new JsonObject(); + } catch(IOException e) { } + + File wkShell = new File(configLocation, "wkhtmltox/bin/wkhtmltoimage"); + if(!wkShell.exists()) { + try { + InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(wkZip).getInputStream(); + unzip(is, configLocation); + } catch (IOException e) { + } + } + + //Unused code, used to automatically grab items from auctions. Leaving here in case I need it. + /*try { + for(int j=0; j<=89; j++) { + JsonObject auctions0 = getJsonFromFile(new File(configLocation, "auctions/auctions"+j+".json")); + + JsonArray arr = auctions0.getAsJsonArray("auctions"); + for(int i=0; i tag.toString().length()) { + writeItemJson(internalname, itemid, displayname, lore, info, clickcommand, damage, tag); + } + } + + } catch(Exception e) { + } + } + } + } catch(Exception e) { + e.printStackTrace(); + } + + throw new RuntimeException();*/ + } + + public class CraftInfo { + public boolean fromRecipe = false; + public float craftCost = -1; + } + + public CraftInfo getCraftCost(String internalname) { + if(craftCost.containsKey(internalname)) { + return craftCost.get(internalname); + } else { + CraftInfo ci = new CraftInfo(); + + JsonObject auctionInfo = getItemAuctionInfo(internalname); + JsonObject bazaarInfo = getBazaarInfo(internalname); + + if(bazaarInfo != null) { + float bazaarInstantBuyPrice = bazaarInfo.get("curr_buy").getAsFloat(); + ci.craftCost = bazaarInstantBuyPrice; + } + if(auctionInfo != null) { + float auctionPrice = auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat(); + if(ci.craftCost < 0 || auctionPrice < ci.craftCost) { + ci.craftCost = auctionPrice; + } + } + JsonObject item = getItemInformation().get(internalname); + if(item != null && item.has("recipe")) { + float craftPrice = 0; + JsonObject recipe = item.get("recipe").getAsJsonObject(); + + String[] x = {"1","2","3"}; + String[] y = {"A","B","C"}; + for(int i=0; i<9; i++) { + String name = y[i/3]+x[i%3]; + String itemS = recipe.get(name).getAsString(); + if(itemS.length() == 0) continue; + + int count = 1; + if(itemS != null && itemS.split(":").length == 2) { + count = Integer.valueOf(itemS.split(":")[1]); + itemS = itemS.split(":")[0]; + } + float compCost = getCraftCost(itemS).craftCost * count; + if(compCost < 0) { + craftCost.put(internalname, ci); + return ci; + } else { + craftPrice += compCost; + } + } + + if(ci.craftCost < 0 || craftPrice < ci.craftCost) { + ci.craftCost = craftPrice; + ci.fromRecipe = true; + } + } + craftCost.put(internalname, ci); + return ci; + } + } + + public void saveConfig() throws IOException { + config.saveToFile(gson, configFile); + } + + public void updatePrices() { + if(System.currentTimeMillis() - auctionLastUpdate > 1000*60*30) { //30 minutes + craftCost.clear(); + System.out.println("UPDATING PRICE INFORMATION"); + auctionLastUpdate = System.currentTimeMillis(); + try(Reader inReader = new InputStreamReader(new GZIPInputStream(new URL(AUCTIONS_PRICE_URL).openStream()))) { + auctionPricesJson = gson.fromJson(inReader, JsonObject.class); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public JsonObject getAuctionPricesJson() { + return auctionPricesJson; + } + + public JsonObject getItemAuctionInfo(String internalname) { + JsonElement e = auctionPricesJson.get("prices").getAsJsonObject().get(internalname); + if(e == null) { + return null; + } + return e.getAsJsonObject(); + } + + public JsonObject getBazaarInfo(String internalname) { + JsonElement e = auctionPricesJson.get("bazaar").getAsJsonObject().get(internalname); + if(e == null) { + return null; + } + return e.getAsJsonObject(); + } + + public float getCostOfEnchants(String internalname, NBTTagCompound tag) { + float costOfEnchants = 0; + JsonObject info = getItemAuctionInfo(i