commit 2b6f29c3f58a3d4ad727f2c75e7207b4a1a4cf7d Author: WanionCane Date: Mon Oct 31 14:53:26 2016 -0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9356a18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.gradle/ +build/ +out/ +run/ +server/ +eclipse/ +src/META-INF/ +/*.iws +/*.ipr +/*.iml \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f4bbcd2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..636b11c --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# WanionLib +Shared Code Library Used by all WanionCane mods! \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..7977247 --- /dev/null +++ b/build.gradle @@ -0,0 +1,66 @@ +buildscript { + repositories { + mavenCentral() + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/repositories/snapshots/" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' + } +} + +apply plugin: 'forge' + +version = "1.7.10-1.0" +group= "wanion.lib" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = "WanionLib" + +minecraft { + version = "1.7.10-10.13.4.1614-1.7.10" + runDir = "run" +} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +dependencies { + // you may put jars on which you depend on in ./libs + // or you may define them like so.. + //compile "some.group:artifact:version:classifier" + //compile "some.group:artifact:version" + + // real examples + //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env + //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env + + // for more info... + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html + +} + +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':project.minecraft.version + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b761216 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 0000000..678d9d8 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Jul 02 15:54:47 CDT 2014 +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/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /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 0000000..8a0b282 --- /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/wanion/lib/Reference.java b/src/main/java/wanion/lib/Reference.java new file mode 100644 index 0000000..703cbd7 --- /dev/null +++ b/src/main/java/wanion/lib/Reference.java @@ -0,0 +1,19 @@ +package wanion.lib; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +public final class Reference +{ + public static final String MOD_ID = "wanionlib"; + public static final String MOD_NAME = "WanionLib"; + public static final String VERSION = "1.7.10-1.0"; + public static final String ACCEPTED_MINECRAFT = "[1.7.10]"; + + private Reference() {} +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/WanionLib.java b/src/main/java/wanion/lib/WanionLib.java new file mode 100644 index 0000000..e74f5f1 --- /dev/null +++ b/src/main/java/wanion/lib/WanionLib.java @@ -0,0 +1,59 @@ +package wanion.lib; +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.event.FMLLoadCompleteEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import org.apache.logging.log4j.Logger; +import wanion.lib.client.ClientTickHandler; +import wanion.lib.common.Dependencies; + +import static wanion.lib.Reference.*; + +@Mod(modid = MOD_ID, name = MOD_NAME, version = VERSION, acceptedMinecraftVersions = ACCEPTED_MINECRAFT) +public final class WanionLib +{ + @Mod.Instance(MOD_ID) + public static WanionLib instance; + + private Dependencies dependencies = new Dependencies<>(); + private Logger logger; + + public static Dependencies getDependencies() + { + return instance.dependencies; + } + + public static Logger getLogger() + { + return instance.logger; + } + + @SideOnly(Side.CLIENT) + public static ClientTickHandler getClientTickHandler() + { + return instance.dependencies.get(ClientTickHandler.class); + } + + @Mod.EventHandler + public void preInit(final FMLPreInitializationEvent event) + { + logger = event.getModLog(); + } + + @Mod.EventHandler + public void loadComplete(final FMLLoadCompleteEvent event) + { + dependencies = null; + } + + public interface IDependency {} +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/client/ClientTickHandler.java b/src/main/java/wanion/lib/client/ClientTickHandler.java new file mode 100644 index 0000000..b252d3b --- /dev/null +++ b/src/main/java/wanion/lib/client/ClientTickHandler.java @@ -0,0 +1,43 @@ +package wanion.lib.client; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import wanion.lib.WanionLib; +import wanion.lib.client.animation.Animation; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; + +@SideOnly(Side.CLIENT) +public final class ClientTickHandler implements WanionLib.IDependency +{ + private final List registeredAnimations = new ArrayList<>(); + + private ClientTickHandler() + { + FMLCommonHandler.instance().bus().register(this); + } + + public void registerAnimation(@Nonnull final Animation animation) + { + registeredAnimations.add(animation); + } + + @SubscribeEvent + public void tickEvent(final TickEvent.ClientTickEvent event) + { + registeredAnimations.forEach(Animation::updateAnimation); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/client/animation/Animation.java b/src/main/java/wanion/lib/client/animation/Animation.java new file mode 100644 index 0000000..93276d4 --- /dev/null +++ b/src/main/java/wanion/lib/client/animation/Animation.java @@ -0,0 +1,36 @@ +package wanion.lib.client.animation; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nonnull; + +@SideOnly(Side.CLIENT) +public abstract class Animation +{ + private final ResourceLocation[] frames; + protected final int lastFrameIndex; + protected int currentFrame = 0; + + public Animation(@Nonnull final ResourceLocation[] frames) + { + if ((lastFrameIndex = (this.frames = frames).length) - 1 == -1) + throw new RuntimeException("What is an Animation with no frames?"); + } + + public abstract void updateAnimation(); + + public final ResourceLocation getCurrentFrame() + { + return frames[currentFrame]; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/client/animation/ComplexAnimation.java b/src/main/java/wanion/lib/client/animation/ComplexAnimation.java new file mode 100644 index 0000000..0dce10a --- /dev/null +++ b/src/main/java/wanion/lib/client/animation/ComplexAnimation.java @@ -0,0 +1,37 @@ +package wanion.lib.client.animation; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nonnull; + +@SideOnly(Side.CLIENT) +public class ComplexAnimation extends Animation +{ + private final int[] animationStages; + private final int lastStageIndex; + private int currentStage = 0; + + public ComplexAnimation(@Nonnull final ResourceLocation[] frames, final int[] animationStages) + { + super(frames); + lastStageIndex = (this.animationStages = animationStages).length - 1; + } + + @Override + public void updateAnimation() + { + if (++currentStage > lastStageIndex) + currentStage = 0; + currentFrame = animationStages[currentStage]; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java b/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java new file mode 100644 index 0000000..89afa09 --- /dev/null +++ b/src/main/java/wanion/lib/client/animation/ComplexHalfAnimation.java @@ -0,0 +1,33 @@ +package wanion.lib.client.animation; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nonnull; + +@SideOnly(Side.CLIENT) +public final class ComplexHalfAnimation extends ComplexAnimation +{ + private boolean half; + + public ComplexHalfAnimation(@Nonnull final ResourceLocation[] frames, final int[] stages) + { + super(frames, stages); + } + + @Override + public void updateAnimation() + { + if (half ^= true) + super.updateAnimation(); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/client/animation/SimpleAnimation.java b/src/main/java/wanion/lib/client/animation/SimpleAnimation.java new file mode 100644 index 0000000..f13d82d --- /dev/null +++ b/src/main/java/wanion/lib/client/animation/SimpleAnimation.java @@ -0,0 +1,31 @@ +package wanion.lib.client.animation; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nonnull; + +@SideOnly(Side.CLIENT) +public class SimpleAnimation extends Animation +{ + public SimpleAnimation(@Nonnull final ResourceLocation[] frames) + { + super(frames); + } + + @Override + public void updateAnimation() + { + if (++currentFrame > lastFrameIndex) + currentFrame = 0; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java b/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java new file mode 100644 index 0000000..4a7d7ee --- /dev/null +++ b/src/main/java/wanion/lib/client/animation/SimpleHalfAnimation.java @@ -0,0 +1,33 @@ +package wanion.lib.client.animation; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nonnull; + +@SideOnly(Side.CLIENT) +public final class SimpleHalfAnimation extends SimpleAnimation +{ + private boolean half; + + public SimpleHalfAnimation(@Nonnull final ResourceLocation[] frames) + { + super(frames); + } + + @Override + public void updateAnimation() + { + if (half ^= true) + super.updateAnimation(); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/common/Dependencies.java b/src/main/java/wanion/lib/common/Dependencies.java new file mode 100644 index 0000000..33d8e81 --- /dev/null +++ b/src/main/java/wanion/lib/common/Dependencies.java @@ -0,0 +1,82 @@ +package wanion.lib.common; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import javax.annotation.Nonnull; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ParameterizedType; +import java.util.IdentityHashMap; +import java.util.Map; + +@SuppressWarnings("unchecked") +public class Dependencies +{ + private final Map dependencies = new IdentityHashMap<>(); + private final Map> dependenciesWatchers = new IdentityHashMap<>(); + + public final void add(final Class typeClass) + { + if (dependencies.containsKey(typeClass)) + return; + final DependenceWatcher dependenceWatcher = dependenciesWatchers.get(typeClass); + if (dependenceWatcher != null) { + add(dependenceWatcher.instantiate()); + return; + } + try { + final Constructor constructor = typeClass.getDeclaredConstructor(); + constructor.setAccessible(true); + add((I) constructor.newInstance()); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + public final void add(final I instance) + { + final Class typeClass = instance.getClass(); + if (dependencies.containsKey(typeClass)) + return; + dependencies.put(typeClass, instance); + } + + public final I get(final Class typeClass) + { + final I instance = (I) dependencies.get(typeClass); + if (instance != null) + return instance; + add(typeClass); + return (I) dependencies.get(typeClass); + } + + public final boolean contains(final Class typeClass) + { + return dependencies.containsKey(typeClass); + } + + public final void subscribe(final DependenceWatcher dependenceWatcher) + { + if (!dependenciesWatchers.containsKey(dependenceWatcher.dependenceClass)) + dependenciesWatchers.put(dependenceWatcher.dependenceClass, dependenceWatcher); + } + + public abstract class DependenceWatcher + { + private final Class dependenceClass; + + protected DependenceWatcher() + { + this.dependenceClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + } + + @Nonnull + public abstract W instantiate(); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/common/FixedSizeList.java b/src/main/java/wanion/lib/common/FixedSizeList.java new file mode 100644 index 0000000..a64c26d --- /dev/null +++ b/src/main/java/wanion/lib/common/FixedSizeList.java @@ -0,0 +1,107 @@ +package wanion.lib.common; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import javax.annotation.Nonnull; +import java.util.AbstractList; +import java.util.Arrays; +import java.util.Collection; + +@SuppressWarnings("unused") +public class FixedSizeList extends AbstractList +{ + private static final int DEFAULT_CAPACITY = 64; + private final E[] allTheData; + private final int capacity; + private int size; + + @SuppressWarnings("unchecked") + public FixedSizeList() + { + allTheData = (E[]) new Object[capacity = DEFAULT_CAPACITY]; + } + + @SuppressWarnings("unchecked") + public FixedSizeList(int capacity) + { + if (capacity <= 0) + capacity = DEFAULT_CAPACITY; + allTheData = (E[]) new Object[this.capacity = capacity]; + } + + @SuppressWarnings("unchecked") + private FixedSizeList(@Nonnull final Collection collection) + { + allTheData = (E[]) Arrays.copyOf(collection.toArray(), capacity = size = collection.size()); + } + + @Override + public int size() + { + return size; + } + + @Override + public boolean isEmpty() + { + return size == 0; + } + + @Override + public boolean add(final E e) + { + if (size == capacity) + return false; + allTheData[size++] = e; + return true; + } + + @Override + public void add(final int index, E e) + { + allTheData[index] = e; + } + + @Override + public E get(final int index) + { + if (index > size) + return null; + return allTheData[index]; + } + + @Override + public E remove(final int index) + { + if (index >= size) + throw new IndexOutOfBoundsException(); + modCount++; + final E removed = allTheData[index]; + if (size != 1) + System.arraycopy(allTheData, index + 1, allTheData, index, size - index - 1); + allTheData[--size] = null; + return removed; + } + + @Override + @Nonnull + public Object[] toArray() + { + return Arrays.copyOf(allTheData, size); + } + + @SuppressWarnings("unchecked") + @Override + public void clear() + { + modCount++; + while (size > 0) + allTheData[--size] = null; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/common/Instantiator.java b/src/main/java/wanion/lib/common/Instantiator.java new file mode 100644 index 0000000..0f54b57 --- /dev/null +++ b/src/main/java/wanion/lib/common/Instantiator.java @@ -0,0 +1,18 @@ +package wanion.lib.common; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import javax.annotation.Nonnull; + +@FunctionalInterface +public interface Instantiator +{ + @Nonnull + I instantiate(Class moduleThreadClass) throws InstantiationException, IllegalAccessException; +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/common/MetaItem.java b/src/main/java/wanion/lib/common/MetaItem.java new file mode 100644 index 0000000..4799e32 --- /dev/null +++ b/src/main/java/wanion/lib/common/MetaItem.java @@ -0,0 +1,85 @@ +package wanion.lib.common; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry; +import cpw.mods.fml.common.registry.GameData; +import gnu.trove.list.TIntList; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.TIntLongMap; +import gnu.trove.map.TIntObjectMap; +import gnu.trove.set.TIntSet; +import gnu.trove.set.hash.TIntHashSet; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.Collection; + +@SuppressWarnings("unused") +public final class MetaItem +{ + private static final FMLControlledNamespacedRegistry itemRegistry = GameData.getItemRegistry(); + + private MetaItem() {} + + public static int get(final ItemStack itemStack) + { + Item item; + if (itemStack == null || (item = itemStack.getItem()) == null) + return 0; + final int id = itemRegistry.getId(item); + return id > 0 ? item.getDamage(itemStack) == OreDictionary.WILDCARD_VALUE ? id : id | item.getDamage(itemStack) + 1 << 16 : 0; + } + + public static int get(final Item item) + { + if (item == null) + return 0; + final int id = itemRegistry.getIDForObject(item); + return id > 0 ? id | 65536 : 0; + } + + public static ItemStack toItemStack(final int metaItemKey) + { + return metaItemKey > 0 ? new ItemStack(itemRegistry.getRaw(metaItemKey ^ (metaItemKey & 65536)), 0, metaItemKey >> 16) : null; + } + + public static int[] getArray(final Collection itemStackCollection) + { + return getList(itemStackCollection).toArray(); + } + + public static TIntList getList(final Collection itemStackCollection) + { + final TIntList keys = new TIntArrayList(); + int hash; + for (final ItemStack itemStack : itemStackCollection) + if ((hash = get(itemStack)) != 0) + keys.add(hash); + return keys; + } + + public static TIntSet getSet(final Collection itemStackCollection) + { + return new TIntHashSet(getList(itemStackCollection)); + } + + public static void populateMap(final Collection itemStackCollection, final TIntObjectMap map, final E defaultValue) + { + for (final int id : getArray(itemStackCollection)) + map.put(id, defaultValue); + } + + public static void populateMap(final Collection itemStackCollection, final TIntLongMap map, long defaultValue) + { + for (final int id : getArray(itemStackCollection)) + map.put(id, defaultValue); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/common/Util.java b/src/main/java/wanion/lib/common/Util.java new file mode 100644 index 0000000..10d8188 --- /dev/null +++ b/src/main/java/wanion/lib/common/Util.java @@ -0,0 +1,45 @@ +package wanion.lib.common; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.common.registry.GameData; +import net.minecraft.item.ItemStack; + +import java.lang.reflect.Field; + +public final class Util +{ + private Util() {} + + @SuppressWarnings("unchecked") + public static E getField(Class clas, String name, Object instance, Class expectedClass) + { + try { + final Field field = clas.getDeclaredField(name); + field.setAccessible(true); + return (E) expectedClass.cast(field.get(instance)); + } catch (Exception e) { e.printStackTrace(); } + return null; + } + + public static void setField(Class clas, String name, Object instance, E newInstance) + { + try { + final Field field = clas.getDeclaredField(name); + field.setAccessible(true); + field.set(instance, newInstance); + } catch (Exception e) { e.printStackTrace(); } + } + + public static String getModName(final ItemStack itemStack) + { + String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem()); + return name.substring(0, name.indexOf(58)); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/module/AbstractModule.java b/src/main/java/wanion/lib/module/AbstractModule.java new file mode 100644 index 0000000..470ff82 --- /dev/null +++ b/src/main/java/wanion/lib/module/AbstractModule.java @@ -0,0 +1,98 @@ +package wanion.lib.module; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import org.apache.logging.log4j.Logger; +import wanion.lib.WanionLib; +import wanion.lib.common.Instantiator; + +import javax.annotation.Nonnull; +import java.util.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public abstract class AbstractModule +{ + protected final Manager manager; + private final String moduleName; + + protected AbstractModule(@Nonnull final String moduleName, @Nonnull final Instantiator moduleThreadInstantiator) + { + this.moduleName = moduleName; + manager = new Manager(moduleThreadInstantiator); + } + + protected abstract void init(); + + final void start(@Nonnull final LoadStage loadStage, @Nonnull final Manager manager) + { + final List threadList = manager.getInstances(loadStage); + if (threadList.isEmpty()) + return; + final ExecutorService moduleThreadExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + final Logger logger = WanionLib.getLogger(); + try { + final long initialTime = System.nanoTime(); + final List> futureOfThreads = moduleThreadExecutor.invokeAll(threadList); + final long took = System.nanoTime() - initialTime; + for (final Future threadModuleSay : futureOfThreads) + logger.info(threadModuleSay.get()); + logger.info("All " + threadList.size() + " " + moduleName + "s took " + took / 1000000 + "ms to finish. at load stage " + loadStage.name()); + } catch (InterruptedException | ExecutionException e) { + logger.error("Something really bad happened on " + moduleName + " at load stage " + loadStage.name()); + e.printStackTrace(); + } + } + + public static class Manager + { + private final Map>> loadStageMap; + private final Instantiator instantiator; + + public Manager(@Nonnull final Instantiator instantiator) + { + this.instantiator = instantiator; + loadStageMap = new EnumMap<>(LoadStage.class); + for (final LoadStage loadStage : LoadStage.values()) + loadStageMap.put(loadStage, new LinkedHashSet<>()); + } + + public boolean add(@Nonnull final Class moduleThreadClass) + { + final LoadStage loadStage = (moduleThreadClass.isAnnotationPresent(SpecifiedLoadStage.class)) ? moduleThreadClass.getAnnotation(SpecifiedLoadStage.class).stage() : LoadStage.POST_INIT; + final Set> classSet = loadStageMap.get(loadStage); + return !classSet.contains(moduleThreadClass) && classSet.add(moduleThreadClass); + } + + public boolean isEmpty() + { + return loadStageMap.values().stream().allMatch(Set::isEmpty); + } + + public boolean isEmpty(final LoadStage loadStage) + { + return loadStageMap.get(loadStage).isEmpty(); + } + + public List getInstances(final LoadStage loadStage) + { + final List abstractModuleThreads = new ArrayList<>(); + loadStageMap.get(loadStage).forEach(t -> { + try { + abstractModuleThreads.add(instantiator.instantiate(t)); + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + }); + return abstractModuleThreads; + } + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/module/AbstractModuleThread.java b/src/main/java/wanion/lib/module/AbstractModuleThread.java new file mode 100644 index 0000000..34e7c71 --- /dev/null +++ b/src/main/java/wanion/lib/module/AbstractModuleThread.java @@ -0,0 +1,21 @@ +package wanion.lib.module; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import java.util.concurrent.Callable; + +public abstract class AbstractModuleThread implements Callable +{ + protected final String threadName; + + public AbstractModuleThread(String threadName, String moduleName) + { + this.threadName = threadName + " " + moduleName + ": "; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/module/LoadStage.java b/src/main/java/wanion/lib/module/LoadStage.java new file mode 100644 index 0000000..4f521f7 --- /dev/null +++ b/src/main/java/wanion/lib/module/LoadStage.java @@ -0,0 +1,36 @@ +package wanion.lib.module; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.common.event.*; + +import javax.annotation.Nonnull; + +public enum LoadStage +{ + PRE_INIT(FMLPreInitializationEvent.class), + INIT(FMLInitializationEvent.class), + POST_INIT(FMLPostInitializationEvent.class), + LOAD_COMPLETE(FMLLoadCompleteEvent.class); + + public final Class stage; + + LoadStage(Class stage) + { + this.stage = stage; + } + + public static LoadStage getStage(@Nonnull final Class stage) + { + for (final LoadStage loadStage : values()) + if (loadStage.stage == stage) + return loadStage; + return null; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/module/ModuleHandler.java b/src/main/java/wanion/lib/module/ModuleHandler.java new file mode 100644 index 0000000..b387255 --- /dev/null +++ b/src/main/java/wanion/lib/module/ModuleHandler.java @@ -0,0 +1,48 @@ +package wanion.lib.module; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import cpw.mods.fml.common.event.FMLStateEvent; +import gnu.trove.map.hash.THashMap; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public final class ModuleHandler +{ + private final Set> moduleClasses = new HashSet<>(); + private final Map modules = new THashMap<>(); + + public void startModules(final FMLStateEvent event) + { + final LoadStage loadStage = (event != null) ? LoadStage.getStage(event.getClass()) : null; + if (modules.isEmpty() || loadStage == null) + return; + modules.entrySet().forEach(e -> { + final AbstractModule module = e.getKey(); + if (e.getValue() == null) + e.setValue(module.manager); + final AbstractModule.Manager manager = e.getValue(); + if (manager.isEmpty()) + module.init(); + if (!manager.isEmpty(loadStage)) + module.start(loadStage, manager); + }); + } + + public void addModule(final AbstractModule module) + { + Class moduleClass = (module != null) ? module.getClass() : null; + if (moduleClass == null || moduleClasses.contains(moduleClass)) + return; + moduleClasses.add(moduleClass); + modules.put(module, null); + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/module/SpecifiedLoadStage.java b/src/main/java/wanion/lib/module/SpecifiedLoadStage.java new file mode 100644 index 0000000..675d67d --- /dev/null +++ b/src/main/java/wanion/lib/module/SpecifiedLoadStage.java @@ -0,0 +1,23 @@ +package wanion.lib.module; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import javax.annotation.Nonnull; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface SpecifiedLoadStage +{ + @Nonnull + LoadStage stage(); +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/recipe/RecipeHelper.java b/src/main/java/wanion/lib/recipe/RecipeHelper.java new file mode 100644 index 0000000..d9131bd --- /dev/null +++ b/src/main/java/wanion/lib/recipe/RecipeHelper.java @@ -0,0 +1,94 @@ +package wanion.lib.recipe; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import gnu.trove.map.TObjectCharMap; +import gnu.trove.map.hash.THashMap; +import gnu.trove.map.hash.TObjectCharHashMap; +import net.minecraft.item.ItemStack; +import wanion.lib.common.MetaItem; + +import javax.annotation.Nonnull; +import java.util.Map; + +public final class RecipeHelper +{ + private RecipeHelper() {} + + @Nonnull + public static Object[] rawShapeToShape(@Nonnull final Object[] objects) + { + return rawShapeToShape(objects, 3); + } + + @Nonnull + public static Object[] rawShapeToShape(@Nonnull final Object[] objects, final int squareRoot) + { + int f = 1; + final char[][] almostTheShape = new char[squareRoot][squareRoot]; + final TObjectCharMap thingToCharMap = new TObjectCharHashMap<>(); + final Map keyStackMap = new THashMap<>(); + boolean done = false; + for (int x = 0; x < squareRoot && !done; x++) { + for (int y = 0; y < squareRoot && !done; y++) { + final int index = y * squareRoot + x; + if ((done = !(index < objects.length)) || objects[index] == null) + continue; + final Object key = objects[index] instanceof ItemStack ? MetaItem.get((ItemStack) objects[index]) : objects[index]; + if (key instanceof Integer) + keyStackMap.put((Integer) key, (ItemStack) objects[index]); + if (thingToCharMap.containsKey(key)) + almostTheShape[x][y] = thingToCharMap.get(key); + else + thingToCharMap.put(key, almostTheShape[x][y] = (char) f++); + } + } + final Object[] shape = new Object[squareRoot + thingToCharMap.size() * 2]; + for (int i = 0; i < squareRoot; i++) + shape[i] = new String(almostTheShape[i]); + int i = 0; + for (final Object object : thingToCharMap.keySet()) { + shape[squareRoot + (2 * i)] = thingToCharMap.get(object); + shape[squareRoot + 1 + (2 * i++)] = (object instanceof Integer) ? keyStackMap.get(object) : object; + } + return shape; + } + + @Nonnull + public static Object[] rawShapeToShape(@Nonnull final Object[][] objects, final int squareRoot) + { + int f = 1; + final char[][] almostTheShape = new char[objects.length][squareRoot]; + final TObjectCharMap thingToCharMap = new TObjectCharHashMap<>(); + final Map keyStackMap = new THashMap<>(); + for (int y = 0; y < objects.length; y++) { + final Object[] inputArray = objects[y]; + if (inputArray == null) + continue; + for (int x = 0; x < inputArray.length; x++) { + final Object key = inputArray[x] instanceof ItemStack ? MetaItem.get((ItemStack) inputArray[x]) : inputArray[x]; + if (key instanceof Integer) + keyStackMap.put((Integer) key, (ItemStack) inputArray[x]); + if (thingToCharMap.containsKey(key)) + almostTheShape[x][y] = thingToCharMap.get(key); + else + thingToCharMap.put(key, almostTheShape[x][y] = (char) f++); + } + } + final Object[] shape = new Object[objects.length + thingToCharMap.size() * 2]; + for (int i = 0; i < squareRoot; i++) + shape[i] = new String(almostTheShape[i]); + int i = 0; + for (final Object object : thingToCharMap.keySet()) { + shape[squareRoot + (2 * i)] = thingToCharMap.get(object); + shape[squareRoot + 1 + (2 * i++)] = (object instanceof Integer) ? keyStackMap.get(object) : object; + } + return shape; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java b/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java new file mode 100644 index 0000000..cec96ca --- /dev/null +++ b/src/main/java/wanion/lib/recipe/advanced/AbstractRecipeRegistry.java @@ -0,0 +1,128 @@ +package wanion.lib.recipe.advanced; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import gnu.trove.map.TIntObjectMap; +import gnu.trove.map.TLongObjectMap; +import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.map.hash.TLongObjectHashMap; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractRecipeRegistry +{ + public final TLongObjectMap> shapedRecipes = new TLongObjectHashMap<>(); + public final TIntObjectMap> shapelessRecipes = new TIntObjectHashMap<>(); + + public final void addRecipe(@Nonnull final R recipe) + { + final long recipeKey = recipe.getRecipeKey(); + if (recipeKey != 0) { + if (!shapedRecipes.containsKey(recipeKey)) + shapedRecipes.put(recipeKey, new ArrayList<>()); + shapedRecipes.get(recipeKey).add(recipe); + } else { + final int recipeSize = recipe.getRecipeSize(); + if (!shapelessRecipes.containsKey(recipeSize)) + shapelessRecipes.put(recipeSize, new ArrayList<>()); + shapelessRecipes.get(recipeSize).add(recipe); + } + } + + public final void removeRecipe(@Nullable final R recipe) + { + if (recipe == null) + return; + final long recipeKey = recipe.getRecipeKey(); + if (recipeKey != 0) { + final List shapedRecipeList = shapedRecipes.get(recipeKey); + if (shapedRecipeList != null) + shapedRecipeList.remove(recipe); + } else { + final List shapelessRecipeList = shapelessRecipes.get(recipe.getRecipeSize()); + if (shapelessRecipeList != null) + shapelessRecipeList.remove(recipe); + } + } + + public final ItemStack findMatchingRecipe(final InventoryCrafting matrix) + { + final int root = (int) Math.sqrt(matrix.getSizeInventory()); + int offSetX = 0, offSetY = 0, width = 0, height = 0,recipeSize = 0; + long recipeKey = 0; + boolean foundX = false, foundY = false; + for (int x = 0; !foundX && x < root; x++) { + for (int y = 0; !foundX && y < root; y++) + if (matrix.getStackInSlot(y * root + x) != null) + foundX = true; + if (foundX) + offSetX = x; + } + for (int y = 0; !foundY && y < root; y++) { + for (int x = 0; x < root; x++) { + if (matrix.getStackInSlot(y * root + x) != null) + foundY = true; + if (foundY) + offSetY = y; + } + } + for (int y = 0; y < root; y++) { + int x = 0; + while (true) { + final int actualY = offSetY + y; + if (actualY < root) { + final int actualX = offSetX + x++; + if (actualX < root && matrix.getStackInSlot(actualY * root + actualX) != null) { + final int xDifference = actualX - (offSetX - 1); + final int yDifference = actualY - (offSetY - 1); + if (xDifference > width) + width = xDifference; + if (yDifference > height) + height = yDifference; + } else break; + } else break; + } + } + for (int y = 0; y < height; y++) { + final int actualY = offSetY + y; + for (int x = 0; x < width; x++) { + final int actualX = offSetX + x; + if (matrix.getStackInSlot(actualY * root + actualX) != null) { + recipeKey |= 1 << (y * root + x); + recipeSize++; + } + } + } + ItemStack output = null; + final List shapedRecipeList = shapedRecipes.get(recipeKey); + if (shapedRecipeList != null) { + for (R shapedRecipe : shapedRecipeList) { + output = shapedRecipe.recipeMatch(matrix, offSetX, offSetY); + if (output != null) + break; + } + } + if (output == null) { + final List shapelessRecipeList = shapelessRecipes.get(recipeSize); + if (shapelessRecipeList != null) { + for (R shapelessRecipe : shapelessRecipeList) { + output = shapelessRecipe.recipeMatch(matrix, offSetX, offSetY); + if (output != null) + break; + } + } + } + return output; + } +} \ No newline at end of file diff --git a/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java b/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java new file mode 100644 index 0000000..f91a8d9 --- /dev/null +++ b/src/main/java/wanion/lib/recipe/advanced/IAdvancedRecipe.java @@ -0,0 +1,26 @@ +package wanion.lib.recipe.advanced; + +/* + * Created by WanionCane(https://github.com/WanionCane). + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public interface IAdvancedRecipe +{ + long getRecipeKey(); + + int getRecipeSize(); + + ItemStack recipeMatch(@Nonnull final InventoryCrafting inventoryCrafting, final int offSetX, final int offSetY); + + @Nonnull + ItemStack getOutput(); +} \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..8746dfc --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,16 @@ +[ +{ + "modid": "wanionlib", + "name": "WanionLib", + "description": "Shared Code Library Used by all WanionCane mods!", + "version": "1.0", + "mcversion": "${mcversion}", + "url": "http://minecraft.curseforge.com/projects/wanion-lib", + "updateUrl": "", + "authorList": ["WanionCane"], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] +} +]