diff --git a/.gitignore b/.gitignore index c67d269..13a72c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,56 @@ -*.gradle +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# Eclipse stuff +/.classpath +/.project +/.settings + +# netbeans +/nbproject + +#gradle stuff +/gradlew +/gradlew.bat +/gradle +/.gradle + +# maven +/build.xml +/target + +# vim +.*.sw[a-p] + +# various other potential build files +/build +/bin +/dist +/manifest.mf +/run +/libs +/eclipse +/classes + +# Mac filesystem dust +/.DS_Store + +# IntelliJ +*.iml +*.ipr +*.iws +.idea/ + +# For good measure... +*.jks +gradle.properties \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f54fbe1 --- /dev/null +++ b/build.gradle @@ -0,0 +1,105 @@ +buildscript { + repositories { + jcenter() + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + } +} +apply plugin: 'net.minecraftforge.gradle.forge' +apply plugin: "java" + +version = "1.12.2-2.0.3" +group= "hellfirepvp.beebetteratbees" +archivesBaseName = "beebetteratbees" + +minecraft { + version = "14.23.4.2751" + runDir = "run" + useDepAts = true + + mappings = "snapshot_20180415" +} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +compileJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 +} + +compileApiJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 +} + +repositories { + + maven { + // location of the maven that hosts JEI files + url = "http://dvs1.progwml6.com/files/maven" + } + + maven { + // forestry stuff + url = "http://maven.ic2.player.to" + } + +} + +dependencies { + + def mc_version = "1.12.2" + def jei_version = "4.8.5.151" + def forestry_version = "5.8.1.350" + + ////JEI stuff + deobfCompile "mezz.jei:jei_${mc_version}:${jei_version}" + + deobfCompile "net.sengir.forestry:forestry_${mc_version}:${forestry_version}" + +} + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + +task signMainJar(type: SignJar, dependsOn: reobfJar) { + onlyIf { // Skip the task if our secret data isn't available + project.hasProperty('keyStore') + } + if (project.hasProperty('keyStore')) { // This needs to be a path to the keystore file + keyStore = project.keyStore + alias = project.alias + storePass = project.storePass + keyPass = project.keyPass + inputFile = jar.archivePath + outputFile = jar.archivePath + } +} +build.dependsOn signMainJar + +processResources +{ + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include "mcmod.info" + + // replace version and mcversion + expand "version": project.version, "mcversion": "1.12" + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude "mcmod.info" + } +} diff --git a/gradle/gradle.iml b/gradle/gradle.iml deleted file mode 100644 index da59c57..0000000 --- a/gradle/gradle.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/gradle/gradle/wrapper/gradle-wrapper.jar b/gradle/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index b761216..0000000 Binary files a/gradle/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/gradle/wrapper/gradle-wrapper.properties b/gradle/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index db5957d..0000000 --- a/gradle/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Thu Apr 28 21:10:07 CEST 2016 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip diff --git a/gradle/gradlew b/gradle/gradlew deleted file mode 100644 index 91a7e26..0000000 --- a/gradle/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/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/gradle/gradlew.bat b/gradle/gradlew.bat deleted file mode 100644 index 8a0b282..0000000 --- a/gradle/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index b761216..d3b8398 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 678d9d8..5620912 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jul 02 15:54:47 CDT 2014 +#Wed Oct 10 22:56:21 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip diff --git a/gradlew b/gradlew index 91a7e26..27309d9 100644 --- a/gradlew +++ b/gradlew @@ -6,12 +6,30 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# 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" @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=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. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +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 @@ -114,6 +113,7 @@ fi 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` diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..832fdb6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @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 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 @@ -46,7 +46,7 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args diff --git a/libs/CodeChickenCore-1.7.10-1.0.7.47-universal.jar b/libs/CodeChickenCore-1.7.10-1.0.7.47-universal.jar deleted file mode 100644 index 93c29f4..0000000 Binary files a/libs/CodeChickenCore-1.7.10-1.0.7.47-universal.jar and /dev/null differ diff --git a/libs/CodeChickenLib-1.7.10-1.1.3.138-dev.jar b/libs/CodeChickenLib-1.7.10-1.1.3.138-dev.jar deleted file mode 100644 index 6d3bb67..0000000 Binary files a/libs/CodeChickenLib-1.7.10-1.1.3.138-dev.jar and /dev/null differ diff --git a/libs/NotEnoughItems-1.7.10-1.0.5.110-universal.jar b/libs/NotEnoughItems-1.7.10-1.0.5.110-universal.jar deleted file mode 100644 index 4aed8e0..0000000 Binary files a/libs/NotEnoughItems-1.7.10-1.0.5.110-universal.jar and /dev/null differ diff --git a/libs/forestry_1.7.10-4.2.11.59.jar b/libs/forestry_1.7.10-4.2.11.59.jar deleted file mode 100644 index 1fe8eba..0000000 Binary files a/libs/forestry_1.7.10-4.2.11.59.jar and /dev/null differ diff --git a/libs/neiaddons-1.12.14.40-mc1.7.10.jar b/libs/neiaddons-1.12.14.40-mc1.7.10.jar deleted file mode 100644 index cade5c3..0000000 Binary files a/libs/neiaddons-1.12.14.40-mc1.7.10.jar and /dev/null differ diff --git a/src/main/java/hellfirepvp/beebetteratbees/BeeBetterAtBees.java b/src/main/java/hellfirepvp/beebetteratbees/BeeBetterAtBees.java new file mode 100644 index 0000000..a7c47ad --- /dev/null +++ b/src/main/java/hellfirepvp/beebetteratbees/BeeBetterAtBees.java @@ -0,0 +1,43 @@ +package hellfirepvp.beebetteratbees; + +import hellfirepvp.beebetteratbees.common.CommonProxy; +import hellfirepvp.beebetteratbees.common.data.Config; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * This class is part of the BeeBetterAtBees Mod + * Class: BeeBetterAtBees + * Created by HellFirePvP + * Date: 10.10.2018 / 22:59 + */ +@Mod(modid = BeeBetterAtBees.MODID, name = BeeBetterAtBees.NAME, version = BeeBetterAtBees.VERSION, + dependencies = "required-after:forge@[14.23.4.2748,);required-after:forestry", + certificateFingerprint = "a0f0b759d895c15ceb3e3bcb5f3c2db7c582edf0", + acceptedMinecraftVersions = "[1.12.2]", clientSideOnly = true) +public class BeeBetterAtBees { + + public static final String MODID = "beebetteratbees"; + public static final String NAME = "Bee Better at Bees"; + public static final String VERSION = "2.0.3"; + public static final String CLIENT_PROXY = "hellfirepvp.beebetteratbees.client.ClientProxy"; + public static final String COMMON_PROXY = "hellfirepvp.beebetteratbees.common.CommonProxy"; + + @Mod.Instance(MODID) + public static BeeBetterAtBees instance; + + public static Logger log = LogManager.getLogger(NAME); + + @SidedProxy(clientSide = CLIENT_PROXY, serverSide = COMMON_PROXY) + public static CommonProxy proxy; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event) { + event.getModMetadata().version = VERSION; + Config.init(event.getSuggestedConfigurationFile()); + } + +} diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/ClientProxy.java b/src/main/java/hellfirepvp/beebetteratbees/client/ClientProxy.java index a4a39e7..f74b49d 100644 --- a/src/main/java/hellfirepvp/beebetteratbees/client/ClientProxy.java +++ b/src/main/java/hellfirepvp/beebetteratbees/client/ClientProxy.java @@ -1,29 +1,12 @@ package hellfirepvp.beebetteratbees.client; -import codechicken.nei.api.API; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler; import hellfirepvp.beebetteratbees.common.CommonProxy; /** - * HellFirePvP@Admin - * Date: 28.04.2016 / 19:51 - * on BeeBetterAtBees - * ClientProxy + * This class is part of the BeeBetterAtBees Mod + * Class: ClientProxy + * Created by HellFirePvP + * Date: 10.10.2018 / 23:12 */ public class ClientProxy extends CommonProxy { - - @Override - public void registerNEIGUIs() { - registerNEIStuff(); - } - - @SideOnly(Side.CLIENT) - private void registerNEIStuff() { - BBABGuiRecipeTreeHandler handler = new BBABGuiRecipeTreeHandler(); - API.registerRecipeHandler(handler); - API.registerUsageHandler(handler); - } - } diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/NEIBBABConfig.java b/src/main/java/hellfirepvp/beebetteratbees/client/NEIBBABConfig.java deleted file mode 100644 index daba8ac..0000000 --- a/src/main/java/hellfirepvp/beebetteratbees/client/NEIBBABConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -package hellfirepvp.beebetteratbees.client; - -import codechicken.nei.api.IConfigureNEI; -import hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler; -import hellfirepvp.beebetteratbees.common.BeeBetterAtBees; - -/** - * HellFirePvP@Admin - * Date: 28.04.2016 / 22:59 - * on BeeBetterAtBees - * NEIBBABConfig - */ -public class NEIBBABConfig implements IConfigureNEI { - - @Override - public void loadConfig() { - BBABGuiRecipeTreeHandler.loadBeeRoot(); - } - - @Override - public String getName() { - return BeeBetterAtBees.NAME; - } - - @Override - public String getVersion() { - return BeeBetterAtBees.VERSION; - } - - /* - - Are you FOR REAL NEI?!?! - The class has to be called NEI_SOMETHING_Config ?!? WTF? - - ClassDiscoverer classDiscoverer = new ClassDiscoverer(new IStringMatcher() { - public boolean matches(String test) { - return (test.startsWith("NEI")) && (test.endsWith("Config.class")); - } - }, new Class[] { IConfigureNEI.class }); - */ - -} diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/gui/AbstractTreeGUIHandler.java b/src/main/java/hellfirepvp/beebetteratbees/client/gui/AbstractTreeGUIHandler.java deleted file mode 100644 index 86bd898..0000000 --- a/src/main/java/hellfirepvp/beebetteratbees/client/gui/AbstractTreeGUIHandler.java +++ /dev/null @@ -1,370 +0,0 @@ -package hellfirepvp.beebetteratbees.client.gui; - -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.NEIClientConfig; -import codechicken.nei.NEIClientUtils; -import codechicken.nei.PositionedStack; -import codechicken.nei.api.DefaultOverlayRenderer; -import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.api.IRecipeOverlayRenderer; -import codechicken.nei.api.IStackPositioner; -import codechicken.nei.guihook.GuiContainerManager; -import codechicken.nei.guihook.IContainerInputHandler; -import codechicken.nei.guihook.IContainerTooltipHandler; -import codechicken.nei.recipe.GuiCraftingRecipe; -import codechicken.nei.recipe.GuiRecipe; -import codechicken.nei.recipe.GuiUsageRecipe; -import codechicken.nei.recipe.ICraftingHandler; -import codechicken.nei.recipe.IUsageHandler; -import codechicken.nei.recipe.RecipeInfo; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Container; -import net.minecraft.item.ItemStack; -import org.lwjgl.opengl.GL11; - -import java.awt.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; - -/** - * HellFirePvP@Admin - * Date: 28.04.2016 / 22:30 - * on BeeBetterAtBees - * AbstractTreeGUIHandler - */ -public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsageHandler { - - public int cycleticks = Math.abs((int) System.currentTimeMillis()); - public LinkedList arecipes = new LinkedList(); - public LinkedList transferRects = new LinkedList(); - - public AbstractTreeGUIHandler() { - loadTransferRects(); - RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), this.transferRects); - } - - private static boolean transferRect(GuiContainer gui, Collection transferRects, int offsetx, int offsety, boolean usage) { - Point pos = GuiDraw.getMousePosition(); - Point relMouse = new Point(pos.x - gui.width - offsetx, pos.y - gui.height - offsety); - for (RecipeTransferRect rect : transferRects) { - if ((rect.rect.contains(relMouse)) && (usage ? GuiUsageRecipe.openRecipeGui(rect.outputId, rect.results) : GuiCraftingRecipe.openRecipeGui(rect.outputId, rect.results))) { - return true; - } - } - return false; - } - - private static List transferRectTooltip(GuiContainer gui, Collection transferRects, int offsetx, int offsety, List currenttip) { - Point pos = GuiDraw.getMousePosition(); - Point relMouse = new Point(pos.x - gui.width - offsetx, pos.y - gui.height - offsety); - for (RecipeTransferRect rect : transferRects) { - if (rect.rect.contains(relMouse)) { - currenttip.add(NEIClientUtils.translate("recipe.tooltip")); - break; - } - } - return currenttip; - } - - public abstract void loadCraftingRecipes(String outId, Object... results); - - public abstract void loadUsageRecipes(String inId, Object... ingredients); - - public String getOverlayIdentifier() { - return null; - } - - public List> getRecipeTransferRectGuis() { - Class clazz = getGuiClass(); - if (clazz != null) { - LinkedList> list = new LinkedList>(); - list.add(clazz); - return list; - } - return null; - } - - public Class getGuiClass() { - return null; - } - - public AbstractTreeGUIHandler newInstance() { - try { - return getClass().newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public ICraftingHandler getRecipeHandler(String outputId, Object... results) { - AbstractTreeGUIHandler handler = newInstance(); - handler.loadCraftingRecipes(outputId, results); - return handler; - } - - @Override - public IUsageHandler getUsageHandler(String inputId, Object... ingredients) { - AbstractTreeGUIHandler handler = newInstance(); - handler.loadUsageRecipes(inputId, ingredients); - return handler; - } - - @Override - public int numRecipes() { - return this.arecipes.size(); - } - - @Override - public void drawBackground(int recipe) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GuiDraw.changeTexture(getGuiTexture()); - GuiDraw.drawTexturedModalRect(0, 0, 5, 11, 166, 65); - } - - @Override - public void drawForeground(int recipe) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glDisable(GL11.GL_LIGHTING); - GuiDraw.changeTexture(getGuiTexture()); - drawExtras(recipe); - } - - @Override - public List getIngredientStacks(int recipe) { - return this.arecipes.get(recipe).getIngredients(); - } - - @Override - public PositionedStack getResultStack(int recipe) { - return this.arecipes.get(recipe).getResult(); - } - - @Override - public List getOtherStacks(int recipe) { - return this.arecipes.get(recipe).getOtherStacks(); - } - - @Override - public void onUpdate() { - if (!NEIClientUtils.shiftKey()) { - this.cycleticks += 1; - } - } - - @Override - public boolean hasOverlay(GuiContainer gui, Container container, int recipe) { - return (RecipeInfo.hasDefaultOverlay(gui, getOverlayIdentifier())) || (RecipeInfo.hasOverlayHandler(gui, getOverlayIdentifier())); - } - - @Override - public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) { - IStackPositioner positioner = RecipeInfo.getStackPositioner(gui, getOverlayIdentifier()); - if (positioner == null) { - return null; - } - return new DefaultOverlayRenderer(getIngredientStacks(recipe), positioner); - } - - @Override - public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe) { - return RecipeInfo.getOverlayHandler(gui, getOverlayIdentifier()); - } - - @Override - public int recipiesPerPage() { - return 1; - } - - @Override - public List handleTooltip(GuiRecipe gui, List currenttip, int recipe) { - if ((GuiContainerManager.shouldShowTooltip(gui)) && (currenttip.size() == 0)) { - Point offset = gui.getRecipePosition(recipe); - currenttip = transferRectTooltip(gui, this.transferRects, offset.x, offset.y, currenttip); - } - return currenttip; - } - - @Override - public List handleItemTooltip(GuiRecipe gui, ItemStack stack, List currenttip, int recipe) { - return currenttip; - } - - @Override - public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) { - if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) { - return transferRect(gui, recipe, false); - } - if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")) { - return transferRect(gui, recipe, true); - } - return false; - } - - @Override - public boolean mouseClicked(GuiRecipe gui, int button, int recipe) { - if (button == 0) { - return transferRect(gui, recipe, false); - } - if (button == 1) { - return transferRect(gui, recipe, true); - } - return false; - } - - private boolean transferRect(GuiRecipe gui, int recipe, boolean usage) { - Point offset = gui.getRecipePosition(recipe); - return transferRect(gui, this.transferRects, offset.x, offset.y, usage); - } - - public void loadTransferRects() {} - - public abstract String getGuiTexture(); - - public void drawExtras(int recipe) {} - - public static class RecipeTransferRect { - - Rectangle rect; - String outputId; - Object[] results; - - public RecipeTransferRect(Rectangle rectangle, String outputId, Object... results) { - this.rect = rectangle; - this.outputId = outputId; - this.results = results; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof RecipeTransferRect)) { - return false; - } - return this.rect.equals(((RecipeTransferRect) obj).rect); - } - - @Override - public int hashCode() { - return this.rect.hashCode(); - } - } - - public static class RecipeTransferRectHandler implements IContainerInputHandler, IContainerTooltipHandler { - - private static HashMap, HashSet> guiMap = new HashMap, HashSet>(); - - public static void registerRectsToGuis(List> classes, List rects) { - if (classes == null) { - return; - } - for (Class clazz : classes) { - HashSet set = guiMap.get(clazz); - if (set == null) { - set = new HashSet(); - guiMap.put(clazz, set); - } - set.addAll(rects); - } - } - - public boolean canHandle(GuiContainer gui) { - return guiMap.containsKey(gui.getClass()); - } - - @Override - public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) { - if (!canHandle(gui)) { - return false; - } - if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) { - return transferRect(gui, false); - } - if (keyCode == NEIClientConfig.getKeyBinding("gui.usage")) { - return transferRect(gui, true); - } - return false; - } - - @Override - public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) { - if (!canHandle(gui)) { - return false; - } - if (button == 0) { - return transferRect(gui, false); - } - if (button == 1) { - return transferRect(gui, true); - } - return false; - } - - private boolean transferRect(GuiContainer gui, boolean usage) { - int[] offset = RecipeInfo.getGuiOffset(gui); - return AbstractTreeGUIHandler.transferRect(gui, guiMap.get(gui.getClass()), offset[0], offset[1], usage); - } - - @Override - public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) { - } - - @Override - public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) { - } - - @Override - public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) { - } - - @Override - public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) { - return false; - } - - @Override - public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) { - return false; - } - - @Override - public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) { - } - - @Override - public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { - if (!canHandle(gui)) { - return currenttip; - } - if ((GuiContainerManager.shouldShowTooltip(gui)) && (currenttip.size() == 0)) { - int[] offset = RecipeInfo.getGuiOffset(gui); - currenttip = AbstractTreeGUIHandler.transferRectTooltip(gui, guiMap.get(gui.getClass()), offset[0], offset[1], currenttip); - } - return currenttip; - } - - @Override - public List handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List currenttip) { - return currenttip; - } - - @Override - public List handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List currenttip) { - return currenttip; - } - - @Override - public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) { - } - - } - - static { - GuiContainerManager.addInputHandler(new RecipeTransferRectHandler()); - GuiContainerManager.addTooltipHandler(new RecipeTransferRectHandler()); - } - -} \ No newline at end of file diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/gui/BBABGuiRecipeTreeHandler.java b/src/main/java/hellfirepvp/beebetteratbees/client/gui/BBABGuiRecipeTreeHandler.java deleted file mode 100644 index d50c0cf..0000000 --- a/src/main/java/hellfirepvp/beebetteratbees/client/gui/BBABGuiRecipeTreeHandler.java +++ /dev/null @@ -1,344 +0,0 @@ -package hellfirepvp.beebetteratbees.client.gui; - -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.guihook.GuiContainerManager; -import codechicken.nei.recipe.GuiRecipe; -import cpw.mods.fml.relauncher.ReflectionHelper; -import forestry.api.apiculture.IBeeMutation; -import forestry.api.apiculture.IBeeRoot; -import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAllele; -import forestry.api.genetics.IAlleleSpecies; -import forestry.api.genetics.IIndividual; -import forestry.api.genetics.ISpeciesRoot; -import hellfirepvp.beebetteratbees.common.BeeBetterAtBees; -import hellfirepvp.beebetteratbees.common.ModConfig; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; -import org.lwjgl.opengl.GL11; - -import java.awt.*; -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * HellFirePvP@Admin - * Date: 28.04.2016 / 22:06 - * on BeeBetterAtBees - * BBABGuiRecipeTreeHandler - */ -public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler { - - public static final int BEE_TYPE_PRINCESS = 1; - public static final int BEE_TYPE_DRONE = 0; - - private static IBeeRoot speciesRoot; - - public static List getMutationsWithResult(IAllele allele) { - if(speciesRoot == null) return new LinkedList(); - LinkedList out = new LinkedList(); - for (IBeeMutation mutation : speciesRoot.getMutations(false)) { - if(mutation.getTemplate()[0].equals(allele)) out.add(mutation); - } - return out; - } - - public static ItemStack createStack(IAlleleSpecies species, int type) { - ISpeciesRoot root = species.getRoot(); - IAllele[] template = root.getTemplate(species.getUID()); - if (template == null) { - BeeBetterAtBees.log.warn("Template for %s doesn't exist! Skipping...", species.getUID()); - return null; - } - IIndividual individual = root.templateAsIndividual(template); - individual.analyze(); - ItemStack stack = root.getMemberStack(individual, type); - if (stack == null) { - BeeBetterAtBees.log.warn("Got no MemberStack back when creating bee (%s) ?", species.getUID()); - } - return stack; - } - - @Override - public void loadCraftingRecipes(String outputId, Object... results) { - if(speciesRoot == null) return; - - if (outputId.equals("item")) { - loadCraftingRecipes((ItemStack) results[0]); - } - } - - public void loadCraftingRecipes(ItemStack result) { - if(speciesRoot == null) return; - - if (!speciesRoot.isMember(result)) { - return; - } - IIndividual resultIndividual = speciesRoot.getMember(result); - if (resultIndividual == null) { - BeeBetterAtBees.log.warn("IIndividual is null searching recipe for %s", result.toString()); - return; - } - if (resultIndividual.getGenome() == null) { - BeeBetterAtBees.log.warn("Genome is null when searching recipe for %s", result.toString()); - return; - } - if (resultIndividual.getGenome().getPrimary() == null) { - BeeBetterAtBees.log.warn("Species is null when searching recipe for %s", result.toString()); - return; - } - IAlleleSpecies species = resultIndividual.getGenome().getPrimary(); - for (IBeeMutation mutation : speciesRoot.getMutations(false)) { - if(mutation.getTemplate()[0].equals(species)) { - if(!mutation.isSecret() || ModConfig.shouldShowSecretRecipes) { - this.arecipes.add(new CachedBeeMutationTree(mutation)); - } - } - } - cleanupDuplicateRecipes(); - } - - private Map> tipBoxes = new HashMap>(); - - @Override - public void drawExtras(int recipe) { - CachedRecipe rec = this.arecipes.get(recipe); - if(rec instanceof CachedBeeMutationTree) { - Map> boxes = new HashMap>(4); - CachedBeeMutationTree.PositionedMutationNodeStack root = ((CachedBeeMutationTree) rec).getRootStack(); - drawExtrasFrom(root, boxes); - this.tipBoxes = boxes; - } - } - - private static final Color lineColorBlack = new Color(0, 0, 0), - lineColorRed = new Color(169, 0, 10); - - private static final int offsetCorrection = 8; - private static final int possibleChildOffset = 16; - - public static void drawExtrasFrom(CachedBeeMutationTree.PositionedMutationNodeStack nodeStack, Map> infoBoxes) { - int nodeX = nodeStack.relx; - int nodeY = nodeStack.rely; - - if(nodeStack.leftChild == null || - nodeStack.rightChild == null) { - if(nodeStack.hasPossibleChildren) { - - Color drawColor = lineColorBlack; - - if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { - drawColor = lineColorRed; - } - - float chance = nodeStack.baseChance; - if(chance > 0) { - int length = drawChanceInfo(nodeX, nodeY, chance, Minecraft.getMinecraft().fontRenderer, drawColor); - if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { - Rectangle rec = new Rectangle(nodeX + 4, nodeY + 17, (int) (length * 0.75F), 5); - infoBoxes.put(rec, nodeStack.requirements); - } - } - - drawLine( - nodeX + offsetCorrection, nodeY + offsetCorrection, - nodeX + offsetCorrection - 4, - nodeY + offsetCorrection + possibleChildOffset, - drawColor); - drawLine( - nodeX + offsetCorrection, nodeY + offsetCorrection, - nodeX + offsetCorrection + 4, - nodeY + offsetCorrection + possibleChildOffset, - drawColor); - } - return; //Has no children anymore. - } - - Color drawColor = lineColorBlack; - - if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { - drawColor = lineColorRed; - } - - float chance = nodeStack.baseChance; - if(chance > 0) { - int length = drawChanceInfo(nodeX, nodeY, chance, Minecraft.getMinecraft().fontRenderer, drawColor); - if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { - Rectangle rec = new Rectangle(nodeX + 4, nodeY + 17, (int) (length * 0.75F), 5); - infoBoxes.put(rec, nodeStack.requirements); - } - } - - CachedBeeMutationTree.PositionedMutationNodeStack left = nodeStack.leftChild; - drawLine( - nodeX + offsetCorrection, nodeY + offsetCorrection, - left.relx + offsetCorrection, left.rely + offsetCorrection, - drawColor); - CachedBeeMutationTree.PositionedMutationNodeStack right = nodeStack.rightChild; - drawLine( - nodeX + offsetCorrection, nodeY + offsetCorrection, - right.relx + offsetCorrection, right.rely + offsetCorrection, - drawColor); - - drawExtrasFrom(left, infoBoxes); - drawExtrasFrom(right, infoBoxes); - } - - private static int drawChanceInfo(int nodeX, int nodeY, float chance, FontRenderer fr, Color drawColor) { - GL11.glPushMatrix(); - GL11.glTranslatef(nodeX + 4, nodeY + 17, 0); - GL11.glScalef(0.65F, 0.65F, 0.65F); - int chAsInt = (int) (chance); - StringBuilder sb = new StringBuilder().append(EnumChatFormatting.BOLD); - if(chAsInt <= 0) { - sb.append("<1%"); - } else { - sb.append(chAsInt).append("%"); - } - int length = fr.drawString(sb.toString(), 0, 0, drawColor.getRGB()); - GL11.glPopMatrix(); - return length; - } - - @Override - public List handleTooltip(GuiRecipe gui, List currenttip, int recipe) { - if(GuiContainerManager.shouldShowTooltip(gui) && currenttip.size() == 0) { - Point pos = GuiDraw.getMousePosition(); - Point guiOffset = getGuiOffset(gui); - Point relMouse = new Point(pos.x - guiOffset.x - 5, pos.y - guiOffset.y - 16); - for (Rectangle rec : tipBoxes.keySet()) { - if(rec.contains(relMouse)) { - return new LinkedList(tipBoxes.get(rec)); - } - } - } - return super.handleTooltip(gui, currenttip, recipe); - } - - private Point getGuiOffset(GuiContainer ct) { - try { - Field fP = ReflectionHelper.findField(GuiContainer.class, "guiLeft", "field_147003_i"); - fP.setAccessible(true); - int left = (Integer) fP.get(ct); - fP = ReflectionHelper.findField(GuiContainer.class, "guiTop", "field_147009_r"); - fP.setAccessible(true); - int top = (Integer) fP.get(ct); - return new Point(left, top); - } catch (Exception e) {} - return new Point(0, 0); - } - - private static void drawLine(double lx, double ly, double hx, double hy, Color color) { - GL11.glPushMatrix(); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glDepthMask(true); - GL11.glLineWidth(3.0F); - GL11.glEnable(GL11.GL_LINE_SMOOTH); - GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - Tessellator tes = Tessellator.instance; - tes.startDrawing(GL11.GL_LINE_STRIP); - tes.setColorRGBA(color.getRed(), color.getGreen(), color.getBlue(), 127); - tes.addVertex(lx, ly, 0); - tes.addVertex(hx, hy, 0); - tes.draw(); - - GL11.glDisable(GL11.GL_LINE_SMOOTH); - GL11.glDepthMask(false); - GL11.glLineWidth(2.0F); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_BLEND); - GL11.glPopMatrix(); - } - - @Override - public void loadUsageRecipes(String inputId, Object... ingredients) { - if(speciesRoot == null) return; - - if (inputId.equals("item")) { - loadUsageRecipes((ItemStack) ingredients[0]); - } - } - - public void loadUsageRecipes(ItemStack ingredient) { - if(speciesRoot == null) return; - - if (!speciesRoot.isMember(ingredient)) { - return; - } - IIndividual individual = speciesRoot.getMember(ingredient); - if (individual == null) { - BeeBetterAtBees.log.warn("IIndividual is null searching recipe for %s", ingredient.toString()); - return; - } - if (individual.getGenome() == null) { - BeeBetterAtBees.log.warn("Genome is null when searching recipe for %s", ingredient.toString()); - return; - } - if (individual.getGenome().getPrimary() == null) { - BeeBetterAtBees.log.warn("Species is null when searching recipe for %s", ingredient.toString()); - return; - } - IAlleleSpecies species = individual.getGenome().getPrimary(); - for (IBeeMutation mutation : speciesRoot.getMutations(false)) { - if(mutation.getAllele0().equals(species) || mutation.getAllele1().equals(species)) { - if(!mutation.isSecret() || ModConfig.shouldShowSecretRecipes) { - this.arecipes.add(new CachedBeeMutationTree(mutation)); - } - } - } - cleanupDuplicateRecipes(); - } - - private void cleanupDuplicateRecipes() { - for (CachedRecipe recipe : arecipes) { - if(recipe instanceof CachedBeeMutationTree) { - boolean clean = true; - Iterator iterator = arecipes.iterator(); - while (iterator.hasNext()) { - CachedRecipe recipeOther = iterator.next(); - if(recipe == recipeOther) continue; - if(recipe.equals(recipeOther)) { - iterator.remove(); - clean = false; - } - } - if(!clean) { - cleanupDuplicateRecipes(); - break; - } - } - } - } - - @Override - public String getGuiTexture() { - return "beebetteratbees:textures/gui/neiBlank.png"; - } - - @Override - public String getRecipeName() { - return StatCollector.translateToLocal("bbab.gui.breedtree"); - } - - public static void loadBeeRoot() { - speciesRoot = (IBeeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); - if (speciesRoot == null) { - BeeBetterAtBees.log.warn("Bee Species Root not found, this mod has no use without it."); - } else { - BeeBetterAtBees.log.info("Bee Species Root found!"); - } - } - -} diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/gui/CachedBeeMutationTree.java b/src/main/java/hellfirepvp/beebetteratbees/client/gui/CachedBeeMutationTree.java deleted file mode 100644 index cf142f2..0000000 --- a/src/main/java/hellfirepvp/beebetteratbees/client/gui/CachedBeeMutationTree.java +++ /dev/null @@ -1,246 +0,0 @@ -package hellfirepvp.beebetteratbees.client.gui; - -import codechicken.nei.PositionedStack; -import forestry.api.apiculture.IBeeMutation; -import forestry.api.genetics.IAllele; -import forestry.api.genetics.IAlleleSpecies; -import hellfirepvp.beebetteratbees.client.util.SimpleBinaryTree; -import hellfirepvp.beebetteratbees.common.ModConfig; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import static hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler.*; - -/** - * HellFirePvP@Admin - * Date: 28.04.2016 / 23:44 - * on BeeBetterAtBees - * CachedBeeMutationTree - */ -public class CachedBeeMutationTree extends CachedRecipe { - - //RENDERING BB - //X = 15 to 135 (Size: 120) - //Y = 10 to 100 (Size: 90) - - private static final int MIN_X = 15, MAX_X = 135; - private static final int X_SEPERATION_THRESHOLD = 7; - private static final int Y_OFFSET = 0; - - private SimpleBinaryTree mutationTree; - private List evaluatedBeePositions; - private int evaluatedMaxX; - public final boolean oversized; - private PositionedMutationNodeStack rootStack; - - public CachedBeeMutationTree(IBeeMutation parentMutation) { - //parentMutation.getTemplate() Gets results primary at array[0], secondary at array[1] - //parentMutation.getAllele0() or getAllele1() Gets bees needed for mutation. - this.mutationTree = new SimpleBinaryTree(4, parentMutation.getTemplate()[0], - new SimpleBinaryTree.RootProvider() { - @Override - public IAllele[] provideSubNodes(IAllele superNode) { - List mutations = BBABGuiRecipeTreeHandler.getMutationsWithResult(superNode); - if(mutations.size() > 0) { - IBeeMutation mutation = mutations.get(0); - - return new IAllele[] { mutation.getAllele0(), mutation.getAllele1() }; - } else { - return null; - } - } - }); - - - if(!ModConfig.showDuplicateTrees) { - List foundMutationTrees = new ArrayList(); - removeAndReplaceDuplicates(this.mutationTree.getRoot(), foundMutationTrees); - } - - //Important: We don't need to buffer root, because that's the "result" - this.evaluatedBeePositions = new LinkedList(); - int iterationDepth = 3; - int maxTotalDepth = Math.min(iterationDepth, mutationTree.getRoot().getMaxFollowingDepth()); - if(maxTotalDepth <= 0) { - oversized = false; - return; //In case the root is a leaf, there is nothing to display anyway except the root. - } - int yStep = 110 / maxTotalDepth; - - this.oversized = checkSeparationWidth(maxTotalDepth, X_SEPERATION_THRESHOLD); - this.evaluatedMaxX = /*this.oversized ? buildNewMaxX(maxTotalDepth, X_SEPERATION_THRESHOLD) :*/ MAX_X; - - int center = (MIN_X + this.evaluatedMaxX) / 2; - PositionedMutationNodeStack leftChild = placeInRenderBuffer(mutationTree.getRoot().getLeftNode(), - Y_OFFSET + yStep, yStep, - MIN_X, center, iterationDepth - 1); - PositionedMutationNodeStack rightChild = placeInRenderBuffer(mutationTree.getRoot().getRightNode(), - Y_OFFSET + yStep, yStep, - center, this.evaluatedMaxX, iterationDepth - 1); - - List mutationsToRoot = getMutationsWithResult(mutationTree.getRoot().getValue()); - float ch = -1; - Collection requirements = new LinkedList(); - if(mutationsToRoot.size() > 0) { - IBeeMutation mut = mutationsToRoot.get(0); - ch = mut.getBaseChance(); - try { - requirements = mut.getSpecialConditions(); - } catch (Throwable tr) {} - } - - this.rootStack = new PositionedMutationNodeStack( - createStack((IAlleleSpecies) mutationTree.getRoot().getValue(), BEE_TYPE_PRINCESS), - (MIN_X + this.evaluatedMaxX) / 2, Y_OFFSET, - ch, requirements, - leftChild, rightChild, true); - } - - private void removeAndReplaceDuplicates(SimpleBinaryTree.Node node, List discoveredMutations) { //Replace with 2 lines. - if(discoveredMutations.contains(node.getValue())) { - List mutations = getMutationsWithResult(node.getValue()); - if(mutations.size() > 0) node.removeDuplicate(); //Only if it actually has mutations that has this node as result. - } else { - discoveredMutations.add(node.getValue()); - if(node.getMaxFollowingDepth() > 0) { - removeAndReplaceDuplicates(node.getLeftNode(), discoveredMutations); - removeAndReplaceDuplicates(node.getRightNode(), discoveredMutations); - } - } - } - - /* - private int buildNewMaxX(int maxTotalDepth, int xSeparationThreshold) { - int maxDivision = (int) Math.pow(2, maxTotalDepth + 1); - return MIN_X + (maxDivision * xSeparationThreshold); - } - */ - - private boolean checkSeparationWidth(int maxTotalDepth, int xSeparationThreshold) { - double maxDivision = Math.pow(2, maxTotalDepth + 1); - int resultingLLWidth = (int) (120 / maxDivision); //LowestLevelWidth - return resultingLLWidth < xSeparationThreshold; - } - - private PositionedMutationNodeStack placeInRenderBuffer(SimpleBinaryTree.Node node, int minY, int yStep, int minX, int maxX, int iterationMaxCount) { - int center = (minX + maxX) / 2; - iterationMaxCount--; - if(iterationMaxCount < 0 || node.getMaxFollowingDepth() <= 0) { - List mutationsToRoot = getMutationsWithResult(node.getValue()); - float ch = -1; - Collection requirements = new LinkedList(); - if(mutationsToRoot.size() > 0) { - IBeeMutation mut = mutationsToRoot.get(0); - ch = mut.getBaseChance(); - try { - requirements = mut.getSpecialConditions(); - } catch (Throwable tr) { - requirements = new LinkedList(); - } - } - PositionedMutationNodeStack leaf = new PositionedMutationNodeStack( //Leaf - createStack((IAlleleSpecies) node.getValue(), BEE_TYPE_DRONE), - center, minY, - ch, requirements, - null, null, node.getMaxFollowingDepth() > 0); - evaluatedBeePositions.add(leaf); - return leaf; - } - - - List mutations = getMutationsWithResult(node.getValue()); - float ch = -1; - Collection requirements = new LinkedList(); - if(mutations.size() > 0) { - IBeeMutation mut = mutations.get(0); - ch = mut.getBaseChance(); - try { - requirements = mut.getSpecialConditions(); - } catch (Throwable tr) { - requirements = new LinkedList(); - } - } - - PositionedMutationNodeStack outNode = new PositionedMutationNodeStack( - createStack((IAlleleSpecies) node.getValue(), BEE_TYPE_DRONE), - center, minY, - ch, requirements, - node.getLeftNode() != null ? - placeInRenderBuffer(node.getLeftNode(), - minY + yStep, yStep, - minX, center, iterationMaxCount) - : null, - node.getRightNode() != null ? - placeInRenderBuffer(node.getRightNode(), - minY + yStep, yStep, - center, maxX, iterationMaxCount) - : null, - true); - evaluatedBeePositions.add(outNode); - return outNode; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - CachedBeeMutationTree that = (CachedBeeMutationTree) o; - return !(mutationTree != null ? !mutationTree.equals(that.mutationTree) : that.mutationTree != null); - } - - @Override - public int hashCode() { - return mutationTree != null ? mutationTree.hashCode() : 0; - } - - @Override - public PositionedStack getResult() { - return rootStack; - } - - public PositionedMutationNodeStack getRootStack() { - return rootStack; - } - - @Override - public List getIngredients() { - return new ArrayList(evaluatedBeePositions); - } - - public static class PositionedMutationNodeStack extends PositionedStack { - - public final boolean hasPossibleChildren; - public final float baseChance; - public final Collection requirements; - public final PositionedMutationNodeStack leftChild, rightChild; - - public PositionedMutationNodeStack(Object object, int x, int y, boolean genPerms, - float baseChance, Collection requirementInfo, - PositionedMutationNodeStack leftChild, PositionedMutationNodeStack rightChild, - boolean hasPossibleChildren) { - super(object, x, y, genPerms); - this.leftChild = leftChild; - this.rightChild = rightChild; - this.hasPossibleChildren = hasPossibleChildren; - this.baseChance = baseChance; - this.requirements = requirementInfo; - } - - public PositionedMutationNodeStack(Object object, int x, int y, - float baseChance, Collection requirementInfo, - PositionedMutationNodeStack leftChild, PositionedMutationNodeStack rightChild, - boolean hasPossibleChildren) { - super(object, x, y); - this.leftChild = leftChild; - this.rightChild = rightChild; - this.hasPossibleChildren = hasPossibleChildren; - this.baseChance = baseChance; - this.requirements = requirementInfo; - } - - } - -} diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/gui/CachedRecipe.java b/src/main/java/hellfirepvp/beebetteratbees/client/gui/CachedRecipe.java deleted file mode 100644 index fa755af..0000000 --- a/src/main/java/hellfirepvp/beebetteratbees/client/gui/CachedRecipe.java +++ /dev/null @@ -1,94 +0,0 @@ -package hellfirepvp.beebetteratbees.client.gui; - -import codechicken.nei.NEIServerUtils; -import codechicken.nei.PositionedStack; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Random; - -/** -* HellFirePvP@Admin -* Date: 28.04.2016 / 23:46 -* on BeeBetterAtBees -* CachedRecipe -*/ -public abstract class CachedRecipe { - - final long offset = System.currentTimeMillis(); - - public abstract PositionedStack getResult(); - - public List getIngredients() { - ArrayList stacks = new ArrayList(); - PositionedStack stack = getIngredient(); - if (stack != null) { - stacks.add(stack); - } - return stacks; - } - - public PositionedStack getIngredient() { - return null; - } - - public List getOtherStacks() { - ArrayList stacks = new ArrayList(); - PositionedStack stack = getOtherStack(); - if (stack != null) { - stacks.add(stack); - } - return stacks; - } - - public PositionedStack getOtherStack() { - return null; - } - - public List getCycledIngredients(int cycle, List ingredients) { - for (int itemIndex = 0; itemIndex < ingredients.size(); itemIndex++) { - randomRenderPermutation(ingredients.get(itemIndex), cycle + itemIndex); - } - return ingredients; - } - - public void randomRenderPermutation(PositionedStack stack, long cycle) { - Random rand = new Random(cycle + this.offset); - stack.setPermutationToRender(Math.abs(rand.nextInt()) % stack.items.length); - } - - public void setIngredientPermutation(Collection ingredients, ItemStack ingredient) { - for (PositionedStack stack : ingredients) { - for (int i = 0; i < stack.items.length; i++) { - if (NEIServerUtils.areStacksSameTypeCrafting(ingredient, stack.items[i])) { - stack.item = stack.items[i]; - stack.item.setTagCompound(ingredient.getTagCompound()); - stack.items = new ItemStack[]{stack.item}; - stack.setPermutationToRender(0); - break; - } - } - } - } - - public boolean contains(Collection ingredients, ItemStack ingredient) { - for (PositionedStack stack : ingredients) { - if (stack.contains(ingredient)) { - return true; - } - } - return false; - } - - public boolean contains(Collection ingredients, Item ingred) { - for (PositionedStack stack : ingredients) { - if (stack.contains(ingred)) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/hellfirepvp/beebetteratbees/client/util/SimpleBinaryTree.java b/src/main/java/hellfirepvp/beebetteratbees/client/util/SimpleBinaryTree.java index 95555de..f28fb84 100644 --- a/src/main/java/hellfirepvp/beebetteratbees/client/util/SimpleBinaryTree.java +++ b/src/main/java/hellfirepvp/beebetteratbees/client/util/SimpleBinaryTree.java @@ -25,14 +25,17 @@ public class SimpleBinaryTree { } private Node buildSubTree(E superNodeValue, int maxFollowingDepth) { + if (maxFollowingDepth <= 0) { + return new Leaf<>(superNodeValue); + } E[] subNodes = rootProvider.provideSubNodes(superNodeValue); - if(subNodes == null || subNodes.length == 0 || maxFollowingDepth <= 0) { - return new Leaf(superNodeValue); + if(subNodes == null || subNodes.length == 0) { + return new Leaf<>(superNodeValue); } else { Node left = buildSubTree(subNodes[0], maxFollowingDepth - 1); Node right = buildSubTree(subNodes[1], maxFollowingDepth - 1); int depth = Math.max(left.getMaxFollowingDepth(), right.getMaxFollowingDepth()); - return new Node(superNodeValue, left, right, depth + 1); + return new Node<>(superNodeValue, left, right, depth + 1); } } diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/BeeBetterAtBees.java b/src/main/java/hellfirepvp/beebetteratbees/common/BeeBetterAtBees.java deleted file mode 100644 index 45be586..0000000 --- a/src/main/java/hellfirepvp/beebetteratbees/common/BeeBetterAtBees.java +++ /dev/null @@ -1,48 +0,0 @@ -package hellfirepvp.beebetteratbees.common; - -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.SidedProxy; -import cpw.mods.fml.common.event.FMLConstructionEvent; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * HellFirePvP@Admin - * Date: 28.04.2016 / 19:50 - * on BeeBetterAtBees - * BeeBetterAtBees - */ -@Mod(modid = BeeBetterAtBees.MODID, name = BeeBetterAtBees.NAME, version = BeeBetterAtBees.VERSION, dependencies = "required-after:NotEnoughItems;required-after:Forestry") -public class BeeBetterAtBees { - - public static final String MODID = "beebetteratbees"; - public static final String NAME = "BeeBetterAtBees"; - - public static final String VERSION = "0.3"; - - private static final String PROXY_CLIENT = "hellfirepvp.beebetteratbees.client.ClientProxy"; - private static final String PROXY_SERVER = "hellfirepvp.beebetteratbees.common.CommonProxy"; - - public static Logger log = LogManager.getLogger(NAME); - - @Mod.Instance(value = MODID) - public static BeeBetterAtBees instance; - - @SidedProxy(clientSide = PROXY_CLIENT, serverSide = PROXY_SERVER) - public static CommonProxy proxy; - - @Mod.EventHandler - public void preInit(FMLPreInitializationEvent event) { - event.getModMetadata().version = VERSION; - ModConfig.init(event.getSuggestedConfigurationFile()); - } - - @Mod.EventHandler - public void postInit(FMLPostInitializationEvent event) { - proxy.registerNEIGUIs(); - } - -} diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/CommonProxy.java b/src/main/java/hellfirepvp/beebetteratbees/common/CommonProxy.java index 2eacee1..0a8377d 100644 --- a/src/main/java/hellfirepvp/beebetteratbees/common/CommonProxy.java +++ b/src/main/java/hellfirepvp/beebetteratbees/common/CommonProxy.java @@ -1,13 +1,11 @@ package hellfirepvp.beebetteratbees.common; /** - * HellFirePvP@Admin - * Date: 28.04.2016 / 19:51 - * on BeeBetterAtBees - * CommonProxy + * This class is part of the BeeBetterAtBees Mod + * Class: CommonProxy + * Created by HellFirePvP + * Date: 10.10.2018 / 23:12 */ public class CommonProxy { - public void registerNEIGUIs() {} - } diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/ModConfig.java b/src/main/java/hellfirepvp/beebetteratbees/common/data/Config.java similarity index 54% rename from src/main/java/hellfirepvp/beebetteratbees/common/ModConfig.java rename to src/main/java/hellfirepvp/beebetteratbees/common/data/Config.java index 444ee8e..55656a5 100644 --- a/src/main/java/hellfirepvp/beebetteratbees/common/ModConfig.java +++ b/src/main/java/hellfirepvp/beebetteratbees/common/data/Config.java @@ -1,40 +1,40 @@ -package hellfirepvp.beebetteratbees.common; +package hellfirepvp.beebetteratbees.common.data; import net.minecraftforge.common.config.Configuration; import java.io.File; /** - * HellFirePvP@Admin - * Date: 01.05.2016 / 22:46 - * on BeeBetterAtBees - * ModConfig + * This class is part of the BeeBetterAtBees Mod + * Class: Config + * Created by HellFirePvP + * Date: 11.10.2018 / 06:38 */ -public class ModConfig { +public class Config { private static Configuration config; public static boolean shouldShowSecretRecipes = false; public static boolean showDuplicateTrees = false; - private ModConfig() {} + private Config() {} public static void init(File file) { config = new Configuration(file); - config.load(); loadFromConfig(); - config.save(); + save(); } private static void loadFromConfig() { - shouldShowSecretRecipes = config.getBoolean("shouldShowSecretMutations", "general", false, "Set this to true, if you wish for the mod to show secret bee mutations."); - showDuplicateTrees = config.getBoolean("shouldShowDuplicateTrees", "general", true, "If this is set to false, it will not show the mutation tree for a specific bee if the same tree is already displayed."); + shouldShowSecretRecipes = config.getBoolean("shouldShowSecretMutations", "general", shouldShowSecretRecipes, "Set this to true, if you wish for the mod to show secret bee mutations."); + showDuplicateTrees = config.getBoolean("shouldShowDuplicateTrees", "general", showDuplicateTrees, "If this is set to false, it will not show the mutation tree for a specific bee if the same tree is already displayed."); } public static void save() { config.save(); } -} \ No newline at end of file + +} diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/integration/ModIntegrationJEI.java b/src/main/java/hellfirepvp/beebetteratbees/common/integration/ModIntegrationJEI.java new file mode 100644 index 0000000..1f76052 --- /dev/null +++ b/src/main/java/hellfirepvp/beebetteratbees/common/integration/ModIntegrationJEI.java @@ -0,0 +1,66 @@ +package hellfirepvp.beebetteratbees.common.integration; + +import com.google.common.collect.Maps; +import forestry.api.apiculture.IAlleleBeeSpecies; +import forestry.api.apiculture.IBeeMutation; +import forestry.api.apiculture.IBeeRoot; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAlleleRegistry; +import forestry.api.genetics.ISpeciesRoot; +import forestry.apiculture.ModuleApiculture; +import forestry.apiculture.items.ItemBeeGE; +import forestry.apiculture.items.ItemRegistryApiculture; +import hellfirepvp.beebetteratbees.common.data.Config; +import hellfirepvp.beebetteratbees.common.integration.jei.BeeTreeRecipeWrapper; +import hellfirepvp.beebetteratbees.common.integration.jei.CategoryBeeTree; +import hellfirepvp.beebetteratbees.common.util.BeeUtil; +import mezz.jei.api.*; +import mezz.jei.api.ingredients.IModIngredientRegistration; +import mezz.jei.api.recipe.IRecipeCategoryRegistration; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * This class is part of the BeeBetterAtBees Mod + * Class: ModIntegrationJEI + * Created by HellFirePvP + * Date: 11.10.2018 / 20:18 + */ +@JEIPlugin +public class ModIntegrationJEI implements IModPlugin { + + public static IBeeRoot beeRoot; + + public static final String idBeeTree = "beebetteratbees.beetree"; + + @Override + public void registerCategories(IRecipeCategoryRegistration registry) { + IGuiHelper guiHelper = registry.getJeiHelpers().getGuiHelper(); + + registry.addRecipeCategories(new CategoryBeeTree(guiHelper)); + } + + @Override + public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { + ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); + if (root == null || !(root instanceof IBeeRoot)) { + throw new IllegalStateException("Forestry bee root not enabled! Is forestry not installed or the bee module not enabled?"); + } + beeRoot = (IBeeRoot) root; + + Map foundRoots = Maps.newHashMap(); + for (IBeeMutation possibleMutation : beeRoot.getMutations(false)) { + if (!Config.shouldShowSecretRecipes && possibleMutation.isSecret()) { + return; + } + IAlleleBeeSpecies rootOfMutation = BeeUtil.getMutationRoot(possibleMutation); + int count = foundRoots.getOrDefault(rootOfMutation.getUID(), 0); + jeiRuntime.getRecipeRegistry().addRecipe(new BeeTreeRecipeWrapper(rootOfMutation, count), idBeeTree); + count++; + foundRoots.put(rootOfMutation.getUID(), count); + } + } + +} diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/integration/jei/BeeTreeRecipeWrapper.java b/src/main/java/hellfirepvp/beebetteratbees/common/integration/jei/BeeTreeRecipeWrapper.java new file mode 100644 index 0000000..6c5697f --- /dev/null +++ b/src/main/java/hellfirepvp/beebetteratbees/common/integration/jei/BeeTreeRecipeWrapper.java @@ -0,0 +1,369 @@ +package hellfirepvp.beebetteratbees.common.integration.jei; + +import com.google.common.collect.Maps; +import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IAlleleBeeSpecies; +import forestry.api.apiculture.IBeeMutation; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleSpecies; +import hellfirepvp.beebetteratbees.client.util.SimpleBinaryTree; +import hellfirepvp.beebetteratbees.common.data.Config; +import hellfirepvp.beebetteratbees.common.util.BeeUtil; +import mezz.jei.api.ingredients.IIngredients; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.client.config.GuiUtils; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.*; +import java.util.List; + +/** + * This class is part of the BeeBetterAtBees Mod + * Class: BeeTreeRecipeWrapper + * Created by HellFirePvP + * Date: 11.10.2018 / 20:20 + */ +public class BeeTreeRecipeWrapper implements IRecipeWrapper { + + private static final int MIN_X = 20, MAX_X = 170; + private static final int X_SEPERATION_THRESHOLD = 7; + private static final int Y_OFFSET = 0; + + private SimpleBinaryTree mutationTree; + private List evaluatedBeePositions; + private PosItemStack rootStack; + + public BeeTreeRecipeWrapper(IAlleleBeeSpecies rootBee, int select) { + this.mutationTree = new SimpleBinaryTree<>(4, rootBee, + new SimpleBinaryTree.RootProvider() { + @Override + public IAlleleBeeSpecies[] provideSubNodes(IAlleleBeeSpecies superNode) { + List mutations = BeeUtil.getMutationsWithResult(superNode); + if(mutations.size() > 0) { + IBeeMutation mutation = mutations.get(superNode == rootBee ? MathHelper.clamp(select, 0, mutations.size() - 1) : 0); + + return new IAlleleBeeSpecies[] { + (IAlleleBeeSpecies) mutation.getAllele0(), + (IAlleleBeeSpecies) mutation.getAllele1() + }; + } else { + return null; + } + } + }); + + + if(!Config.showDuplicateTrees) { + List foundMutationTrees = new ArrayList<>(); + removeAndReplaceDuplicates(this.mutationTree.getRoot(), foundMutationTrees); + } + + //Important: We don't need to buffer root, because that's the "result" + this.evaluatedBeePositions = new LinkedList<>(); + int iterationDepth = 3; + int maxTotalDepth = Math.min(iterationDepth, mutationTree.getRoot().getMaxFollowingDepth()); + if(maxTotalDepth <= 0) { + return; //In case the root is a leaf, there is nothing to display anyway except the root. + } + int yStep = 110 / maxTotalDepth; + + boolean oversized = checkSeparationWidth(maxTotalDepth, X_SEPERATION_THRESHOLD); + int evaluatedMaxX = /*this.oversized ? buildNewMaxX(maxTotalDepth, X_SEPERATION_THRESHOLD) :*/ MAX_X; + + int center = (MIN_X + evaluatedMaxX) / 2; + PosItemStack leftChild = placeInRenderBuffer(mutationTree.getRoot().getLeftNode(), + Y_OFFSET + yStep, yStep, + MIN_X, center, iterationDepth - 1); + PosItemStack rightChild = placeInRenderBuffer(mutationTree.getRoot().getRightNode(), + Y_OFFSET + yStep, yStep, + center, evaluatedMaxX, iterationDepth - 1); + + List mutationsToRoot = BeeUtil.getMutationsWithResult(mutationTree.getRoot().getValue()); + float ch = -1; + List requirements = new LinkedList<>(); + if(mutationsToRoot.size() > 0) { + IBeeMutation mut = mutationsToRoot.get(0); + ch = mut.getBaseChance(); + try { + requirements.addAll(mut.getSpecialConditions()); + } catch (Throwable tr) {} + } + + this.rootStack = new PosItemStack( + mutationTree.getRoot().getValue(), + (MIN_X + evaluatedMaxX) / 2, Y_OFFSET, + ch, requirements, + leftChild, rightChild, true); + } + + private void removeAndReplaceDuplicates(SimpleBinaryTree.Node node, List discoveredMutations) { //Replace with 2 lines. + if(discoveredMutations.contains(node.getValue())) { + List mutations = BeeUtil.getMutationsWithResult(node.getValue()); + if(mutations.size() > 0) node.removeDuplicate(); //Only if it actually has mutations that has this node as result. + } else { + discoveredMutations.add(node.getValue()); + if(node.getMaxFollowingDepth() > 0) { + removeAndReplaceDuplicates(node.getLeftNode(), discoveredMutations); + removeAndReplaceDuplicates(node.getRightNode(), discoveredMutations); + } + } + } + + @Override + public void getIngredients(IIngredients ingredients) { + List inputs = new LinkedList<>(); + this.evaluatedBeePositions.forEach(i -> inputs.add(BeeUtil.createStack(i.beeSpecies, EnumBeeType.DRONE))); + this.evaluatedBeePositions.forEach(i -> inputs.add(BeeUtil.createStack(i.beeSpecies, EnumBeeType.PRINCESS))); + this.evaluatedBeePositions.forEach(i -> inputs.add(BeeUtil.createStack(i.beeSpecies, EnumBeeType.QUEEN))); + this.evaluatedBeePositions.forEach(i -> inputs.add(BeeUtil.createStack(i.beeSpecies, EnumBeeType.LARVAE))); + ingredients.setInputs(ItemStack.class, inputs); + + List outputs = new LinkedList<>(); + outputs.add(BeeUtil.createStack(this.rootStack.beeSpecies, EnumBeeType.DRONE)); + outputs.add(BeeUtil.createStack(this.rootStack.beeSpecies, EnumBeeType.PRINCESS)); + outputs.add(BeeUtil.createStack(this.rootStack.beeSpecies, EnumBeeType.QUEEN)); + outputs.add(BeeUtil.createStack(this.rootStack.beeSpecies, EnumBeeType.LARVAE)); + ingredients.setOutputs(ItemStack.class, outputs); + } + + @Override + public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { + Map> boxes = Maps.newHashMap(); + drawExtrasFrom(this.rootStack, boxes); + for (Map.Entry> etr : boxes.entrySet()) { + if (etr.getKey().contains(mouseX, mouseY)) { + GlStateManager.disableDepth(); + GuiUtils.drawHoveringText(etr.getValue(), mouseX, mouseY, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, minecraft.fontRenderer); + GlStateManager.enableDepth(); + } + } + } + + private static final Color lineColorBlack = new Color(0, 0, 0), + lineColorRed = new Color(169, 0, 10); + + private static final int offsetCorrection = 8; + private static final int possibleChildOffset = 16; + + public static void drawExtrasFrom(PosItemStack nodeStack, Map> infoBoxes) { + int nodeX = nodeStack.posX; + int nodeY = nodeStack.posY; + + if(nodeStack.leftChild == null || + nodeStack.rightChild == null) { + if(nodeStack.hasPossibleChildren) { + + Color drawColor = lineColorBlack; + + if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { + drawColor = lineColorRed; + } + + float chance = nodeStack.baseChance; + if(chance > 0) { + int length = drawChanceInfo(nodeX, nodeY, chance, Minecraft.getMinecraft().fontRenderer, drawColor); + if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { + Rectangle rec = new Rectangle(nodeX + 4, nodeY + 17, (int) (length * 0.75F), 5); + infoBoxes.put(rec, nodeStack.requirements); + } + } + + drawLine( + nodeX + offsetCorrection, nodeY + offsetCorrection, + nodeX + offsetCorrection - 4, + nodeY + offsetCorrection + possibleChildOffset, + drawColor); + drawLine( + nodeX + offsetCorrection, nodeY + offsetCorrection, + nodeX + offsetCorrection + 4, + nodeY + offsetCorrection + possibleChildOffset, + drawColor); + } + return; //Has no children anymore. + } + + Color drawColor = lineColorBlack; + + if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { + drawColor = lineColorRed; + } + + float chance = nodeStack.baseChance; + if(chance > 0) { + int length = drawChanceInfo(nodeX, nodeY, chance, Minecraft.getMinecraft().fontRenderer, drawColor); + if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) { + Rectangle rec = new Rectangle(nodeX + 4, nodeY + 17, (int) (length * 0.75F), 5); + infoBoxes.put(rec, nodeStack.requirements); + } + } + + PosItemStack left = nodeStack.leftChild; + drawLine( + nodeX + offsetCorrection, nodeY + offsetCorrection, + left.posX + offsetCorrection, left.posY + offsetCorrection, + drawColor); + PosItemStack right = nodeStack.rightChild; + drawLine( + nodeX + offsetCorrection, nodeY + offsetCorrection, + right.posX + offsetCorrection, right.posY + offsetCorrection, + drawColor); + + drawExtrasFrom(left, infoBoxes); + drawExtrasFrom(right, infoBoxes); + } + + private static int drawChanceInfo(int nodeX, int nodeY, float chance, FontRenderer fr, Color drawColor) { + GL11.glPushMatrix(); + GL11.glTranslatef(nodeX + 4, nodeY + 17, 0); + GL11.glScalef(0.65F, 0.65F, 0.65F); + int chAsInt = (int) (chance); + StringBuilder sb = new StringBuilder().append(TextFormatting.BOLD); + if(chAsInt <= 0) { + sb.append("<1%"); + } else { + sb.append(chAsInt).append("%"); + } + int length = fr.drawString(sb.toString(), 0, 0, drawColor.getRGB()); + GL11.glPopMatrix(); + return length; + } + + private static void drawLine(double lx, double ly, double hx, double hy, Color color) { + GlStateManager.pushMatrix(); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + GlStateManager.glLineWidth(3.0F); + GL11.glEnable(GL11.GL_LINE_SMOOTH); + GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + + GL11.glColor4f(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 0.4F); + + Tessellator t = Tessellator.getInstance(); + BufferBuilder vb = t.getBuffer(); + vb.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + vb.pos(lx, ly, 0).endVertex(); + vb.pos(hx, hy, 0).endVertex(); + t.draw(); + + GL11.glColor4f(1F, 1F, 1F, 1F); + GlStateManager.color(1F, 1F, 1F, 1F); + + GL11.glDisable(GL11.GL_LINE_SMOOTH); + GlStateManager.depthMask(false); + GlStateManager.glLineWidth(2.0F); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } + + public List getEvaluatedBeePositions() { + return evaluatedBeePositions; + } + + public PosItemStack getRootStack() { + return rootStack; + } + + private boolean checkSeparationWidth(int maxTotalDepth, int xSeparationThreshold) { + double maxDivision = Math.pow(2, maxTotalDepth + 1); + int resultingLLWidth = (int) (120 / maxDivision); //LowestLevelWidth + return resultingLLWidth < xSeparationThreshold; + } + + private PosItemStack placeInRenderBuffer(SimpleBinaryTree.Node node, int minY, int yStep, int minX, int maxX, int iterationMaxCount) { + int center = (minX + maxX) / 2; + iterationMaxCount--; + if(iterationMaxCount < 0 || node.getMaxFollowingDepth() <= 0) { + List mutationsToRoot = BeeUtil.getMutationsWithResult(node.getValue()); + float ch = -1; + List requirements = new LinkedList<>(); + if(mutationsToRoot.size() > 0) { + IBeeMutation mut = mutationsToRoot.get(0); + ch = mut.getBaseChance(); + try { + requirements.addAll(mut.getSpecialConditions()); + } catch (Throwable tr) { + requirements = new LinkedList<>(); + } + } + PosItemStack leaf = new PosItemStack( //Leaf + node.getValue(), + center, minY, + ch, requirements, + null, null, node.getMaxFollowingDepth() > 0); + evaluatedBeePositions.add(leaf); + return leaf; + } + + + List mutations = BeeUtil.getMutationsWithResult(node.getValue()); + float ch = -1; + List requirements = new LinkedList<>(); + if(mutations.size() > 0) { + IBeeMutation mut = mutations.get(0); + ch = mut.getBaseChance(); + try { + requirements.addAll(mut.getSpecialConditions()); + } catch (Throwable tr) { + requirements = new LinkedList<>(); + } + } + + PosItemStack outNode = new PosItemStack( + node.getValue(), + center, minY, + ch, requirements, + node.getLeftNode() != null ? + placeInRenderBuffer(node.getLeftNode(), + minY + yStep, yStep, + minX, center, iterationMaxCount) + : null, + node.getRightNode() != null ? + placeInRenderBuffer(node.getRightNode(), + minY + yStep, yStep, + center, maxX, iterationMaxCount) + : null, + true); + evaluatedBeePositions.add(outNode); + return outNode; + } + + public static class PosItemStack { + + public final IAlleleBeeSpecies beeSpecies; + public final int posX, posY; + + public final boolean hasPossibleChildren; + public final float baseChance; + public final List requirements; + public final PosItemStack leftChild, rightChild; + + public PosItemStack(IAlleleBeeSpecies species, int x, int y, + float baseChance, List requirementInfo, + PosItemStack leftChild, PosItemStack rightChild, + boolean hasPossibleChildren) { + this.beeSpecies = species; + this.posX = x; + this.posY = y; + this.leftChild = leftChild; + this.rightChild = rightChild; + this.hasPossibleChildren = hasPossibleChildren; + this.baseChance = baseChance; + this.requirements = requirementInfo; + } + + } + +} diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/integration/jei/CategoryBeeTree.java b/src/main/java/hellfirepvp/beebetteratbees/common/integration/jei/CategoryBeeTree.java new file mode 100644 index 0000000..107b6cb --- /dev/null +++ b/src/main/java/hellfirepvp/beebetteratbees/common/integration/jei/CategoryBeeTree.java @@ -0,0 +1,62 @@ +package hellfirepvp.beebetteratbees.common.integration.jei; + +import hellfirepvp.beebetteratbees.BeeBetterAtBees; +import hellfirepvp.beebetteratbees.common.integration.ModIntegrationJEI; +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.gui.IGuiItemStackGroup; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.ingredients.IIngredients; +import mezz.jei.api.recipe.IRecipeCategory; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; + +/** + * This class is part of the BeeBetterAtBees Mod + * Class: CategoryBeeTree + * Created by HellFirePvP + * Date: 11.10.2018 / 20:19 + */ +public class CategoryBeeTree implements IRecipeCategory { + + private final IDrawable background; + + public CategoryBeeTree(IGuiHelper guiHelper) { + ResourceLocation location = new ResourceLocation(BeeBetterAtBees.MODID, "textures/jei/blank.png"); + background = guiHelper.createDrawable(location, 0, 0, 210, 180); + } + + @Override + public String getUid() { + return ModIntegrationJEI.idBeeTree; + } + + @Override + public String getTitle() { + return I18n.format("jei.beebetteratbees.tree"); + } + + @Override + public String getModName() { + return BeeBetterAtBees.NAME; + } + + @Override + public IDrawable getBackground() { + return background; + } + + @Override + public void setRecipe(IRecipeLayout recipeLayout, BeeTreeRecipeWrapper recipeWrapper, IIngredients ingredients) { + IGuiItemStackGroup grp = recipeLayout.getItemStacks(); + + int idx = 0; + grp.init(idx++, false, recipeWrapper.getRootStack().posX, recipeWrapper.getRootStack().posY); + + for (BeeTreeRecipeWrapper.PosItemStack in : recipeWrapper.getEvaluatedBeePositions()) { + grp.init(idx++, true, in.posX, in.posY); + } + + grp.set(ingredients); + } +} diff --git a/src/main/java/hellfirepvp/beebetteratbees/common/util/BeeUtil.java b/src/main/java/hellfirepvp/beebetteratbees/common/util/BeeUtil.java new file mode 100644 index 0000000..9878b0e --- /dev/null +++ b/src/main/java/hellfirepvp/beebetteratbees/common/util/BeeUtil.java @@ -0,0 +1,54 @@ +package hellfirepvp.beebetteratbees.common.util; + +import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IAlleleBeeSpecies; +import forestry.api.apiculture.IBeeMutation; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; +import hellfirepvp.beebetteratbees.BeeBetterAtBees; +import hellfirepvp.beebetteratbees.common.integration.ModIntegrationJEI; +import net.minecraft.item.ItemStack; + +import java.util.LinkedList; +import java.util.List; + +/** + * This class is part of the BeeBetterAtBees Mod + * Class: BeeUtil + * Created by HellFirePvP + * Date: 11.10.2018 / 21:36 + */ +public class BeeUtil { + + public static List getMutationsWithResult(IAllele allele) { + if(ModIntegrationJEI.beeRoot == null) return new LinkedList<>(); + LinkedList out = new LinkedList<>(); + for (IBeeMutation mutation : ModIntegrationJEI.beeRoot.getMutations(false)) { + if(getMutationRoot(mutation).equals(allele)) out.add(mutation); + } + return out; + } + + public static IAlleleBeeSpecies getMutationRoot(IBeeMutation mutation) { + return (IAlleleBeeSpecies) mutation.getTemplate()[0]; + } + + public static ItemStack createStack(IAlleleSpecies species, EnumBeeType type) { + ISpeciesRoot root = species.getRoot(); + IAllele[] template = root.getTemplate(species.getUID()); + if (template == null) { + BeeBetterAtBees.log.warn("Template for %s doesn't exist! Skipping...", species.getUID()); + return ItemStack.EMPTY; + } + IIndividual individual = root.templateAsIndividual(template); + individual.analyze(); + ItemStack stack = root.getMemberStack(individual, type); + if (stack.isEmpty()) { + BeeBetterAtBees.log.warn("Got no MemberStack back when creating bee (%s) ?", species.getUID()); + } + return stack; + } + +} diff --git a/src/main/resources/META-INF/beebetteratbees_at.cfg b/src/main/resources/META-INF/beebetteratbees_at.cfg deleted file mode 100644 index 17e1ce8..0000000 --- a/src/main/resources/META-INF/beebetteratbees_at.cfg +++ /dev/null @@ -1,2 +0,0 @@ -public net.minecraft.client.gui.inventory.GuiContainer field_147003_i #guiLeft -public net.minecraft.client.gui.inventory.GuiContainer field_147009_r #guiTop \ No newline at end of file diff --git a/src/main/resources/assets/beebetteratbees/lang/en_US.lang b/src/main/resources/assets/beebetteratbees/lang/en_US.lang index 06097c7..a00711b 100644 --- a/src/main/resources/assets/beebetteratbees/lang/en_US.lang +++ b/src/main/resources/assets/beebetteratbees/lang/en_US.lang @@ -1 +1 @@ -bbab.gui.breedtree=Bee Breeding Tree \ No newline at end of file +jei.beebetteratbees.tree=Bee Breeding Tree \ No newline at end of file diff --git a/src/main/resources/assets/beebetteratbees/textures/gui/neiBlank.png b/src/main/resources/assets/beebetteratbees/textures/jei/blank.png similarity index 56% rename from src/main/resources/assets/beebetteratbees/textures/gui/neiBlank.png rename to src/main/resources/assets/beebetteratbees/textures/jei/blank.png index cff2ff3..2085b68 100644 Binary files a/src/main/resources/assets/beebetteratbees/textures/gui/neiBlank.png and b/src/main/resources/assets/beebetteratbees/textures/jei/blank.png differ diff --git a/src/main/resources/assets/beebetteratbees/textures/logo.png b/src/main/resources/assets/beebetteratbees/textures/logo.png new file mode 100644 index 0000000..1de82a8 Binary files /dev/null and b/src/main/resources/assets/beebetteratbees/textures/logo.png differ diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 916d8c1..12902a9 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,15 +1,15 @@ [ { "modid": "beebetteratbees", - "name": "BeeBetterAtBees", - "description": "ClientSide NEI Addon to make bees a little less painful", + "name": "Bee Better at Bees", + "description": "JEI-Utility mod that provides a more easily readable bee-breeding guidance", "version": "${version}", "mcversion": "${mcversion}", - "url": "", + "url": "https://minecraft.curseforge.com/projects/beebetteratbees", "updateUrl": "", "authorList": ["HellFirePvP"], - "credits": "", - "logoFile": "", + "credits": "HellFirePvP", + "logoFile": "assets/beebetteratbees/textures/logo.png", "screenshots": [], "dependencies": [] }