commit 419ac849d02f4086b52d9da644ca432eb8564932 Author: jaredlll08 Date: Sun Jan 11 21:59:45 2015 +0200 Initial Comment diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2824c52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +/LICENSE-fml.txt +/MinecraftForge-Credits.txt +/MinecraftForge-License.txt +/README.txt +/CREDITS-fml.txt +/forge-1.7.2* +/build +/common +/eclipse/* +/.gradle +/bin/* +.classpath +.project +.settings/* +src/api/resources/* +run/ +.metadata/ +/.nb-gradle/private/ +/mods/* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dc3b8de --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 joshiejack + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f28a724 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +ModTweaker +========== +ModTweaker is an addon for MineTweaker 3. Minetweaker lets you adjust recipes, remove them entirely, or add new recipes. While it has decent mod support, there are many mods that use custom crafting handlers that are not supported natively. ModTweaker plans to provide additional support for as many of these mods over time as possible. \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..3c63696 --- /dev/null +++ b/build.gradle @@ -0,0 +1,47 @@ +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 = "${mod_version}" +group= "modtweaker" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = "ModTweaker 2" + +minecraft { + version = "${mc_version}-${forge_version}" + runDir = "eclipse" +} + +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.properties b/gradle.properties new file mode 100644 index 0000000..471bb42 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +mc_version=1.7.10 +forge_version=10.13.2.1284 +mod_version=0.3.0 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/libs/Baubles-deobf-1.7.10-1.0.1.10.jar b/libs/Baubles-deobf-1.7.10-1.0.1.10.jar new file mode 100644 index 0000000..8585569 Binary files /dev/null and b/libs/Baubles-deobf-1.7.10-1.0.1.10.jar differ diff --git a/libs/Botania r1.3-149-deobf.jar b/libs/Botania r1.3-149-deobf.jar new file mode 100644 index 0000000..42ad927 Binary files /dev/null and b/libs/Botania r1.3-149-deobf.jar differ diff --git a/libs/CoFHCore-[1.7.10]3.0.0B9-40.jar b/libs/CoFHCore-[1.7.10]3.0.0B9-40.jar new file mode 100644 index 0000000..34fa3e5 Binary files /dev/null and b/libs/CoFHCore-[1.7.10]3.0.0B9-40.jar differ diff --git a/libs/CoFHLib-[1.7.10]1.0.0B8-34.jar b/libs/CoFHLib-[1.7.10]1.0.0B8-34.jar new file mode 100644 index 0000000..7e8e347 Binary files /dev/null and b/libs/CoFHLib-[1.7.10]1.0.0B8-34.jar differ diff --git a/libs/Ex-Nihilo-1.37-dev.jar b/libs/Ex-Nihilo-1.37-dev.jar new file mode 100644 index 0000000..8e0ee8f Binary files /dev/null and b/libs/Ex-Nihilo-1.37-dev.jar differ diff --git a/libs/HardcoreEnderExpansion MC-1.7.10 v1.-dev.jar b/libs/HardcoreEnderExpansion MC-1.7.10 v1.-dev.jar new file mode 100644 index 0000000..04681f9 Binary files /dev/null and b/libs/HardcoreEnderExpansion MC-1.7.10 v1.-dev.jar differ diff --git a/libs/Mantle-1.7.10-0.3.2.jenkins187-deobf.jar b/libs/Mantle-1.7.10-0.3.2.jenkins187-deobf.jar new file mode 100644 index 0000000..90abb3f Binary files /dev/null and b/libs/Mantle-1.7.10-0.3.2.jenkins187-deobf.jar differ diff --git a/libs/Mariculture-Deluxe-1.7.10-deobf.jar b/libs/Mariculture-Deluxe-1.7.10-deobf.jar new file mode 100644 index 0000000..9e5053d Binary files /dev/null and b/libs/Mariculture-Deluxe-1.7.10-deobf.jar differ diff --git a/libs/MekanismAll-1.7.10-7.1.2.homebaked-dev.jar b/libs/MekanismAll-1.7.10-7.1.2.homebaked-dev.jar new file mode 100644 index 0000000..dadf1de Binary files /dev/null and b/libs/MekanismAll-1.7.10-7.1.2.homebaked-dev.jar differ diff --git a/libs/Metallurgy-1.7.10-4.0.6.80-deobf.jar b/libs/Metallurgy-1.7.10-4.0.6.80-deobf.jar new file mode 100644 index 0000000..a09d3cc Binary files /dev/null and b/libs/Metallurgy-1.7.10-4.0.6.80-deobf.jar differ diff --git a/libs/MetallurgyCore-1.7.10-4.0.4.18-deobf.jar b/libs/MetallurgyCore-1.7.10-4.0.4.18-deobf.jar new file mode 100644 index 0000000..23584e4 Binary files /dev/null and b/libs/MetallurgyCore-1.7.10-4.0.4.18-deobf.jar differ diff --git a/libs/MineTweaker3-Dev-1.7.10-3.0.9C.jar b/libs/MineTweaker3-Dev-1.7.10-3.0.9C.jar new file mode 100644 index 0000000..7f5b529 Binary files /dev/null and b/libs/MineTweaker3-Dev-1.7.10-3.0.9C.jar differ diff --git a/libs/PneumaticCraft-1.7.10-1.5.2-50-userdev.jar b/libs/PneumaticCraft-1.7.10-1.5.2-50-userdev.jar new file mode 100644 index 0000000..cf7d705 Binary files /dev/null and b/libs/PneumaticCraft-1.7.10-1.5.2-50-userdev.jar differ diff --git a/libs/Railcraft_1.7.10-9.4.0.0-dev.jar b/libs/Railcraft_1.7.10-9.4.0.0-dev.jar new file mode 100644 index 0000000..d77da66 Binary files /dev/null and b/libs/Railcraft_1.7.10-9.4.0.0-dev.jar differ diff --git a/libs/Steamcraft-0.27.3-dev.jar b/libs/Steamcraft-0.27.3-dev.jar new file mode 100644 index 0000000..a58eba7 Binary files /dev/null and b/libs/Steamcraft-0.27.3-dev.jar differ diff --git a/libs/TConstruct-1.7.10-1.8.2.build858-deobf.jar b/libs/TConstruct-1.7.10-1.8.2.build858-deobf.jar new file mode 100644 index 0000000..78f966f Binary files /dev/null and b/libs/TConstruct-1.7.10-1.8.2.build858-deobf.jar differ diff --git a/libs/Thaumcraft-deobf-1.7.10-4.2.3.0.jar b/libs/Thaumcraft-deobf-1.7.10-4.2.3.0.jar new file mode 100644 index 0000000..1bdded9 Binary files /dev/null and b/libs/Thaumcraft-deobf-1.7.10-4.2.3.0.jar differ diff --git a/libs/ThermalExpansion-[1.7.10]4.0.0B5-dev-13.jar b/libs/ThermalExpansion-[1.7.10]4.0.0B5-dev-13.jar new file mode 100644 index 0000000..9430f84 Binary files /dev/null and b/libs/ThermalExpansion-[1.7.10]4.0.0B5-dev-13.jar differ diff --git a/libs/ThermalFoundation-[1.7.10]1.0.0B3-dev-8 (1).jar b/libs/ThermalFoundation-[1.7.10]1.0.0B3-dev-8 (1).jar new file mode 100644 index 0000000..3e8fa02 Binary files /dev/null and b/libs/ThermalFoundation-[1.7.10]1.0.0B3-dev-8 (1).jar differ diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java b/src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java new file mode 100644 index 0000000..d34dd41 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/ColourAndCoords.java @@ -0,0 +1,45 @@ +package WayofTime.alchemicalWizardry.api; + +import net.minecraft.nbt.NBTTagCompound; + +public class ColourAndCoords +{ + public int colourRed; + public int colourGreen; + public int colourBlue; + public int colourIntensity; + + public int xCoord; + public int yCoord; + public int zCoord; + + public ColourAndCoords(int red, int green, int blue, int intensity, int x, int y, int z) + { + this.colourRed = red; + this.colourGreen = green; + this.colourBlue = blue; + this.colourIntensity = intensity; + + this.xCoord = x; + this.yCoord = y; + this.zCoord = z; + } + + public static ColourAndCoords readFromNBT(NBTTagCompound tag) + { + return new ColourAndCoords(tag.getInteger("colourRed"), tag.getInteger("colourGreen"), tag.getInteger("colourBlue"), tag.getInteger("colourIntensity"), tag.getInteger("xCoord"), tag.getInteger("yCoord"), tag.getInteger("zCoord")); + } + + public NBTTagCompound writeToNBT(NBTTagCompound tag) + { + tag.setInteger("colourRed", colourRed); + tag.setInteger("colourGreen", colourGreen); + tag.setInteger("colourBlue", colourBlue); + tag.setInteger("colourIntensity", colourIntensity); + tag.setInteger("xCoord", xCoord); + tag.setInteger("yCoord", yCoord); + tag.setInteger("zCoord", zCoord); + + return tag; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java new file mode 100644 index 0000000..6af0491 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemicalPotionCreationHandler.java @@ -0,0 +1,79 @@ +package WayofTime.alchemicalWizardry.api.alchemy; + +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; + +public class AlchemicalPotionCreationHandler +{ + public static ArrayList registeredPotionEffects = new ArrayList(); + + public static void addPotion(ItemStack itemStack, int potionID, int tickDuration) + { + registeredPotionEffects.add(new AlchemyPotionHandlerComponent(itemStack, potionID, tickDuration)); + } + + public static int getPotionIDForStack(ItemStack itemStack) + { + for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects) + { + if (aphc.compareItemStack(itemStack)) + { + return aphc.getPotionID(); + } + } + + return -1; + } + + public static int getPotionTickDurationForStack(ItemStack itemStack) + { + { + for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects) + { + if (aphc.compareItemStack(itemStack)) + { + return aphc.getTickDuration(); + } + } + + return -1; + } + } + + public static boolean containsRegisteredPotionIngredient(ItemStack[] stackList) + { + for (ItemStack is : stackList) + { + for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects) + { + if (aphc.compareItemStack(is)) + { + return true; + } + } + } + + return false; + } + + public static int getRegisteredPotionIngredientPosition(ItemStack[] stackList) + { + int i = 0; + + for (ItemStack is : stackList) + { + for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects) + { + if (aphc.compareItemStack(is)) + { + return i; + } + } + + i++; + } + + return -1; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyPotionHandlerComponent.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyPotionHandlerComponent.java new file mode 100644 index 0000000..6f0d461 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyPotionHandlerComponent.java @@ -0,0 +1,52 @@ +package WayofTime.alchemicalWizardry.api.alchemy; + +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class AlchemyPotionHandlerComponent +{ + private ItemStack itemStack; + private int potionID; + private int tickDuration; + + public AlchemyPotionHandlerComponent(ItemStack itemStack, int potionID, int tickDuration) + { + this.itemStack = itemStack; + this.potionID = potionID; + this.tickDuration = tickDuration; + } + + public boolean compareItemStack(ItemStack comparedStack) + { + if (comparedStack != null && itemStack != null) + { + if (comparedStack.getItem() instanceof ItemBlock) + { + if (itemStack.getItem() instanceof ItemBlock) + { + return comparedStack.getItem().equals(itemStack.getItem()) && comparedStack.getItemDamage() == itemStack.getItemDamage(); + } + } else if (!(itemStack.getItem() instanceof ItemBlock)) + { + return comparedStack.getItem().equals(itemStack.getItem()) && comparedStack.getItemDamage() == itemStack.getItemDamage(); + } + } + + return false; + } + + public ItemStack getItemStack() + { + return itemStack; + } + + public int getPotionID() + { + return this.potionID; + } + + public int getTickDuration() + { + return this.tickDuration; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyPotionHelper.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyPotionHelper.java new file mode 100644 index 0000000..d346255 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyPotionHelper.java @@ -0,0 +1,76 @@ +package WayofTime.alchemicalWizardry.api.alchemy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +public class AlchemyPotionHelper +{ + private int potionID; + private int tickDuration; + private int concentration; + private int durationFactor; + + public AlchemyPotionHelper(int potionID, int tickDuration, int concentration, int durationFactor) + { + this.potionID = potionID; + this.tickDuration = tickDuration; + this.concentration = concentration; + this.durationFactor = durationFactor; + } + + public void setConcentration(int concentration) + { + this.concentration = concentration; + } + + public void setDurationFactor(int durationFactor) + { + this.durationFactor = durationFactor; + } + + public int getPotionID() + { + return this.potionID; + } + + public int getTickDuration() + { + return this.tickDuration; + } + + public int getConcentration() + { + return this.concentration; + } + + public int getdurationFactor() + { + return this.durationFactor; + } + + public PotionEffect getPotionEffect() + { + if (potionID == Potion.heal.id || potionID == Potion.harm.id) + { + return (new PotionEffect(potionID, 1, concentration)); + } + + return (new PotionEffect(potionID, (int) (tickDuration * Math.pow(0.5f, concentration) * Math.pow(8.0f / 3.0f, durationFactor)), concentration)); + } + + public static AlchemyPotionHelper readEffectFromNBT(NBTTagCompound tagCompound) + { + return new AlchemyPotionHelper(tagCompound.getInteger("potionID"), tagCompound.getInteger("tickDuration"), tagCompound.getInteger("concentration"), tagCompound.getInteger("durationFactor")); + } + + public static NBTTagCompound setEffectToNBT(AlchemyPotionHelper aph) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setInteger("potionID", aph.getPotionID()); + tagCompound.setInteger("tickDuration", aph.getTickDuration()); + tagCompound.setInteger("concentration", aph.getConcentration()); + tagCompound.setInteger("durationFactor", aph.getdurationFactor()); + return tagCompound; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java new file mode 100644 index 0000000..aad27ee --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipe.java @@ -0,0 +1,143 @@ +package WayofTime.alchemicalWizardry.api.alchemy; + +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +public class AlchemyRecipe +{ + private ItemStack output; + private ItemStack[] recipe; + private int bloodOrbLevel; + private int amountNeeded; + + public AlchemyRecipe(ItemStack output, int amountNeeded, ItemStack[] recipe, int bloodOrbLevel) + { + this.output = output; + this.recipe = recipe; + this.amountNeeded = amountNeeded; + this.bloodOrbLevel = bloodOrbLevel; + } + + public boolean doesRecipeMatch(ItemStack[] items, int slottedBloodOrbLevel) + { + if (slottedBloodOrbLevel < bloodOrbLevel) + { + return false; + } + + ItemStack[] recipe = new ItemStack[5]; + + if (items.length < 5) + { + return false; + } + + if (this.recipe.length != 5) + { + ItemStack[] newRecipe = new ItemStack[5]; + + for (int i = 0; i < 5; i++) + { + if (i + 1 > this.recipe.length) + { + newRecipe[i] = null; + } else + { + newRecipe[i] = this.recipe[i]; + } + } + + recipe = newRecipe; + } else + { + recipe = this.recipe; + } + + boolean[] checkList = new boolean[5]; + + for (int i = 0; i < 5; i++) + { + checkList[i] = false; + } + + for (int i = 0; i < 5; i++) + { + ItemStack recipeItemStack = recipe[i]; + + if (recipeItemStack == null) + { + continue; + } + + boolean test = false; + + for (int j = 0; j < 5; j++) + { + if (checkList[j]) + { + continue; + } + + ItemStack checkedItemStack = items[j]; + + if (checkedItemStack == null) + { + continue; + } + + boolean quickTest = false; + + if (recipeItemStack.getItem() instanceof ItemBlock) + { + if (checkedItemStack.getItem() instanceof ItemBlock) + { + quickTest = true; + } + } else if (!(checkedItemStack.getItem() instanceof ItemBlock)) + { + quickTest = true; + } + + if (!quickTest) + { + continue; + } + + if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage() || OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage()) && checkedItemStack.getItem() == recipeItemStack.getItem()) + { + test = true; + checkList[j] = true; + break; + } + } + + if (!test) + { + return false; + } + } + + return true; + } + + public ItemStack getResult() + { + return output.copy(); + } + + public int getAmountNeeded() + { + return this.amountNeeded; + } + + public ItemStack[] getRecipe() + { + return this.recipe; + } + + public int getOrbLevel() + { + return this.bloodOrbLevel; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java new file mode 100644 index 0000000..dfb2459 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/AlchemyRecipeRegistry.java @@ -0,0 +1,85 @@ +package WayofTime.alchemicalWizardry.api.alchemy; + +import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class AlchemyRecipeRegistry +{ + public static List recipes = new ArrayList(); + + public static void registerRecipe(ItemStack output, int amountNeeded, ItemStack[] recipe, int bloodOrbLevel) + { + recipes.add(new AlchemyRecipe(output, amountNeeded, recipe, bloodOrbLevel)); + } + + public static ItemStack getResult(ItemStack[] recipe, ItemStack bloodOrb) + { + if (bloodOrb == null) + { + return null; + } + + if (!(bloodOrb.getItem() instanceof IBloodOrb)) + { + return null; + } + + int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel(); + + for (AlchemyRecipe ar : recipes) + { + if (ar.doesRecipeMatch(recipe, bloodOrbLevel)) + { + return (ar.getResult()); + } + } + + return null; + } + + public static int getAmountNeeded(ItemStack[] recipe, ItemStack bloodOrb) + { + if (bloodOrb == null) + { + return 0; + } + + if (!(bloodOrb.getItem() instanceof IBloodOrb)) + { + return 0; + } + + int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel(); + + for (AlchemyRecipe ar : recipes) + { + if (ar.doesRecipeMatch(recipe, bloodOrbLevel)) + { + return (ar.getAmountNeeded()); + } + } + + return 0; + } + + public static ItemStack[] getRecipeForItemStack(ItemStack itemStack) + { + for (AlchemyRecipe ar : recipes) + { + ItemStack result = ar.getResult(); + + if (result != null) + { + if (result.isItemEqual(itemStack)) + { + return ar.getRecipe(); + } + } + } + + return null; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java new file mode 100644 index 0000000..8b3e227 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IAlchemyGoggles.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IAlchemyGoggles +{ + public boolean showIngameHUD(World world, ItemStack stack, EntityPlayer player); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java new file mode 100644 index 0000000..804fa72 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentContainer.java @@ -0,0 +1,16 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +public interface IReagentContainer +{ + public ReagentStack getReagent(); + + public int getReagentStackAmount(); + + public int getCapacity(); + + public int fill(ReagentStack resource, boolean doFill); + + public ReagentStack drain(int maxDrain, boolean doDrain); + + public ReagentContainerInfo getInfo(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java new file mode 100644 index 0000000..165e9ab --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/IReagentHandler.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IReagentHandler +{ + int fill(ForgeDirection from, ReagentStack resource, boolean doFill); + + ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain); + + ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain); + + boolean canFill(ForgeDirection from, Reagent reagent); + + boolean canDrain(ForgeDirection from, Reagent reagent); + + ReagentContainerInfo[] getContainerInfo(ForgeDirection from); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java new file mode 100644 index 0000000..14cb51c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ISegmentedReagentHandler.java @@ -0,0 +1,14 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import java.util.Map; + +public interface ISegmentedReagentHandler extends IReagentHandler +{ + public int getNumberOfTanks(); + + public int getTanksTunedToReagent(Reagent reagent); + + public void setTanksTunedToReagent(Reagent reagent, int total); + + public Map getAttunedTankMap(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java new file mode 100644 index 0000000..1abbc0b --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java @@ -0,0 +1,52 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +public class Reagent +{ + public final String name; + + public static final int REAGENT_SIZE = 1000; + + private int colourRed = 0; + private int colourGreen = 0; + private int colourBlue = 0; + private int colourIntensity = 255; + + public Reagent(String name) + { + this.name = name; + } + + public void setColour(int red, int green, int blue, int intensity) + { + this.colourRed = red; + this.colourGreen = green; + this.colourBlue = blue; + this.colourIntensity = intensity; + } + + public int getColourRed() + { + return colourRed; + } + + public int getColourGreen() + { + return colourGreen; + } + + public int getColourBlue() + { + return colourBlue; + } + + public int getColourIntensity() + { + return colourIntensity; + } + + @Override + public boolean equals(Object o) + { + return o instanceof Reagent ? this == o && name.equals(((Reagent) o).name) : false; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java new file mode 100644 index 0000000..c135274 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainer.java @@ -0,0 +1,153 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; + +public class ReagentContainer implements IReagentContainer +{ + protected ReagentStack reagentStack; + protected int capacity; + + public ReagentContainer(int capacity) + { + this(null, capacity); + } + + public ReagentContainer(ReagentStack stack, int capacity) + { + this.reagentStack = stack; + this.capacity = capacity; + } + + public ReagentContainer(Reagent reagent, int amount, int capacity) + { + this(new ReagentStack(reagent, amount), capacity); + } + + public static ReagentContainer readFromNBT(NBTTagCompound nbt) + { + ReagentStack reagent = ReagentStack.loadReagentStackFromNBT(nbt); + int capacity = nbt.getInteger("capacity"); + + if (reagent != null) + { + return new ReagentContainer(reagent, capacity); + } else + { + return new ReagentContainer(null, capacity); + } + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) + { + if (reagentStack != null) + { + reagentStack.writeToNBT(nbt); + } + + nbt.setInteger("capacity", capacity); + + return nbt; + } + + @Override + public ReagentStack getReagent() + { + return reagentStack; + } + + @Override + public int getReagentStackAmount() + { + if (reagentStack == null) + { + return 0; + } + return reagentStack.amount; + } + + @Override + public int getCapacity() + { + return capacity; + } + + @Override + public int fill(ReagentStack resource, boolean doFill) + { + if (resource == null) + { + return 0; + } + + if (!doFill) + { + if (reagentStack == null) + { + return Math.min(capacity, resource.amount); + } + + if (!reagentStack.isReagentEqual(resource)) + { + return 0; + } + + return Math.min(capacity - reagentStack.amount, resource.amount); + } + + if (reagentStack == null) + { + reagentStack = new ReagentStack(resource, Math.min(capacity, resource.amount)); + + return reagentStack.amount; + } + + if (!reagentStack.isReagentEqual(resource)) + { + return 0; + } + int filled = capacity - reagentStack.amount; + + if (resource.amount < filled) + { + reagentStack.amount += resource.amount; + filled = resource.amount; + } else + { + reagentStack.amount = capacity; + } + + return filled; + } + + @Override + public ReagentStack drain(int maxDrain, boolean doDrain) + { + if (reagentStack == null) + { + return null; + } + + int drained = maxDrain; + if (reagentStack.amount < drained) + { + drained = reagentStack.amount; + } + + ReagentStack stack = new ReagentStack(reagentStack, drained); + if (doDrain) + { + reagentStack.amount -= drained; + if (reagentStack.amount <= 0) + { + reagentStack = null; + } + } + return stack; + } + + @Override + public ReagentContainerInfo getInfo() + { + return new ReagentContainerInfo(this); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java new file mode 100644 index 0000000..99521dc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentContainerInfo.java @@ -0,0 +1,19 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +public final class ReagentContainerInfo +{ + public final ReagentStack reagent; + public final int capacity; + + public ReagentContainerInfo(ReagentStack reagent, int capacity) + { + this.reagent = reagent; + this.capacity = capacity; + } + + public ReagentContainerInfo(IReagentContainer tank) + { + this.reagent = tank.getReagent(); + this.capacity = tank.getCapacity(); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java new file mode 100644 index 0000000..20b4393 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentRegistry.java @@ -0,0 +1,174 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import net.minecraft.item.ItemStack; + +public class ReagentRegistry +{ + public static Map reagentList = new HashMap(); + public static Map itemToReagentMap = new HashMap(); + + public static Reagent sanctusReagent; + public static Reagent incendiumReagent; + public static Reagent aquasalusReagent; + public static Reagent magicalesReagent; + public static Reagent aetherReagent; + public static Reagent crepitousReagent; + public static Reagent crystallosReagent; + public static Reagent terraeReagent; + public static Reagent tenebraeReagent; + + public static Reagent offensaReagent; + public static Reagent praesidiumReagent; + public static Reagent orbisTerraeReagent; + public static Reagent virtusReagent; + public static Reagent reductusReagent; + public static Reagent potentiaReagent; + + public static void initReagents() + { + sanctusReagent = new Reagent("sanctus"); + incendiumReagent = new Reagent("incendium"); + aquasalusReagent = new Reagent("aquasalus"); + magicalesReagent = new Reagent("magicales"); + aetherReagent = new Reagent("aether"); + crepitousReagent = new Reagent("crepitous"); + crystallosReagent = new Reagent("crystallos"); + terraeReagent = new Reagent("terrae"); + tenebraeReagent = new Reagent("tenebrae"); + offensaReagent = new Reagent("offensa"); + praesidiumReagent = new Reagent("praesidium"); + orbisTerraeReagent = new Reagent("orbisTerrae"); + virtusReagent = new Reagent("virtus"); + reductusReagent = new Reagent("reductus"); + potentiaReagent = new Reagent("potentia"); + + sanctusReagent.setColour(255, 255, 0, 255); + incendiumReagent.setColour(255, 0, 0, 255); + aquasalusReagent.setColour(0, 0, 255, 255); + magicalesReagent.setColour(150, 0, 146, 255); + aetherReagent.setColour(105, 223, 86, 255); + crepitousReagent.setColour(145, 145, 145, 255); + crystallosReagent.setColour(135, 255, 231, 255); + terraeReagent.setColour(147, 48, 13, 255); + tenebraeReagent.setColour(86, 86, 86, 255); + offensaReagent.setColour(126, 0, 0, 255); + praesidiumReagent.setColour(135, 135, 135, 255); + orbisTerraeReagent.setColour(32, 94, 14, 255); + virtusReagent.setColour(180, 0, 0, 255); + reductusReagent.setColour(20, 93, 2, 255); + potentiaReagent.setColour(64, 81, 208, 255); + + registerReagent("sanctus", sanctusReagent); + registerReagent("incendium", incendiumReagent); + registerReagent("aquasalus", aquasalusReagent); + registerReagent("magicales", magicalesReagent); + registerReagent("aether", aetherReagent); + registerReagent("crepitous", crepitousReagent); + registerReagent("crystallos", crystallosReagent); + registerReagent("terrae", terraeReagent); + registerReagent("tenebrae", tenebraeReagent); + registerReagent("offensa", offensaReagent); + registerReagent("praesidium", praesidiumReagent); + registerReagent("orbisTerrae", orbisTerraeReagent); + registerReagent("virtus", virtusReagent); + registerReagent("reductus", reductusReagent); + registerReagent("potentia", potentiaReagent); + } + + public static boolean registerReagent(String key, Reagent reagent) + { + if (reagentList.containsKey(key) || reagent == null) + { + return false; + } + + reagentList.put(key, reagent); + + return true; + } + + public static Reagent getReagentForKey(String key) + { + if (reagentList.containsKey(key)) + { + return reagentList.get(key); + } + + return null; + } + + public static String getKeyForReagent(Reagent reagent) + { + if (reagentList.containsValue(reagent)) + { + Set> set = reagentList.entrySet(); + for (Entry entry : set) + { + if (entry.getValue().equals(reagent)) + { + return entry.getKey(); + } + } + } + + return ""; + } + + public static void registerItemAndReagent(ItemStack stack, ReagentStack reagentStack) + { + itemToReagentMap.put(stack, reagentStack); + } + + public static ReagentStack getReagentStackForItem(ItemStack stack) + { + if (stack == null) + { + return null; + } + + for (Entry entry : itemToReagentMap.entrySet()) + { + if (entry.getKey() != null && entry.getKey().isItemEqual(stack)) + { + if (entry.getValue() == null) + { + return null; + } else + { + return entry.getValue().copy(); + } + } + } + + return null; + } + + public static ItemStack getItemForReagent(Reagent reagent) + { + if (reagent == null) + { + return null; + } + + for (Entry entry : itemToReagentMap.entrySet()) + { + if (entry.getValue() != null && entry.getValue().reagent == reagent) + { + if (entry.getKey() == null) + { + return null; + } else + { + return entry.getKey().copy(); + } + } + } + + return null; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java new file mode 100644 index 0000000..f858397 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/ReagentStack.java @@ -0,0 +1,63 @@ +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; + +public class ReagentStack +{ + public Reagent reagent; + public int amount; + + public ReagentStack(Reagent reagent, int amount) + { + this.reagent = reagent; + this.amount = amount; + } + + public ReagentStack(ReagentStack reagentStack, int amount) + { + this(reagentStack.reagent, amount); + } + + public static ReagentStack loadReagentStackFromNBT(NBTTagCompound tag) + { + Reagent reagent = ReagentRegistry.getReagentForKey(tag.getString("Reagent")); + + if (reagent == null) + { + return null; + } + + int amount = tag.getInteger("amount"); + ReagentStack stack = new ReagentStack(reagent, amount); + + return stack; + } + + public NBTTagCompound writeToNBT(NBTTagCompound tag) + { + tag.setString("Reagent", ReagentRegistry.getKeyForReagent(this.reagent)); + tag.setInteger("amount", this.amount); + + return tag; + } + + public ReagentStack splitStack(int amount) + { + ReagentStack copyStack = this.copy(); + int splitAmount = Math.min(amount, this.amount); + copyStack.amount = splitAmount; + this.amount -= splitAmount; + + return copyStack; + } + + public ReagentStack copy() + { + return new ReagentStack(this.reagent, this.amount); + } + + public boolean isReagentEqual(ReagentStack other) + { + return other != null && this.reagent == other.reagent; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java new file mode 100644 index 0000000..3e75464 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileReagentHandler.java @@ -0,0 +1,66 @@ + +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileReagentHandler extends TileEntity implements IReagentHandler +{ + protected ReagentContainer tank = new ReagentContainer(4000); + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + tank.readFromNBT(tag); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + tank.writeToNBT(tag); + } + + /* IReagentHandler */ + @Override + public int fill(ForgeDirection from, ReagentStack resource, boolean doFill) + { + return tank.fill(resource, doFill); + } + + @Override + public ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain) + { + if (resource == null || !resource.isReagentEqual(tank.getReagent())) + { + return null; + } + return tank.drain(resource.amount, doDrain); + } + + @Override + public ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + return tank.drain(maxDrain, doDrain); + } + + @Override + public boolean canFill(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public boolean canDrain(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public ReagentContainerInfo[] getContainerInfo(ForgeDirection from) + { + return new ReagentContainerInfo[]{tank.getInfo()}; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java new file mode 100644 index 0000000..a088b8a --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/alchemy/energy/TileSegmentedReagentHandler.java @@ -0,0 +1,283 @@ + +package WayofTime.alchemicalWizardry.api.alchemy.energy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class TileSegmentedReagentHandler extends TileEntity implements ISegmentedReagentHandler +{ + protected ReagentContainer[] tanks; + protected Map attunedTankMap; + + public TileSegmentedReagentHandler() + { + this(1); + } + + public TileSegmentedReagentHandler(int numberOfTanks) + { + this(numberOfTanks, 1000); + } + + public TileSegmentedReagentHandler(int numberOfTanks, int tankSize) + { + super(); + + this.attunedTankMap = new HashMap(); + this.tanks = new ReagentContainer[numberOfTanks]; + for (int i = 0; i < numberOfTanks; i++) + { + this.tanks[i] = new ReagentContainer(tankSize); + } + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + + NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND); + + int size = tagList.tagCount(); + this.tanks = new ReagentContainer[size]; + + for (int i = 0; i < size; i++) + { + NBTTagCompound savedTag = tagList.getCompoundTagAt(i); + this.tanks[i] = ReagentContainer.readFromNBT(savedTag); + } + + NBTTagList attunedTagList = tag.getTagList("attunedTankMap", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < attunedTagList.tagCount(); i++) + { + NBTTagCompound savedTag = attunedTagList.getCompoundTagAt(i); + Reagent reagent = ReagentRegistry.getReagentForKey(savedTag.getString("reagent")); + this.attunedTankMap.put(reagent, savedTag.getInteger("amount")); + } + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + + NBTTagList tagList = new NBTTagList(); + + for (int i = 0; i < this.tanks.length; i++) + { + NBTTagCompound savedTag = new NBTTagCompound(); + if (this.tanks[i] != null) + { + this.tanks[i].writeToNBT(savedTag); + } + tagList.appendTag(savedTag); + } + + tag.setTag("reagentTanks", tagList); + + NBTTagList attunedTagList = new NBTTagList(); + + for (Entry entry : this.attunedTankMap.entrySet()) + { + NBTTagCompound savedTag = new NBTTagCompound(); + savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey())); + savedTag.setInteger("amount", entry.getValue()); + attunedTagList.appendTag(savedTag); + } + + tag.setTag("attunedTankMap", attunedTagList); + } + + /* ISegmentedReagentHandler */ + @Override + public int fill(ForgeDirection from, ReagentStack resource, boolean doFill) + { + int totalFill = 0; + + boolean useTankLimit = !this.attunedTankMap.isEmpty(); + + if (resource != null) + { + int totalTanksFillable = useTankLimit ? this.getTanksTunedToReagent(resource.reagent) : this.tanks.length; + int tanksFilled = 0; + + int maxFill = resource.amount; + + for (int i = this.tanks.length - 1; i >= 0; i--) + { + ReagentStack remainingStack = resource.copy(); + remainingStack.amount = maxFill - totalFill; + + boolean doesReagentMatch = tanks[i].getReagent() == null ? false : tanks[i].getReagent().isReagentEqual(remainingStack); + + if (doesReagentMatch) + { + totalFill += tanks[i].fill(remainingStack, doFill); + tanksFilled++; + } else + { + continue; + } + + if (totalFill >= maxFill || tanksFilled >= totalTanksFillable) + { + return totalFill; + } + } + + if (tanksFilled >= totalTanksFillable) + { + return totalFill; + } + + for (int i = this.tanks.length - 1; i >= 0; i--) + { + ReagentStack remainingStack = resource.copy(); + remainingStack.amount = maxFill - totalFill; + + boolean isTankEmpty = tanks[i].getReagent() == null; + + if (isTankEmpty) + { + totalFill += tanks[i].fill(remainingStack, doFill); + tanksFilled++; + } else + { + continue; + } + + if (totalFill >= maxFill || tanksFilled >= totalTanksFillable) + { + return totalFill; + } + } + } + return totalFill; + } + + @Override + public ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain) + { + if (resource == null) + { + return null; + } + + int maxDrain = resource.amount; + Reagent reagent = resource.reagent; + int drained = 0; + + for (int i = 0; i < tanks.length; i++) + { + if (drained >= maxDrain) + { + break; + } + + if (resource.isReagentEqual(tanks[i].getReagent())) + { + ReagentStack drainStack = tanks[i].drain(maxDrain - drained, doDrain); + if (drainStack != null) + { + drained += drainStack.amount; + } + } + } + + return new ReagentStack(reagent, drained); + } + + /* Only returns the amount from the first available tank */ + @Override + public ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + for (int i = 0; i < tanks.length; i++) + { + ReagentStack stack = tanks[i].drain(maxDrain, doDrain); + if (stack != null) + { + return stack; + } + } + + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public boolean canDrain(ForgeDirection from, Reagent reagent) + { + return true; + } + + @Override + public ReagentContainerInfo[] getContainerInfo(ForgeDirection from) + { + ReagentContainerInfo[] info = new ReagentContainerInfo[this.getNumberOfTanks()]; + for (int i = 0; i < this.getNumberOfTanks(); i++) + { + info[i] = tanks[i].getInfo(); + } + return info; + } + + @Override + public int getNumberOfTanks() + { + return tanks.length; + } + + @Override + public int getTanksTunedToReagent(Reagent reagent) + { + if (this.attunedTankMap.containsKey(reagent) && this.attunedTankMap.get(reagent) != null) + { + return this.attunedTankMap.get(reagent); + } + return 0; + } + + @Override + public void setTanksTunedToReagent(Reagent reagent, int total) + { + if (total == 0 && this.attunedTankMap.containsKey(reagent)) + { + this.attunedTankMap.remove(reagent); + return; + } + + this.attunedTankMap.put(reagent, new Integer(total)); + } + + @Override + public Map getAttunedTankMap() + { + return this.attunedTankMap; + } + + public boolean areTanksEmpty() + { + for (int i = 0; i < this.tanks.length; i++) + { + if (tanks[i] != null && tanks[i].reagentStack != null) + { + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java new file mode 100644 index 0000000..fab96be --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipe.java @@ -0,0 +1,134 @@ +package WayofTime.alchemicalWizardry.api.altarRecipeRegistry; + +import java.util.Set; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; + +public class AltarRecipe +{ + public int minTier; + public int liquidRequired; + public boolean canBeFilled; //Tells the system that the item is an orb + public int consumptionRate; + public int drainRate; + public ItemStack requiredItem; + public ItemStack result; + public boolean useTag; + + public AltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) + { + this(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled, false); + } + + public AltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled, boolean useTag) + { + this.result = result; + this.requiredItem = requiredItem; + this.minTier = minTier; + this.liquidRequired = liquidRequired; + this.consumptionRate = consumptionRate; + this.drainRate = drainRate; + this.canBeFilled = canBeFilled; + this.useTag = useTag; + } + + public ItemStack getResult() + { + return this.result; + } + + public ItemStack getRequiredItem() + { + return this.requiredItem; + } + + public boolean doesRequiredItemMatch(ItemStack comparedStack, int tierCheck) + { + if (comparedStack == null || this.requiredItem == null) + { + return false; + } + + return tierCheck >= minTier && this.requiredItem.isItemEqual(comparedStack) && (this.useTag ? this.areRequiredTagsEqual(comparedStack) : true); + } + + public boolean areRequiredTagsEqual(ItemStack comparedStack) + { + if(requiredItem.hasTagCompound()) + { + NBTTagCompound tag = requiredItem.getTagCompound(); + if(!comparedStack.hasTagCompound()) + { + return false; + } + + NBTTagCompound comparedTag = comparedStack.getTagCompound(); + + return this.areTagsEqual(tag, comparedTag); + } + + return true; + } + + protected boolean areTagsEqual(NBTTagCompound tag, NBTTagCompound comparedTag) + { + Set set = tag.func_150296_c(); + + for(Object obj : set) + { + if(obj instanceof String) + { + String str = (String)obj; + + NBTBase baseTag = comparedTag.getTag(str); + + if(baseTag instanceof NBTTagCompound) + { + NBTBase comparedBaseTag = comparedTag.getTag(str); + if(comparedBaseTag instanceof NBTTagCompound) + { + if(!this.areTagsEqual((NBTTagCompound) tag, comparedTag)) + { + return false; + } + } + }else + { + if(baseTag != null && !baseTag.equals(comparedTag.getTag(str))) + { + return false; + } + } + } + } + + return true; + } + + public int getMinTier() + { + return this.minTier; + } + + public int getLiquidRequired() + { + return this.liquidRequired; + } + + public int getConsumptionRate() + { + return this.consumptionRate; + } + + public int getDrainRate() + { + return this.drainRate; + } + + public boolean getCanBeFilled() + { + return this.canBeFilled; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java new file mode 100644 index 0000000..d8077f3 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/altarRecipeRegistry/AltarRecipeRegistry.java @@ -0,0 +1,65 @@ +package WayofTime.alchemicalWizardry.api.altarRecipeRegistry; + +import net.minecraft.item.ItemStack; + +import java.util.LinkedList; +import java.util.List; + +public class AltarRecipeRegistry +{ + public static List altarRecipes = new LinkedList(); + + public static void registerAltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) + { + altarRecipes.add(new AltarRecipe(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled)); + } + + public static void registerNBTAltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled) + { + altarRecipes.add(new AltarRecipe(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled, true)); + } + + public static void registerAltarOrbRecipe(ItemStack orbStack, int minTier, int consumptionRate) + { + registerAltarRecipe(null, orbStack, minTier, 0, consumptionRate, 0, true); + } + + public static boolean isRequiredItemValid(ItemStack testItem, int currentTierAltar) + { + for (AltarRecipe recipe : altarRecipes) + { + if (recipe.doesRequiredItemMatch(testItem, currentTierAltar)) + { + return true; + } + } + + return false; + } + + public static ItemStack getItemForItemAndTier(ItemStack testItem, int currentTierAltar) + { + for (AltarRecipe recipe : altarRecipes) + { + if (recipe.doesRequiredItemMatch(testItem, currentTierAltar)) + { + return ItemStack.copyItemStack(recipe.getResult()); + } + } + + return null; + } + + public static AltarRecipe getAltarRecipeForItemAndTier(ItemStack testItem, int currentTierAltar) + { + for (AltarRecipe recipe : altarRecipes) + { + if (recipe.doesRequiredItemMatch(testItem, currentTierAltar)) + { + return recipe; + } + } + + return null; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java new file mode 100644 index 0000000..fc0ba2d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRecipe.java @@ -0,0 +1,35 @@ +package WayofTime.alchemicalWizardry.api.bindingRegistry; + +import net.minecraft.item.ItemStack; + +public class BindingRecipe +{ + public ItemStack requiredItem; + public ItemStack outputItem; + + public BindingRecipe(ItemStack outputItem, ItemStack requiredItem) + { + this.requiredItem = requiredItem; + this.outputItem = outputItem; + } + + public boolean doesRequiredItemMatch(ItemStack testStack) + { + if (testStack == null || this.requiredItem == null) + { + return false; + } + + return this.requiredItem.isItemEqual(testStack); + } + + public ItemStack getResult(ItemStack inputItem) + { + return this.getResult(); + } + + public ItemStack getResult() + { + return this.outputItem; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java new file mode 100644 index 0000000..ba06911 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/bindingRegistry/BindingRegistry.java @@ -0,0 +1,67 @@ +package WayofTime.alchemicalWizardry.api.bindingRegistry; + +import net.minecraft.item.ItemStack; + +import java.util.LinkedList; +import java.util.List; + +public class BindingRegistry +{ + public static List bindingRecipes = new LinkedList(); + + public static void registerRecipe(ItemStack output, ItemStack input) + { + bindingRecipes.add(new BindingRecipe(output, input)); + } + + public static boolean isRequiredItemValid(ItemStack testItem) + { + for (BindingRecipe recipe : bindingRecipes) + { + if (recipe.doesRequiredItemMatch(testItem)) + { + return true; + } + } + + return false; + } + + public static ItemStack getItemForItemAndTier(ItemStack testItem) + { + for (BindingRecipe recipe : bindingRecipes) + { + if (recipe.doesRequiredItemMatch(testItem)) + { + return recipe.getResult(testItem).copy(); + } + } + + return null; + } + + public static int getIndexForItem(ItemStack testItem) + { + int i = 0; + for (BindingRecipe recipe : bindingRecipes) + { + if (recipe.doesRequiredItemMatch(testItem)) + { + return i; + } + i++; + } + + return -1; + } + + public static ItemStack getOutputForIndex(int index) + { + if (bindingRecipes.size() <= index) + { + return null; + } + + return bindingRecipes.get(index).getResult(); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java new file mode 100644 index 0000000..a05c700 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/compress/CompressionHandler.java @@ -0,0 +1,14 @@ +package WayofTime.alchemicalWizardry.api.compress; + +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public abstract class CompressionHandler +{ + /** + * Called to look at the inventory and syphons the required stack. Returns resultant stack if successful, and null if not. + * @param inv The inventory iterated through + * @return The result of the compression + */ + public abstract ItemStack compressInventory(ItemStack[] inv, World world); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java new file mode 100644 index 0000000..fd17c8b --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/compress/CompressionRegistry.java @@ -0,0 +1,67 @@ +package WayofTime.alchemicalWizardry.api.compress; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * A registry aimed to help compress items in an inventory into its compressible form. + * + */ +public class CompressionRegistry +{ + public static List compressionRegistry = new ArrayList(); + public static Map thresholdMap = new HashMap(); + + public static void registerHandler(CompressionHandler handler) + { + compressionRegistry.add(handler); + } + + /** + * Registers an item so that it only compresses while above this threshold + * @param stack + * @param threshold + */ + public static void registerItemThreshold(ItemStack stack, int threshold) + { + thresholdMap.put(stack, new Integer(threshold)); + } + + public static ItemStack compressInventory(ItemStack[] inv, World world) + { + for(CompressionHandler handler : compressionRegistry) + { + ItemStack stack = handler.compressInventory(inv, world); + if(stack != null) + { + return stack; + } + } + + return null; + } + + public static int getItemThreshold(ItemStack stack) + { + for(Entry entry : thresholdMap.entrySet()) + { + if(areItemStacksEqual(entry.getKey(), stack)) + { + return entry.getValue(); + } + } + + return 0; + } + + public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack) + { + return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound())); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java new file mode 100644 index 0000000..ddcc3b0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/AddToNetworkEvent.java @@ -0,0 +1,38 @@ +package WayofTime.alchemicalWizardry.api.event; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; + +@Cancelable +public class AddToNetworkEvent extends Event +{ + public String ownerNetwork; + public int addedAmount; + public int maximum; + + /** + * This event is called whenever the network is added to. If cancelled, no LP will be drained from the source. If result is set to Result.DENY, + * the LP will still be drained but the soul network will not be added to. + * + * @param ownerNetwork Key used for the soul network + * @param addedAmount Amount added + * @param maximum Ceiling that the network can add to + */ + public AddToNetworkEvent(String ownerNetwork, int addedAmount, int maximum) + { + super(); + this.ownerNetwork = ownerNetwork; + this.addedAmount = addedAmount; + this.maximum = maximum; + } + + public String getOwnerNetwork() + { + return this.ownerNetwork; + } + + public int getAddedAmount() + { + return this.addedAmount; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java new file mode 100644 index 0000000..a0a9273 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemBindEvent.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Event; + +public class ItemBindEvent extends Event +{ + public final EntityPlayer player; + public String key; + public ItemStack itemStack; + + public ItemBindEvent(EntityPlayer player, String key, ItemStack itemStack) + { + super(); + this.player = player; + this.key = key; + this.itemStack = itemStack; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainInContainerEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainInContainerEvent.java new file mode 100644 index 0000000..5a81c1d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainInContainerEvent.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class ItemDrainInContainerEvent extends SoulNetworkEvent +{ + public ItemStack stack; + public ItemDrainInContainerEvent(ItemStack stack, String ownerNetwork, int drainAmount) + { + super(ownerNetwork, drainAmount); + this.stack = stack; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java new file mode 100644 index 0000000..d75fd7d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/ItemDrainNetworkEvent.java @@ -0,0 +1,29 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent +{ + public final ItemStack itemStack; + public boolean shouldDamage; //If true, will damage regardless of if the network had enough inside it + public float damageAmount; //Amount of damage that would incur if the network could not drain properly + + /** + * Set result to deny the action i.e. damage/drain anyways. Cancelling event prevents action without penalties + * + * @param player Player using the item + * @param ownerNetwork Network that the item is tied to + * @param itemStack Item used + * @param drainAmount Original drain amount - change to alter cost + */ + public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, ItemStack itemStack, int drainAmount) + { + super(player, ownerNetwork, drainAmount); + this.itemStack = itemStack; + this.shouldDamage = false; + this.damageAmount = (float)(drainAmount) / 100.0f; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java new file mode 100644 index 0000000..f752255 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerAddToNetworkEvent.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class PlayerAddToNetworkEvent extends AddToNetworkEvent +{ + public final EntityPlayer player; + public ItemStack itemStack; + public PlayerAddToNetworkEvent(EntityPlayer player, ItemStack itemStack, String ownerNetwork, int addedAmount, int maximum) + { + super(ownerNetwork, addedAmount, maximum); + this.player = player; + this.itemStack = itemStack; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java new file mode 100644 index 0000000..dacb26d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/PlayerDrainNetworkEvent.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class PlayerDrainNetworkEvent extends SoulNetworkEvent +{ + public final EntityPlayer player; //Player that activated the event + public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) + { + super(ownerNetwork, drainAmount); + this.player = player; + } + + public EntityPlayer getPlayer() + { + return player; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java new file mode 100644 index 0000000..83c10c0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualActivatedEvent.java @@ -0,0 +1,23 @@ +package WayofTime.alchemicalWizardry.api.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class RitualActivatedEvent extends RitualEvent +{ + public final EntityPlayer player; + public final ItemStack crystalStack; + public int crystalTier; + + public RitualActivatedEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey, EntityPlayer player, ItemStack activationCrystal, int crystalTier) + { + super(mrs, ownerKey, ritualKey); + + this.player = player; + this.crystalStack = activationCrystal; + this.crystalTier = crystalTier; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java new file mode 100644 index 0000000..fbe1649 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualEvent.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.event; + +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import cpw.mods.fml.common.eventhandler.Event; + +public class RitualEvent extends Event +{ + public final IMasterRitualStone mrs; + public String ownerKey; + public final String ritualKey; + + public RitualEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey) + { + this.mrs = mrs; + this.ownerKey = ownerKey; + this.ritualKey = ritualKey; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java new file mode 100644 index 0000000..4bcf075 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualRunEvent.java @@ -0,0 +1,16 @@ +package WayofTime.alchemicalWizardry.api.event; + +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import cpw.mods.fml.common.eventhandler.Cancelable; + +@Cancelable +public class RitualRunEvent extends RitualEvent +{ + + + public RitualRunEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey) + { + super(mrs, ownerKey, ritualKey); + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java new file mode 100644 index 0000000..4fc998f --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/RitualStopEvent.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.event; + +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; +import WayofTime.alchemicalWizardry.api.rituals.RitualBreakMethod; + +public class RitualStopEvent extends RitualEvent +{ + public final RitualBreakMethod method; + public RitualStopEvent(IMasterRitualStone mrs, String ownerKey, String ritualKey, RitualBreakMethod method) + { + super(mrs, ownerKey, ritualKey); + + this.method = method; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java b/src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java new file mode 100644 index 0000000..bf47a13 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/event/SoulNetworkEvent.java @@ -0,0 +1,26 @@ +package WayofTime.alchemicalWizardry.api.event; + +import cpw.mods.fml.common.eventhandler.Event; + +public class SoulNetworkEvent extends Event +{ + public String ownerNetwork; + public int drainAmount; + + public SoulNetworkEvent(String ownerNetwork, int drainAmount) + { + super(); + this.ownerNetwork = ownerNetwork; + this.drainAmount = drainAmount; + } + + public String getOwnerNetwork() + { + return this.ownerNetwork; + } + + public int getDrainAmount() + { + return this.drainAmount; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java new file mode 100644 index 0000000..aac57f5 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/HarvestRegistry.java @@ -0,0 +1,33 @@ +package WayofTime.alchemicalWizardry.api.harvest; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.List; + +public class HarvestRegistry +{ + public static List handlerList = new ArrayList(); + + public static void registerHarvestHandler(IHarvestHandler handler) + { + handlerList.add(handler); + } + + public static boolean harvestBlock(World world, int xCoord, int yCoord, int zCoord) + { + Block block = world.getBlock(xCoord, yCoord, zCoord); + int meta = world.getBlockMetadata(xCoord, yCoord, zCoord); + + for (IHarvestHandler handler : handlerList) + { + if (handler.harvestAndPlant(world, xCoord, yCoord, zCoord, block, meta)) + { + return true; + } + } + + return false; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java new file mode 100644 index 0000000..d5e479d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/harvest/IHarvestHandler.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.harvest; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public interface IHarvestHandler +{ + /** + * A handler that is used to harvest and replant the block at the specified location + * + * @param world + * @param xCoord + * @param yCoord + * @param zCoord + * @param block block at this given location + * @param meta meta at this given location + * @return true if successfully harvested, false if not + */ + public boolean harvestAndPlant(World world, int xCoord, int yCoord, int zCoord, Block block, int meta); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java new file mode 100644 index 0000000..b84f95c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/IAltarManipulator.java @@ -0,0 +1,6 @@ +package WayofTime.alchemicalWizardry.api.items; + +public interface IAltarManipulator +{ + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java new file mode 100644 index 0000000..72f0c83 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/ItemSpellMultiTool.java @@ -0,0 +1,806 @@ +package WayofTime.alchemicalWizardry.api.items; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; +import WayofTime.alchemicalWizardry.api.spell.APISpellHelper; +import WayofTime.alchemicalWizardry.api.spell.SpellEffect; +import WayofTime.alchemicalWizardry.api.spell.SpellParadigmTool; + +public class ItemSpellMultiTool extends Item +{ + private static final String harvestLevelSuffix = "harvestLvl"; + private static final String digLevelSuffix = "digLvl"; + private static final String tagName = "BloodMagicTool"; + private Random rand = new Random(); + + public ItemSpellMultiTool() + { + super(); + this.setMaxDamage(0); + this.setMaxStackSize(1); + this.setFull3D(); + } + + @Override + public void registerIcons(IIconRegister iconRegister) + { + this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:BoundTool"); + } + + @Override + public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) + { + float damage = this.getCustomItemAttack(par1ItemStack); + + SpellParadigmTool parad = this.loadParadigmFromStack(par1ItemStack); + + if (parad != null) + { + parad.onLeftClickEntity(par1ItemStack, par2EntityLivingBase, par3EntityLivingBase); + } + + damage += parad.getAddedDamageForEntity(par2EntityLivingBase); + + if (rand.nextFloat() < this.getCritChance(par1ItemStack)) + { + damage *= 1.75f; + } + + if (par3EntityLivingBase instanceof EntityPlayer) + { + par2EntityLivingBase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) par3EntityLivingBase), damage); + } else + { + par2EntityLivingBase.attackEntityFrom(DamageSource.causeMobDamage(par3EntityLivingBase), damage); + } + + return true; + } + + @Override + public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) + { + SpellParadigmTool parad = this.loadParadigmFromStack(stack); + + if (parad != null && entity instanceof EntityLivingBase) + { + parad.onLeftClickEntity(stack, (EntityLivingBase) entity, player); + } + + return false; + } + + @Override + public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) + { + if (player.worldObj.isRemote) + { + return false; + } + + if (!stack.hasTagCompound()) + return false; + + World world = player.worldObj; + Block block = player.worldObj.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + if (block == null || block == Blocks.air) + return false; + int hlvl = -1; + float blockHardness = block.getBlockHardness(world, x, y, z); + + MovingObjectPosition mop = APISpellHelper.raytraceFromEntity(world, player, true, 5.0D); + + Block localBlock = world.getBlock(x, y, z); + int localMeta = world.getBlockMetadata(x, y, z); + String toolClass = block.getHarvestTool(meta); + if (toolClass != null && this.getHarvestLevel(stack, toolClass) != -1) + hlvl = block.getHarvestLevel(meta); + int toolLevel = this.getHarvestLevel(stack, toolClass); + + float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, x, y, z); + + if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness) + { + boolean cancelHarvest = false; + + if (!cancelHarvest) + { + if (localBlock != null && !(localHardness < 0)) + { + boolean isEffective = false; + + String localToolClass = this.getToolClassForMaterial(localBlock.getMaterial()); + + if (localToolClass != null && this.getHarvestLevel(stack, toolClass) >= localBlock.getHarvestLevel(localMeta)) + { + isEffective = true; + } + + + if (localBlock.getMaterial().isToolNotRequired()) + { + isEffective = true; + } + + if (!player.capabilities.isCreativeMode) + { + if (isEffective) + { + if (localBlock.removedByPlayer(world, player, x, y, z)) + { + localBlock.onBlockDestroyedByPlayer(world, x, y, z, localMeta); + } + localBlock.onBlockHarvested(world, x, y, z, localMeta, player); + if (blockHardness > 0f) + onBlockDestroyed(stack, world, localBlock, x, y, z, player); + + List items = APISpellHelper.getItemsFromBlock(world, localBlock, x, y, z, localMeta, this.getSilkTouch(stack), this.getFortuneLevel(stack)); + + SpellParadigmTool parad = this.loadParadigmFromStack(stack); + List newItems = parad.handleItemList(stack, items); + + if (!world.isRemote) + { + APISpellHelper.spawnItemListInWorld(newItems, world, x + 0.5f, y + 0.5f, z + 0.5f); + } + + world.func_147479_m(x, y, z); + + int cost = 0; + + cost += parad.digSurroundingArea(stack, world, player, mop, localToolClass, localHardness, toolLevel, this); + + cost += parad.onBreakBlock(stack, world, player, localBlock, localMeta, x, y, z, ForgeDirection.getOrientation(mop.sideHit)); + + if (cost > 0) + { + SoulNetworkHandler.syphonAndDamageFromNetwork(stack, player, cost); + } + } else + { + world.setBlockToAir(x, y, z); + world.func_147479_m(x, y, z); + } + + } else + { + world.setBlockToAir(x, y, z); + world.func_147479_m(x, y, z); + } + } + } + } + + if (!world.isRemote) + world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); + return true; + + } + + public Material[] getMaterialsForToolclass(String toolClass) + { + if ("pickaxe".equals(toolClass)) + { + return new Material[]{Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil, Material.circuits}; + } else if ("shovel".equals(toolClass)) + { + return new Material[]{Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay}; + } else if ("axe".equals(toolClass)) + { + return new Material[]{Material.wood, Material.vine, Material.circuits, Material.cactus}; + } + return new Material[0]; + } + + public String getToolClassForMaterial(Material mat) + { + String testString = "pickaxe"; + + Material[] matList = this.getMaterialsForToolclass(testString); + for (int i = 0; i < matList.length; i++) + { + if (matList[i] == mat) + { + return testString; + } + } + + testString = "shovel"; + matList = this.getMaterialsForToolclass(testString); + for (int i = 0; i < matList.length; i++) + { + if (matList[i] == mat) + { + return testString; + } + } + + testString = "axe"; + matList = this.getMaterialsForToolclass(testString); + for (int i = 0; i < matList.length; i++) + { + if (matList[i] == mat) + { + return testString; + } + } + + return null; + } + + public Set getToolClasses(ItemStack stack) + { + Set set = new HashSet(); + + if (this.getHarvestLevel(stack, "pickaxe") > -1) + { + set.add("pickaxe"); + } + + if (this.getHarvestLevel(stack, "axe") > -1) + { + set.add("axe"); + } + + if (this.getHarvestLevel(stack, "shovel") > -1) + { + set.add("shovel"); + } + + return set; + } + + @Override + public float getDigSpeed(ItemStack stack, Block block, int meta) + { + String toolClass = block.getHarvestTool(meta); + + if (toolClass == null || toolClass.equals("")) + { + return 1.0f; + } + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat(digLevelSuffix + toolClass); + } else + { + stack.setTagCompound(new NBTTagCompound()); + } + } + + return 1.0f; + } + + @Override + public int getHarvestLevel(ItemStack stack, String toolClass) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + if (tag.hasKey(harvestLevelSuffix + toolClass)) + { + return tag.getInteger(harvestLevelSuffix + toolClass); + } else + { + return -1; + } + } else + { + stack.setTagCompound(new NBTTagCompound()); + } + + return -1; + } + + @Override + public boolean canHarvestBlock(Block par1Block, ItemStack itemStack) + { + + return true; + } + + @Override + public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) + { + return false; + } + + @Override + public void onUpdate(ItemStack toolStack, World world, Entity par3Entity, int par4, boolean par5) + { + if (world.isRemote) + { + return; + } + + SpellParadigmTool parad = this.loadParadigmFromStack(toolStack); + int cost = parad.onUpdate(toolStack, world, par3Entity, par4, par5); + + if (par3Entity instanceof EntityPlayer && cost > 0) + SoulNetworkHandler.syphonAndDamageFromNetwork(toolStack, (EntityPlayer) par3Entity, cost); + + int duration = Math.max(this.getDuration(toolStack, world), 0); + + if (duration <= 0 && par3Entity instanceof EntityPlayer) + { + int banishCost = parad.onBanishTool(toolStack, world, par3Entity, par4, par5); + SoulNetworkHandler.syphonAndDamageFromNetwork(toolStack, (EntityPlayer) par3Entity, banishCost); + ((EntityPlayer) par3Entity).inventory.mainInventory[par4] = this.getContainedCrystal(toolStack); + } + } + + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) + { + if (par3EntityPlayer.isSneaking()) + { + par3EntityPlayer.setCurrentItemOrArmor(0, this.getContainedCrystal(par1ItemStack)); + return par1ItemStack; + } + + SpellParadigmTool parad = this.loadParadigmFromStack(par1ItemStack); + + MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false); + + int cost = 0; + + if (mop != null && mop.typeOfHit.equals(MovingObjectPosition.MovingObjectType.BLOCK)) + { + cost = parad.onRightClickBlock(par1ItemStack, par3EntityPlayer, par2World, mop); + } else + { + cost = parad.onRightClickAir(par1ItemStack, par2World, par3EntityPlayer); + } + + if (cost > 0) + { + SoulNetworkHandler.syphonAndDamageFromNetwork(par1ItemStack, par3EntityPlayer, cost); + } + + return par1ItemStack; + } + + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + par3List.add("A mace filled with ancient alchemy"); + + if (!(par1ItemStack.stackTagCompound == null)) + { + if (!par1ItemStack.stackTagCompound.getString("ownerName").equals("")) + { + par3List.add("Current owner: " + par1ItemStack.stackTagCompound.getString("ownerName")); + } + + for (String str : this.getToolListString(par1ItemStack)) + { + par3List.add(str); + } + + par3List.add(""); + float damage = this.getCustomItemAttack(par1ItemStack); + par3List.add("\u00A79+" + ((int) (damage * 10)) / 10.0f + " " + "Attack Damage"); + float critChance = ((int) (this.getCritChance(par1ItemStack) * 1000)) / 10.0f; + par3List.add("\u00A79+" + critChance + "% " + "Crit Chance"); + } + } + + //--------------Custom methods--------------// + + public void setHarvestLevel(ItemStack stack, String toolClass, int harvestLevel) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger(harvestLevelSuffix + toolClass, Math.max(-1, harvestLevel)); + + stack.getTagCompound().setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger(harvestLevelSuffix + toolClass, Math.max(-1, harvestLevel)); + + stack.getTagCompound().setTag(tagName, tag); + } + } + + public void setDigSpeed(ItemStack stack, String toolClass, float digSpeed) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat(digLevelSuffix + toolClass, digSpeed); + + stack.getTagCompound().setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat(digLevelSuffix + toolClass, digSpeed); + + stack.getTagCompound().setTag(tagName, tag); + } + } + + public float getDigSpeed(ItemStack stack, String toolClass) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat(digLevelSuffix + toolClass); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return 0.0f; + } + } + + public void setItemAttack(ItemStack stack, float damage) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("itemAttack", Math.max(damage, 0.0f)); + + stack.stackTagCompound.setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("itemAttack", Math.max(damage, 0.0f)); + + stack.stackTagCompound.setTag(tagName, tag); + } + } + + public float getCustomItemAttack(ItemStack stack) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat("itemAttack"); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return 0.0f; + } + } + + public ItemStack getContainedCrystal(ItemStack container) + { + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName).getCompoundTag("heldItem"); + + return ItemStack.loadItemStackFromNBT(tag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + return null; + } + } + + public void setContainedCrystal(ItemStack container, ItemStack crystal) + { + if (container.hasTagCompound()) + { + NBTTagCompound compTag = container.getTagCompound().getCompoundTag(tagName); + NBTTagCompound tag = compTag.getCompoundTag("heldItem"); + + crystal.writeToNBT(tag); + + compTag.setTag("heldItem", tag); + container.getTagCompound().setTag(tagName, compTag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + NBTTagCompound compTag = container.getTagCompound().getCompoundTag(tagName); + NBTTagCompound tag = compTag.getCompoundTag("heldItem"); + + crystal.writeToNBT(tag); + + compTag.setTag("heldItem", tag); + container.getTagCompound().setTag(tagName, compTag); + } + } + + public void setDuration(ItemStack container, World world, int duration) + { + if (world.isRemote) + { + return; + } else + { + World overWorld = DimensionManager.getWorld(0); + long worldtime = overWorld.getTotalWorldTime(); + + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setLong("duration", Math.max(duration + worldtime, worldtime)); + + container.getTagCompound().setTag(tagName, tag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setLong("duration", Math.max(duration + worldtime, worldtime)); + + container.getTagCompound().setTag(tagName, tag); + } + } + } + + public int getDuration(ItemStack container, World world) + { + if (world.isRemote) + { + return 0; + } else + { + World overWorld = DimensionManager.getWorld(0); + long worldtime = overWorld.getTotalWorldTime(); + + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + return (int) (tag.getLong("duration") - worldtime); + } else + { + container.setTagCompound(new NBTTagCompound()); + + return 0; + } + } + } + + public void loadParadigmIntoStack(ItemStack container, List list) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList effectList = new NBTTagList(); + + for (SpellEffect eff : list) + { + effectList.appendTag(eff.getTag()); + } + + tagiest.setTag("Effects", effectList); + + container.getTagCompound().setTag(tagName, tagiest); + } + + public SpellParadigmTool loadParadigmFromStack(ItemStack container) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList tagList = tagiest.getTagList("Effects", Constants.NBT.TAG_COMPOUND); + + List spellEffectList = new LinkedList(); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + + SpellEffect eff = SpellEffect.getEffectFromTag(tag); + if (eff != null) + { + spellEffectList.add(eff); + } + } + + return SpellParadigmTool.getParadigmForEffectArray(spellEffectList); + } + + public void setSilkTouch(ItemStack stack, boolean silkTouch) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setBoolean("silkTouch", silkTouch); + + stack.stackTagCompound.setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setBoolean("silkTouch", silkTouch); + + stack.stackTagCompound.setTag(tagName, tag); + } + } + + public boolean getSilkTouch(ItemStack stack) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getBoolean("silkTouch"); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return false; + } + } + + public void setFortuneLevel(ItemStack stack, int fortune) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger("fortuneLevel", Math.max(fortune, 0)); + + stack.stackTagCompound.setTag(tagName, tag); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + tag.setInteger("fortuneLevel", Math.max(fortune, 0)); + + stack.stackTagCompound.setTag(tagName, tag); + } + } + + public int getFortuneLevel(ItemStack stack) + { + if (stack.hasTagCompound()) + { + NBTTagCompound tag = stack.getTagCompound().getCompoundTag(tagName); + + return tag.getInteger("fortuneLevel"); + } else + { + stack.setTagCompound(new NBTTagCompound()); + + return 0; + } + } + + public List getToolListString(ItemStack container) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList tagList = tagiest.getTagList("ToolTips", Constants.NBT.TAG_COMPOUND); + + List toolTipList = new LinkedList(); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + + String str = tag.getString("tip"); + if (str != null) + { + toolTipList.add(str); + } + } + + return toolTipList; + } + + public void setToolListString(ItemStack container, List toolTipString) + { + if (!container.hasTagCompound()) + { + container.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound tagiest = container.getTagCompound().getCompoundTag(tagName); + + NBTTagList stringList = new NBTTagList(); + + for (String str : toolTipString) + { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("tip", str); + + stringList.appendTag(tag); + } + + tagiest.setTag("ToolTips", stringList); + + container.getTagCompound().setTag(tagName, tagiest); + } + + public void setCritChance(ItemStack container, float chance) + { + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("critChance", Math.max(chance, 0)); + + container.stackTagCompound.setTag(tagName, tag); + } else + { + container.setTagCompound(new NBTTagCompound()); + + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + tag.setFloat("critChance", Math.max(chance, 0)); + + container.stackTagCompound.setTag(tagName, tag); + } + } + + public float getCritChance(ItemStack container) + { + if (container.hasTagCompound()) + { + NBTTagCompound tag = container.getTagCompound().getCompoundTag(tagName); + + return tag.getFloat("critChance"); + } else + { + container.setTagCompound(new NBTTagCompound()); + + return 0; + } + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java new file mode 100644 index 0000000..6e5b0f9 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapedBloodOrbRecipe.java @@ -0,0 +1,281 @@ +package WayofTime.alchemicalWizardry.api.items; + +import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; +import net.minecraft.block.Block; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Shaped Blood Orb Recipe Handler by joshie * + */ +public class ShapedBloodOrbRecipe implements IRecipe +{ + private static final int MAX_CRAFT_GRID_WIDTH = 3; + private static final int MAX_CRAFT_GRID_HEIGHT = 3; + + private ItemStack output = null; + private Object[] input = null; + public int width = 0; + public int height = 0; + private boolean mirrored = true; + + public ShapedBloodOrbRecipe(Block result, Object... recipe) + { + this(new ItemStack(result), recipe); + } + + public ShapedBloodOrbRecipe(Item result, Object... recipe) + { + this(new ItemStack(result), recipe); + } + + public ShapedBloodOrbRecipe(ItemStack result, Object... recipe) + { + output = result.copy(); + + String shape = ""; + int idx = 0; + + if (recipe[idx] instanceof Boolean) + { + mirrored = (Boolean) recipe[idx]; + if (recipe[idx + 1] instanceof Object[]) + { + recipe = (Object[]) recipe[idx + 1]; + } else + { + idx = 1; + } + } + + if (recipe[idx] instanceof String[]) + { + String[] parts = ((String[]) recipe[idx++]); + + for (String s : parts) + { + width = s.length(); + shape += s; + } + + height = parts.length; + } else + { + while (recipe[idx] instanceof String) + { + String s = (String) recipe[idx++]; + shape += s; + width = s.length(); + height++; + } + } + + if (width * height != shape.length()) + { + String ret = "Invalid shaped ore recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } + + HashMap itemMap = new HashMap(); + + for (; idx < recipe.length; idx += 2) + { + Character chr = (Character) recipe[idx]; + Object in = recipe[idx + 1]; + + if (in instanceof IBloodOrb || (in instanceof ItemStack && ((ItemStack) in).getItem() instanceof IBloodOrb)) + { //If the item is an instanceof IBloodOrb then save the level of the orb + if (in instanceof ItemStack) + itemMap.put(chr, (Integer) (((IBloodOrb) ((ItemStack) in).getItem()).getOrbLevel())); + else itemMap.put(chr, (Integer) (((IBloodOrb) in).getOrbLevel())); + } else if (in instanceof ItemStack) + { + itemMap.put(chr, ((ItemStack) in).copy()); + } else if (in instanceof Item) + { + itemMap.put(chr, new ItemStack((Item) in)); + } else if (in instanceof Block) + { + itemMap.put(chr, new ItemStack((Block) in, 1, OreDictionary.WILDCARD_VALUE)); + } else if (in instanceof String) + { + itemMap.put(chr, OreDictionary.getOres((String) in)); + } else + { + String ret = "Invalid shaped ore recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } + } + + input = new Object[width * height]; + int x = 0; + for (char chr : shape.toCharArray()) + { + input[x++] = itemMap.get(chr); + } + } + + ShapedBloodOrbRecipe(ShapedRecipes recipe, Map replacements) + { + output = recipe.getRecipeOutput(); + width = recipe.recipeWidth; + height = recipe.recipeHeight; + + input = new Object[recipe.recipeItems.length]; + + for (int i = 0; i < input.length; i++) + { + ItemStack ingred = recipe.recipeItems[i]; + + if (ingred == null) + continue; + + input[i] = recipe.recipeItems[i]; + + for (Entry replace : replacements.entrySet()) + { + if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) + { + input[i] = OreDictionary.getOres(replace.getValue()); + break; + } + } + } + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) + { + return output.copy(); + } + + @Override + public int getRecipeSize() + { + return input.length; + } + + @Override + public ItemStack getRecipeOutput() + { + return output; + } + + @Override + public boolean matches(InventoryCrafting inv, World world) + { + for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++) + { + for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y) + { + if (checkMatch(inv, x, y, false)) + { + return true; + } + + if (mirrored && checkMatch(inv, x, y, true)) + { + return true; + } + } + } + + return false; + } + + @SuppressWarnings("unchecked") + private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) + { + for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) + { + for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) + { + int subX = x - startX; + int subY = y - startY; + Object target = null; + + if (subX >= 0 && subY >= 0 && subX < width && subY < height) + { + if (mirror) + { + target = input[width - subX - 1 + subY * width]; + } else + { + target = input[subX + subY * width]; + } + } + + ItemStack slot = inv.getStackInRowAndColumn(x, y); + //If target is integer, then we should be check the blood orb value of the item instead + if (target instanceof Integer) + { + if (slot != null && slot.getItem() instanceof IBloodOrb) + { + IBloodOrb orb = (IBloodOrb) slot.getItem(); + if (orb.getOrbLevel() < (Integer) target) + { + return false; + } + } else return false; + } else if (target instanceof ItemStack) + { + if (!OreDictionary.itemMatches((ItemStack) target, slot, false)) + { + return false; + } + } else if (target instanceof ArrayList) + { + boolean matched = false; + + Iterator itr = ((ArrayList) target).iterator(); + while (itr.hasNext() && !matched) + { + matched = OreDictionary.itemMatches(itr.next(), slot, false); + } + + if (!matched) + { + return false; + } + } else if (target == null && slot != null) + { + return false; + } + } + } + + return true; + } + + public ShapedBloodOrbRecipe setMirrored(boolean mirror) + { + mirrored = mirror; + return this; + } + + public Object[] getInput() + { + return this.input; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java new file mode 100644 index 0000000..3b22ded --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/ShapelessBloodOrbRecipe.java @@ -0,0 +1,174 @@ +package WayofTime.alchemicalWizardry.api.items; + +import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; +import net.minecraft.block.Block; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Shapeless Blood Orb Recipe Handler by joshie * + */ +public class ShapelessBloodOrbRecipe implements IRecipe +{ + private ItemStack output = null; + private ArrayList input = new ArrayList(); + + public ShapelessBloodOrbRecipe(Block result, Object... recipe) + { + this(new ItemStack(result), recipe); + } + + public ShapelessBloodOrbRecipe(Item result, Object... recipe) + { + this(new ItemStack(result), recipe); + } + + public ShapelessBloodOrbRecipe(ItemStack result, Object... recipe) + { + output = result.copy(); + for (Object in : recipe) + { + if (in instanceof ItemStack) + { + input.add(((ItemStack) in).copy()); + } else if (in instanceof IBloodOrb) + { //If the item is an instanceof IBloodOrb then save the level of the orb + input.add((Integer) (((IBloodOrb) in).getOrbLevel())); + } else if (in instanceof Item) + { + input.add(new ItemStack((Item) in)); + } else if (in instanceof Block) + { + input.add(new ItemStack((Block) in)); + } else if (in instanceof String) + { + input.add(OreDictionary.getOres((String) in)); + } else + { + String ret = "Invalid shapeless ore recipe: "; + for (Object tmp : recipe) + { + ret += tmp + ", "; + } + ret += output; + throw new RuntimeException(ret); + } + } + } + + @SuppressWarnings("unchecked") + ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map replacements) + { + output = recipe.getRecipeOutput(); + + for (ItemStack ingred : ((List) recipe.recipeItems)) + { + Object finalObj = ingred; + for (Entry replace : replacements.entrySet()) + { + if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) + { + finalObj = OreDictionary.getOres(replace.getValue()); + break; + } + } + input.add(finalObj); + } + } + + @Override + public int getRecipeSize() + { + return input.size(); + } + + @Override + public ItemStack getRecipeOutput() + { + return output; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) + { + return output.copy(); + } + + @SuppressWarnings("unchecked") + @Override + public boolean matches(InventoryCrafting var1, World world) + { + ArrayList required = new ArrayList(input); + + for (int x = 0; x < var1.getSizeInventory(); x++) + { + ItemStack slot = var1.getStackInSlot(x); + + if (slot != null) + { + boolean inRecipe = false; + Iterator req = required.iterator(); + + while (req.hasNext()) + { + boolean match = false; + + Object next = req.next(); + + //If target is integer, then we should be check the blood orb value of the item instead + if (next instanceof Integer) + { + if (slot != null && slot.getItem() instanceof IBloodOrb) + { + IBloodOrb orb = (IBloodOrb) slot.getItem(); + if (orb.getOrbLevel() < (Integer) next) + { + return false; + } + } else return false; + } else if (next instanceof ItemStack) + { + match = OreDictionary.itemMatches((ItemStack) next, slot, false); + } else if (next instanceof ArrayList) + { + Iterator itr = ((ArrayList) next).iterator(); + while (itr.hasNext() && !match) + { + match = OreDictionary.itemMatches(itr.next(), slot, false); + } + } + + if (match) + { + inRecipe = true; + required.remove(next); + break; + } + } + + if (!inRecipe) + { + return false; + } + } + } + + return required.isEmpty(); + } + + public ArrayList getInput() + { + return this.input; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/ArmourUpgrade.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/ArmourUpgrade.java new file mode 100644 index 0000000..7fce7cd --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/ArmourUpgrade.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.items.interfaces; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface ArmourUpgrade +{ + //Called when the armour ticks + public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack); + + public boolean isUpgrade(); + + public int getEnergyForTenSeconds(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBindable.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBindable.java new file mode 100644 index 0000000..46a7993 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBindable.java @@ -0,0 +1,5 @@ +package WayofTime.alchemicalWizardry.api.items.interfaces; + +public interface IBindable +{ +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java new file mode 100644 index 0000000..e88e9cc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IBloodOrb.java @@ -0,0 +1,8 @@ +package WayofTime.alchemicalWizardry.api.items.interfaces; + +public interface IBloodOrb +{ + public int getMaxEssence(); + + public int getOrbLevel(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java new file mode 100644 index 0000000..4150abe --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IHolding.java @@ -0,0 +1,6 @@ +package WayofTime.alchemicalWizardry.api.items.interfaces; + +public interface IHolding +{ + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java new file mode 100644 index 0000000..23ac780 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/items/interfaces/IReagentManipulator.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.items.interfaces; + +/** + * Implement this interface to have reagent blocks return false on activating them, to allow manipulation of said block + */ +public interface IReagentManipulator +{ + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java b/src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java new file mode 100644 index 0000000..7eea34c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/renderer/MRSRenderer.java @@ -0,0 +1,21 @@ +package WayofTime.alchemicalWizardry.api.renderer; + +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.util.ResourceLocation; +import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; + +public abstract class MRSRenderer +{ + public abstract void renderAt(IMasterRitualStone tile, double x, double y, double z); + + protected void bindTexture(ResourceLocation p_147499_1_) + { + TextureManager texturemanager = TileEntityRendererDispatcher.instance.field_147553_e; + + if (texturemanager != null) + { + texturemanager.bindTexture(p_147499_1_); + } + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java new file mode 100644 index 0000000..6704d97 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IMasterRitualStone.java @@ -0,0 +1,40 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +import WayofTime.alchemicalWizardry.api.alchemy.energy.ISegmentedReagentHandler; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public interface IMasterRitualStone extends ISegmentedReagentHandler +{ + public void performRitual(World world, int x, int y, int z, String ritualID); + + public String getOwner(); + + public void setCooldown(int newCooldown); + + public int getCooldown(); + + public void setVar1(int newVar1); + + public int getVar1(); + + public void setActive(boolean active); + + public int getDirection(); + + public World getWorld(); + + public int getXCoord(); + + public int getYCoord(); + + public int getZCoord(); + + public NBTTagCompound getCustomRitualTag(); + + public void setCustomRitualTag(NBTTagCompound tag); + + public boolean areTanksEmpty(); + + public int getRunningTime(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java new file mode 100644 index 0000000..c2cec51 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/IRitualStone.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +import net.minecraft.world.World; + +public interface IRitualStone +{ + /** + * x, y, and z give the position of the Ritual Stone + * @param world + * @param x + * @param y + * @param z + * @param meta + * @param runeType + * @return + */ + public boolean isRuneType(World world, int x, int y, int z, int meta, int runeType); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/ITileRitualStone.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/ITileRitualStone.java new file mode 100644 index 0000000..7204515 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/ITileRitualStone.java @@ -0,0 +1,6 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +public interface ITileRitualStone +{ + public boolean isRuneType(int runeType); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java new file mode 100644 index 0000000..a705056 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualBreakMethod.java @@ -0,0 +1,11 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +public enum RitualBreakMethod +{ + REDSTONE, + BREAK_MRS, + BREAK_STONE, + ACTIVATE, //When an activation crystal activates the MRS, overwriting the current ritual + DEACTIVATE, + EXPLOSION, //When the MRS is destroyed by an explosion +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java new file mode 100644 index 0000000..6e896e0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualComponent.java @@ -0,0 +1,71 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +public class RitualComponent +{ + private int x; + private int y; + private int z; + private int stoneType; + public static final int BLANK = 0; + public static final int WATER = 1; + public static final int FIRE = 2; + public static final int EARTH = 3; + public static final int AIR = 4; + public static final int DUSK = 5; + + public RitualComponent(int x, int y, int z, int stoneType) + { + this.x = x; + this.y = y; + this.z = z; + this.stoneType = stoneType; + } + + public int getX() + { + return this.x; + } + + public int getY() + { + return this.y; + } + + public int getZ() + { + return this.z; + } + + public int getX(int direction) + { + switch(direction) + { + case 2: + return -this.getZ(); + case 3: + return -this.getX(); + case 4: + return this.getZ(); + default: return this.getX(); + } + } + + public int getZ(int direction) + { + switch(direction) + { + case 2: + return this.getX(); + case 3: + return -this.getZ(); + case 4: + return -this.getX(); + default: return this.getZ(); + } + } + + public int getStoneType() + { + return this.stoneType; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java new file mode 100644 index 0000000..498c803 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/RitualEffect.java @@ -0,0 +1,56 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack; + +public abstract class RitualEffect +{ + public abstract void performEffect(IMasterRitualStone ritualStone); + + public boolean startRitual(IMasterRitualStone ritualStone, EntityPlayer player) + { + return true; + } + + public void onRitualBroken(IMasterRitualStone ritualStone, RitualBreakMethod method) + { + + } + + public abstract int getCostPerRefresh(); + + public int getInitialCooldown() + { + return 0; + } + + public abstract List getRitualComponentList(); + + public boolean canDrainReagent(IMasterRitualStone ritualStone, Reagent reagent, int amount, boolean doDrain) + { + if (ritualStone == null || reagent == null || amount == 0) + { + return false; + } + + ReagentStack reagentStack = new ReagentStack(reagent, amount); + + ReagentStack stack = ritualStone.drain(ForgeDirection.UNKNOWN, reagentStack, false); + + if (stack != null && stack.amount >= amount) + { + if (doDrain) + { + ritualStone.drain(ForgeDirection.UNKNOWN, reagentStack, true); + } + + return true; + } + + return false; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java new file mode 100644 index 0000000..7609e82 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java @@ -0,0 +1,377 @@ +package WayofTime.alchemicalWizardry.api.rituals; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import WayofTime.alchemicalWizardry.api.event.RitualRunEvent; +import WayofTime.alchemicalWizardry.api.event.RitualStopEvent; +import WayofTime.alchemicalWizardry.api.renderer.MRSRenderer; +import cpw.mods.fml.common.eventhandler.Event; + +public class Rituals +{ + public final int crystalLevel; + public final int actCost; + public final RitualEffect effect; + public final String name; + + public final MRSRenderer customRenderer; + + public static Map ritualMap = new HashMap(); + public static List keyList = new LinkedList(); + + public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name, MRSRenderer renderer) + { + this.crystalLevel = crystalLevel; + this.actCost = actCost; + this.effect = effect; + this.name = name; + keyList.add(name); + ritualMap.put(name, this); + this.customRenderer = renderer; + } + + public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name) + { + this(crystalLevel, actCost, effect, name, null); + } + + /** + * Static method to register a ritual to the Ritual Registry + * + * @param key Unique identification key - must be different from all others to properly register + * @param crystalLevel Crystal level required to activate + * @param actCost LP amount required to activate + * @param effect The effect that will be ticked + * @param name The name of the ritual + * @return Returns true if properly registered, or false if the key is already used + */ + public static boolean registerRitual(String key, int crystalLevel, int actCost, RitualEffect effect, String name, MRSRenderer renderer) + { + if (ritualMap.containsKey(key)) + { + return false; + } else + { + Rituals ritual = new Rituals(crystalLevel, actCost, effect, name, renderer); + ritual.removeRitualFromList(); + ritualMap.put(key, ritual); + keyList.add(key); + return true; + } + } + + public static boolean registerRitual(String key, int crystalLevel, int actCost, RitualEffect effect, String name) + { + if (ritualMap.containsKey(key)) + { + return false; + } else + { + Rituals ritual = new Rituals(crystalLevel, actCost, effect, name); + ritual.removeRitualFromList(); + ritualMap.put(key, ritual); + keyList.add(key); + return true; + } + } + + public void removeRitualFromList() + { + if (ritualMap.containsValue(this)) + { + ritualMap.remove(ritualMap.remove(this.name)); + } + if (keyList.contains(this.name)) + { + keyList.remove(this.name); + } + } + + public static String checkValidRitual(World world, int x, int y, int z) + { + for (String key : ritualMap.keySet()) + { + if (checkRitualIsValid(world, x, y, z, key)) + { + return key; + } + } + + return ""; + } + + public static boolean canCrystalActivate(String ritualID, int crystalLevel) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.getCrystalLevel() <= crystalLevel; + } + } + + return false; + } + + public static boolean checkRitualIsValid(World world, int x, int y, int z, String ritualID) + { + int direction = Rituals.getDirectionOfRitual(world, x, y, z, ritualID); + + if (direction != -1) + { + return true; + } + + return false; + } + + /** + * 1 - NORTH + * 2 - EAST + * 3 - SOUTH + * 4 - WEST + */ + public static boolean checkDirectionOfRitualValid(World world, int x, int y, int z, String ritualID, int direction) + { + List ritual = Rituals.getRitualList(ritualID); + + if (ritual == null) + { + return false; + } + + Block test = null; + TileEntity te = null; + + for (RitualComponent rc : ritual) + { + test = world.getBlock(x + rc.getX(direction), y + rc.getY(), z + rc.getZ(direction)); + te = world.getTileEntity(x + rc.getX(direction), y + rc.getY(), z + rc.getZ(direction)); + + if (!(test instanceof IRitualStone && ((IRitualStone)test).isRuneType(world, x + rc.getX(direction), y, z+ rc.getZ(direction), world.getBlockMetadata(x + rc.getX(direction), y + rc.getY(), z + rc.getZ(direction)), rc.getStoneType())) + && !(te instanceof ITileRitualStone && ((ITileRitualStone)te).isRuneType(rc.getStoneType()))) + { + return false; + } + } + + return true; + } + + public static int getDirectionOfRitual(World world, int x, int y, int z, String ritualID) + { + for (int i = 1; i <= 4; i++) + { + if (Rituals.checkDirectionOfRitualValid(world, x, y, z, ritualID, i)) + { + return i; + } + } + + return -1; + } + + public static int getCostForActivation(String ritualID) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.actCost; + } + } + + return 0; + } + + public static int getInitialCooldown(String ritualID) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null && ritual.effect != null) + { + return ritual.effect.getInitialCooldown(); + } + } + + return 0; + } + + public static List getRitualList(String ritualID) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.obtainComponents(); + } else + { + return null; + } + } else + { + return null; + } + } + + private List obtainComponents() + { + return this.effect.getRitualComponentList(); + } + + private int getCrystalLevel() + { + return this.crystalLevel; + } + + private MRSRenderer getRenderer() + { + return this.customRenderer; + } + + public static void performEffect(IMasterRitualStone ritualStone, String ritualID) + { + String ownerName = ritualStone.getOwner(); + + RitualRunEvent event = new RitualRunEvent(ritualStone, ownerName, ritualID); + + if(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) + { + return; + } + + if (ritualMap.containsKey(event.ritualKey)) + { + Rituals ritual = ritualMap.get(event.ritualKey); + if (ritual != null && ritual.effect != null) + { + ritual.effect.performEffect(ritualStone); + } + } + } + + public static boolean startRitual(IMasterRitualStone ritualStone, String ritualID, EntityPlayer player) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null && ritual.effect != null) + { + return ritual.effect.startRitual(ritualStone, player); + } + } + + return false; + } + + public static void onRitualBroken(IMasterRitualStone ritualStone, String ritualID, RitualBreakMethod method) + { + String ownerName = ritualStone.getOwner(); + RitualStopEvent event = new RitualStopEvent(ritualStone, ownerName, ritualID, method); + MinecraftForge.EVENT_BUS.post(event); + + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null && ritual.effect != null) + { + ritual.effect.onRitualBroken(ritualStone, method); + } + } + } + + public static int getNumberOfRituals() + { + return ritualMap.size(); + } + + public String getRitualName() + { + return this.name; + } + + public static String getNameOfRitual(String id) + { + if (ritualMap.containsKey(id)) + { + Rituals ritual = ritualMap.get(id); + if (ritual != null) + { + return ritual.getRitualName(); + } + } + + return ""; + } + + public static String getNextRitualKey(String key) + { + boolean hasSpotted = false; + String firstKey = ""; + + for (String str : keyList) + { + if (firstKey.equals("")) + { + firstKey = str; + } + if (hasSpotted) + { + return str; + } + if (str.equals(key)) + { + hasSpotted = true; + } + } + + return firstKey; + } + + public static String getPreviousRitualKey(String key) + { + boolean hasSpotted = false; + String lastKey = keyList.get(keyList.size() - 1); + + for (String str : keyList) + { + if (str.equals(key)) + { + hasSpotted = true; + } + if (hasSpotted) + { + return lastKey; + } + lastKey = str; + } + + return lastKey; + } + + public static MRSRenderer getRendererForKey(String ritualID) + { + if (ritualMap.containsKey(ritualID)) + { + Rituals ritual = ritualMap.get(ritualID); + if (ritual != null) + { + return ritual.getRenderer(); + } + } + + return null; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/ComplexNetworkHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/ComplexNetworkHandler.java new file mode 100644 index 0000000..c9b6931 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/ComplexNetworkHandler.java @@ -0,0 +1,126 @@ +package WayofTime.alchemicalWizardry.api.soulNetwork; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mojang.authlib.GameProfile; + + +/** + * Temporary class to hash-out how to create a network not completely tied to the player. + */ +public class ComplexNetworkHandler +{ + public static String fileName = "config/BloodMagic/soulnetworkKeys"; + static HashMap keyMap = new HashMap(); + public static UUID getUUIDFromPlayer(EntityPlayer player) + { + return player.getPersistentID(); + } + + public static EntityPlayer getPlayerFromUUID(UUID uuid) + { + MinecraftServer server = MinecraftServer.getServer(); + GameProfile gameProfile; + gameProfile = server.func_152358_ax().func_152652_a(uuid); + String str = uuid.toString(); + //TODO ServerConfigurationManager d.createPlayerForUser + UUID.fromString(str); + return null; + } + + public static String getKeyForPlayer(EntityPlayer player) + { + return ""; + } + + public static UUID getUUIDForKey(String key) + { +// if (MinecraftServer.getServer() == null) +// { +// return null; +// } +// +// World world = MinecraftServer.getServer().worldServers[0]; +// UUIDKeyMap data = (UUIDKeyMap) world.loadItemData(UUIDKeyMap.class, key); +// +// if (data == null) +// { +// data = new UUIDKeyMap(key); +// world.setItemData(key, data); +// } + return null; + } + + public static String assignKeyToPlayer(EntityPlayer player) + { + return ""; + } + + public static void save() + { + keyMap.put(new UUID(0, 0), "test"); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String json = gson.toJson(keyMap); + Writer writer; + try + { + writer = new FileWriter(fileName + ".json"); + writer.write(json); + writer.close(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + public static void load() + { + File save = new File(fileName + ".json"); + + if(save.canRead()) + { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + BufferedReader br; + + try + { + br = new BufferedReader(new FileReader(save)); + HashMap schema = gson.fromJson(br, keyMap.getClass()); + + keyMap = schema; + + if(keyMap != null) + { + for(Entry entry : keyMap.entrySet()) + { + System.out.println("" + entry.getValue() + " gave: "+ entry.getKey()); + } + } + } catch (FileNotFoundException e) + { + e.printStackTrace(); + } + } + + else + { + keyMap = null; + } + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/LifeEssenceNetwork.java b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/LifeEssenceNetwork.java new file mode 100644 index 0000000..91bcdaf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/LifeEssenceNetwork.java @@ -0,0 +1,30 @@ +package WayofTime.alchemicalWizardry.api.soulNetwork; + +import net.minecraft.nbt.NBTTagCompound; + +public class LifeEssenceNetwork extends net.minecraft.world.WorldSavedData +{ + public int currentEssence; + public int maxOrb; + + public LifeEssenceNetwork(String par1Str) + { + super(par1Str); + currentEssence = 0; + maxOrb = 0; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) + { + currentEssence = nbttagcompound.getInteger("currentEssence"); + maxOrb = nbttagcompound.getInteger("maxOrb"); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + nbttagcompound.setInteger("currentEssence", currentEssence); + nbttagcompound.setInteger("maxOrb", maxOrb); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java new file mode 100644 index 0000000..e366ee6 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/soulNetwork/SoulNetworkHandler.java @@ -0,0 +1,458 @@ +package WayofTime.alchemicalWizardry.api.soulNetwork; + +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import WayofTime.alchemicalWizardry.api.event.AddToNetworkEvent; +import WayofTime.alchemicalWizardry.api.event.ItemBindEvent; +import WayofTime.alchemicalWizardry.api.event.ItemDrainInContainerEvent; +import WayofTime.alchemicalWizardry.api.event.ItemDrainNetworkEvent; + +import com.mojang.authlib.GameProfile; + +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.common.eventhandler.Event.Result; + +public class SoulNetworkHandler +{ + public static UUID getUUIDFromPlayer(EntityPlayer player) + { + return player.getPersistentID(); + } + + public static EntityPlayer getPlayerFromUUID(UUID uuid) + { + MinecraftServer server = MinecraftServer.getServer(); + GameProfile gameProfile; + gameProfile = server.func_152358_ax().func_152652_a(uuid); + return null; + } + + public static boolean syphonFromNetworkWhileInContainer(ItemStack ist, int damageToBeDone) + { + String ownerName = ""; + if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) + { + ownerName = ist.getTagCompound().getString("ownerName"); + } + + ItemDrainInContainerEvent event = new ItemDrainInContainerEvent(ist, ownerName, damageToBeDone); + + if(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Result.DENY) + { + return false; + } + + return syphonFromNetwork(event.ownerNetwork, event.drainAmount) >= damageToBeDone; + } + + public static int getCurrentMaxOrb(String ownerName) + { + if (MinecraftServer.getServer() == null) + { + return 0; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + return data.maxOrb; + } + + public static void setMaxOrbToMax(String ownerName, int maxOrb) + { + if (MinecraftServer.getServer() == null) + { + return; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + data.maxOrb = Math.max(maxOrb, data.maxOrb); + data.markDirty(); + } + + public static int getMaximumForOrbTier(int maxOrb) + { + switch(maxOrb) + { + case 1: + return 5000; + case 2: + return 25000; + case 3: + return 150000; + case 4: + return 1000000; + case 5: + return 10000000; + case 6: + return 30000000; + default: + return 1; + } + } + + public static int syphonFromNetwork(ItemStack ist, int damageToBeDone) + { + if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = ist.getTagCompound().getString("ownerName"); + + return syphonFromNetwork(ownerName, damageToBeDone); + } + return 0; + } + + public static int syphonFromNetwork(String ownerName, int damageToBeDone) + { + if (MinecraftServer.getServer() == null) + { + return 0; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + if (data.currentEssence >= damageToBeDone) + { + data.currentEssence -= damageToBeDone; + data.markDirty(); + return damageToBeDone; + } + + return 0; + } + + /** + * Master method used to syphon from the player's network, and will damage them accordingly if they do not have enough LP. + * Does not drain on the client side. + * + * @param ist Owned itemStack + * @param player Player using the item + * @param damageToBeDone + * @return True if the action should be executed and false if it should not. Always returns false if client-sided. + */ + public static boolean syphonAndDamageFromNetwork(ItemStack ist, EntityPlayer player, int drain) + { + if (player.worldObj.isRemote) + { + return false; + } + + if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = ist.getTagCompound().getString("ownerName"); + + ItemDrainNetworkEvent event = new ItemDrainNetworkEvent(player, ownerName, ist, drain); + + if(MinecraftForge.EVENT_BUS.post(event)) + { + return false; + } + + int drainAmount = syphonFromNetwork(event.ownerNetwork, event.drainAmount); + if(drainAmount == 0 || event.shouldDamage) + { + hurtPlayer(player, event.damageAmount); + } + + return (event.getResult() != Event.Result.DENY); //The event has been told to prevent the action but allow all repercussions of using the item. + } + + int amount = SoulNetworkHandler.syphonFromNetwork(ist, drain); + + hurtPlayer(player, drain - amount); + + return true; + } + + public static boolean syphonAndDamageFromNetwork(String ownerName, EntityPlayer player, int damageToBeDone) + { + if (player.worldObj.isRemote) + { + return false; + } + + World world = player.worldObj; + if (world != null) + { + double posX = player.posX; + double posY = player.posY; + double posZ = player.posZ; + + world.playSoundEffect((double) ((float) player.posX + 0.5F), (double) ((float) player.posY + 0.5F), (double) ((float) player.posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F); + } + + int amount = SoulNetworkHandler.syphonFromNetwork(ownerName, damageToBeDone); + + hurtPlayer(player, damageToBeDone - amount); + + return true; + } + + public static boolean canSyphonFromOnlyNetwork(ItemStack ist, int damageToBeDone) + { + if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = ist.getTagCompound().getString("ownerName"); + + return canSyphonFromOnlyNetwork(ownerName, damageToBeDone); + } + + return false; + } + + public static boolean canSyphonFromOnlyNetwork(String ownerName, int damageToBeDone) + { + if (MinecraftServer.getServer() == null) + { + return false; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + return data.currentEssence >= damageToBeDone; + } + + public static int getCurrentEssence(String ownerName) + { + if (MinecraftServer.getServer() == null) + { + return 0; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + return data.currentEssence; + } + + public static void setCurrentEssence(String ownerName, int essence) + { + if (MinecraftServer.getServer() == null) + { + return; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName); + + if (data == null) + { + data = new LifeEssenceNetwork(ownerName); + world.setItemData(ownerName, data); + } + + data.currentEssence = essence; + data.markDirty(); + } + + /** + * A method to add to an owner's network up to a maximum value. + * + * @param ownerName + * @param addedEssence + * @param maximum + * @return amount added to the network + */ + public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) + { + AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum); + + if(MinecraftForge.EVENT_BUS.post(event)) + { + return 0; + } + + if (MinecraftServer.getServer() == null) + { + return 0; + } + + World world = MinecraftServer.getServer().worldServers[0]; + LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, event.ownerNetwork); + + if (data == null) + { + data = new LifeEssenceNetwork(event.ownerNetwork); + world.setItemData(event.ownerNetwork, data); + } + + int currEss = data.currentEssence; + + if (currEss >= event.maximum) + { + return 0; + } + + int newEss = Math.min(event.maximum, currEss + event.addedAmount); + if(event.getResult() != Event.Result.DENY) + { + data.currentEssence = newEss; + } + + return newEss - currEss; + } + + public static void hurtPlayer(EntityPlayer user, int energySyphoned) + { + if (energySyphoned < 100 && energySyphoned > 0) + { + if (!user.capabilities.isCreativeMode) + { + user.setHealth((user.getHealth() - 1)); + + if (user.getHealth() <= 0.0005f) + { + user.onDeath(DamageSource.generic); + } + } + } else if (energySyphoned >= 100) + { + if (!user.capabilities.isCreativeMode) + { + for (int i = 0; i < ((energySyphoned + 99) / 100); i++) + { + user.setHealth((user.getHealth() - 1)); + + if (user.getHealth() <= 0.0005f) + { + user.onDeath(DamageSource.generic); + break; + } + } + } + } + } + + public static void hurtPlayer(EntityPlayer user, float damage) + { + if (!user.capabilities.isCreativeMode) + { + user.setHealth((user.getHealth() - damage)); + + if (user.getHealth() <= 0.0005f) + { + user.onDeath(DamageSource.generic); + } + } + } + + public static void checkAndSetItemOwner(ItemStack item, EntityPlayer player) + { + if (item.stackTagCompound == null) + { + item.setTagCompound(new NBTTagCompound()); + } + + if (item.stackTagCompound.getString("ownerName").equals("")) + { + ItemBindEvent event = new ItemBindEvent(player, SoulNetworkHandler.getUsername(player), item); + + if(!MinecraftForge.EVENT_BUS.post(event)) + { + item.stackTagCompound.setString("ownerName", event.key); + } + } + } + + public static void checkAndSetItemOwner(ItemStack item, String ownerName) + { + if (item.stackTagCompound == null) + { + item.setTagCompound(new NBTTagCompound()); + } + + if (item.stackTagCompound.getString("ownerName").equals("")) + { + item.stackTagCompound.setString("ownerName", ownerName); + } + } + + public static String getUsername(EntityPlayer player) + { + return player.getDisplayName(); + } + + public static EntityPlayer getPlayerForUsername(String str) + { + if (MinecraftServer.getServer() == null) + { + return null; + } + return MinecraftServer.getServer().getConfigurationManager().func_152612_a(str); + } + + public static void causeNauseaToPlayer(ItemStack stack) + { + if (stack.getTagCompound() != null && !(stack.getTagCompound().getString("ownerName").equals(""))) + { + String ownerName = stack.getTagCompound().getString("ownerName"); + + SoulNetworkHandler.causeNauseaToPlayer(ownerName); + } + } + + public static void causeNauseaToPlayer(String ownerName) + { + EntityPlayer entityOwner = SoulNetworkHandler.getPlayerForUsername(ownerName); + + if (entityOwner == null) + { + return; + } + + entityOwner.addPotionEffect(new PotionEffect(Potion.confusion.id, 80)); + } + + public static String getOwnerName(ItemStack item) + { + if (item.stackTagCompound == null) + { + item.setTagCompound(new NBTTagCompound()); + } + + return item.stackTagCompound.getString("ownerName"); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java new file mode 100644 index 0000000..ce40bd4 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java @@ -0,0 +1,228 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; + +public class APISpellHelper +{ + public static int getPlayerLPTag(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:StoredLP")) + { + return data.getInteger("BM:StoredLP"); + } + + return 0; + } + + public static void setPlayerLPTag(EntityPlayer player, int amount) + { + NBTTagCompound data = player.getEntityData(); + data.setInteger("BM:StoredLP", amount); + } + + public static int getPlayerMaxLPTag(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:MaxStoredLP")) + { + return data.getInteger("BM:MaxStoredLP"); + } + + return 0; + } + + public static void setPlayerMaxLPTag(EntityPlayer player, int amount) + { + NBTTagCompound data = player.getEntityData(); + data.setInteger("BM:MaxStoredLP", amount); + } + + public static float getPlayerCurrentReagentAmount(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:StoredReagentAmount")) + { + return data.getFloat("BM:StoredReagentAmount"); + } + + return 0; + } + + public static void setPlayerCurrentReagentAmount(EntityPlayer player, float amount) + { + NBTTagCompound data = player.getEntityData(); + data.setFloat("BM:StoredReagentAmount", amount); + } + + public static float getPlayerMaxReagentAmount(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:MaxReagentAmount")) + { + return data.getFloat("BM:MaxReagentAmount"); + } + + return 0; + } + + public static void setPlayerMaxReagentAmount(EntityPlayer player, float amount) + { + NBTTagCompound data = player.getEntityData(); + data.setFloat("BM:MaxReagentAmount", amount); + } + + public static Reagent getPlayerReagentType(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:ReagentType")) + { + return ReagentRegistry.getReagentForKey(data.getString("BM:ReagentType")); + } + + return null; + } + + public static void setPlayerReagentType(EntityPlayer player, String str) + { + NBTTagCompound data = player.getEntityData(); + data.setString("BM:ReagentType", str); + } + + public static void setPlayerReagentType(EntityPlayer player, Reagent reagent) + { + setPlayerReagentType(player, ReagentRegistry.getKeyForReagent(reagent)); + } + + public static int getCurrentAdditionalHP(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:CurrentAddedHP")) + { + return data.getInteger("BM:CurrentAddedHP"); + } + + return 0; + } + + public static void setCurrentAdditionalHP(EntityPlayer player, int amount) + { + NBTTagCompound data = player.getEntityData(); + data.setInteger("BM:CurrentAddedHP", amount); + } + + public static int getCurrentAdditionalMaxHP(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:MaxAddedHP")) + { + return data.getInteger("BM:MaxAddedHP"); + } + + return 0; + } + + public static void setCurrentAdditionalMaxHP(EntityPlayer player, int amount) + { + NBTTagCompound data = player.getEntityData(); + data.setInteger("BM:MaxAddedHP", amount); + } + + public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range) + { + float f = 1.0F; + float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f; + float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f; + double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double) f; + double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double) f; + if (!world.isRemote && player instanceof EntityPlayer) + d1 += 1.62D; + double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) f; + Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2); + float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI); + float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI); + float f5 = -MathHelper.cos(-f1 * 0.017453292F); + float f6 = MathHelper.sin(-f1 * 0.017453292F); + float f7 = f4 * f5; + float f8 = f3 * f5; + double d3 = range; + if (player instanceof EntityPlayerMP) + { +// d3 = ((EntityPlayerMP) player).theItemInWorldManager.getBlockReachDistance(); + } + Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3); + return world.func_147447_a(vec3, vec31, par3, !par3, par3); + } + + public static List getItemsFromBlock(World world, Block block, int x, int y, int z, int meta, boolean silkTouch, int fortune) + { + boolean canSilk = block.canSilkHarvest(world, null, x, y, z, meta); + + if (canSilk && silkTouch) + { + ArrayList items = new ArrayList(); + ItemStack item = new ItemStack(block, 1, meta); + + items.add(item); + + return items; + } else + { + return block.getDrops(world, x, y, z, meta, fortune); + } + } + + public static void spawnItemListInWorld(List items, World world, float x, float y, float z) + { + for (ItemStack stack : items) + { + EntityItem itemEntity = new EntityItem(world, x, y, z, stack); + itemEntity.delayBeforeCanPickup = 10; + world.spawnEntityInWorld(itemEntity); + } + } + + public static String getNumeralForInt(int num) + { + switch (num) + { + case 1: + return "I"; + case 2: + return "II"; + case 3: + return "III"; + case 4: + return "IV"; + case 5: + return "V"; + case 6: + return "VI"; + case 7: + return "VII"; + case 8: + return "VIII"; + case 9: + return "IX"; + case 10: + return "X"; + default: + return ""; + } + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java new file mode 100644 index 0000000..26bcfc2 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellEffect.java @@ -0,0 +1,92 @@ +package WayofTime.alchemicalWizardry.api.spell; + + +public abstract class ComplexSpellEffect +{ + public final ComplexSpellType type; + public final ComplexSpellModifier modifier; + + protected int powerEnhancement; + protected int costEnhancement; + protected int potencyEnhancement; + + public ComplexSpellEffect(ComplexSpellType type, ComplexSpellModifier modifier) + { + this.type = type; + this.modifier = modifier; + } + + public ComplexSpellEffect(ComplexSpellType type, ComplexSpellModifier modifier, int power, int cost, int potency) + { + this(type, modifier); + + this.powerEnhancement = power; + this.costEnhancement = cost; + this.potencyEnhancement = potency; + } + + public abstract void modifyParadigm(SpellParadigm parad); + + public ComplexSpellType getType() + { + return this.type; + } + + public ComplexSpellModifier getModifier() + { + return this.modifier; + } + + public abstract ComplexSpellEffect copy(int power, int cost, int potency); + + public abstract int getCostOfEffect(); + +// public NBTTagCompound getTag() +// { +// NBTTagCompound tag = new NBTTagCompound(); +// +// tag.setString("Class", this.getClass().getName()); +// tag.setInteger("modifier", modifierState); +// tag.setInteger("power", powerEnhancement); +// tag.setInteger("cost", costEnhancement); +// tag.setInteger("potency", potencyEnhancement); +// +// return tag; +// } +// +// public static SpellEffect getEffectFromTag(NBTTagCompound tag) +// { +// try +// { +// Class clazz = Class.forName(tag.getString("Class")); +// if (clazz != null) +// { +// try +// { +// Object obj = clazz.newInstance(); +// if (obj instanceof SpellEffect) +// { +// SpellEffect eff = (SpellEffect) obj; +// +// eff.modifierState = tag.getInteger("modifier"); +// eff.powerEnhancement = tag.getInteger("power"); +// eff.costEnhancement = tag.getInteger("cost"); +// eff.potencyEnhancement = tag.getInteger("potency"); +// +// return eff; +// } +// } catch (InstantiationException e) +// { +// e.printStackTrace(); +// } catch (IllegalAccessException e) +// { +// e.printStackTrace(); +// } +// } +// } catch (ClassNotFoundException e) +// { +// e.printStackTrace(); +// } +// return null; +// } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java new file mode 100644 index 0000000..537a5e2 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellModifier.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class ComplexSpellModifier +{ + public static ComplexSpellModifier DEFAULT = new ComplexSpellModifier(); + public static ComplexSpellModifier OFFENSIVE = new ComplexSpellModifier(); + public static ComplexSpellModifier DEFENSIVE = new ComplexSpellModifier(); + public static ComplexSpellModifier ENVIRONMENTAL = new ComplexSpellModifier(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java new file mode 100644 index 0000000..1c308a8 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ComplexSpellType.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class ComplexSpellType +{ + public static ComplexSpellType FIRE = new ComplexSpellType(); + public static ComplexSpellType ICE = new ComplexSpellType(); + public static ComplexSpellType EARTH = new ComplexSpellType(); + public static ComplexSpellType WIND = new ComplexSpellType(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java new file mode 100644 index 0000000..becdb32 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/EntitySpellProjectile.java @@ -0,0 +1,650 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.*; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +public class EntitySpellProjectile extends Entity implements IProjectile +{ + private int xTile = -1; + private int yTile = -1; + private int zTile = -1; + private int inTile = 0; + private int inData = 0; + private boolean inGround = false; + /** + * The owner of this arrow. + */ + public EntityPlayer shootingEntity; + private int ticksInAir = 0; + private int ricochetCounter = 0; + private boolean scheduledForDeath = false; + private boolean isSilkTouch = false; + + //Custom variables + private int maxRicochet = 0; + private float damage = 1; + public List impactList = new ArrayList(); + private boolean penetration = false; + public List updateEffectList = new ArrayList(); + public List spellEffectList = new LinkedList(); + private int blocksBroken = 0; + + public EntitySpellProjectile(World par1World) + { + super(par1World); + this.setSize(0.5F, 0.5F); + } + + public EntitySpellProjectile(World par1World, double par2, double par4, double par6) + { + super(par1World); + this.setSize(0.5F, 0.5F); + this.setPosition(par2, par4, par6); + yOffset = 0.0F; + } + + public EntitySpellProjectile(World par1World, EntityPlayer par2EntityPlayer) + { + super(par1World); + shootingEntity = par2EntityPlayer; + float par3 = 0.8F; + this.setSize(0.1F, 0.1F); + this.setLocationAndAngles(par2EntityPlayer.posX, par2EntityPlayer.posY + par2EntityPlayer.getEyeHeight(), par2EntityPlayer.posZ, par2EntityPlayer.rotationYaw, par2EntityPlayer.rotationPitch); + posX -= MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * 0.16F; + posY -= 0.2D; + posZ -= MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * 0.16F; + this.setPosition(posX, posY, posZ); + yOffset = 0.0F; + motionX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI); + motionZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI); + motionY = -MathHelper.sin(rotationPitch / 180.0F * (float) Math.PI); + this.setThrowableHeading(motionX, motionY, motionZ, par3 * 1.5F, 1.0F); + + } + + @Override + protected void entityInit() + { + dataWatcher.addObject(16, Byte.valueOf((byte) 0)); + } + + /** + * Similar to setArrowHeading, it's point the throwable entity to a x, y, z + * direction. + */ + @Override + public void setThrowableHeading(double var1, double var3, double var5, float var7, float var8) + { + float var9 = MathHelper.sqrt_double(var1 * var1 + var3 * var3 + var5 * var5); + var1 /= var9; + var3 /= var9; + var5 /= var9; + var1 += rand.nextGaussian() * 0.007499999832361937D * var8; + var3 += rand.nextGaussian() * 0.007499999832361937D * var8; + var5 += rand.nextGaussian() * 0.007499999832361937D * var8; + var1 *= var7; + var3 *= var7; + var5 *= var7; + motionX = var1; + motionY = var3; + motionZ = var5; + float var10 = MathHelper.sqrt_double(var1 * var1 + var5 * var5); + prevRotationYaw = rotationYaw = (float) (Math.atan2(var1, var5) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch = (float) (Math.atan2(var3, var10) * 180.0D / Math.PI); + } + + @Override + @SideOnly(Side.CLIENT) + /** + * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX, + * posY, posZ, yaw, pitch + */ + public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9) + { + this.setPosition(par1, par3, par5); + this.setRotation(par7, par8); + } + + @Override + @SideOnly(Side.CLIENT) + /** + * Sets the velocity to the args. Args: x, y, z + */ + public void setVelocity(double par1, double par3, double par5) + { + motionX = par1; + motionY = par3; + motionZ = par5; + if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) + { + float var7 = MathHelper.sqrt_double(par1 * par1 + par5 * par5); + prevRotationYaw = rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch = (float) (Math.atan2(par3, var7) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch; + prevRotationYaw = rotationYaw; + this.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch); + } + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void onUpdate() + { + super.onUpdate(); + this.performUpdateEffects(); + if (ticksInAir > 600) + { + this.setDead(); + } + if (shootingEntity == null) + { + List players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(posX - 1, posY - 1, posZ - 1, posX + 1, posY + 1, posZ + 1)); + Iterator i = players.iterator(); + double closestDistance = Double.MAX_VALUE; + EntityPlayer closestPlayer = null; + while (i.hasNext()) + { + EntityPlayer e = (EntityPlayer) i.next(); + double distance = e.getDistanceToEntity(this); + if (distance < closestDistance) + { + closestPlayer = e; + } + } + if (closestPlayer != null) + { + shootingEntity = closestPlayer; + } + } + if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) + { + float var1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); + prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI); + prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, var1) * 180.0D / Math.PI); + } + Block var16 = worldObj.getBlock(xTile, yTile, zTile); + + if (var16 != null) + { + var16.setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile); + AxisAlignedBB var2 = var16.getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile); + + if (var2 != null && var2.isVecInside(Vec3.createVectorHelper(posX, posY, posZ))) + { + inGround = true; + } + } + + if (inGround) + { + Block var18 = worldObj.getBlock(xTile, yTile, zTile); + int var19 = worldObj.getBlockMetadata(xTile, yTile, zTile); + + if (var18.equals(Block.getBlockById(inTile)) && var19 == inData) + { + // this.groundImpact(); + // this.setDead(); + } + } else + { + ++ticksInAir; + + if (ticksInAir > 1 && ticksInAir < 3) + { + //worldObj.spawnParticle("flame", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), 0D, 0D, 0D); + for (int particles = 0; particles < 3; particles++) + { + this.doFiringParticles(); + } + } + + Vec3 var17 = Vec3.createVectorHelper(posX, posY, posZ); + Vec3 var3 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); + MovingObjectPosition var4 = worldObj.func_147447_a(var17, var3, true, false, false); + var17 = Vec3.createVectorHelper(posX, posY, posZ); + var3 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); + + if (var4 != null) + { + var3 = Vec3.createVectorHelper(var4.hitVec.xCoord, var4.hitVec.yCoord, var4.hitVec.zCoord); + } + + Entity var5 = null; + List var6 = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); + double var7 = 0.0D; + Iterator var9 = var6.iterator(); + float var11; + + while (var9.hasNext()) + { + Entity var10 = (Entity) var9.next(); + + if (var10.canBeCollidedWith() && (var10 != shootingEntity || ticksInAir >= 5)) + { + var11 = 0.3F; + AxisAlignedBB var12 = var10.boundingBox.expand(var11, var11, var11); + MovingObjectPosition var13 = var12.calculateIntercept(var17, var3); + + if (var13 != null) + { + double var14 = var17.distanceTo(var13.hitVec); + + if (var14 < var7 || var7 == 0.0D) + { + var5 = var10; + var7 = var14; + } + } + } + } + + if (var5 != null) + { + var4 = new MovingObjectPosition(var5); + } + + if (var4 != null) + { + this.onImpact(var4); + + if (scheduledForDeath) + { + this.setDead(); + } + } + + posX += motionX; + posY += motionY; + posZ += motionZ; + MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); + this.setPosition(posX, posY, posZ); + //this.doBlockCollisions(); + } + } + + private void doFlightParticles() + { + if (ticksInAir % 3 == 0) + { + double gauss = gaussian(1.0F); + worldObj.spawnParticle("mobSpell", posX, posY, posZ, gauss, gauss, 0.0F); + } + } + + private void doFiringParticles() + { + worldObj.spawnParticle("mobSpellAmbient", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), 0.5D, 0.5D, 0.5D); + worldObj.spawnParticle("flame", posX, posY, posZ, gaussian(motionX), gaussian(motionY), gaussian(motionZ)); + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + @Override + public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) + { + par1NBTTagCompound.setShort("xTile", (short) xTile); + par1NBTTagCompound.setShort("yTile", (short) yTile); + par1NBTTagCompound.setShort("zTile", (short) zTile); + par1NBTTagCompound.setByte("inTile", (byte) inTile); + par1NBTTagCompound.setByte("inData", (byte) inData); + par1NBTTagCompound.setByte("inGround", (byte) (inGround ? 1 : 0)); + + NBTTagList effectList = new NBTTagList(); + + for (SpellEffect eff : spellEffectList) + { + effectList.appendTag(eff.getTag()); + } + +// for (String str : this.effectList) +// { +// if (str != null) +// { +// NBTTagCompound tag = new NBTTagCompound(); +// +// tag.setString("Class", str); +// effectList.appendTag(tag); +// } +// } + + par1NBTTagCompound.setTag("Effects", effectList); + par1NBTTagCompound.setInteger("blocksBroken", blocksBroken); + par1NBTTagCompound.setBoolean("isSilkTouch", isSilkTouch); + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + @Override + public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) + { + xTile = par1NBTTagCompound.getShort("xTile"); + yTile = par1NBTTagCompound.getShort("yTile"); + zTile = par1NBTTagCompound.getShort("zTile"); + inTile = par1NBTTagCompound.getByte("inTile") & 255; + inData = par1NBTTagCompound.getByte("inData") & 255; + inGround = par1NBTTagCompound.getByte("inGround") == 1; + blocksBroken = par1NBTTagCompound.getInteger("blocksBroken"); + isSilkTouch = par1NBTTagCompound.getBoolean("isSilkTouch"); + + NBTTagList tagList = par1NBTTagCompound.getTagList("Effects", Constants.NBT.TAG_COMPOUND); + + List spellEffectList = new LinkedList(); + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + + SpellEffect eff = SpellEffect.getEffectFromTag(tag); + if (eff != null) + { + spellEffectList.add(eff); + } + } + this.spellEffectList = spellEffectList; + + +// this.effectList = new LinkedList(); +// for (int i = 0; i < tagList.tagCount(); i++) +// { +// NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); +// +// this.effectList.add(tag.getString("Class")); +// } + + //SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForStringArray(effectList); + SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForEffectArray(spellEffectList); + parad.applyAllSpellEffects(); + parad.prepareProjectile(this); + } + + /** + * returns if this entity triggers Block.onEntityWalking on the blocks they + * walk on. used for spiders and wolves to prevent them from trampling crops + */ + @Override + protected boolean canTriggerWalking() + { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public float getShadowSize() + { + return 0.0F; + } + + /** + * Sets the amount of knockback the arrow applies when it hits a mob. + */ + public void setKnockbackStrength(int par1) + { + } + + /** + * If returns false, the item will not inflict any damage against entities. + */ + @Override + public boolean canAttackWithItem() + { + return false; + } + + /** + * Whether the arrow has a stream of critical hit particles flying behind + * it. + */ + public void setIsCritical(boolean par1) + { + byte var2 = dataWatcher.getWatchableObjectByte(16); + if (par1) + { + dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 | 1))); + } else + { + dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 & -2))); + } + } + + /** + * Whether the arrow has a stream of critical hit particles flying behind + * it. + */ + public boolean getIsCritical() + { + byte var1 = dataWatcher.getWatchableObjectByte(16); + return (var1 & 1) != 0; + } + + private void onImpact(MovingObjectPosition mop) + { + if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY && mop.entityHit != null) + { + if (mop.entityHit == shootingEntity) return; + this.onImpact(mop.entityHit); + this.performEntityImpactEffects(mop.entityHit); + } else if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) + { + if (!this.penetration) + { + this.groundImpact(mop.sideHit); + this.performTileImpactEffects(mop); + } + } + } + + private void onImpact(Entity mop) //TODO + { + if (mop == shootingEntity && ticksInAir > 3) + { + shootingEntity.attackEntityFrom(DamageSource.causePlayerDamage(shootingEntity), 1); + this.setDead(); + } else + { + doDamage(this.damage, mop); + } + spawnHitParticles("exorcism", 8); + this.setDead(); + } + + + private void spawnHitParticles(String string, int i) + { + for (int particles = 0; particles < i; particles++) + { + worldObj.spawnParticle("mobSpellAmbient", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), posGauss(1.0F), posGauss(1.0F), 0.0F); + } + } + + private void doDamage(float f, Entity mop) + { + mop.attackEntityFrom(this.getDamageSource(), f); + } + + private DamageSource getDamageSource() + { + return DamageSource.causePlayerDamage(shootingEntity); + } + + private void groundImpact(int sideHit) + { + this.ricochet(sideHit); + } + + private double smallGauss(double d) + { + return (worldObj.rand.nextFloat() - 0.5D) * d; + } + + private double posGauss(double d) + { + return rand.nextFloat() * 0.5D * d; + } + + private double gaussian(double d) + { + return d + d * ((rand.nextFloat() - 0.5D) / 4); + } + + private void ricochet(int sideHit) + { + switch (sideHit) + { + case 0: + case 1: + // topHit, bottomHit, reflect Y + motionY = motionY * -1; + break; + case 2: + case 3: + // westHit, eastHit, reflect Z + motionZ = motionZ * -1; + break; + case 4: + case 5: + // southHit, northHit, reflect X + motionX = motionX * -1; + break; + } + ricochetCounter++; + if (ricochetCounter > this.getRicochetMax()) + { + scheduledForDeath = true; + for (int particles = 0; particles < 4; particles++) + { + switch (sideHit) + { + case 0: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), -gaussian(0.1D), gaussian(0.1D)); + break; + case 1: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + case 2: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), -gaussian(0.1D)); + break; + case 3: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + case 4: + worldObj.spawnParticle("smoke", posX, posY, posZ, -gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + case 5: + worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D)); + break; + } + } + } + } + + //Custom stuff + public int getRicochetMax() + { + return this.maxRicochet; + } + + public void setRicochetMax(int ricochet) + { + this.maxRicochet = ricochet; + } + + public void setImpactList(List list) + { + this.impactList = list; + } + + public void setUpdateEffectList(List list) + { + this.updateEffectList = list; + } + + private void performEntityImpactEffects(Entity mop) + { + if (impactList != null) + { + for (IProjectileImpactEffect impactEffect : impactList) + { + impactEffect.onEntityImpact(mop, this); + } + } + } + + private void performTileImpactEffects(MovingObjectPosition mop) + { + if (impactList != null) + { + for (IProjectileImpactEffect impactEffect : impactList) + { + impactEffect.onTileImpact(worldObj, mop); + } + } + } + + private void performUpdateEffects() + { + if (updateEffectList != null) + { + for (IProjectileUpdateEffect updateEffect : updateEffectList) + { + updateEffect.onUpdateEffect(this); + } + } + } + + public void setPenetration(boolean penetration) + { + this.penetration = penetration; + } + + public float getDamage() + { + return this.damage; + } + + public void setDamage(float damage) + { + this.damage = damage; + } + + public void setSpellEffectList(List list) + { + this.spellEffectList = list; + } + + public int getBlocksBroken() + { + return this.blocksBroken; + } + + public void setBlocksBroken(int blocksBroken) + { + this.blocksBroken = blocksBroken; + } + + public boolean getIsSilkTouch() + { + return this.isSilkTouch; + } + + public void setIsSilkTouch(boolean bool) + { + this.isSilkTouch = bool; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java new file mode 100644 index 0000000..0392937 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ExtrapolatedMeleeEntityEffect.java @@ -0,0 +1,72 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import java.util.List; + +public abstract class ExtrapolatedMeleeEntityEffect implements IMeleeSpellEntityEffect +{ + protected float range; + protected float radius; + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + protected int maxHit; + + public ExtrapolatedMeleeEntityEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + this.range = 0; + this.radius = 0; + this.maxHit = 1; + } + + @Override + public void onEntityImpact(World world, EntityPlayer entityPlayer) + { + Vec3 lookVec = entityPlayer.getLook(range); + double x = entityPlayer.posX + lookVec.xCoord; + double y = entityPlayer.posY + entityPlayer.getEyeHeight() + lookVec.yCoord; + double z = entityPlayer.posZ + lookVec.zCoord; + + List entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(x - 0.5f, y - 0.5f, z - 0.5f, x + 0.5f, y + 0.5f, z + 0.5f).expand(radius, radius, radius)); + int hit = 0; + + if (entities != null) + { + for (Entity entity : entities) + { + if (hit < maxHit && !entity.equals(entityPlayer)) + { + if (this.entityEffect(world, entity, entityPlayer)) + { + hit++; + } + } + } + } + } + + protected abstract boolean entityEffect(World world, Entity entity, EntityPlayer player); + + public void setRange(float range) + { + this.range = range; + } + + public void setRadius(float radius) + { + this.radius = radius; + } + + public void setMaxNumberHit(int maxHit) + { + this.maxHit = maxHit; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java new file mode 100644 index 0000000..2355ed7 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IDigAreaEffect.java @@ -0,0 +1,12 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import WayofTime.alchemicalWizardry.api.items.ItemSpellMultiTool; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public interface IDigAreaEffect +{ + public abstract int digSurroundingArea(ItemStack container, World world, EntityPlayer player, MovingObjectPosition blockPos, String usedToolClass, float blockHardness, int harvestLvl, ItemSpellMultiTool itemTool); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java new file mode 100644 index 0000000..eb9b766 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IItemManipulator.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.item.ItemStack; + +import java.util.List; + +public interface IItemManipulator +{ + public List handleItemsOnBlockBroken(ItemStack toolStack, List itemList); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java new file mode 100644 index 0000000..65f53f8 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ILeftClickEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +public interface ILeftClickEffect +{ + public abstract int onLeftClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java new file mode 100644 index 0000000..6b5d7ef --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellEntityEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface IMeleeSpellEntityEffect +{ + public void onEntityImpact(World world, EntityPlayer entityPlayer); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java new file mode 100644 index 0000000..b0560cf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IMeleeSpellWorldEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface IMeleeSpellWorldEffect +{ + public void onWorldEffect(World world, EntityPlayer entityPlayer); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java new file mode 100644 index 0000000..4e12fdd --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBanishTool.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IOnBanishTool +{ + public abstract int onBanishTool(ItemStack toolStack, World world, Entity entity, int invSlot, boolean inHand); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java new file mode 100644 index 0000000..12f844c --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnBreakBlock.java @@ -0,0 +1,12 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IOnBreakBlock +{ + public abstract int onBlockBroken(ItemStack container, World world, EntityPlayer player, Block block, int meta, int x, int y, int z, ForgeDirection sideBroken); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java new file mode 100644 index 0000000..6a5ea4d --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IOnSummonTool.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IOnSummonTool +{ + public abstract int onSummonTool(ItemStack toolStack, World world, Entity entity); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java new file mode 100644 index 0000000..c534823 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileImpactEffect.java @@ -0,0 +1,12 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public interface IProjectileImpactEffect +{ + public void onEntityImpact(Entity mop, Entity projectile); + + public void onTileImpact(World world, MovingObjectPosition mop); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java new file mode 100644 index 0000000..e973538 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IProjectileUpdateEffect.java @@ -0,0 +1,8 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; + +public interface IProjectileUpdateEffect +{ + public void onUpdateEffect(Entity projectile); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java new file mode 100644 index 0000000..dd9f7d2 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IRightClickEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public interface IRightClickEffect +{ + //public abstract int onRightClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder); + + public abstract int onRightClickBlock(ItemStack stack, EntityLivingBase weilder, World world, MovingObjectPosition mop); + + public abstract int onRightClickAir(ItemStack stack, EntityLivingBase weilder); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java new file mode 100644 index 0000000..c49edaf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISelfSpellEffect.java @@ -0,0 +1,9 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface ISelfSpellEffect +{ + public void onSelfUse(World world, EntityPlayer player); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java new file mode 100644 index 0000000..323ccf3 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ISpecialDamageEffect.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; + +public interface ISpecialDamageEffect +{ + public float getDamageForEntity(Entity entity); + + public String getKey(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java new file mode 100644 index 0000000..c3bacfc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/IToolUpdateEffect.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface IToolUpdateEffect +{ + public abstract int onUpdate(ItemStack toolStack, World world, Entity par3Entity, int invSlot, boolean inHand); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java new file mode 100644 index 0000000..68ec013 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellCenteredWorldEffect.java @@ -0,0 +1,33 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +public abstract class MeleeSpellCenteredWorldEffect extends MeleeSpellWorldEffect +{ + protected float range; + + public MeleeSpellCenteredWorldEffect(int power, int potency, int cost) + { + super(power, potency, cost); + } + + @Override + public void onWorldEffect(World world, EntityPlayer entityPlayer) + { + Vec3 lookVec = entityPlayer.getLook(range).normalize(); + int x = (int) (entityPlayer.posX + lookVec.xCoord * range); + int y = (int) (entityPlayer.posY + entityPlayer.getEyeHeight() + lookVec.yCoord * range); + int z = (int) (entityPlayer.posZ + lookVec.zCoord * range); + + this.onCenteredWorldEffect(entityPlayer, world, x, y, z); + } + + public void setRange(float range) + { + this.range = range; + } + + public abstract void onCenteredWorldEffect(EntityPlayer player, World world, int posX, int posY, int posZ); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java new file mode 100644 index 0000000..844b540 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/MeleeSpellWorldEffect.java @@ -0,0 +1,21 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public abstract class MeleeSpellWorldEffect implements IMeleeSpellWorldEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public MeleeSpellWorldEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } + + @Override + public abstract void onWorldEffect(World world, EntityPlayer entityPlayer); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java new file mode 100644 index 0000000..22ef5db --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileImpactEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public abstract class ProjectileImpactEffect implements IProjectileImpactEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public ProjectileImpactEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java new file mode 100644 index 0000000..500e7cf --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/ProjectileUpdateEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public abstract class ProjectileUpdateEffect implements IProjectileUpdateEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public ProjectileUpdateEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java new file mode 100644 index 0000000..5e9e356 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SelfSpellEffect.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public abstract class SelfSpellEffect implements ISelfSpellEffect +{ + protected int powerUpgrades; + protected int potencyUpgrades; + protected int costUpgrades; + + public SelfSpellEffect(int power, int potency, int cost) + { + this.powerUpgrades = power; + this.potencyUpgrades = potency; + this.costUpgrades = cost; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java new file mode 100644 index 0000000..1ae52ba --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffect.java @@ -0,0 +1,500 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import net.minecraft.nbt.NBTTagCompound; + +/** + * New wrapper class to enclose the ComplexSpellEffect + */ +public class SpellEffect +{ + public ComplexSpellType type; + public ComplexSpellModifier modifier; + + protected int powerEnhancement; + protected int costEnhancement; + protected int potencyEnhancement; + + public SpellEffect() + { + this(ComplexSpellType.FIRE); + } + + public SpellEffect(ComplexSpellType type) + { + this(type, ComplexSpellModifier.DEFAULT); + } + + public SpellEffect(ComplexSpellType type, ComplexSpellModifier modifier) + { + this.type = type; + this.modifier = modifier; + + this.powerEnhancement = 0; + this.potencyEnhancement = 0; + this.costEnhancement = 0; + } + + public void enhanceEffect(SpellEnhancement enh) + { + if (enh != null) + { + switch (enh.getState()) + { + case SpellEnhancement.POWER: + this.powerEnhancement++; + break; + case SpellEnhancement.EFFICIENCY: + this.costEnhancement++; + break; + case SpellEnhancement.POTENCY: + this.potencyEnhancement++; + break; + } + } + } + + public void modifyEffect(ComplexSpellModifier mod) + { + if(mod != null) + { + this.modifier = mod; + } + } + + public void modifyParadigm(SpellParadigm parad) //When modifying the paradigm it will instead get the class name and ask the registry + { + if(parad == null) + { + return; + } + + Class paraClass = parad.getClass(); + + ComplexSpellEffect effect = SpellEffectRegistry.getSpellEffect(paraClass, type, modifier, powerEnhancement, potencyEnhancement, costEnhancement); + + if(effect != null) + { + effect.modifyParadigm(parad); + } + } + + public int getCostOfEffect(SpellParadigm parad) + { + if(parad == null) + { + return 0; + } + + Class paraClass = parad.getClass(); + + ComplexSpellEffect effect = SpellEffectRegistry.getSpellEffect(paraClass, type, modifier, powerEnhancement, potencyEnhancement, costEnhancement); + + if(effect == null) + { + return 0; + } + + return effect.getCostOfEffect(); + } + + public NBTTagCompound getTag() + { + NBTTagCompound tag = new NBTTagCompound(); + + tag.setString("Class", this.getClass().getName()); + tag.setString("type", SpellEffectRegistry.getKeyForType(type)); + tag.setString("modifier", SpellEffectRegistry.getKeyForModifier(modifier)); + tag.setInteger("power", powerEnhancement); + tag.setInteger("cost", costEnhancement); + tag.setInteger("potency", potencyEnhancement); + + return tag; + } + + public static SpellEffect getEffectFromTag(NBTTagCompound tag) + { + try + { + Class clazz = Class.forName(tag.getString("Class")); + if (clazz != null) + { + try + { + Object obj = clazz.newInstance(); + if (obj instanceof SpellEffect) + { + SpellEffect eff = (SpellEffect) obj; + + eff.type = SpellEffectRegistry.getTypeForKey(tag.getString("type")); + eff.modifier = SpellEffectRegistry.getModifierForKey(tag.getString("modifier")); + eff.powerEnhancement = tag.getInteger("power"); + eff.costEnhancement = tag.getInteger("cost"); + eff.potencyEnhancement = tag.getInteger("potency"); + + return eff; + } + } catch (InstantiationException e) + { + e.printStackTrace(); + } catch (IllegalAccessException e) + { + e.printStackTrace(); + } + } + } catch (ClassNotFoundException e) + { + e.printStackTrace(); + } + return null; + } + + public int getPowerEnhancements() + { + return this.powerEnhancement; + } + + public int getPotencyEnhancements() + { + return this.potencyEnhancement; + } + + public int getCostEnhancements() + { + return this.costEnhancement; + } +} + +//package WayofTime.alchemicalWizardry.common.spell.complex.effect; +// +//import WayofTime.alchemicalWizardry.common.spell.complex.*; +//import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancement; +//import net.minecraft.nbt.NBTTagCompound; +// +//public abstract class SpellEffect +//{ +// protected int modifierState; +// protected int powerEnhancement; +// protected int costEnhancement; +// protected int potencyEnhancement; +// +// public SpellEffect() +// { +// this.modifierState = SpellModifier.DEFAULT; +// this.powerEnhancement = 0; +// this.costEnhancement = 0; +// this.potencyEnhancement = 0; +// } +// +// public void enhanceEffect(SpellEnhancement enh) +// { +// if (enh != null) +// { +// switch (enh.getState()) +// { +// case SpellEnhancement.POWER: +// this.powerEnhancement++; +// break; +// case SpellEnhancement.EFFICIENCY: +// this.costEnhancement++; +// break; +// case SpellEnhancement.POTENCY: +// this.potencyEnhancement++; +// break; +// } +// } +// } +// +// public void modifyEffect(SpellModifier mod) +// { +// if (mod != null) +// modifierState = mod.getModifier(); +// } +// +// public void modifyParadigm(SpellParadigm parad) //When modifying the paradigm it will instead get the class name and ask the registry +// { +// if (parad instanceof SpellParadigmProjectile) +// { +// this.modifyProjectileParadigm((SpellParadigmProjectile) parad); +// } +// if (parad instanceof SpellParadigmSelf) +// { +// this.modifySelfParadigm((SpellParadigmSelf) parad); +// } +// if (parad instanceof SpellParadigmMelee) +// { +// this.modifyMeleeParadigm((SpellParadigmMelee) parad); +// } +// if (parad instanceof SpellParadigmTool) +// { +// this.modifyToolParadigm((SpellParadigmTool) parad); +// } +// } +// +// public void modifyProjectileParadigm(SpellParadigmProjectile parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationProjectile(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationProjectile(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationProjectile(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationProjectile(parad); +// break; +// } +// } +// +// public abstract void defaultModificationProjectile(SpellParadigmProjectile parad); +// +// public abstract void offensiveModificationProjectile(SpellParadigmProjectile parad); +// +// public abstract void defensiveModificationProjectile(SpellParadigmProjectile parad); +// +// public abstract void environmentalModificationProjectile(SpellParadigmProjectile parad); +// +// public void modifySelfParadigm(SpellParadigmSelf parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationSelf(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationSelf(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationSelf(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationSelf(parad); +// break; +// } +// } +// +// public abstract void defaultModificationSelf(SpellParadigmSelf parad); +// +// public abstract void offensiveModificationSelf(SpellParadigmSelf parad); +// +// public abstract void defensiveModificationSelf(SpellParadigmSelf parad); +// +// public abstract void environmentalModificationSelf(SpellParadigmSelf parad); +// +// public void modifyMeleeParadigm(SpellParadigmMelee parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationMelee(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationMelee(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationMelee(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationMelee(parad); +// break; +// } +// } +// +// public abstract void defaultModificationMelee(SpellParadigmMelee parad); +// +// public abstract void offensiveModificationMelee(SpellParadigmMelee parad); +// +// public abstract void defensiveModificationMelee(SpellParadigmMelee parad); +// +// public abstract void environmentalModificationMelee(SpellParadigmMelee parad); +// +// public void modifyToolParadigm(SpellParadigmTool parad) +// { +// switch (modifierState) +// { +// case SpellModifier.DEFAULT: +// this.defaultModificationTool(parad); +// break; +// case SpellModifier.OFFENSIVE: +// this.offensiveModificationTool(parad); +// break; +// case SpellModifier.DEFENSIVE: +// this.defensiveModificationTool(parad); +// break; +// case SpellModifier.ENVIRONMENTAL: +// this.environmentalModificationTool(parad); +// break; +// } +// } +// +// public abstract void defaultModificationTool(SpellParadigmTool parad); +// +// public abstract void offensiveModificationTool(SpellParadigmTool parad); +// +// public abstract void defensiveModificationTool(SpellParadigmTool parad); +// +// public abstract void environmentalModificationTool(SpellParadigmTool parad); +// +// public int getCostForProjectile() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultProjectile(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseProjectile(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseProjectile(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentProjectile(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultProjectile(); +// +// protected abstract int getCostForOffenseProjectile(); +// +// protected abstract int getCostForDefenseProjectile(); +// +// protected abstract int getCostForEnvironmentProjectile(); +// +// public int getCostForSelf() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultSelf(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseSelf(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseSelf(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentSelf(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultSelf(); +// +// protected abstract int getCostForOffenseSelf(); +// +// protected abstract int getCostForDefenseSelf(); +// +// protected abstract int getCostForEnvironmentSelf(); +// +// public int getCostForMelee() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultMelee(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseMelee(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseMelee(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentMelee(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultMelee(); +// +// protected abstract int getCostForOffenseMelee(); +// +// protected abstract int getCostForDefenseMelee(); +// +// protected abstract int getCostForEnvironmentMelee(); +// +// public int getCostForTool() +// { +// switch (this.modifierState) +// { +// case SpellModifier.DEFAULT: +// return this.getCostForDefaultTool(); +// case SpellModifier.OFFENSIVE: +// return this.getCostForOffenseTool(); +// case SpellModifier.DEFENSIVE: +// return this.getCostForDefenseTool(); +// case SpellModifier.ENVIRONMENTAL: +// return this.getCostForEnvironmentTool(); +// } +// return 0; +// } +// +// protected abstract int getCostForDefaultTool(); +// +// protected abstract int getCostForOffenseTool(); +// +// protected abstract int getCostForDefenseTool(); +// +// protected abstract int getCostForEnvironmentTool(); +// +// public int getPowerEnhancements() +// { +// return this.powerEnhancement; +// } +// +// public int getCostEnhancements() +// { +// return this.costEnhancement; +// } +// +// public int getPotencyEnhancements() +// { +// return this.potencyEnhancement; +// } +// +// public NBTTagCompound getTag() +// { +// NBTTagCompound tag = new NBTTagCompound(); +// +// tag.setString("Class", this.getClass().getName()); +// tag.setInteger("modifier", modifierState); +// tag.setInteger("power", powerEnhancement); +// tag.setInteger("cost", costEnhancement); +// tag.setInteger("potency", potencyEnhancement); +// +// return tag; +// } +// +// public static SpellEffect getEffectFromTag(NBTTagCompound tag) +// { +// try +// { +// Class clazz = Class.forName(tag.getString("Class")); +// if (clazz != null) +// { +// try +// { +// Object obj = clazz.newInstance(); +// if (obj instanceof SpellEffect) +// { +// SpellEffect eff = (SpellEffect) obj; +// +// eff.modifierState = tag.getInteger("modifier"); +// eff.powerEnhancement = tag.getInteger("power"); +// eff.costEnhancement = tag.getInteger("cost"); +// eff.potencyEnhancement = tag.getInteger("potency"); +// +// return eff; +// } +// } catch (InstantiationException e) +// { +// e.printStackTrace(); +// } catch (IllegalAccessException e) +// { +// e.printStackTrace(); +// } +// } +// } catch (ClassNotFoundException e) +// { +// e.printStackTrace(); +// } +// return null; +// } +//} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java new file mode 100644 index 0000000..f217b12 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEffectRegistry.java @@ -0,0 +1,157 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class SpellEffectRegistry +{ + public static Map, List> effectRegistry = new HashMap(); + public static Map typeRegistry = new HashMap(); + public static Map modifierRegistry = new HashMap(); + + public static void registerSpellEffect(Class paraClass, ComplexSpellEffect effect) + { + if(paraClass == null || effect == null) + { + return; + } + + if(effectRegistry.containsKey(paraClass)) + { + List effectList = effectRegistry.get(paraClass); + ComplexSpellType type = effect.getType(); + ComplexSpellModifier modifier = effect.getModifier(); + + if(type == null || modifier == null) + { + return; + } + + for(ComplexSpellEffect eff : effectList) + { + if(type.equals(eff.getType()) && modifier.equals(eff.getModifier())) + { + effectList.remove(eff); + effectList.add(effect); + return; + } + } + + effectList.add(effect); + }else + { + List effectList = new LinkedList(); + effectList.add(effect); + effectRegistry.put(paraClass, effectList); + } + } + + /** + * + * @param paraClass + * @param type + * @param mod + * @return A copy of the spell effect + */ + public static ComplexSpellEffect getSpellEffect(Class paraClass, ComplexSpellType type, ComplexSpellModifier mod) + { + return SpellEffectRegistry.getSpellEffect(paraClass, type, mod, 0, 0, 0); + } + + public static ComplexSpellEffect getSpellEffect(Class paraClass, ComplexSpellType type, ComplexSpellModifier mod, int power, int potency, int cost) + { + if(paraClass == null || type == null || mod == null) + { + return null; + } + + List list = effectRegistry.get(paraClass); + + if(list == null || list.isEmpty()) + { + return null; + } + + for(ComplexSpellEffect effect : list) + { + if(effect != null && type.equals(effect.type) && mod.equals(effect.modifier)) + { + return effect.copy(power, cost, potency); + } + } + + return null; + } + + public static void registerSpellType(String key, ComplexSpellType type) + { + typeRegistry.put(key, type); + } + + public static void registerSpellModifier(String key, ComplexSpellModifier modifier) + { + modifierRegistry.put(key, modifier); + } + + public static ComplexSpellType getTypeForKey(String key) + { + return typeRegistry.get(key); + } + + public static String getKeyForType(ComplexSpellType type) + { + if(type == null) + { + return ""; + } + + for(Entry entry : typeRegistry.entrySet()) + { + if(type.equals(entry.getValue())) + { + return entry.getKey(); + } + } + + return ""; + } + + public static ComplexSpellModifier getModifierForKey(String key) + { + return modifierRegistry.get(key); + } + + public static String getKeyForModifier(ComplexSpellModifier modifier) + { + if(modifier == null) + { + return ""; + } + + for(Entry entry : modifierRegistry.entrySet()) + { + if(modifier.equals(entry.getValue())) + { + return entry.getKey(); + } + } + + return ""; + } + + public static void initiateRegistry() + { + SpellEffectRegistry.registerSpellType("FIRE", ComplexSpellType.FIRE); + SpellEffectRegistry.registerSpellType("ICE", ComplexSpellType.ICE); + SpellEffectRegistry.registerSpellType("EARTH", ComplexSpellType.EARTH); + SpellEffectRegistry.registerSpellType("WIND", ComplexSpellType.WIND); + + SpellEffectRegistry.registerSpellModifier("DEFAULT", ComplexSpellModifier.DEFAULT); + SpellEffectRegistry.registerSpellModifier("OFFENSIVE", ComplexSpellModifier.OFFENSIVE); + SpellEffectRegistry.registerSpellModifier("DEFENSIVE", ComplexSpellModifier.DEFENSIVE); + SpellEffectRegistry.registerSpellModifier("ENVIRONMENTAL", ComplexSpellModifier.ENVIRONMENTAL); + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java new file mode 100644 index 0000000..acbbdcc --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancement.java @@ -0,0 +1,20 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancement +{ + public static final int POWER = 0; + public static final int EFFICIENCY = 1; + public static final int POTENCY = 2; + + private int state = this.POWER; + + protected SpellEnhancement(int state) + { + this.state = state; + } + + public int getState() + { + return this.state; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java new file mode 100644 index 0000000..8078ce6 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementCost.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancementCost extends SpellEnhancement +{ + + public SpellEnhancementCost() + { + super(SpellEnhancement.EFFICIENCY); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java new file mode 100644 index 0000000..a540f89 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPotency.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancementPotency extends SpellEnhancement +{ + public SpellEnhancementPotency() + { + super(SpellEnhancement.POTENCY); + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java new file mode 100644 index 0000000..044ef10 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellEnhancementPower.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.spell; + +public class SpellEnhancementPower extends SpellEnhancement +{ + + public SpellEnhancementPower() + { + super(SpellEnhancement.POWER); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java new file mode 100644 index 0000000..5423cb4 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigm.java @@ -0,0 +1,131 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public abstract class SpellParadigm +{ + protected List bufferedEffectList = new LinkedList(); + + public void addBufferedEffect(SpellEffect effect) + { + if (effect != null) + { + this.bufferedEffectList.add(effect); + } + } + + public void modifyBufferedEffect(ComplexSpellModifier modifier) + { + SpellEffect effect = this.getBufferedEffect(); + if (effect != null) + { + effect.modifyEffect(modifier); + } + } + + public void applyEnhancement(SpellEnhancement enh) + { + if (enh != null) + { + if (bufferedEffectList.isEmpty()) + { + this.enhanceParadigm(enh); + } else + { + SpellEffect effect = this.getBufferedEffect(); + if (effect != null) + { + effect.enhanceEffect(enh); + } + } + } + + } + + public abstract void enhanceParadigm(SpellEnhancement enh); + + public abstract void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack); + + public void applySpellEffect(SpellEffect effect) + { + effect.modifyParadigm(this); + } + + public void applyAllSpellEffects() + { + for (SpellEffect effect : bufferedEffectList) + { + this.applySpellEffect(effect); + } + } + + public SpellEffect getBufferedEffect() + { + if (bufferedEffectList.isEmpty()) + { + return null; + } else + { + return bufferedEffectList.get(bufferedEffectList.size() - 1); + } + } + + public int getTotalCost() + { + int cost = 0; + if (this.bufferedEffectList != null && !this.bufferedEffectList.isEmpty()) + { + for(SpellEffect effect : bufferedEffectList) + { + cost += effect.getCostOfEffect(this); + } + + return (int) (cost * Math.sqrt(this.bufferedEffectList.size())); + } + + return getDefaultCost(); + } + + public abstract int getDefaultCost(); + + public int getBufferedEffectPower() + { + SpellEffect eff = this.getBufferedEffect(); + + if (eff != null) + { + return eff.getPowerEnhancements(); + } + + return 0; + } + + public int getBufferedEffectCost() + { + SpellEffect eff = this.getBufferedEffect(); + + if (eff != null) + { + return eff.getCostEnhancements(); + } + + return 0; + } + + public int getBufferedEffectPotency() + { + SpellEffect eff = this.getBufferedEffect(); + + if (eff != null) + { + return eff.getPotencyEnhancements(); + } + + return 0; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java new file mode 100644 index 0000000..629f7db --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmMelee.java @@ -0,0 +1,70 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmMelee extends SpellParadigm +{ + private List entityEffectList; + private List worldEffectList; + + public SpellParadigmMelee() + { + this.entityEffectList = new ArrayList(); + this.worldEffectList = new ArrayList(); + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack) + { + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(itemStack, entityPlayer, cost)) + { + return; + } + + for (IMeleeSpellEntityEffect effect : entityEffectList) + { + effect.onEntityImpact(world, entityPlayer); + } + + for (IMeleeSpellWorldEffect effect : worldEffectList) + { + effect.onWorldEffect(world, entityPlayer); + } + } + + public void addEntityEffect(IMeleeSpellEntityEffect eff) + { + if (eff != null) + { + this.entityEffectList.add(eff); + } + } + + public void addWorldEffect(IMeleeSpellWorldEffect eff) + { + if (eff != null) + { + this.worldEffectList.add(eff); + } + } + + @Override + public int getDefaultCost() + { + return 0; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java new file mode 100644 index 0000000..8b6f6a3 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmProjectile.java @@ -0,0 +1,101 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmProjectile extends SpellParadigm +{ + public DamageSource damageSource; + public float damage; + public int cost; + public List impactList; + public List updateEffectList; + public boolean penetration; + public int ricochetMax; + public boolean isSilkTouch; + + public SpellParadigmProjectile() + { + this.damageSource = DamageSource.generic; + this.damage = 1; + this.cost = 0; + this.impactList = new ArrayList(); + this.updateEffectList = new ArrayList(); + this.penetration = false; + this.ricochetMax = 0; + this.isSilkTouch = false; + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack) + { + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(itemStack, entityPlayer, cost)) + { + return; + } + + EntitySpellProjectile proj = new EntitySpellProjectile(world, entityPlayer); + this.prepareProjectile(proj); + world.spawnEntityInWorld(proj); + } + + public static SpellParadigmProjectile getParadigmForEffectArray(List effectList) + { + SpellParadigmProjectile parad = new SpellParadigmProjectile(); + + for (SpellEffect eff : effectList) + { + parad.addBufferedEffect(eff); + } + + return parad; + } + + public void prepareProjectile(EntitySpellProjectile proj) + { + proj.setDamage(damage); + proj.setImpactList(impactList); + proj.setUpdateEffectList(updateEffectList); + proj.setPenetration(penetration); + proj.setRicochetMax(ricochetMax); + proj.setIsSilkTouch(isSilkTouch); + proj.setSpellEffectList(bufferedEffectList); + } + + public void addImpactEffect(IProjectileImpactEffect eff) + { + if (eff != null) + { + this.impactList.add(eff); + } + } + + public void addUpdateEffect(IProjectileUpdateEffect eff) + { + if (eff != null) + { + this.updateEffectList.add(eff); + } + } + + @Override + public int getDefaultCost() + { + return 50; + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java new file mode 100644 index 0000000..89cffe0 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmSelf.java @@ -0,0 +1,58 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmSelf extends SpellParadigm +{ + public List selfSpellEffectList; + + public SpellParadigmSelf() + { + selfSpellEffectList = new ArrayList(); + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack) + { + this.applyAllSpellEffects(); + + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(itemStack, entityPlayer, cost)) + { + return; + } + + for (ISelfSpellEffect eff : selfSpellEffectList) + { + eff.onSelfUse(world, entityPlayer); + } + } + + public void addSelfSpellEffect(ISelfSpellEffect eff) + { + if (eff != null) + { + this.selfSpellEffectList.add(eff); + } + } + + @Override + public int getDefaultCost() + { + return 100; + } + +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java new file mode 100644 index 0000000..f6cc001 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/spell/SpellParadigmTool.java @@ -0,0 +1,485 @@ +package WayofTime.alchemicalWizardry.api.spell; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.items.ItemSpellMultiTool; +import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; + +public class SpellParadigmTool extends SpellParadigm +{ + private List leftClickEffectList; + private List rightClickEffectList; + private List toolUpdateEffectList; + private List toolSummonEffectList; + private List toolBanishEffectList; + private List breakBlockEffectList; + private List itemManipulatorEffectList; + private List digAreaEffectList; + private List specialDamageEffectList; + + private float maxDamage; + private HashMap harvestLevel; + private HashMap digSpeed; + private HashMap maxDamageHash; + private HashMap critChanceHash; + private HashMap durationHash; + + private HashMap toolInfoString; + + private int fortuneLevel; + private boolean silkTouch; + + private int duration; + + public static Item customTool; + + public SpellParadigmTool() + { + this.leftClickEffectList = new LinkedList(); + this.rightClickEffectList = new LinkedList(); + this.toolUpdateEffectList = new LinkedList(); + this.toolSummonEffectList = new LinkedList(); + this.toolBanishEffectList = new LinkedList(); + this.breakBlockEffectList = new LinkedList(); + this.itemManipulatorEffectList = new LinkedList(); + this.digAreaEffectList = new LinkedList(); + this.specialDamageEffectList = new LinkedList(); + this.durationHash = new HashMap(); + + this.toolInfoString = new HashMap(); + this.critChanceHash = new HashMap(); + + this.maxDamage = 5; + + this.harvestLevel = new HashMap(); + this.harvestLevel.put("pickaxe", -1); + this.harvestLevel.put("shovel", -1); + this.harvestLevel.put("axe", -1); + + this.digSpeed = new HashMap(); + this.digSpeed.put("pickaxe", 1.0f); + this.digSpeed.put("shovel", 1.0f); + this.digSpeed.put("axe", 1.0f); + + this.maxDamageHash = new HashMap(); + this.maxDamageHash.put("default", 5.0f); + + this.fortuneLevel = 0; + this.silkTouch = false; + this.duration = 0; + this.durationHash.put("default", 2400); + } + + @Override + public void enhanceParadigm(SpellEnhancement enh) + { + + } + + @Override + public void castSpell(World world, EntityPlayer entityPlayer, ItemStack crystal) + { + if (entityPlayer.worldObj.isRemote) + { + return; + } + + int cost = this.getTotalCost(); + + if(!SoulNetworkHandler.syphonAndDamageFromNetwork(crystal, entityPlayer, cost)) + { + return; + } + + ItemStack toolStack = this.prepareTool(crystal, world); + + entityPlayer.setCurrentItemOrArmor(0, toolStack); + + this.onSummonTool(toolStack, world, entityPlayer); + } + + /** + * @param crystalStack + * @return stack containing the new multitool + */ + public ItemStack prepareTool(ItemStack crystalStack, World world) + { + ItemStack toolStack = new ItemStack(customTool, 1); + + ItemSpellMultiTool itemTool = (ItemSpellMultiTool) customTool; + + itemTool.setItemAttack(toolStack, this.composeMaxDamageFromHash()); + + Set> harvestLevelSet = this.harvestLevel.entrySet(); + + for (Entry testMap : harvestLevelSet) + { + String tool = testMap.getKey(); + int level = testMap.getValue(); + + itemTool.setHarvestLevel(toolStack, tool, level); + } + + Set> digSpeedSet = this.digSpeed.entrySet(); + + for (Entry testMap : digSpeedSet) + { + String tool = testMap.getKey(); + float speed = testMap.getValue(); + + itemTool.setDigSpeed(toolStack, tool, speed); + } + + itemTool.setFortuneLevel(toolStack, getFortuneLevel()); + itemTool.setSilkTouch(toolStack, this.getSilkTouch()); + + if (this.getSilkTouch()) + { + this.addToolString("SilkTouch", "Silk Touch" + " " + APISpellHelper.getNumeralForInt(1)); + } + + if (this.getFortuneLevel() > 0) + { + this.addToolString("Fortune", "Fortune" + " " + APISpellHelper.getNumeralForInt(this.getFortuneLevel())); + } + + itemTool.setCritChance(toolStack, this.getCritChance() / 100f); + + List toolStringList = new LinkedList(); + + for (String str : this.toolInfoString.values()) + { + toolStringList.add(str); + } + + itemTool.setToolListString(toolStack, toolStringList); + + for (Integer integ : this.durationHash.values()) + { + this.duration += integ; + } + + itemTool.setDuration(toolStack, world, this.duration); + itemTool.loadParadigmIntoStack(toolStack, this.bufferedEffectList); + + SoulNetworkHandler.checkAndSetItemOwner(toolStack, SoulNetworkHandler.getOwnerName(crystalStack)); + + itemTool.setContainedCrystal(toolStack, crystalStack); + + return toolStack; + } + + @Override + public int getDefaultCost() + { + return 100; + } + + public static SpellParadigmTool getParadigmForEffectArray(List effectList) + { + SpellParadigmTool parad = new SpellParadigmTool(); + + for (SpellEffect eff : effectList) + { + parad.addBufferedEffect(eff); + } + + parad.applyAllSpellEffects(); + + return parad; + } + + public void addLeftClickEffect(ILeftClickEffect eff) + { + if (eff != null) + { + this.leftClickEffectList.add(eff); + } + } + + public void addRightClickEffect(IRightClickEffect eff) + { + if (eff != null) + { + this.rightClickEffectList.add(eff); + } + } + + public void addUpdateEffect(IToolUpdateEffect eff) + { + if (eff != null) + { + this.toolUpdateEffectList.add(eff); + } + } + + public void addToolSummonEffect(IOnSummonTool eff) + { + if (eff != null) + { + this.toolSummonEffectList.add(eff); + } + } + + public void addToolBanishEffect(IOnBanishTool eff) + { + if (eff != null) + { + this.toolBanishEffectList.add(eff); + } + } + + public void addBlockBreakEffect(IOnBreakBlock eff) + { + if (eff != null) + { + this.breakBlockEffectList.add(eff); + } + } + + public void addItemManipulatorEffect(IItemManipulator eff) + { + if (eff != null) + { + this.itemManipulatorEffectList.add(eff); + } + } + + public void addDigAreaEffect(IDigAreaEffect eff) + { + if (eff != null) + { + this.digAreaEffectList.add(eff); + } + } + + public void addSpecialDamageEffect(ISpecialDamageEffect eff) + { + if (eff != null) + { + this.specialDamageEffectList.add(eff); + } + } + + public int onLeftClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder) + { + int total = 0; + for (ILeftClickEffect effect : this.leftClickEffectList) + { + total += effect.onLeftClickEntity(stack, attacked, weilder); + } + + return total; + } + + public int onRightClickBlock(ItemStack toolStack, EntityLivingBase weilder, World world, MovingObjectPosition mop) + { + int total = 0; + for (IRightClickEffect effect : this.rightClickEffectList) + { + total += effect.onRightClickBlock(toolStack, weilder, world, mop); + } + + return total; + } + + public int onRightClickAir(ItemStack toolStack, World world, EntityPlayer player) + { + int total = 0; + for (IRightClickEffect effect : this.rightClickEffectList) + { + total += effect.onRightClickAir(toolStack, player); + } + + return total; + } + + public int onUpdate(ItemStack toolStack, World world, Entity par3Entity, int invSlot, boolean inHand) + { + int total = 0; + for (IToolUpdateEffect effect : this.toolUpdateEffectList) + { + total += effect.onUpdate(toolStack, world, par3Entity, invSlot, inHand); + } + + return total; + } + + public int onSummonTool(ItemStack toolStack, World world, Entity entity) + { + int total = 0; + for (IOnSummonTool effect : this.toolSummonEffectList) + { + total += effect.onSummonTool(toolStack, world, entity); + } + + return total; + } + + public int onBanishTool(ItemStack toolStack, World world, Entity entity, int invSlot, boolean inHand) + { + int total = 0; + for (IOnBanishTool effect : this.toolBanishEffectList) + { + total += effect.onBanishTool(toolStack, world, entity, invSlot, inHand); + } + + return total; + } + + public int onBreakBlock(ItemStack container, World world, EntityPlayer player, Block block, int meta, int x, int y, int z, ForgeDirection sideBroken) + { + int total = 0; + for (IOnBreakBlock effect : this.breakBlockEffectList) + { + total += effect.onBlockBroken(container, world, player, block, meta, x, y, z, sideBroken); + } + + return total; + } + + public List handleItemList(ItemStack toolStack, List items) + { + List heldList = items; + + for (IItemManipulator eff : this.itemManipulatorEffectList) + { + List newHeldList = eff.handleItemsOnBlockBroken(toolStack, heldList); + heldList = newHeldList; + } + + return heldList; + } + + public int digSurroundingArea(ItemStack container, World world, EntityPlayer player, MovingObjectPosition blockPos, String usedToolClass, float blockHardness, int harvestLvl, ItemSpellMultiTool itemTool) + { + int cost = 0; + + for (IDigAreaEffect effect : this.digAreaEffectList) + { + cost += effect.digSurroundingArea(container, world, player, blockPos, usedToolClass, blockHardness, harvestLvl, itemTool); + } + + return cost; + } + + public int getFortuneLevel() + { + return this.fortuneLevel; + } + + public void setFortuneLevel(int fortuneLevel) + { + this.fortuneLevel = fortuneLevel; + } + + public boolean getSilkTouch() + { + return this.silkTouch; + } + + public void setSilkTouch(boolean silkTouch) + { + this.silkTouch = silkTouch; + } + + public int getDuration() + { + return this.duration; + } + + public void setDuration(int duration) + { + this.duration = duration; + } + + public void setDigSpeed(String toolClass, float digSpeed) + { + this.digSpeed.put(toolClass, digSpeed); + } + + public void setHarvestLevel(String toolClass, int hlvl) + { + this.harvestLevel.put(toolClass, hlvl); + } + + public float composeMaxDamageFromHash() + { + float damage = 0.0f; + + for (float f : this.maxDamageHash.values()) + { + damage += f; + } + + return damage; + } + + public void addDamageToHash(String key, float dmg) + { + this.maxDamageHash.put(key, dmg); + } + + public void addToolString(String key, String str) + { + if (str != null && key != null) + { + this.toolInfoString.put(key, str); + } + } + + public void addCritChance(String key, float chance) + { + //Chance is in percentage chance i.e. chance = 1.0 means 1.0% + this.critChanceHash.put(key, chance); + } + + public void addDuration(String key, int dur) + { + this.durationHash.put(key, dur); + } + + public float getCritChance() + { + float chance = 0.0f; + + for (float fl : this.critChanceHash.values()) + { + chance += fl; + } + + return chance; + } + + public float getAddedDamageForEntity(Entity entity) + { + HashMap hash = new HashMap(); + + for (ISpecialDamageEffect effect : this.specialDamageEffectList) + { + hash.put(effect.getKey(), effect.getDamageForEntity(entity)); + } + + float addedDmg = 0.0f; + + for (float fl : hash.values()) + { + addedDmg += fl; + } + + return addedDmg; + } +} \ No newline at end of file diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java new file mode 100644 index 0000000..84c4d3a --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningHelper.java @@ -0,0 +1,21 @@ +package WayofTime.alchemicalWizardry.api.summoningRegistry; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.world.World; + +public abstract class SummoningHelper +{ + protected String id; + + public SummoningHelper(String id) + { + this.id = id; + } + + public abstract EntityLivingBase getEntity(World worldObj); + + public String getSummoningHelperID() + { + return id; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java new file mode 100644 index 0000000..18180d8 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistry.java @@ -0,0 +1,70 @@ +package WayofTime.alchemicalWizardry.api.summoningRegistry; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.List; + +public class SummoningRegistry +{ + public static List summoningList = new ArrayList(); + + public static void registerSummon(SummoningHelper s, ItemStack[] ring1, ItemStack[] ring2, ItemStack[] ring3, int amountUsed, int bloodOrbLevel) + { + summoningList.add(new SummoningRegistryComponent(s, ring1, ring2, ring3, amountUsed, bloodOrbLevel)); + } + + public static boolean isRecipeValid(int bloodOrbLevel, ItemStack[] test1, ItemStack[] test2, ItemStack[] test3) + { + for (SummoningRegistryComponent src : summoningList) + { + if (src.getBloodOrbLevel() <= bloodOrbLevel && src.compareRing(1, test1) && src.compareRing(2, test2) && src.compareRing(3, test3)) + { + return true; + } + } + + return false; + } + + public static SummoningRegistryComponent getRegistryComponent(int bloodOrbLevel, ItemStack[] test1, ItemStack[] test2, ItemStack[] test3) + { + for (SummoningRegistryComponent src : summoningList) + { + if (src.getBloodOrbLevel() <= bloodOrbLevel && src.compareRing(1, test1) && src.compareRing(2, test2) && src.compareRing(3, test3)) + { + return src; + } + } + + return null; + } + + public static EntityLivingBase getEntity(World worldObj, int bloodOrbLevel, ItemStack[] test1, ItemStack[] test2, ItemStack[] test3) + { + for (SummoningRegistryComponent src : summoningList) + { + if (src.getBloodOrbLevel() <= bloodOrbLevel && src.compareRing(1, test1) && src.compareRing(2, test2) && src.compareRing(3, test3)) + { + return src.getEntity(worldObj); + } + } + + return null; + } + + public static EntityLivingBase getEntityWithID(World worldObj, String id) + { + for (SummoningRegistryComponent src : summoningList) + { + if (src.getSummoningHelperID().equals(id)) + { + return src.getEntity(worldObj); + } + } + + return null; + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java new file mode 100644 index 0000000..72dbd83 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/summoningRegistry/SummoningRegistryComponent.java @@ -0,0 +1,231 @@ +package WayofTime.alchemicalWizardry.api.summoningRegistry; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +public class SummoningRegistryComponent +{ + public ItemStack[] ring1 = new ItemStack[6]; + public ItemStack[] ring2 = new ItemStack[6]; + public ItemStack[] ring3 = new ItemStack[6]; + public SummoningHelper summoningHelper; + public int summoningCost; + public int bloodOrbLevel; + + public SummoningRegistryComponent(SummoningHelper s, ItemStack[] newRing1, ItemStack[] newRing2, ItemStack[] newRing3, int amount, int bloodOrbLevel) + { + this.summoningHelper = s; + this.ring1 = newRing1; + this.ring2 = newRing2; + this.ring3 = newRing3; + this.summoningCost = amount; + this.bloodOrbLevel = bloodOrbLevel; + + if (this.ring1.length != 6) + { + ItemStack[] newRecipe = new ItemStack[6]; + + for (int i = 0; i < 6; i++) + { + if (i + 1 > this.ring1.length) + { + newRecipe[i] = null; + } else + { + newRecipe[i] = this.ring1[i]; + } + } + + this.ring1 = newRecipe; + } + + if (this.ring2.length != 6) + { + ItemStack[] newRecipe = new ItemStack[6]; + + for (int i = 0; i < 6; i++) + { + if (i + 1 > this.ring2.length) + { + newRecipe[i] = null; + } else + { + newRecipe[i] = this.ring2[i]; + } + } + + this.ring2 = newRecipe; + } + + if (this.ring3.length != 6) + { + ItemStack[] newRecipe = new ItemStack[6]; + + for (int i = 0; i < 6; i++) + { + if (i + 1 > this.ring3.length) + { + newRecipe[i] = null; + } else + { + newRecipe[i] = this.ring3[i]; + } + } + + this.ring3 = newRecipe; + } + } + + public boolean compareRing(int ring, ItemStack[] checkedRingRecipe) + { + ItemStack[] recipe; + + if (checkedRingRecipe.length < 6) + { + return false; + } + + switch (ring) + { + case 1: + recipe = ring1; + break; + + case 2: + recipe = ring2; + break; + + case 3: + recipe = ring3; + break; + + default: + recipe = ring1; + } + + if (recipe.length != 6) + { + ItemStack[] newRecipe = new ItemStack[6]; + + for (int i = 0; i < 6; i++) + { + if (i + 1 > recipe.length) + { + newRecipe[i] = null; + } else + { + newRecipe[i] = recipe[i]; + } + } + + recipe = newRecipe; + } + + boolean[] checkList = new boolean[6]; + + for (int i = 0; i < 6; i++) + { + checkList[i] = false; + } + + for (int i = 0; i < 6; i++) + { + ItemStack recipeItemStack = recipe[i]; + + if (recipeItemStack == null) + { + continue; + } + + boolean test = false; + + for (int j = 0; j < 6; j++) + { + if (checkList[j]) + { + continue; + } + + ItemStack checkedItemStack = checkedRingRecipe[j]; + + if (checkedItemStack == null) + { + continue; + } + + boolean quickTest = false; + + if (recipeItemStack.getItem() instanceof ItemBlock) + { + if (checkedItemStack.getItem() instanceof ItemBlock) + { + quickTest = true; + } + } else if (!(checkedItemStack.getItem() instanceof ItemBlock)) + { + quickTest = true; + } + + if (!quickTest) + { + continue; + } + + if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage() || OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage()) && checkedItemStack.getItem() == recipeItemStack.getItem()) + { + test = true; + checkList[j] = true; + break; + } + } + + if (!test) + { + return false; + } + } + + return true; + } + + public int getSummoningCost() + { + return summoningCost; + } + + public EntityLivingBase getEntity(World world) + { + return this.summoningHelper.getEntity(world); + } + + public int getBloodOrbLevel() + { + return this.bloodOrbLevel; + } + + public ItemStack[] getRingRecipeForRing(int ring) + { + switch (ring) + { + case 1: + return ring1; + + case 2: + return ring2; + + case 3: + return ring3; + + default: + return null; + } + } + + public String getSummoningHelperID() + { + return this.summoningHelper.getSummoningHelperID(); + } +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java b/src/api/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java new file mode 100644 index 0000000..c70d618 --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/tile/IBloodAltar.java @@ -0,0 +1,26 @@ +package WayofTime.alchemicalWizardry.api.tile; + +/** + * Created by Pokefenn. + */ +public interface IBloodAltar +{ + + public int getCapacity(); + + public int getCurrentBlood(); + + public int getTier(); + + public int getProgress(); + + public float getSacrificeMultiplier(); + + public float getSelfSacrificeMultiplier(); + + public float getOrbMultiplier(); + + public float getDislocationMultiplier(); + + public int getBufferCapacity(); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java new file mode 100644 index 0000000..de9994b --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellParadigmTile.java @@ -0,0 +1,10 @@ +package WayofTime.alchemicalWizardry.api.tile; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public interface ISpellParadigmTile extends ISpellTile +{ + public void castSpell(World world, EntityPlayer entity, ItemStack spellCasterStack); +} diff --git a/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java new file mode 100644 index 0000000..143a0ea --- /dev/null +++ b/src/api/java/WayofTime/alchemicalWizardry/api/tile/ISpellTile.java @@ -0,0 +1,11 @@ +package WayofTime.alchemicalWizardry.api.tile; + +import net.minecraftforge.common.util.ForgeDirection; +import WayofTime.alchemicalWizardry.api.spell.SpellParadigm; + +public interface ISpellTile +{ + public void modifySpellParadigm(SpellParadigm parad); + + public boolean canInputRecieveOutput(ForgeDirection output); +} diff --git a/src/api/java/chylex/hee/api/AbstractAPI.java b/src/api/java/chylex/hee/api/AbstractAPI.java new file mode 100644 index 0000000..7a22e9e --- /dev/null +++ b/src/api/java/chylex/hee/api/AbstractAPI.java @@ -0,0 +1,11 @@ +package chylex.hee.api; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.LoaderState; + +public class AbstractAPI{ + protected AbstractAPI(){} + + protected final void validate(){ + if (!Loader.instance().isInState(LoaderState.POSTINITIALIZATION))throw new IllegalStateException("Do not use HEE API outside post initialization!"); + } +} diff --git a/src/api/java/chylex/hee/api/DecompositionAPI.java b/src/api/java/chylex/hee/api/DecompositionAPI.java new file mode 100644 index 0000000..a63dad2 --- /dev/null +++ b/src/api/java/chylex/hee/api/DecompositionAPI.java @@ -0,0 +1,37 @@ +package chylex.hee.api; +import net.minecraft.item.Item; +import chylex.hee.mechanics.misc.StardustDecomposition; + +/** + * API for Stardust and Decomposition Table (uncrafting). + */ +public final class DecompositionAPI extends AbstractAPI{ + DecompositionAPI(){} + + /** + * Blacklists an item and all of its damage values in the Decomposition Table. + * @param item Item to be banned. To ban a block, use {@link net.minecraft.item.Item#getItemFromBlock(net.minecraft.block.Block) getItemFromBlock(Block)} to convert it. + */ + public static void blacklistItem(Item item){ + blacklistItem(item,-1); + } + + /** + * Blacklists an item and selected damage values of it in the Decomposition Table. + * @param item Item to be banned. To ban a block, use {@link net.minecraft.item.Item#getItemFromBlock(net.minecraft.block.Block) getItemFromBlock(Block)} to convert it. + * @param blacklistedDamageValues Array of damage values to blacklist. + */ + public static void blacklistItem(Item item, int...blacklistedDamageValues){ + short[] damages = new short[blacklistedDamageValues.length]; + for(int a = 0; a < blacklistedDamageValues.length; a++)damages[a] = (short)blacklistedDamageValues[a]; + StardustDecomposition.addToBlacklist(item,damages); + } + + /** + * Blacklists items by parsing a string, which follows the same syntax rules as decompositionBlackList in configuration - {@code http://hardcore-ender-expansion.wikia.com/wiki/Configuration}. + * @param data String to parse. + */ + public static void blacklistItemFromString(String data){ + StardustDecomposition.addFromString(data); + } +} diff --git a/src/api/java/chylex/hee/api/EssenceAPI.java b/src/api/java/chylex/hee/api/EssenceAPI.java new file mode 100644 index 0000000..a137a9f --- /dev/null +++ b/src/api/java/chylex/hee/api/EssenceAPI.java @@ -0,0 +1,44 @@ +package chylex.hee.api; +import net.minecraft.item.ItemStack; +import chylex.hee.item.ItemList; +import chylex.hee.mechanics.essence.EssenceType; +import chylex.hee.mechanics.essence.handler.DragonEssenceHandler; +import chylex.hee.mechanics.essence.handler.dragon.AltarItemRecipe; + +/** + * API for Essences and Essence Altars. + */ +public final class EssenceAPI extends AbstractAPI{ + EssenceAPI(){} + + /** + * Adds an item exchange recipe to the Dragon Essence Altar. + * @param source ItemStack that will trigger the exchange. The stacks are compared using {@link ItemStack#isItemEqual(ItemStack) isItemEqual(ItemStack)}, if a different comparison method is needed, extend {@link chylex.hee.mechanics.essence.handler.dragon.AltarItemRecipe AltarItemRecipe}, override {@link chylex.hee.mechanics.essence.handler.dragon.AltarItemRecipe#isApplicable(ItemStack) isApplicable(ItemStack)} and register using {@link #addDragonItemRecipe(AltarItemRecipe)}. + * @param result Final ItemStack that is created after the exchange. + * @param cost Amount of Dragon Essence used, the final number may be lower if sockets are used. + */ + public void addDragonItemRecipe(ItemStack source, ItemStack result, int cost){ + validate(); + DragonEssenceHandler.recipes.add(new AltarItemRecipe(source,result,cost)); + } + + /** + * Adds an item exchange recipe to the Dragon Essence Altar. + * @param recipe Custom instance of AltarItemRecipe to use. + */ + public void addDragonItemRecipe(AltarItemRecipe recipe){ + validate(); + DragonEssenceHandler.recipes.add(recipe); + } + + /** + * Creates an ItemStack consisting of one essence of provided type. + * @param essenceType Type of essence. + * @return New ItemStack, or null if provided invalid value. + */ + public ItemStack createEssenceItemStack(EssenceType essenceType){ + validate(); + if (essenceType == null || essenceType == EssenceType.INVALID)return null; + return new ItemStack(ItemList.essence,1,essenceType.getItemDamage()); + } +} diff --git a/src/api/java/chylex/hee/api/HeeAPI.java b/src/api/java/chylex/hee/api/HeeAPI.java new file mode 100644 index 0000000..8834bd3 --- /dev/null +++ b/src/api/java/chylex/hee/api/HeeAPI.java @@ -0,0 +1,42 @@ +package chylex.hee.api; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.LoaderState; + +/** + * Main API class that contains and provides specific API instances. + */ +public final class HeeAPI{ + private static final EssenceAPI essenceAPI = new EssenceAPI(); + private static final WorldAPI worldAPI = new WorldAPI(); + private static final DecompositionAPI decompositionAPI = new DecompositionAPI(); + + /** + * @return API instance for Essences and Essence Altars. + */ + public static EssenceAPI essence(){ + validate(); + return essenceAPI; + } + + /** + * @return API instance for loot and new biomes in the End. + */ + public static WorldAPI world(){ + validate(); + return worldAPI; + } + + /** + * @return API instance for Stardust and Decomposition Table. + */ + public static DecompositionAPI decomposition(){ + validate(); + return decompositionAPI; + } + + private static void validate(){ + if (!Loader.instance().isInState(LoaderState.POSTINITIALIZATION))throw new IllegalStateException("Do not use HEE API outside post initialization!"); + } + + private HeeAPI(){} +} diff --git a/src/api/java/chylex/hee/api/WorldAPI.java b/src/api/java/chylex/hee/api/WorldAPI.java new file mode 100644 index 0000000..645ab2f --- /dev/null +++ b/src/api/java/chylex/hee/api/WorldAPI.java @@ -0,0 +1,104 @@ +package chylex.hee.api; +import net.minecraft.entity.EntityLiving; +import chylex.hee.api.wrappers.LootList; +import chylex.hee.world.structure.island.biome.IslandBiomeBase; +import chylex.hee.world.structure.island.biome.IslandBiomeBurningMountains; +import chylex.hee.world.structure.island.biome.IslandBiomeEnchantedIsland; +import chylex.hee.world.structure.island.biome.IslandBiomeInfestedForest; +import chylex.hee.world.structure.island.biome.feature.forest.StructureSilverfishDungeon; +import chylex.hee.world.structure.tower.ComponentTower; +import chylex.hee.world.util.SpawnEntry; + +/** + * API for manipulating with new biomes and loot. + */ +public final class WorldAPI extends AbstractAPI{ + WorldAPI(){} + + /** + * Adds a mob spawning entry to specified biome. List of existing entries is in javadoc of each {@link Biome}. + * @param biome Biome to add the entry to. + * @param mobClass Class of the mob to spawn. + * @param maxAmount Maximum amount of mobs of this type that can exist on the island at one point in time. + * @param weight Weight of the spawn entry. + */ + public static void addMobToBiome(Biome biome, Class mobClass, int maxAmount, int weight){ + SpawnEntry entry = new SpawnEntry(mobClass,maxAmount,weight); + + switch(biome){ + case InfestedForestDeep: IslandBiomeBase.infestedForest.getSpawnEntries(IslandBiomeInfestedForest.DEEP).add(entry); break; + case InfestedForestRavaged: IslandBiomeBase.infestedForest.getSpawnEntries(IslandBiomeInfestedForest.RAVAGED).add(entry); break; + case InfestedForestRuins: IslandBiomeBase.infestedForest.getSpawnEntries(IslandBiomeInfestedForest.RUINS).add(entry); break; + case BurningMountainsScorching: IslandBiomeBase.burningMountains.getSpawnEntries(IslandBiomeBurningMountains.SCORCHING).add(entry); break; + case BurningMountainsMine: IslandBiomeBase.burningMountains.getSpawnEntries(IslandBiomeBurningMountains.MINE).add(entry); break; + case EnchantedIslandHomeland: IslandBiomeBase.enchantedIsland.getSpawnEntries(IslandBiomeEnchantedIsland.HOMELAND).add(entry); break; + default: + } + } + + /** + * Returns manipulatable loot list. Always cache the returned object if you plan on using it multiple times! + * @param loot Type of loot to use. + * @return Instance of {@link chylex.hee.api.wrappers.LootList LootList}, or null if {@code loot} parameter is null. + */ + public LootList getLootList(LootType loot){ + switch(loot){ + case DungeonTowerRegular: return new LootList(ComponentTower.lootTower); + case DungeonTowerFuel: return new LootList(ComponentTower.lootFuel); + case SilverfishDungeon: return new LootList(StructureSilverfishDungeon.lootDungeon); + default: return null; + } + } + + /** + * List of biomes that generate in the End. + */ + public static enum Biome{ + /** + * {@code Mob type, max amount, weight}
+ * {@code EntitySilverfish, 35, 35}
+ * {@code EntityMobInfestedBat, 8, 10}
+ */ + InfestedForestDeep, + + InfestedForestRavaged, + + InfestedForestRuins, + + /** + * {@code Mob type, max amount, weight}
+ * {@code EntityMobFireGolem, 14, 10}
+ * {@code EntityMobScorchingLens, 10, 6}
+ */ + BurningMountainsScorching, + + BurningMountainsMine, + + /** + * {@code Mob type, max amount, weight}
+ * {@code EntityMobEnderGuardian, 9, 30}
+ * {@code EntityMobBabyEnderman, 16, 20}
+ */ + EnchantedIslandHomeland + } + + /** + * List of structures which generate loot inside them. + */ + public static enum LootType{ + /** + * Loot spawned inside chests, dispensers and similar containers in Dungeon Tower. + */ + DungeonTowerRegular, + + /** + * Loot spawned inside fuel slot of furnaces in Dungeon Tower. + */ + DungeonTowerFuel, + + /** + * Loot spawned inside Silverfish Dungeon chest. + */ + SilverfishDungeon + } +} diff --git a/src/api/java/chylex/hee/api/interfaces/IAcceptFieryEssence.java b/src/api/java/chylex/hee/api/interfaces/IAcceptFieryEssence.java new file mode 100644 index 0000000..eaff2af --- /dev/null +++ b/src/api/java/chylex/hee/api/interfaces/IAcceptFieryEssence.java @@ -0,0 +1,18 @@ +package chylex.hee.api.interfaces; + +/** + * Use this interface for any tile entities that should use Fiery Essence for a speed boost (or some other effect). + */ +public interface IAcceptFieryEssence{ + /** + * Returns how many times the Altar can boost the acceptor. Higher levels of essence should have higher boost. + * @param essenceLevel current level of essence + * @return amount of boosts available + */ + int getBoostAmount(int essenceLevel); + + /** + * Performs a single boost. This method is called multiple times, based on number returned by {@link #getBoostAmount(int)}. + */ + void boost(); +} diff --git a/src/api/java/chylex/hee/api/interfaces/IIgnoreEnderGoo.java b/src/api/java/chylex/hee/api/interfaces/IIgnoreEnderGoo.java new file mode 100644 index 0000000..f2caac2 --- /dev/null +++ b/src/api/java/chylex/hee/api/interfaces/IIgnoreEnderGoo.java @@ -0,0 +1,6 @@ +package chylex.hee.api.interfaces; + +/** + * Ender Goo will not give bad effects to entities that implement this interface. + */ +public interface IIgnoreEnderGoo{} diff --git a/src/api/java/chylex/hee/api/wrappers/LootList.java b/src/api/java/chylex/hee/api/wrappers/LootList.java new file mode 100644 index 0000000..03ea2b7 --- /dev/null +++ b/src/api/java/chylex/hee/api/wrappers/LootList.java @@ -0,0 +1,49 @@ +package chylex.hee.api.wrappers; +import java.util.Iterator; +import net.minecraft.item.Item; +import chylex.hee.world.loot.IItemPostProcessor; +import chylex.hee.world.loot.LootItemStack; +import chylex.hee.world.loot.WeightedLootList; + +/** + * A wrapper class for simplified access to weighted loot list. + */ +public class LootList{ + private final WeightedLootList wrappedCollection; + + public LootList(WeightedLootList loot){ + this.wrappedCollection = loot; + } + + /** + * Adds new loot to the list. + * @param lootItemStack Instance of {@link chylex.hee.world.loot.LootItemStack LootItemStack} that holds basic generation properties. + */ + public void addLoot(LootItemStack lootItemStack){ + wrappedCollection.add(lootItemStack); + } + + /** + * Adds a post processor to the list, using anonymous class is suggested. + * @param postProcessor Handler that will modify item right before it's placed into the container. + */ + public void addPostProcessor(IItemPostProcessor postProcessor){ + wrappedCollection.addItemPostProcessor(postProcessor); + } + + /** + * Deletes a specific item from the list. Iteration is performed, and first instance of {@link chylex.hee.world.loot.LootItemStack LootItemStack} with specified item is removed. + * @param item Item to remove. + * @return True if any item was removed. + */ + public boolean removeItem(Item item){ + for(Iterator iter = wrappedCollection.iterator(); iter.hasNext();){ + if (iter.next().getItem() == item){ + iter.remove(); + return true; + } + } + + return false; + } +} diff --git a/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedCraftingManager.java b/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedCraftingManager.java new file mode 100644 index 0000000..26a0bfb --- /dev/null +++ b/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedCraftingManager.java @@ -0,0 +1,141 @@ +package naruto1310.extendedWorkbench.crafting; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; + +public class ExtendedCraftingManager +{ + /** The static instance of this class */ + private static final ExtendedCraftingManager instance = new ExtendedCraftingManager(); + + /** A list of all the recipes added */ + private List recipes = new ArrayList(); + + /** + * Returns the static instance of this class + */ + public static final ExtendedCraftingManager getInstance() + { + return instance; + } + + private void addExtendedRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj) + { + String var3 = ""; + int var4 = 0; + int var5 = 0; + int var6 = 0; + + if(par2ArrayOfObj[var4] instanceof String[]) + { + String[] var7 =((String[])par2ArrayOfObj[var4++]); + + for(int var8 = 0; var8 < var7.length; ++var8) + { + String var9 = var7[var8]; + ++var6; + var5 = var9.length(); + var3 = var3 + var9; + } + } + else + { + while(par2ArrayOfObj[var4] instanceof String) + { + String var11 =(String)par2ArrayOfObj[var4++]; + ++var6; + var5 = var11.length(); + var3 = var3 + var11; + } + } + + HashMap var12; + + for(var12 = new HashMap(); var4 < par2ArrayOfObj.length; var4 += 2) + { + Character var13 =(Character)par2ArrayOfObj[var4]; + ItemStack var14 = null; + + if(par2ArrayOfObj[var4 + 1] instanceof Item) + var14 = new ItemStack((Item)par2ArrayOfObj[var4 + 1], 1, 32767); + if(par2ArrayOfObj[var4 + 1] instanceof Block) + var14 = new ItemStack((Block)par2ArrayOfObj[var4 + 1], 1, 32767); + if(par2ArrayOfObj[var4 + 1] instanceof ItemStack) + var14 =(ItemStack)par2ArrayOfObj[var4 + 1]; + + var12.put(var13, var14); + } + + ItemStack[] var15 = new ItemStack[var5 * var6]; + + for(int var16 = 0; var16 < var5 * var6; ++var16) + { + char var10 = var3.charAt(var16); + + if(var12.containsKey(Character.valueOf(var10))) + var15[var16] = var12.get(Character.valueOf(var10)).copy(); + else + var15[var16] = null; + } + + this.recipes.add(new ExtendedShapedRecipes(var5, var6, var15, par1ItemStack)); + } + + private void addExtendedShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj) + { + ArrayList var3 = new ArrayList(); + Object[] var4 = par2ArrayOfObj; + int var5 = par2ArrayOfObj.length; + + for(int var6 = 0; var6 < var5; var6++) + { + Object var7 = var4[var6]; + + if(var7 instanceof Item) + var3.add(new ItemStack((Item)var7, 1, 32767)); + else if(var7 instanceof Block) + var3.add(new ItemStack((Block)var7, 1, 32767)); + else if(var7 instanceof ItemStack) + var3.add(((ItemStack)var7).copy()); + else throw new RuntimeException("Invalid shapeless recipy!"); + } + + this.recipes.add(new ExtendedShapelessRecipes(par1ItemStack, var3)); + } + + public ItemStack findMatchingRecipe(InventoryCrafting inv, World world) + { + for(int i = 0; i < this.recipes.size(); i++) + { + IRecipe recipe = this.recipes.get(i); + + if(recipe.matches(inv, world)) + return recipe.getCraftingResult(inv); + } + + return null; + } + + public List getRecipeList() + { + return this.recipes; + } + + public static void addRecipe(ItemStack output, Object ... input) + { + ExtendedCraftingManager.getInstance().addExtendedRecipe(output, input); + } + + public static void addShapelessRecipe(ItemStack output, Object ... input) + { + ExtendedCraftingManager.getInstance().addExtendedShapelessRecipe(output, input); + } +} diff --git a/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedShapedRecipes.java b/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedShapedRecipes.java new file mode 100644 index 0000000..78c6c09 --- /dev/null +++ b/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedShapedRecipes.java @@ -0,0 +1,103 @@ +package naruto1310.extendedWorkbench.crafting; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ExtendedShapedRecipes implements IExtendedRecipe +{ + private int maxRecipeSize = 6; + + /** How many horizontal slots this recipe is wide. */ + private int recipeWidth; + + /** How many vertical slots this recipe uses. */ + private int recipeHeight; + + /** Is a array of ItemStack that composes the recipe. */ + private ItemStack[] recipeItems; + + /** Is the ItemStack that you get when craft the recipe. */ + private ItemStack recipeOutput; + + public ExtendedShapedRecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack) + { + this.recipeWidth = par1; + this.recipeHeight = par2; + this.recipeItems = par3ArrayOfItemStack; + this.recipeOutput = par4ItemStack; + } + + @Override + public ItemStack getRecipeOutput() + { + return this.recipeOutput; + } + + /** + * Used to check if a recipe matches current crafting inventory + */ + @Override + public boolean matches(InventoryCrafting par1InventoryCrafting, World world) + { + for(int x = 0; x <= this.maxRecipeSize - this.recipeWidth; ++x) + for(int y = 0; y <= this.maxRecipeSize - this.recipeHeight; ++y) + if(this.checkMatch(par1InventoryCrafting, x, y, true) || this.checkMatch(par1InventoryCrafting, x, y, false)) + return true; + + return false; + } + + /** + * Checks if the region of a crafting inventory is match for the recipe. + */ + private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int x, int y, boolean mirrored) + { + for(int i = 0; i < this.maxRecipeSize; ++i) + { + for(int j = 0; j < this.maxRecipeSize; ++j) + { + int var7 = i - x; + int var8 = j - y; + ItemStack stackFound = null; + + if(var7 >= 0 && var8 >= 0 && var7 < this.recipeWidth && var8 < this.recipeHeight) + if(mirrored) + stackFound = this.recipeItems[this.recipeWidth - var7 - 1 + var8 * this.recipeWidth]; + else + stackFound = this.recipeItems[var7 + var8 * this.recipeWidth]; + + ItemStack stackExcpected = par1InventoryCrafting.getStackInRowAndColumn(i, j); + + if(stackFound == null && stackExcpected == null) + continue; + if((stackExcpected == null && stackFound != null) || (stackExcpected != null && stackFound == null)) + return false; + if(stackFound.getItem() != stackExcpected.getItem()) + return false; + if(stackFound.getItemDamage() != 32767 && stackFound.getItemDamage() != stackExcpected.getItemDamage()) + return false; + } + } + + return true; + } + + /** + * Returns an Item that is the result of this recipe + */ + @Override + public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) + { + return this.getRecipeOutput().copy(); + } + + /** + * Returns the size of the recipe area + */ + @Override + public int getRecipeSize() + { + return this.recipeWidth * this.recipeHeight; + } +} diff --git a/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedShapelessRecipes.java b/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedShapelessRecipes.java new file mode 100644 index 0000000..077e823 --- /dev/null +++ b/src/api/java/naruto1310/extendedWorkbench/crafting/ExtendedShapelessRecipes.java @@ -0,0 +1,92 @@ +package naruto1310.extendedWorkbench.crafting; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class ExtendedShapelessRecipes implements IExtendedRecipe +{ + private int maxRecipeSize = 6; + + /** Is the ItemStack that you get when craft the recipe. */ + private final ItemStack recipeOutput; + + /** Is a List of ItemStack that composes the recipe. */ + private final List recipeItems; + + public ExtendedShapelessRecipes(ItemStack par1ItemStack, List par2List) + { + this.recipeOutput = par1ItemStack; + this.recipeItems = par2List; + } + + @Override + public ItemStack getRecipeOutput() + { + return this.recipeOutput; + } + + /** + * Used to check if a recipe matches current crafting inventory + */ + @Override + public boolean matches(InventoryCrafting par1InventoryCrafting, World world) + { + ArrayList var2 = new ArrayList(this.recipeItems); + + for (int var3 = 0; var3 < this.maxRecipeSize; ++var3) + { + for (int var4 = 0; var4 < this.maxRecipeSize; ++var4) + { + ItemStack var5 = par1InventoryCrafting.getStackInRowAndColumn(var4, var3); + + if (var5 != null) + { + boolean var6 = false; + Iterator var7 = var2.iterator(); + + while (var7.hasNext()) + { + ItemStack var8 = var7.next(); + + if (var5 == var8 && (var8.getItemDamage() == 32767 || var5.getItemDamage() == var8.getItemDamage())) + { + var6 = true; + var2.remove(var8); + break; + } + } + + if (!var6) + { + return false; + } + } + } + } + + return var2.isEmpty(); + } + + /** + * Returns an Item that is the result of this recipe + */ + @Override + public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) + { + return this.recipeOutput.copy(); + } + + /** + * Returns the size of the recipe area + */ + @Override + public int getRecipeSize() + { + return this.recipeItems.size(); + } +} diff --git a/src/api/java/naruto1310/extendedWorkbench/crafting/IExtendedRecipe.java b/src/api/java/naruto1310/extendedWorkbench/crafting/IExtendedRecipe.java new file mode 100644 index 0000000..526cfca --- /dev/null +++ b/src/api/java/naruto1310/extendedWorkbench/crafting/IExtendedRecipe.java @@ -0,0 +1,8 @@ +package naruto1310.extendedWorkbench.crafting; + +import net.minecraft.item.crafting.IRecipe; + +public interface IExtendedRecipe extends IRecipe +{ + +} diff --git a/src/main/java/modtweaker/ClientEvents.java b/src/main/java/modtweaker/ClientEvents.java new file mode 100644 index 0000000..1545106 --- /dev/null +++ b/src/main/java/modtweaker/ClientEvents.java @@ -0,0 +1,35 @@ +package modtweaker; + +import static modtweaker.helpers.LogHelper.print; +import minetweaker.api.item.IItemStack; +import minetweaker.api.minecraft.MineTweakerMC; +import minetweaker.api.player.IPlayer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.GameSettings; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class ClientEvents { + public static int cooldown; + public static boolean active; + + @SubscribeEvent + public void onDrawTooltip(ItemTooltipEvent event) { + if (active) { + IPlayer player = MineTweakerMC.getIPlayer(event.entityPlayer); + if (player != null) { + IItemStack hand = MineTweakerMC.getIItemStack(event.itemStack); + if (hand != null) { + String print = hand.toString(); + event.toolTip.add(print); + if (GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint)) { + if (cooldown <= 0) { + cooldown = 30; + print(print + " -- " + hand.getDisplayName()); + } else cooldown--; + } else cooldown--; + } + } + } + } +} diff --git a/src/main/java/modtweaker/ModProps.java b/src/main/java/modtweaker/ModProps.java new file mode 100644 index 0000000..2e37793 --- /dev/null +++ b/src/main/java/modtweaker/ModProps.java @@ -0,0 +1,9 @@ +package modtweaker; + +public class ModProps { + + public static final String NAME = "Mod Tweaker 2", name = NAME; + public static final String MODID = "modtweaker2", modid = MODID; + public static final String VERSION = "0.0.1", version = VERSION; + public static final String DEPENDENCIES = "required-after:MineTweaker3", dependencies = DEPENDENCIES; +} diff --git a/src/main/java/modtweaker/ModTweaker.java b/src/main/java/modtweaker/ModTweaker.java new file mode 100644 index 0000000..1c7043a --- /dev/null +++ b/src/main/java/modtweaker/ModTweaker.java @@ -0,0 +1,78 @@ +package modtweaker; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.player.IPlayer; +import minetweaker.api.server.ICommandFunction; +import modtweaker.mods.bloodmagic.BloodMagic; +import modtweaker.mods.botania.Botania; +import modtweaker.mods.exnihilo.ExNihilo; +import modtweaker.mods.extendedworkbench.ExtendedWorkbench; +import modtweaker.mods.factorization.Factorization; +import modtweaker.mods.fsp.Steamcraft; +import modtweaker.mods.hee.HardcoreEnderExpansion; +import modtweaker.mods.mariculture.Mariculture; +import modtweaker.mods.mekanism.Mekanism; +import modtweaker.mods.mekanism.gas.GasLogger; +import modtweaker.mods.metallurgy.Metallurgy; +import modtweaker.mods.pneumaticcraft.PneumaticCraft; +import modtweaker.mods.railcraft.Railcraft; +import modtweaker.mods.tconstruct.MaterialLogger; +import modtweaker.mods.tconstruct.TConstruct; +import modtweaker.mods.thaumcraft.Thaumcraft; +import modtweaker.mods.thaumcraft.research.ResearchLogger; +import modtweaker.mods.thermalexpansion.ThermalExpansion; +import modtweaker.util.TweakerPlugin; +import net.minecraftforge.common.MinecraftForge; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.relauncher.Side; + +@Mod(modid = ModProps.modid, name = ModProps.name, dependencies = ModProps.dependencies) +public class ModTweaker { + @EventHandler + public void init(FMLInitializationEvent event) { + TweakerPlugin.register("AWWayofTime", BloodMagic.class); + TweakerPlugin.register("Botania", Botania.class); + TweakerPlugin.register("exnihilo", ExNihilo.class); + TweakerPlugin.register("extendedWorkbench", ExtendedWorkbench.class); + TweakerPlugin.register("factorization", Factorization.class); + TweakerPlugin.register("HardcoreEnderExpansion", HardcoreEnderExpansion.class); + TweakerPlugin.register("Mariculture", Mariculture.class); + TweakerPlugin.register("Mekanism", Mekanism.class); + TweakerPlugin.register("Metallurgy", Metallurgy.class); + TweakerPlugin.register("PneumaticCraft", PneumaticCraft.class); + TweakerPlugin.register("Railcraft", Railcraft.class); + TweakerPlugin.register("Steamcraft", Steamcraft.class); + TweakerPlugin.register("TConstruct", TConstruct.class); + TweakerPlugin.register("Thaumcraft", Thaumcraft.class); + TweakerPlugin.register("ThermalExpansion", ThermalExpansion.class); + if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { + MinecraftForge.EVENT_BUS.register(new ClientEvents()); + } + } + + @EventHandler + public void onServerStart(FMLServerStartingEvent event) { + MineTweakerAPI.server.addMineTweakerCommand("tooltips", new String[] { "/minetweaker tooltips", " Adds tooltips to all items ingame with their mt script name, press ctrl on an item to print to the log" }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + ClientEvents.active = !ClientEvents.active; + } + }); + + if (TweakerPlugin.isLoaded("Mekanism")) { + MineTweakerAPI.server.addMineTweakerCommand("gases", new String[] { "/minetweaker gases", " Outputs a list of all gas names in the game to the minetweaker log" }, new GasLogger()); + } + + if (TweakerPlugin.isLoaded("Thaumcraft")) { + MineTweakerAPI.server.addMineTweakerCommand("research", new String[] { "/minetweaker research", "/minetweaker research [CATEGORY]", " Outputs a list of all category names in the game to the minetweaker log," + " or outputs a list of all research keys in a category to the log." }, new ResearchLogger()); + } + + if (TweakerPlugin.isLoaded("TConstruct")) { + MineTweakerAPI.server.addMineTweakerCommand("materials", new String[] { "/minetweaker materials", " Outputs a list of all Tinker's Construct material names in the game to the minetweaker log" }, new MaterialLogger()); + } + } +} diff --git a/src/main/java/modtweaker/helpers/ForgeHelper.java b/src/main/java/modtweaker/helpers/ForgeHelper.java new file mode 100644 index 0000000..02ab887 --- /dev/null +++ b/src/main/java/modtweaker/helpers/ForgeHelper.java @@ -0,0 +1,48 @@ +package modtweaker.helpers; + +import static modtweaker.helpers.ReflectionHelper.getFinalObject; +import static modtweaker.helpers.ReflectionHelper.getStaticObject; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.ForgeHooks; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; + +public class ForgeHelper { + public static Map translate = null; + public static List seeds = null; + public static HashMap loot = null; + + static { + try { + seeds = getStaticObject(ForgeHooks.class, "seedList"); + loot = getStaticObject(ChestGenHooks.class, "chestInfo"); + translate = getFinalObject(getStaticObject(StatCollector.class, "localizedName", "field_74839_a"), "languageList", "field_74816_c"); + } catch (Exception e) {} + } + + private ForgeHelper() {} + + public static Object getSeedEntry(ItemStack stack, int weight) { + try { + Class clazz = Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry"); + Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, int.class); + constructor.setAccessible(true); + return constructor.newInstance(stack, weight); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate SeedEntry"); + } + } + + public static boolean isLangActive(String lang) { + return FMLCommonHandler.instance().getSide() == Side.SERVER ? null : FMLClientHandler.instance().getCurrentLanguage().equals(lang); + } +} diff --git a/src/main/java/modtweaker/helpers/InputHelper.java b/src/main/java/modtweaker/helpers/InputHelper.java new file mode 100644 index 0000000..e279fd7 --- /dev/null +++ b/src/main/java/modtweaker/helpers/InputHelper.java @@ -0,0 +1,118 @@ +package modtweaker.helpers; + +import java.util.ArrayList; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import minetweaker.api.oredict.IOreDictEntry; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +public class InputHelper { + public static boolean isABlock(IItemStack block) { + if (!(isABlock(toStack(block)))) { + MineTweakerAPI.getLogger().logError("Item must be a block, or you must specify a block to render as when adding a TConstruct Melting recipe"); + return false; + } else return true; + } + + public static boolean isABlock(ItemStack block) { + return block.getItem() instanceof ItemBlock; + } + + public static ItemStack toStack(IItemStack iStack) { + if (iStack == null) return null; + else { + Object internal = iStack.getInternal(); + if (internal == null || !(internal instanceof ItemStack)) { + MineTweakerAPI.getLogger().logError("Not a valid item stack: " + iStack); + } + + return (ItemStack) internal; + } + } + + public static ItemStack[] toStacks(IItemStack[] iStack) { + if (iStack == null) return null; + else { + ItemStack[] output = new ItemStack[iStack.length]; + for (int i = 0; i < iStack.length; i++) { + output[i] = toStack(iStack[i]); + } + + return output; + } + } + + public static Object toObject(IIngredient iStack) { + if (iStack == null) return null; + else { + if (iStack instanceof IOreDictEntry) { + return toString((IOreDictEntry) iStack); + } else if (iStack instanceof IItemStack) { + return toStack((IItemStack) iStack); + } else return null; + } + } + + public static Object[] toObjects(IIngredient[] ingredient) { + if (ingredient == null) return null; + else { + Object[] output = new Object[ingredient.length]; + for (int i = 0; i < ingredient.length; i++) { + if (ingredient[i] != null) { + output[i] = toObject(ingredient[i]); + } else output[i] = ""; + } + + return output; + } + } + + public static Object[] toShapedObjects(IIngredient[][] ingredients) { + if (ingredients == null) return null; + else { + ArrayList prep = new ArrayList(); + prep.add("abc"); + prep.add("def"); + prep.add("ghi"); + char[][] map = new char[][] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' } }; + for (int x = 0; x < ingredients.length; x++) { + if (ingredients[x] != null) { + for (int y = 0; y < ingredients[x].length; y++) { + if (ingredients[x][y] != null && x < map.length && y < map[x].length) { + prep.add(map[x][y]); + prep.add(toObject(ingredients[x][y])); + } + } + } + } + return prep.toArray(); + } + } + + public static String toString(IOreDictEntry entry) { + return ((IOreDictEntry) entry).getName(); + } + + public static FluidStack toFluid(ILiquidStack iStack) { + if (iStack == null) { + return null; + } else return FluidRegistry.getFluidStack(iStack.getName(), iStack.getAmount()); + } + + public static FluidStack[] toFluids(IIngredient[] input) { + return toFluids((IItemStack[]) input); + } + + public static FluidStack[] toFluids(ILiquidStack[] iStack) { + FluidStack[] stack = new FluidStack[iStack.length]; + for (int i = 0; i < stack.length; i++) + stack[i] = toFluid(iStack[i]); + return stack; + } +} diff --git a/src/main/java/modtweaker/helpers/LogHelper.java b/src/main/java/modtweaker/helpers/LogHelper.java new file mode 100644 index 0000000..cc536a5 --- /dev/null +++ b/src/main/java/modtweaker/helpers/LogHelper.java @@ -0,0 +1,24 @@ +package modtweaker.helpers; + +import minetweaker.MineTweakerAPI; +import minetweaker.MineTweakerImplementationAPI; +import minetweaker.api.player.IPlayer; + +public class LogHelper { + public static void logPrinted(IPlayer player) { + if (player != null) { + player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir")); + } + } + + public static void log(IPlayer player, String message) { + if (player != null) { + player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message)); + } + } + + public static void print(String string) { + System.out.println(string); + MineTweakerAPI.logCommand(string); + } +} diff --git a/src/main/java/modtweaker/helpers/ReflectionHelper.java b/src/main/java/modtweaker/helpers/ReflectionHelper.java new file mode 100644 index 0000000..b3b32fd --- /dev/null +++ b/src/main/java/modtweaker/helpers/ReflectionHelper.java @@ -0,0 +1,71 @@ +package modtweaker.helpers; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +public class ReflectionHelper { + public static Constructor getConstructor(String string, Class... types) { + try { + Class clazz = Class.forName(string); + Constructor constructor = clazz.getDeclaredConstructor(types); + constructor.setAccessible(true); + return constructor; + } catch (Exception ex) {} + + return null; + } + + public static T getObject(Object o, String... fieldName) { + Class cls = o.getClass(); + for (String field : fieldName) { + try { + Field result = cls.getDeclaredField(field); + result.setAccessible(true); + return (T) result.get(o); + } catch (Exception ex) {} + } + + return null; + } + + public static T getFinalObject(Object o, String... fieldName) { + Class cls = o.getClass(); + for (String field : fieldName) { + try { + Field result = cls.getDeclaredField(field); + result.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(result, result.getModifiers() & ~Modifier.FINAL); + return (T) result.get(o); + } catch (Exception ex) {} + } + + return null; + } + + public static T getStaticObject(Class cls, String... fieldName) { + for (String field : fieldName) { + try { + Field result = cls.getDeclaredField(field); + result.setAccessible(true); + return (T) result.get(null); + } catch (Exception e) {} + } + + return null; + } + + public static void setPrivateValue(Class cls, String field, int var) { + try { + Field f = cls.getDeclaredField(field); + f.setAccessible(true); + f.setInt(null, var); + } catch (Exception e) {} + } + + public static void setPrivateValue(Class cls, Object o, String field, Object var) { + cpw.mods.fml.relauncher.ReflectionHelper.setPrivateValue(cls, o, var, field); + } +} diff --git a/src/main/java/modtweaker/helpers/StackHelper.java b/src/main/java/modtweaker/helpers/StackHelper.java new file mode 100644 index 0000000..dea561d --- /dev/null +++ b/src/main/java/modtweaker/helpers/StackHelper.java @@ -0,0 +1,15 @@ +package modtweaker.helpers; + +import modtweaker.mods.botania.Botania; +import modtweaker.util.TweakerPlugin; +import net.minecraft.item.ItemStack; + +public class StackHelper { + //Stack is the stack that is part of a recipe, stack2 is the one input trying to match + public static boolean areEqual(ItemStack stack, ItemStack stack2) { + if (stack == null || stack2 == null) return false; + else if (TweakerPlugin.isLoaded("Botania") && Botania.isSubtile(stack) && Botania.isSubtile(stack2)) { + return Botania.subtileMatches(stack, stack2); + } else return stack.isItemEqual(stack2); + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java b/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java new file mode 100644 index 0000000..928f65a --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/BloodMagic.java @@ -0,0 +1,16 @@ +package modtweaker.mods.bloodmagic; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.bloodmagic.handlers.Alchemy; +import modtweaker.mods.bloodmagic.handlers.Binding; +import modtweaker.mods.bloodmagic.handlers.BloodAltar; +import modtweaker.mods.bloodmagic.handlers.BloodOrb; + +public class BloodMagic { + public BloodMagic() { + MineTweakerAPI.registerClass(Alchemy.class); + MineTweakerAPI.registerClass(Binding.class); + MineTweakerAPI.registerClass(BloodAltar.class); + MineTweakerAPI.registerClass(BloodOrb.class); + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/Alchemy.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/Alchemy.java new file mode 100644 index 0000000..22dcf7e --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/Alchemy.java @@ -0,0 +1,68 @@ +package modtweaker.mods.bloodmagic.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.InputHelper.toStacks; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipe; +import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry; + +@ZenClass("mods.bloodmagic.Alchemy") +public class Alchemy { + //Adding a Blood Magic Alchemical Chemistry Set recipe + @ZenMethod + public static void addRecipe(IItemStack output, IItemStack[] input, int tier, int lp) { + MineTweakerAPI.apply(new Add(new AlchemyRecipe(toStack(output), (int) (((double) lp) / 100), toStacks(input), tier))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(AlchemyRecipe recipe) { + super("Alchemical Chemistry Set", AlchemyRecipeRegistry.recipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((AlchemyRecipe) recipe).getResult().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Blood Magic Alchemical Chemistry Set recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Alchemical Chemistry Set", AlchemyRecipeRegistry.recipes, stack); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (AlchemyRecipe r : AlchemyRecipeRegistry.recipes) { + if (r.getResult() != null && areEqual(r.getResult(), stack)) { + recipe = r; + break; + } + } + + AlchemyRecipeRegistry.recipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/Binding.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/Binding.java new file mode 100644 index 0000000..220a47b --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/Binding.java @@ -0,0 +1,67 @@ +package modtweaker.mods.bloodmagic.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import WayofTime.alchemicalWizardry.api.bindingRegistry.BindingRecipe; +import WayofTime.alchemicalWizardry.api.bindingRegistry.BindingRegistry; + +@ZenClass("mods.bloodmagic.Binding") +public class Binding { + //Adding a Blood Magic Binding recipe + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new BindingRecipe(toStack(output), toStack(input)))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(BindingRecipe recipe) { + super("Binding", BindingRegistry.bindingRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((BindingRecipe) recipe).getResult().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Blood Magic Binding recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Binding", BindingRegistry.bindingRecipes, stack); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (BindingRecipe r : BindingRegistry.bindingRecipes) { + if (r.getResult() != null && areEqual(r.getResult(), stack)) { + recipe = r; + break; + } + } + + BindingRegistry.bindingRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/BloodAltar.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/BloodAltar.java new file mode 100644 index 0000000..448c535 --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/BloodAltar.java @@ -0,0 +1,71 @@ +package modtweaker.mods.bloodmagic.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipe; +import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipeRegistry; + +@ZenClass("mods.bloodmagic.Altar") +public class BloodAltar { + //Adding a Blood Magic Altar recipe + @ZenMethod + public static void addRecipe(IItemStack output, IItemStack input, int tier, int lp, @Optional int consume, @Optional int drain) { + consume = consume > 0 ? consume : 20; + drain = drain > 0 ? drain : 20; + + MineTweakerAPI.apply(new Add(new AltarRecipe(toStack(output), toStack(input), tier, lp, consume, drain, false))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(AltarRecipe recipe) { + super("Blood Altar", AltarRecipeRegistry.altarRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((AltarRecipe) recipe).getResult().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Blood Magic Altar recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Blood Altar", AltarRecipeRegistry.altarRecipes, stack); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (AltarRecipe r : AltarRecipeRegistry.altarRecipes) { + if (r.getResult() != null && areEqual(r.getResult(), stack)) { + recipe = r; + break; + } + } + + AltarRecipeRegistry.altarRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/bloodmagic/handlers/BloodOrb.java b/src/main/java/modtweaker/mods/bloodmagic/handlers/BloodOrb.java new file mode 100644 index 0000000..376f747 --- /dev/null +++ b/src/main/java/modtweaker/mods/bloodmagic/handlers/BloodOrb.java @@ -0,0 +1,58 @@ +package modtweaker.mods.bloodmagic.handlers; + +import static modtweaker.helpers.InputHelper.toObjects; +import static modtweaker.helpers.InputHelper.toShapedObjects; +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseCraftingAddition; +import modtweaker.util.BaseCraftingRemoval; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe; +import WayofTime.alchemicalWizardry.api.items.ShapelessBloodOrbRecipe; + +@ZenClass("mods.bloodmagic.BloodOrb") +public class BloodOrb { + @ZenMethod + public static void addShaped(IItemStack output, IIngredient[][] ingredients) { + MineTweakerAPI.apply(new Add(false, toStack(output), toShapedObjects(ingredients))); + } + + @ZenMethod + public static void addShapeless(IItemStack output, IIngredient[] ingredients) { + MineTweakerAPI.apply(new Add(true, toStack(output), toObjects(ingredients))); + } + + private static class Add extends BaseCraftingAddition { + public Add(boolean shapeless, ItemStack output, Object... recipe) { + super("Blood Orb", shapeless, CraftingManager.getInstance().getRecipeList(), output, recipe); + } + + @Override + public void applyShaped() { + list.add(new ShapedBloodOrbRecipe(output, recipe)); + } + + @Override + public void applyShapeless() { + list.add(new ShapelessBloodOrbRecipe(output, recipe)); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseCraftingRemoval { + public Remove(ItemStack stack) { + super("Blood Orb", CraftingManager.getInstance().getRecipeList(), stack); + } + } +} diff --git a/src/main/java/modtweaker/mods/botania/Botania.java b/src/main/java/modtweaker/mods/botania/Botania.java new file mode 100644 index 0000000..861f755 --- /dev/null +++ b/src/main/java/modtweaker/mods/botania/Botania.java @@ -0,0 +1,28 @@ +package modtweaker.mods.botania; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.botania.handlers.Apothecary; +import modtweaker.mods.botania.handlers.ElvenTrade; +import modtweaker.mods.botania.handlers.ManaInfusion; +import modtweaker.mods.botania.handlers.Orechid; +import modtweaker.mods.botania.handlers.RuneAltar; +import net.minecraft.item.ItemStack; +import vazkii.botania.common.item.block.ItemBlockSpecialFlower; + +public class Botania { + public Botania() { + MineTweakerAPI.registerClass(Apothecary.class); + MineTweakerAPI.registerClass(ElvenTrade.class); + MineTweakerAPI.registerClass(ManaInfusion.class); + MineTweakerAPI.registerClass(Orechid.class); + MineTweakerAPI.registerClass(RuneAltar.class); + } + + public static boolean isSubtile(ItemStack stack) { + return stack.getItem() instanceof ItemBlockSpecialFlower; + } + + public static boolean subtileMatches(ItemStack stack, ItemStack stack2) { + return (ItemBlockSpecialFlower.getType(stack2).equals(ItemBlockSpecialFlower.getType(stack))); + } +} diff --git a/src/main/java/modtweaker/mods/botania/handlers/Apothecary.java b/src/main/java/modtweaker/mods/botania/handlers/Apothecary.java new file mode 100644 index 0000000..1afc0f9 --- /dev/null +++ b/src/main/java/modtweaker/mods/botania/handlers/Apothecary.java @@ -0,0 +1,75 @@ +package modtweaker.mods.botania.handlers; + +import static modtweaker.helpers.InputHelper.toObjects; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.recipe.RecipePetals; +import vazkii.botania.common.item.block.ItemBlockSpecialFlower; + +@ZenClass("mods.botania.Apothecary") +public class Apothecary { + @ZenMethod + public static void addRecipe(IItemStack output, IIngredient[] input) { + MineTweakerAPI.apply(new Add(new RecipePetals(toStack(output), toObjects(input)))); + } + + @ZenMethod + public static void addRecipe(String output, IIngredient[] input) { + MineTweakerAPI.apply(new Add(new RecipePetals(ItemBlockSpecialFlower.ofType(output), toObjects(input)))); + } + + private static class Add extends BaseListAddition { + public Add(RecipePetals recipe) { + super("Botania Petal Recipe", BotaniaAPI.petalRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipePetals) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + @ZenMethod + public static void removeRecipe(String output) { + MineTweakerAPI.apply(new Remove(ItemBlockSpecialFlower.ofType(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Botania Petal recipe", BotaniaAPI.petalRecipes, stack); + } + + @Override + public void apply() { + for (RecipePetals r : BotaniaAPI.petalRecipes) { + if (areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + + BotaniaAPI.petalRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/botania/handlers/ElvenTrade.java b/src/main/java/modtweaker/mods/botania/handlers/ElvenTrade.java new file mode 100644 index 0000000..46cb499 --- /dev/null +++ b/src/main/java/modtweaker/mods/botania/handlers/ElvenTrade.java @@ -0,0 +1,64 @@ +package modtweaker.mods.botania.handlers; + +import static modtweaker.helpers.InputHelper.toObjects; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.recipe.RecipeElvenTrade; + +@ZenClass("mods.botania.ElvenTrade") +public class ElvenTrade { + @ZenMethod + public static void addRecipe(IItemStack output, IIngredient[] input) { + MineTweakerAPI.apply(new Add(new RecipeElvenTrade(toStack(output), toObjects(input)))); + } + + private static class Add extends BaseListAddition { + public Add(RecipeElvenTrade recipe) { + super("Botania Eleven Trade", BotaniaAPI.elvenTradeRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipeElvenTrade) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Botania Elven Trade", BotaniaAPI.elvenTradeRecipes, stack); + } + + @Override + public void apply() { + for (RecipeElvenTrade r : BotaniaAPI.elvenTradeRecipes) { + if (r.getOutput() != null && areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + + BotaniaAPI.elvenTradeRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/botania/handlers/ManaInfusion.java b/src/main/java/modtweaker/mods/botania/handlers/ManaInfusion.java new file mode 100644 index 0000000..2dff771 --- /dev/null +++ b/src/main/java/modtweaker/mods/botania/handlers/ManaInfusion.java @@ -0,0 +1,78 @@ +package modtweaker.mods.botania.handlers; + +import static modtweaker.helpers.InputHelper.toObject; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.recipe.RecipeManaInfusion; + +@ZenClass("mods.botania.ManaInfusion") +public class ManaInfusion { + @ZenMethod + public static void addInfusion(IItemStack output, IIngredient input, int mana) { + MineTweakerAPI.apply(new Add(new RecipeManaInfusion(toStack(output), toObject(input), mana))); + } + + @ZenMethod + public static void addAlchemy(IItemStack output, IIngredient input, int mana) { + RecipeManaInfusion recipe = new RecipeManaInfusion(toStack(output), toObject(input), mana); + recipe.setAlchemy(true); + MineTweakerAPI.apply(new Add(recipe)); + } + + @ZenMethod + public static void addConjuration(IItemStack output, IIngredient input, int mana) { + RecipeManaInfusion recipe = new RecipeManaInfusion(toStack(output), toObject(input), mana); + recipe.setConjuration(true); + MineTweakerAPI.apply(new Add(recipe)); + } + + private static class Add extends BaseListAddition { + public Add(RecipeManaInfusion recipe) { + super("Botania Mana Infusion", BotaniaAPI.manaInfusionRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipeManaInfusion) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Botania Mana Infusion", BotaniaAPI.manaInfusionRecipes, stack); + } + + @Override + public void apply() { + for (RecipeManaInfusion r : BotaniaAPI.manaInfusionRecipes) { + if (r.getOutput() != null && areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + + BotaniaAPI.manaInfusionRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/botania/handlers/Orechid.java b/src/main/java/modtweaker/mods/botania/handlers/Orechid.java new file mode 100644 index 0000000..05213df --- /dev/null +++ b/src/main/java/modtweaker/mods/botania/handlers/Orechid.java @@ -0,0 +1,114 @@ +package modtweaker.mods.botania.handlers; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.oredict.IOreDictEntry; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import vazkii.botania.api.BotaniaAPI; + +@ZenClass("mods.botania.Orechid") +public class Orechid { + @ZenMethod + public static void addOre(IOreDictEntry oreDict, int weight) { + MineTweakerAPI.apply(new Add(oreDict.getName(), weight)); + } + + @ZenMethod + public static void addOre(String oreDict, int weight) { + MineTweakerAPI.apply(new Add(oreDict, weight)); + } + + private static class Add implements IUndoableAction { + String oreDict; + int weight; + + public Add(String ore, int prop) { + oreDict = ore; + weight = prop; + } + + @Override + public void apply() { + + BotaniaAPI.addOreWeight(oreDict, weight); + } + + @Override + public String describe() { + return "Adding Orechid Ore Weight: " + oreDict + ":" + weight; + } + + @Override + public boolean canUndo() { + return oreDict != null; + } + + @Override + public void undo() { + BotaniaAPI.oreWeights.remove(oreDict); + } + + @Override + public String describeUndo() { + return "Removing Orechid Ore: " + oreDict; + } + + @Override + public String getOverrideKey() { + return null; + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeOre(IOreDictEntry oreDict) { + MineTweakerAPI.apply(new Remove(oreDict.getName())); + } + + @ZenMethod + public static void removeOre(String oreDict) { + MineTweakerAPI.apply(new Remove(oreDict)); + } + + private static class Remove implements IUndoableAction { + String oreDict; + int weight; + + public Remove(String ore) { + oreDict = ore; + } + + @Override + public void apply() { + weight = BotaniaAPI.getOreWeight(oreDict); + BotaniaAPI.oreWeights.remove(oreDict); + } + + @Override + public String describe() { + return "Removing Orechid Ore: " + oreDict; + } + + @Override + public boolean canUndo() { + return weight > 0; + } + + @Override + public void undo() { + BotaniaAPI.addOreWeight(oreDict, weight); + } + + @Override + public String describeUndo() { + return "Restoring Orechid Ore Weight: " + oreDict + ":" + weight; + } + + @Override + public String getOverrideKey() { + return null; + } + } +} diff --git a/src/main/java/modtweaker/mods/botania/handlers/RuneAltar.java b/src/main/java/modtweaker/mods/botania/handlers/RuneAltar.java new file mode 100644 index 0000000..896efab --- /dev/null +++ b/src/main/java/modtweaker/mods/botania/handlers/RuneAltar.java @@ -0,0 +1,64 @@ +package modtweaker.mods.botania.handlers; + +import static modtweaker.helpers.InputHelper.toObjects; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.recipe.RecipeRuneAltar; + +@ZenClass("mods.botania.RuneAltar") +public class RuneAltar { + @ZenMethod + public static void addRecipe(IItemStack output, IIngredient[] input, int mana) { + MineTweakerAPI.apply(new Add(new RecipeRuneAltar(toStack(output), mana, toObjects(input)))); + } + + private static class Add extends BaseListAddition { + public Add(RecipeRuneAltar recipe) { + super("Botania Rune Altar", BotaniaAPI.runeAltarRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipeRuneAltar) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Botania Rune Altar", BotaniaAPI.runeAltarRecipes, stack); + } + + @Override + public void apply() { + for (RecipeRuneAltar r : BotaniaAPI.runeAltarRecipes) { + if (r.getOutput() != null && areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + + BotaniaAPI.runeAltarRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/exnihilo/ExNihilo.java b/src/main/java/modtweaker/mods/exnihilo/ExNihilo.java new file mode 100644 index 0000000..671bd53 --- /dev/null +++ b/src/main/java/modtweaker/mods/exnihilo/ExNihilo.java @@ -0,0 +1,16 @@ +package modtweaker.mods.exnihilo; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.exnihilo.handlers.Compost; +import modtweaker.mods.exnihilo.handlers.Crucible; +import modtweaker.mods.exnihilo.handlers.Hammer; +import modtweaker.mods.exnihilo.handlers.Sieve; + +public class ExNihilo { + public ExNihilo() { + MineTweakerAPI.registerClass(Compost.class); + MineTweakerAPI.registerClass(Crucible.class); + MineTweakerAPI.registerClass(Hammer.class); + MineTweakerAPI.registerClass(Sieve.class); + } +} diff --git a/src/main/java/modtweaker/mods/exnihilo/handlers/Compost.java b/src/main/java/modtweaker/mods/exnihilo/handlers/Compost.java new file mode 100644 index 0000000..470ec76 --- /dev/null +++ b/src/main/java/modtweaker/mods/exnihilo/handlers/Compost.java @@ -0,0 +1,56 @@ +package modtweaker.mods.exnihilo.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import exnihilo.registries.CompostRegistry; +import exnihilo.registries.helpers.Color; +import exnihilo.registries.helpers.Compostable; + +@ZenClass("mods.exnihilo.Composting") +public class Compost { + //Adding a Ex Nihilo Composting recipe + @ZenMethod + public static void addRecipe(IItemStack input, double value, @Optional String hex) { + hex = (hex == null || hex.equals("")) ? "35A82A" : hex; + MineTweakerAPI.apply(new Add(new Compostable(toStack(input).getItem(), toStack(input).getItemDamage(), Math.min(1.0F, (float) value), new Color(hex)))); + } + + //Passes the list to the map list implementation, and adds the recipe + private static class Add extends BaseMapAddition { + public Add(Compostable recipe) { + super("ExNihilo Composting", CompostRegistry.entries, recipe.item + ":" + recipe.meta, recipe); + } + + @Override + public String getRecipeInfo() { + return new ItemStack(((Compostable) recipe).item, 1, ((Compostable) recipe).meta).getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Ex Nihilo Composting recipe + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + //Removes a recipe, will always remove the key, so all should be good + private static class Remove extends BaseMapRemoval { + public Remove(ItemStack stack) { + super("ExNihilo Composting", CompostRegistry.entries, stack.getItem() + ":" + stack.getItemDamage(), stack); + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) stack).getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/exnihilo/handlers/Crucible.java b/src/main/java/modtweaker/mods/exnihilo/handlers/Crucible.java new file mode 100644 index 0000000..7199839 --- /dev/null +++ b/src/main/java/modtweaker/mods/exnihilo/handlers/Crucible.java @@ -0,0 +1,112 @@ +package modtweaker.mods.exnihilo.handlers; + +import static modtweaker.helpers.InputHelper.isABlock; +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import exnihilo.registries.CrucibleRegistry; +import exnihilo.registries.HeatRegistry; +import exnihilo.registries.helpers.HeatSource; +import exnihilo.registries.helpers.Meltable; + +@ZenClass("mods.exnihilo.Crucible") +public class Crucible { + + /************************************************ Crucible Melting ************************************************/ + //Adding a Ex Nihilo Crucible recipe + @ZenMethod + public static void addRecipe(IItemStack input, ILiquidStack fluid) { + if (isABlock(input)) { + Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); + int theMeta = toStack(input).getItemDamage(); + MineTweakerAPI.apply(new AddRecipe(new Meltable(theBlock, theMeta, 2000, toFluid(fluid).getFluid(), toFluid(fluid).amount, theBlock))); + } + } + + //Passes the list to the map list implementation, and adds the recipe + private static class AddRecipe extends BaseMapAddition { + public AddRecipe(Meltable recipe) { + super("ExNihilo Crucible", CrucibleRegistry.entries, recipe.block + ":" + recipe.meta, recipe); + } + + @Override + public String getRecipeInfo() { + return new ItemStack(((Meltable) recipe).block, 1, ((Meltable) recipe).meta).getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Ex Nihilo Crucible recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + if (isABlock(output)) { + MineTweakerAPI.apply(new RemoveRecipe(toStack(output))); + } + } + + //Removes a recipe, will always remove the key, so all should be good + private static class RemoveRecipe extends BaseMapRemoval { + public RemoveRecipe(ItemStack stack) { + super("ExNihilo Crucible", CrucibleRegistry.entries, Block.getBlockFromItem(stack.getItem()) + ":" + stack.getItemDamage(), stack); + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) stack).getDisplayName(); + } + } + + /********************************************** Crucible Heat Sources **********************************************/ + //Adding a Ex Nihilo Crucible heat source + @ZenMethod + public static void addHeatSource(IItemStack input, double value) { + if (isABlock(input)) { + Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); + int theMeta = toStack(input).getItemDamage(); + MineTweakerAPI.apply(new AddHeatSource(new HeatSource(theBlock, theMeta, (float) value))); + } + } + + //Passes the list to the base map implementation, and adds the recipe + private static class AddHeatSource extends BaseMapAddition { + public AddHeatSource(HeatSource recipe) { + super("ExNihilo Crucible - Heat Source", HeatRegistry.entries, recipe.block + ":" + recipe.meta, recipe); + } + + @Override + public String getRecipeInfo() { + return new ItemStack(((HeatSource) recipe).block, 1, ((HeatSource) recipe).meta).getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Ex Nihilo Crucible heat source + @ZenMethod + public static void removeHeatSource(IItemStack output) { + if (isABlock(output)) { + MineTweakerAPI.apply(new RemoveHeatSource(toStack(output))); + } + } + + //Removes a recipe, will always remove the key, so all should be good + private static class RemoveHeatSource extends BaseMapRemoval { + public RemoveHeatSource(ItemStack stack) { + super("ExNihilo Crucible - Heat Source", HeatRegistry.entries, Block.getBlockFromItem(stack.getItem()) + ":" + stack.getItemDamage(), stack); + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) stack).getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/exnihilo/handlers/Hammer.java b/src/main/java/modtweaker/mods/exnihilo/handlers/Hammer.java new file mode 100644 index 0000000..a9443de --- /dev/null +++ b/src/main/java/modtweaker/mods/exnihilo/handlers/Hammer.java @@ -0,0 +1,74 @@ +package modtweaker.mods.exnihilo.handlers; + +import static modtweaker.helpers.InputHelper.isABlock; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import exnihilo.registries.HammerRegistry; +import exnihilo.registries.helpers.Smashable; + +@ZenClass("mods.exnihilo.Hammer") +public class Hammer { + //Adding a Ex Nihilo Hammer recipe + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output, double chance, double luck) { + if (isABlock(input)) { + Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); + int theMeta = toStack(input).getItemDamage(); + MineTweakerAPI.apply(new Add(new Smashable(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), (float) chance, (float) luck))); + } + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(Smashable recipe) { + super("ExNihilo Hammer", HammerRegistry.rewards, recipe); + } + + @Override + public String getRecipeInfo() { + return new ItemStack(((Smashable) recipe).source, 1, ((Smashable) recipe).sourceMeta).getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Ex Nihilo Hammer recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("ExNihilo Hammer", HammerRegistry.rewards, stack); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (Smashable r : HammerRegistry.rewards) { + ItemStack check = new ItemStack(r.item, 1, r.meta); + if (check != null && areEqual(check, stack)) { + recipe = r; + break; + } + } + + HammerRegistry.rewards.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/exnihilo/handlers/Sieve.java b/src/main/java/modtweaker/mods/exnihilo/handlers/Sieve.java new file mode 100644 index 0000000..0223dcc --- /dev/null +++ b/src/main/java/modtweaker/mods/exnihilo/handlers/Sieve.java @@ -0,0 +1,80 @@ +package modtweaker.mods.exnihilo.handlers; + +import static modtweaker.helpers.InputHelper.isABlock; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseMultipleListRemoval; +import modtweaker.util.BaseMultipleListRemoval.Position; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import exnihilo.registries.SieveRegistry; +import exnihilo.registries.helpers.SiftReward; + +@ZenClass("mods.exnihilo.Sieve") +public class Sieve { + //Adding a Ex Nihilo Sieve recipe + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output, int rarity) { + if (isABlock(input)) { + Block theBlock = Block.getBlockFromItem(toStack(input).getItem()); + int theMeta = toStack(input).getItemDamage(); + MineTweakerAPI.apply(new Add(new SiftReward(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), rarity))); + } + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(SiftReward recipe) { + super("ExNihilo Sieve", SieveRegistry.rewards, recipe); + } + + @Override + public String getRecipeInfo() { + return new ItemStack(((SiftReward) recipe).source, 1, ((SiftReward) recipe).sourceMeta).getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Ex Nihilo Sieve recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), Position.ALL)); + } + + @ZenMethod + public static void removeFirst(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), Position.FIRST)); + } + + @ZenMethod + public static void removeLast(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), Position.LAST)); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseMultipleListRemoval { + public Remove(ItemStack stack, Position pos) { + super("ExNihilo Sieve", SieveRegistry.rewards, stack, pos); + } + + @Override + protected boolean isEqual(Object recipe, Object search) { + SiftReward r = (SiftReward) recipe; + ItemStack c = new ItemStack(r.item, 1, r.meta); + if (c != null && areEqual(c, (ItemStack) search)) { + return true; + } else return false; + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) search).getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/extendedworkbench/ExtendedWorkbench.java b/src/main/java/modtweaker/mods/extendedworkbench/ExtendedWorkbench.java new file mode 100644 index 0000000..09eabe5 --- /dev/null +++ b/src/main/java/modtweaker/mods/extendedworkbench/ExtendedWorkbench.java @@ -0,0 +1,10 @@ +package modtweaker.mods.extendedworkbench; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.extendedworkbench.handlers.ExtendedCrafting; + +public class ExtendedWorkbench { + public ExtendedWorkbench() { + MineTweakerAPI.registerClass(ExtendedCrafting.class); + } +} diff --git a/src/main/java/modtweaker/mods/extendedworkbench/handlers/ExtendedCrafting.java b/src/main/java/modtweaker/mods/extendedworkbench/handlers/ExtendedCrafting.java new file mode 100644 index 0000000..68ae774 --- /dev/null +++ b/src/main/java/modtweaker/mods/extendedworkbench/handlers/ExtendedCrafting.java @@ -0,0 +1,104 @@ +package modtweaker.mods.extendedworkbench.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.InputHelper.toStacks; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.Arrays; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import naruto1310.extendedWorkbench.crafting.ExtendedCraftingManager; +import naruto1310.extendedWorkbench.crafting.ExtendedShapedRecipes; +import naruto1310.extendedWorkbench.crafting.ExtendedShapelessRecipes; +import naruto1310.extendedWorkbench.crafting.IExtendedRecipe; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.extendedworkbench") +public class ExtendedCrafting { + @ZenMethod + public static void addShaped(IItemStack output, IItemStack[][] ingredients) { + MineTweakerAPI.apply(new Add(getShapedRecipe(output, ingredients))); + } + + @ZenMethod + public static void addShapeless(IItemStack output, IItemStack[] ingredients) { + MineTweakerAPI.apply(new Add(new ExtendedShapelessRecipes(toStack(output), Arrays.asList(toStacks(ingredients))))); + } + + private static class Add extends BaseListAddition { + public Add(IExtendedRecipe recipe) { + super("Extended Workbench", ExtendedCraftingManager.getInstance().getRecipeList(), recipe); + } + + @Override + public String getRecipeInfo() { + Object out = ((IExtendedRecipe) recipe).getRecipeOutput(); + if (out != null) { + return ((ItemStack) out).getDisplayName(); + } else return super.getRecipeInfo(); + } + } + + private static IExtendedRecipe getShapedRecipe(IItemStack out, IItemStack[][] ingredients) { + + int width = 0; + int height = ingredients.length; + ItemStack[] recipe; + + for (int x = 0; x < ingredients.length; x++) { + if (ingredients[x] != null && ingredients[x].length > width) width = ingredients[x].length; + } + + recipe = new ItemStack[width * height]; + int counter = 0; + for (int x = 0; x < ingredients.length; x++) { + if (ingredients[x] != null) { + for (int y = 0; y < ingredients[x].length; y++) { + recipe[counter++] = toStack(ingredients[x][y]); + } + } + } + + return new ExtendedShapedRecipes(width, height, recipe, toStack(out)); + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Extended Workbench", ExtendedCraftingManager.getInstance().getRecipeList(), stack); + } + + @Override + public void apply() { + for (Object o : ExtendedCraftingManager.getInstance().getRecipeList()) { + if (o instanceof IExtendedRecipe) { + IExtendedRecipe r = (IExtendedRecipe) o; + if (r.getRecipeOutput() != null && areEqual((ItemStack) r.getRecipeOutput(), stack)) { + recipe = r; + break; + } + } + } + + ExtendedCraftingManager.getInstance().getRecipeList().remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + +} diff --git a/src/main/java/modtweaker/mods/factorization/Factorization.java b/src/main/java/modtweaker/mods/factorization/Factorization.java new file mode 100644 index 0000000..98d9dd2 --- /dev/null +++ b/src/main/java/modtweaker/mods/factorization/Factorization.java @@ -0,0 +1,14 @@ +package modtweaker.mods.factorization; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.factorization.handlers.Crystallizer; +import modtweaker.mods.factorization.handlers.Lacerator; +import modtweaker.mods.factorization.handlers.SlagFurnace; + +public class Factorization { + public Factorization() { + MineTweakerAPI.registerClass(Crystallizer.class); + MineTweakerAPI.registerClass(Lacerator.class); + MineTweakerAPI.registerClass(SlagFurnace.class); + } +} diff --git a/src/main/java/modtweaker/mods/factorization/FactorizationHelper.java b/src/main/java/modtweaker/mods/factorization/FactorizationHelper.java new file mode 100644 index 0000000..530eec7 --- /dev/null +++ b/src/main/java/modtweaker/mods/factorization/FactorizationHelper.java @@ -0,0 +1,57 @@ +package modtweaker.mods.factorization; + +import static modtweaker.helpers.ReflectionHelper.getStaticObject; + +import java.lang.reflect.Constructor; +import java.util.List; + +import net.minecraft.item.ItemStack; + +public class FactorizationHelper { + public static List lacerator = null; + public static List slag = null; + public static List crystallizer = null; + + static { + try { + lacerator = getStaticObject(Class.forName("factorization.oreprocessing.TileEntityGrinder"), "recipes"); + slag = getStaticObject(Class.forName("factorization.oreprocessing.TileEntitySlagFurnace$SlagRecipes"), "smeltingResults"); + crystallizer = getStaticObject(Class.forName("factorization.oreprocessing.TileEntityCrystallizer"), "recipes"); + } catch (Exception e) {} + } + + private FactorizationHelper() {} + + public static Object getLaceratorRecipe(ItemStack input, ItemStack output, float probability) { + try { + Class clazz = Class.forName("factorization.oreprocessing.TileEntityGrinder$GrinderRecipe"); + Constructor constructor = clazz.getDeclaredConstructor(Object.class, ItemStack.class, float.class); + constructor.setAccessible(true); + return constructor.newInstance(input, output, probability); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate Lacerator Recipe"); + } + } + + public static Object getSlagFurnaceRecipe(ItemStack input, float chance1, ItemStack output1, float chance2, ItemStack output2) { + try { + Class clazz = Class.forName("factorization.oreprocessing.TileEntitySlagFurnace$SmeltingResult"); + Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, float.class, ItemStack.class, float.class, ItemStack.class); + constructor.setAccessible(true); + return constructor.newInstance(input, chance1, output1, chance2, output2); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate SmeltingResult"); + } + } + + public static Object getCrystallizerRecipe(ItemStack input, ItemStack output, ItemStack solution, float output_count) { + try { + Class clazz = Class.forName("factorization.oreprocessing.TileEntityCrystallizer$CrystalRecipe"); + Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, ItemStack.class, float.class, ItemStack.class); + constructor.setAccessible(true); + return constructor.newInstance(input, output, output_count, solution); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate CrystalRecipe"); + } + } +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/factorization/handlers/Crystallizer.java b/src/main/java/modtweaker/mods/factorization/handlers/Crystallizer.java new file mode 100644 index 0000000..f7b9a4f --- /dev/null +++ b/src/main/java/modtweaker/mods/factorization/handlers/Crystallizer.java @@ -0,0 +1,74 @@ +package modtweaker.mods.factorization.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.factorization.FactorizationHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.factorization.Crystallizer") +public class Crystallizer { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output, IItemStack solution, double output_count) { + Object recipe = FactorizationHelper.getCrystallizerRecipe(toStack(input), toStack(output), toStack(solution), (float) output_count); + MineTweakerAPI.apply(new Add(toStack(input), recipe)); + } + + private static class Add extends BaseListAddition { + private final ItemStack output; + + public Add(ItemStack output, Object recipe) { + super("Crystallizer", FactorizationHelper.crystallizer, recipe); + this.output = output; + } + + @Override + public String getRecipeInfo() { + return output.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Crystallizer", FactorizationHelper.crystallizer, stack); + } + + //Returns the output ItemStack + private ItemStack getOutput(Object o) { + return (ItemStack) ReflectionHelper.getObject(o, "output"); + } + + @Override + public void apply() { + for (Object r : list) { + if (r != null) { + ItemStack output = getOutput(r); + if (output != null && areEqual(output, stack)) { + recipe = r; + break; + } + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/factorization/handlers/Lacerator.java b/src/main/java/modtweaker/mods/factorization/handlers/Lacerator.java new file mode 100644 index 0000000..79f61ca --- /dev/null +++ b/src/main/java/modtweaker/mods/factorization/handlers/Lacerator.java @@ -0,0 +1,72 @@ +package modtweaker.mods.factorization.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.factorization.FactorizationHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.factorization.Lacerator") +public class Lacerator { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output, double probability) { + Object recipe = FactorizationHelper.getLaceratorRecipe(toStack(input), toStack(output), (float) probability); + MineTweakerAPI.apply(new Add(toStack(input), recipe)); + } + + private static class Add extends BaseListAddition { + private final ItemStack output; + + public Add(ItemStack output, Object recipe) { + super("Lacerator", FactorizationHelper.lacerator, recipe); + this.output = output; + } + + @Override + public String getRecipeInfo() { + return output.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Lacerator", FactorizationHelper.lacerator, stack); + } + + //Returns the output ItemStack + private ItemStack getOutput(Object o) { + return (ItemStack) ReflectionHelper.getObject(o, "output"); + } + + @Override + public void apply() { + for (Object r : list) { + ItemStack output = getOutput(r); + if (output != null && areEqual(output, stack)) { + recipe = r; + break; + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/factorization/handlers/SlagFurnace.java b/src/main/java/modtweaker/mods/factorization/handlers/SlagFurnace.java new file mode 100644 index 0000000..64e8c5f --- /dev/null +++ b/src/main/java/modtweaker/mods/factorization/handlers/SlagFurnace.java @@ -0,0 +1,73 @@ +package modtweaker.mods.factorization.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.factorization.FactorizationHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseMultipleListRemoval; +import modtweaker.util.BaseMultipleListRemoval.Position; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.factorization.SlagFurnace") +public class SlagFurnace { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output1, double chance1, IItemStack output2, double chance2) { + Object recipe = FactorizationHelper.getSlagFurnaceRecipe(toStack(input), (float) chance1, toStack(output1), (float) chance2, toStack(output2)); + MineTweakerAPI.apply(new Add(toStack(input), recipe)); + } + + private static class Add extends BaseListAddition { + private final ItemStack input; + + public Add(ItemStack input, Object recipe) { + super("Slag Furnace", FactorizationHelper.slag, recipe); + this.input = input; + } + + @Override + public String getRecipeInfo() { + return input.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input), Position.ALL)); + } + + @ZenMethod + public static void removeFirst(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), Position.FIRST)); + } + + @ZenMethod + public static void removeLast(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), Position.LAST)); + } + + private static class Remove extends BaseMultipleListRemoval { + public Remove(ItemStack stack, Position pos) { + super("Slag Furnace", FactorizationHelper.slag, stack, pos); + } + + @Override + protected boolean isEqual(Object recipe, Object search) { + ItemStack input = (ItemStack) ReflectionHelper.getObject(recipe, "input"); + if (input != null && areEqual(input, (ItemStack) search)) { + return true; + } else return false; + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) search).getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/fsp/FSPHelper.java b/src/main/java/modtweaker/mods/fsp/FSPHelper.java new file mode 100644 index 0000000..7633e38 --- /dev/null +++ b/src/main/java/modtweaker/mods/fsp/FSPHelper.java @@ -0,0 +1,16 @@ +package modtweaker.mods.fsp; + +import flaxbeard.steamcraft.api.CrucibleLiquid; +import flaxbeard.steamcraft.api.SteamcraftRegistry; + +public class FSPHelper { + public static CrucibleLiquid getLiquid(String name) { + for (CrucibleLiquid l : SteamcraftRegistry.liquids) { + if (l.name.equals(name)) { + return l; + } + } + + return null; + } +} diff --git a/src/main/java/modtweaker/mods/fsp/Steamcraft.java b/src/main/java/modtweaker/mods/fsp/Steamcraft.java new file mode 100644 index 0000000..5ed823a --- /dev/null +++ b/src/main/java/modtweaker/mods/fsp/Steamcraft.java @@ -0,0 +1,12 @@ +package modtweaker.mods.fsp; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.fsp.handlers.Crucible; +import modtweaker.mods.fsp.handlers.Furnace; + +public class Steamcraft { + public Steamcraft() { + MineTweakerAPI.registerClass(Crucible.class); + MineTweakerAPI.registerClass(Furnace.class); + } +} diff --git a/src/main/java/modtweaker/mods/fsp/handlers/Crucible.java b/src/main/java/modtweaker/mods/fsp/handlers/Crucible.java new file mode 100644 index 0000000..8791c1a --- /dev/null +++ b/src/main/java/modtweaker/mods/fsp/handlers/Crucible.java @@ -0,0 +1,127 @@ +package modtweaker.mods.fsp.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.mods.fsp.FSPHelper.getLiquid; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; + +import org.apache.commons.lang3.tuple.MutablePair; + +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import flaxbeard.steamcraft.api.CrucibleFormula; +import flaxbeard.steamcraft.api.CrucibleLiquid; +import flaxbeard.steamcraft.api.SteamcraftRegistry; +import flaxbeard.steamcraft.api.Tuple3; + +@ZenClass("mods.fsp.Crucible") +public class Crucible { + @ZenMethod + public static void addLiquid(String name, IItemStack ingot, IItemStack plate, IItemStack nugget, int r, int g, int b) { + MineTweakerAPI.apply(new AddLiquid(new CrucibleLiquid(name, toStack(ingot), toStack(plate), toStack(nugget), null, r, g, b))); + } + + @ZenMethod + public static void addLiquid(String name, IItemStack ingot, IItemStack plate, IItemStack nugget, int r, int g, int b, String l1, int n1, String l2, int n2, int n3) { + MineTweakerAPI.apply(new AddLiquid(new CrucibleLiquid(name, toStack(ingot), toStack(plate), toStack(nugget), new CrucibleFormula(getLiquid(l1), n1, getLiquid(l2), n2, n3), r, g, b))); + } + + private static class AddLiquid extends BaseListAddition { + public AddLiquid(CrucibleLiquid recipe) { + super("FSP Crucible Liquid", SteamcraftRegistry.liquids, recipe); + } + + @Override + public String getRecipeInfo() { + return ((CrucibleLiquid) recipe).name; + } + } + + @ZenMethod + public static void addMelting(IItemStack input, String liquid, int volume) { + ItemStack stack = toStack(input); + CrucibleLiquid fluid = getLiquid(liquid); + if (fluid != null) { + MineTweakerAPI.apply(new AddMelting(stack, MutablePair.of(stack.getItem(), stack.getItemDamage()), MutablePair.of(fluid, volume))); + } + } + + private static class AddMelting extends BaseMapAddition { + private final ItemStack stack; + + public AddMelting(ItemStack stack, Object key, Object recipe) { + super("FSP Crucible Melting", SteamcraftRegistry.smeltThings, key, recipe); + this.stack = stack; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + @ZenMethod + public static void removeMelting(IItemStack input) { + MineTweakerAPI.apply(new RemoveMelting(toStack(input), MutablePair.of(toStack(input).getItem(), toStack(input).getItemDamage()))); + } + + private static class RemoveMelting extends BaseMapRemoval { + private final ItemStack stack; + + public RemoveMelting(ItemStack stack, Object key) { + super("FSP Crucible Melting", SteamcraftRegistry.smeltThings, key); + this.stack = stack; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + @ZenMethod + public static void addDunking(IItemStack input, String liquid, int volume, IItemStack output) { + ItemStack stack = toStack(input); + CrucibleLiquid fluid = getLiquid(liquid); + if (fluid != null) { + MineTweakerAPI.apply(new AddDunking(toStack(input), new Tuple3(stack.getItem(), stack.getItemDamage(), fluid), MutablePair.of(volume, toStack(output)))); + } + } + + private static class AddDunking extends BaseMapAddition { + private final ItemStack stack; + + public AddDunking(ItemStack stack, Object key, Object recipe) { + super("FSP Crucible Dunking", SteamcraftRegistry.dunkThings, key, recipe); + this.stack = stack; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + @ZenMethod + public static void removeDunking(IItemStack input, String liquid) { + MineTweakerAPI.apply(new RemoveDunking(toStack(input), new Tuple3(toStack(input).getItem(), toStack(input).getItemDamage(), getLiquid(liquid)))); + } + + private static class RemoveDunking extends BaseMapRemoval { + private final ItemStack stack; + + public RemoveDunking(ItemStack stack, Object key) { + super("FSP Crucible Dunking", SteamcraftRegistry.dunkThings, key); + this.stack = stack; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/fsp/handlers/Furnace.java b/src/main/java/modtweaker/mods/fsp/handlers/Furnace.java new file mode 100644 index 0000000..b3294f0 --- /dev/null +++ b/src/main/java/modtweaker/mods/fsp/handlers/Furnace.java @@ -0,0 +1,55 @@ +package modtweaker.mods.fsp.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; + +import org.apache.commons.lang3.tuple.MutablePair; + +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import flaxbeard.steamcraft.api.SteamcraftRegistry; + +@ZenClass("mods.fsp.Furnace") +public class Furnace { + @ZenMethod + public static void addSteamFood(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new AddSteamFood(toStack(input), MutablePair.of(toStack(input).getItem(), toStack(input).getItemDamage()), MutablePair.of(toStack(output).getItem(), toStack(output).getItemDamage()))); + } + + private static class AddSteamFood extends BaseMapAddition { + private final ItemStack stack; + + public AddSteamFood(ItemStack stack, MutablePair key, MutablePair recipe) { + super("FSP Furnace - Steam Food", SteamcraftRegistry.steamedFoods, key, recipe); + this.stack = stack; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + @ZenMethod + public static void removeSteamFood(IItemStack input) { + MineTweakerAPI.apply(new RemoveSteamFood(toStack(input), MutablePair.of(toStack(input).getItem(), toStack(input).getItemDamage()))); + } + + private static class RemoveSteamFood extends BaseMapRemoval { + private final ItemStack stack; + + public RemoveSteamFood(ItemStack stack, MutablePair key) { + super("FSP Furnace - Steam Food", SteamcraftRegistry.steamedFoods, key); + this.stack = stack; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/hee/HardcoreEnderExpansion.java b/src/main/java/modtweaker/mods/hee/HardcoreEnderExpansion.java new file mode 100644 index 0000000..0918015 --- /dev/null +++ b/src/main/java/modtweaker/mods/hee/HardcoreEnderExpansion.java @@ -0,0 +1,10 @@ +package modtweaker.mods.hee; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.hee.handlers.EssenceAltar; + +public class HardcoreEnderExpansion { + public HardcoreEnderExpansion() { + MineTweakerAPI.registerClass(EssenceAltar.class); + } +} diff --git a/src/main/java/modtweaker/mods/hee/handlers/EssenceAltar.java b/src/main/java/modtweaker/mods/hee/handlers/EssenceAltar.java new file mode 100644 index 0000000..4bce1a9 --- /dev/null +++ b/src/main/java/modtweaker/mods/hee/handlers/EssenceAltar.java @@ -0,0 +1,76 @@ +package modtweaker.mods.hee.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.List; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import chylex.hee.mechanics.essence.handler.DragonEssenceHandler; +import chylex.hee.mechanics.essence.handler.dragon.AltarItemRecipe; + +@ZenClass("mods.hee.EssenceAltar") +public class EssenceAltar { + @ZenMethod + public static void addRecipe(IItemStack source, IItemStack result, int cost) { + MineTweakerAPI.apply(new Add(toStack(result), new AltarItemRecipe(toStack(source), toStack(result), cost))); + } + + private static class Add extends BaseListAddition { + private final ItemStack result; + + public Add(ItemStack result, AltarItemRecipe recipe) { + super("Essence Altar", DragonEssenceHandler.recipes, recipe); + this.result = result; + } + + @Override + public String getRecipeInfo() { + return result.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Essence Altar", DragonEssenceHandler.recipes, stack); + } + + //Returns the output ItemStack + private ItemStack getOutput(Object o) { + return (ItemStack) ReflectionHelper.getObject(o, "result"); + } + + @Override + public void apply() { + for (AltarItemRecipe r : (List) list) { + ItemStack output = getOutput(r); + if (output != null && areEqual(output, stack)) { + recipe = r; + break; + + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/Mariculture.java b/src/main/java/modtweaker/mods/mariculture/Mariculture.java new file mode 100644 index 0000000..491b2fd --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/Mariculture.java @@ -0,0 +1,18 @@ +package modtweaker.mods.mariculture; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.mariculture.handlers.Anvil; +import modtweaker.mods.mariculture.handlers.Casting; +import modtweaker.mods.mariculture.handlers.Crucible; +import modtweaker.mods.mariculture.handlers.Fishing; +import modtweaker.mods.mariculture.handlers.Vat; + +public class Mariculture { + public Mariculture() { + MineTweakerAPI.registerClass(Anvil.class); + MineTweakerAPI.registerClass(Casting.class); + MineTweakerAPI.registerClass(Crucible.class); + MineTweakerAPI.registerClass(Fishing.class); + MineTweakerAPI.registerClass(Vat.class); + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/MaricultureHelper.java b/src/main/java/modtweaker/mods/mariculture/MaricultureHelper.java new file mode 100644 index 0000000..20ad74c --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/MaricultureHelper.java @@ -0,0 +1,49 @@ +package modtweaker.mods.mariculture; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import mariculture.api.core.MaricultureHandlers; +import mariculture.api.fishery.Fishing; +import mariculture.api.fishery.Loot; +import mariculture.api.fishery.Loot.Rarity; +import modtweaker.helpers.ReflectionHelper; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; + +public class MaricultureHelper { + public static Map fuels = null; + public static HashMap> loot = null; + + static { + try { + fuels = ReflectionHelper.getFinalObject(MaricultureHandlers.crucible, "fuels"); + loot = ReflectionHelper.getFinalObject(Fishing.fishing, "fishing_loot"); + } catch (Exception e) {} + } + + private MaricultureHelper() {} + + //Helper for getting the key that is used when adding/removing fuels + public static String getKey(Object o) { + if (o instanceof String) return (String) o; + else if (o instanceof ItemStack) { + String name = ""; + ItemStack stack = (ItemStack) o; + if (OreDictionary.getOreIDs(stack).length > 0) { + name = OreDictionary.getOreName(OreDictionary.getOreIDs(stack)[0]); + } else if (stack.isItemStackDamageable()) { + name = Item.itemRegistry.getNameForObject(stack.getItem()) + "|ignore"; + } else { + name = Item.itemRegistry.getNameForObject(stack.getItem()) + "|" + stack.getItemDamage(); + } + + return name; + } else if (o instanceof FluidStack) { + return ((FluidStack) o).getFluid().getName(); + } else return null; + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/handlers/Anvil.java b/src/main/java/modtweaker/mods/mariculture/handlers/Anvil.java new file mode 100644 index 0000000..b362b3d --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/handlers/Anvil.java @@ -0,0 +1,52 @@ +package modtweaker.mods.mariculture.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import mariculture.api.core.IAnvilHandler.RecipeAnvil; +import mariculture.api.core.MaricultureHandlers; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mariculture.MaricultureHelper; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mariculture.Anvil") +public class Anvil { + //Adding a Mariculture Anvil recipe + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output, int hits) { + MineTweakerAPI.apply(new Add(new RecipeAnvil(toStack(input), toStack(output), hits))); + } + + private static class Add extends BaseMapAddition { + public Add(RecipeAnvil recipe) { + super("Mariculture Anvil", MaricultureHandlers.anvil.getRecipes(), MaricultureHelper.getKey(recipe.input), recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipeAnvil) recipe).output.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Mariculture Anvil recipe + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove extends BaseMapRemoval { + public Remove(ItemStack stack) { + super("Mariculture Anvil", MaricultureHandlers.anvil.getRecipes(), MaricultureHelper.getKey(stack), stack); + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) stack).getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/handlers/Casting.java b/src/main/java/modtweaker/mods/mariculture/handlers/Casting.java new file mode 100644 index 0000000..d33df1b --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/handlers/Casting.java @@ -0,0 +1,78 @@ +package modtweaker.mods.mariculture.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; + +import java.util.HashMap; + +import mariculture.api.core.MaricultureHandlers; +import mariculture.api.core.RecipeCasting; +import mariculture.api.core.RecipeCasting.RecipeNuggetCasting; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.mods.mariculture.MaricultureHelper; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mariculture.Casting") +public class Casting { + //Adding Mariculture Casting Recipes + @ZenMethod + public static void addNuggetRecipe(ILiquidStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new RecipeNuggetCasting(toFluid(input), toStack(output)), MaricultureHandlers.casting.getNuggetRecipes())); + } + + @ZenMethod + public static void addIngotRecipe(ILiquidStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new RecipeNuggetCasting(toFluid(input), toStack(output)), MaricultureHandlers.casting.getIngotRecipes())); + } + + @ZenMethod + public static void addBlockRecipe(ILiquidStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new RecipeNuggetCasting(toFluid(input), toStack(output)), MaricultureHandlers.casting.getBlockRecipes())); + } + + private static class Add extends BaseMapAddition { + public Add(RecipeCasting recipe, HashMap map) { + super("Mariculture Casting", map, MaricultureHelper.getKey(recipe.fluid), recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipeCasting) recipe).output.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing Mariculture Casting Recipes + @ZenMethod + public static void removeNuggetRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input), MaricultureHandlers.casting.getNuggetRecipes())); + } + + @ZenMethod + public static void removeIngotRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input), MaricultureHandlers.casting.getIngotRecipes())); + } + + @ZenMethod + public static void removeBlockRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input), MaricultureHandlers.casting.getBlockRecipes())); + } + + private static class Remove extends BaseMapRemoval { + public Remove(ItemStack stack, HashMap map) { + super("Mariculture Casting", map, MaricultureHelper.getKey(stack), stack); + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) stack).getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/handlers/Crucible.java b/src/main/java/modtweaker/mods/mariculture/handlers/Crucible.java new file mode 100644 index 0000000..9375299 --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/handlers/Crucible.java @@ -0,0 +1,134 @@ +package modtweaker.mods.mariculture.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import mariculture.api.core.FuelInfo; +import mariculture.api.core.MaricultureHandlers; +import mariculture.api.core.RecipeSmelter; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.mods.mariculture.MaricultureHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mariculture.Crucible") +public class Crucible { + + /********************************************** Mariculture Crucible Recipes **********************************************/ + + //Adding a Mariculture Crucible recipe + @ZenMethod + public static void addRecipe(int temp, IItemStack input, ILiquidStack fluid, @Optional IItemStack output, @Optional int chance) { + ItemStack out = output != null ? toStack(output) : null; + MineTweakerAPI.apply(new AddRecipe(new RecipeSmelter(toStack(input), null, temp, toFluid(fluid), out, chance))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class AddRecipe extends BaseListAddition { + public AddRecipe(RecipeSmelter recipe) { + super("Mariculture Crucible", MaricultureHandlers.crucible.getRecipes(), recipe); + } + + @Override + public String getRecipeInfo() { + return ((RecipeSmelter) recipe).input.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Mariculture Crucible recipe + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new RemoveRecipe(toStack(input))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class RemoveRecipe extends BaseListRemoval { + public RemoveRecipe(ItemStack stack) { + super("Mariculture Crucible", MaricultureHandlers.crucible.getRecipes(), stack); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (RecipeSmelter r : MaricultureHandlers.crucible.getRecipes()) { + if (r.input != null && areEqual(r.input, stack)) { + recipe = r; + break; + } + } + + MaricultureHandlers.crucible.getRecipes().remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + /********************************************** Crucible Fuels **********************************************/ + @ZenMethod + public static void addFuel(IItemStack input, int max, int per, int time) { + MineTweakerAPI.apply(new AddFuel(toStack(input), new FuelInfo(max, per, time))); + } + + @ZenMethod + public static void addFuel(ILiquidStack input, int max, int per, int time) { + MineTweakerAPI.apply(new AddFuel(toFluid(input), new FuelInfo(max, per, time))); + } + + @ZenMethod + public static void addFuel(String input, int max, int per, int time) { + MineTweakerAPI.apply(new AddFuel(input, new FuelInfo(max, per, time))); + } + + //Passes the list to the base map implementation, and adds the recipe + private static class AddFuel extends BaseMapAddition { + public AddFuel(Object o, FuelInfo info) { + super("Mariculture Crucible Fuel", MaricultureHelper.fuels, MaricultureHelper.getKey(o), info); + } + + @Override + public String getRecipeInfo() { + return (String) key; + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + @ZenMethod + public static void removeFuel(IItemStack fuel) { + MineTweakerAPI.apply(new RemoveFuel(fuel)); + } + + @ZenMethod + public static void removeFuel(ILiquidStack fuel) { + MineTweakerAPI.apply(new RemoveFuel(fuel)); + } + + @ZenMethod + public static void removeFuel(String fuel) { + MineTweakerAPI.apply(new RemoveFuel(fuel)); + } + + //Removes a recipe, will always remove the key, so all should be good + private static class RemoveFuel extends BaseMapRemoval { + public RemoveFuel(Object o) { + super("Mariculture Crucible Fuel", MaricultureHelper.fuels, MaricultureHelper.getKey(o), null); + } + + @Override + public String getRecipeInfo() { + return (String) key; + } + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/handlers/Fishing.java b/src/main/java/modtweaker/mods/mariculture/handlers/Fishing.java new file mode 100644 index 0000000..188d9f4 --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/handlers/Fishing.java @@ -0,0 +1,159 @@ +package modtweaker.mods.mariculture.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import mariculture.api.fishery.Loot; +import mariculture.api.fishery.Loot.Rarity; +import mariculture.api.fishery.RodType; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.mariculture.MaricultureHelper; +import modtweaker.util.BaseDescriptionAddition; +import modtweaker.util.BaseDescriptionRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import cpw.mods.fml.common.Loader; + +@ZenClass("mods.mariculture.Fishing") +public class Fishing { + //HashMap Helper for converting strings to rodtypes, (will personally add a registry to mariculture eventually...) + public static HashMap rodTypes = new HashMap(); + + static { + rodTypes.put("net", RodType.NET); + rodTypes.put("old", RodType.OLD); + rodTypes.put("good", RodType.GOOD); + rodTypes.put("dire", RodType.DIRE); + rodTypes.put("super", RodType.SUPER); + rodTypes.put("flux", RodType.FLUX); + if (Loader.isModLoaded("AWWayofTime")) { + try { + rodTypes.put("blood", (RodType) ReflectionHelper.getStaticObject(Class.forName("mariculture.plugins.PluginBloodMagic"), "BLOOD")); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + + //Adding Fishing Loot + @ZenMethod + public static void addJunk(IItemStack loot, double chance, @Optional String type, @Optional boolean exact, @Optional int[] dimension) { + addLoot(toStack(loot), chance, type, exact, dimension, Rarity.JUNK); + } + + @ZenMethod + public static void addGood(IItemStack loot, double chance, @Optional String type, @Optional boolean exact, @Optional int[] dimension) { + addLoot(toStack(loot), chance, type, exact, dimension, Rarity.GOOD); + } + + @ZenMethod + public static void addRare(IItemStack loot, double chance, @Optional String type, @Optional boolean exact, @Optional int[] dimension) { + addLoot(toStack(loot), chance, type, exact, dimension, Rarity.RARE); + } + + private static void addLoot(ItemStack stack, double chance, String type, boolean exact, int[] dimension, Rarity rarity) { + if (dimension == null || dimension.length == 0) dimension = new int[] { Short.MAX_VALUE }; + if (type == null) type = "dire"; + for (int dim : dimension) { + MineTweakerAPI.apply(new AddLoot(new Loot(stack, chance, rarity, dim, rodTypes.get(type), exact), rarity.name())); + } + } + + private static class AddLoot extends BaseDescriptionAddition { + private final Loot loot; + + public AddLoot(Loot loot, String description) { + super("Fishing Loot - " + description); + this.loot = loot; + } + + @Override + public void apply() { + ArrayList list = MaricultureHelper.loot.get(loot.rarity); + list.add(loot); + MaricultureHelper.loot.put(loot.rarity, list); + } + + @Override + public void undo() { + ArrayList list = MaricultureHelper.loot.get(loot.rarity); + list.remove(loot); + MaricultureHelper.loot.put(loot.rarity, list); + } + + @Override + public String getRecipeInfo() { + return loot.loot.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing Fishing Loot, will remove it from every single list + @ZenMethod + public static void removeLoot(IItemStack loot) { + MineTweakerAPI.apply(new RemoveLoot(toStack(loot))); + } + + private static class RemoveLoot extends BaseDescriptionRemoval { + private HashMap loot; + private final ItemStack stack; + + public RemoveLoot(ItemStack stack) { + super("Fishing Loot"); + this.loot = new HashMap(); + this.stack = stack; + } + + @Override + public void apply() { + loot.clear(); + apply(Rarity.JUNK); + apply(Rarity.GOOD); + apply(Rarity.RARE); + } + + //Performs the apply function on all rarity types + public void apply(Rarity rarity) { + ArrayList list = MaricultureHelper.loot.get(rarity); + int preSize = list.size(); + for (Loot l : list) { + if (areEqual(l.loot, stack)) { + loot.put(rarity, l); + break; + } + } + + list.remove(loot); + + if (list.size() != preSize) MaricultureHelper.loot.put(rarity, list); + } + + @Override + public void undo() { + for (Map.Entry entry : loot.entrySet()) { + undo(entry.getKey(), entry.getValue()); + } + } + + //Undoes the action on the applicable rarities + public void undo(Rarity rarity, Loot l) { + ArrayList list = MaricultureHelper.loot.get(rarity); + list.add(l); + MaricultureHelper.loot.put(rarity, list); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mariculture/handlers/Vat.java b/src/main/java/modtweaker/mods/mariculture/handlers/Vat.java new file mode 100644 index 0000000..fb40a6e --- /dev/null +++ b/src/main/java/modtweaker/mods/mariculture/handlers/Vat.java @@ -0,0 +1,131 @@ +package modtweaker.mods.mariculture.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import mariculture.api.core.MaricultureHandlers; +import mariculture.api.core.RecipeVat; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mariculture.Vat") +public class Vat { + //Adding a Mariculture Vat recipe + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, ILiquidStack outputFluid, int time) { + addRecipe(fluid1, fluid2, null, outputFluid, null, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, IItemStack outputItem, int time) { + addRecipe(fluid1, fluid2, null, null, outputItem, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, ILiquidStack outputFluid, IItemStack outputItem, int time) { + addRecipe(fluid1, fluid2, null, outputFluid, outputItem, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, IItemStack input, ILiquidStack outputFluid, int time) { + addRecipe(fluid1, null, input, outputFluid, null, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, IItemStack input, IItemStack outputItem, int time) { + addRecipe(fluid1, null, input, null, outputItem, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, IItemStack input, ILiquidStack outputFluid, IItemStack outputItem, int time) { + addRecipe(fluid1, null, input, outputFluid, outputItem, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, IItemStack input, ILiquidStack outputFluid, int time) { + addRecipe(fluid1, fluid2, input, outputFluid, null, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, IItemStack input, IItemStack outputItem, int time) { + addRecipe(fluid1, fluid2, input, null, outputItem, time); + } + + @ZenMethod + public static void addRecipe(ILiquidStack fluid1, ILiquidStack fluid2, IItemStack input, ILiquidStack outputFluid, IItemStack outputItem, int time) { + MineTweakerAPI.apply(new Add(new RecipeVat(toStack(input), toFluid(fluid1), toFluid(fluid2), toFluid(outputFluid), toStack(outputItem), time))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(RecipeVat recipe) { + super("Mariculture Vat", MaricultureHandlers.vat.getRecipes(), recipe); + } + + @Override + public String getRecipeInfo() { + if (((RecipeVat) recipe).outputItem != null) return ((RecipeVat) recipe).outputItem.getDisplayName(); + else return ((RecipeVat) recipe).outputFluid.getFluid().getLocalizedName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Mariculture Vat recipe + @ZenMethod + public static void removeRecipe(IItemStack outputItem) { + MineTweakerAPI.apply(new Remove(toStack(outputItem), null)); + } + + @ZenMethod + public static void removeRecipe(ILiquidStack outputFluid) { + MineTweakerAPI.apply(new Remove(null, toFluid(outputFluid))); + } + + @ZenMethod + public static void removeRecipe(IItemStack outputItem, ILiquidStack outputFluid) { + MineTweakerAPI.apply(new Remove(toStack(outputItem), toFluid(outputFluid))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + private final FluidStack fluid; + + public Remove(ItemStack stack, FluidStack fluid) { + super("Mariculture Vat", MaricultureHandlers.vat.getRecipes(), stack); + this.fluid = fluid; + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (RecipeVat r : MaricultureHandlers.vat.getRecipes()) { + if (r.outputItem != null && stack != null && areEqual(r.outputItem, stack)) { + if (r.outputFluid == null || (fluid != null && r.outputFluid.isFluidStackIdentical(fluid))) { + recipe = r; + break; + } + } + + if ((r.outputFluid != null && fluid != null && r.outputFluid.isFluidStackIdentical(fluid))) { + recipe = r; + break; + } + } + + MaricultureHandlers.vat.getRecipes().remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack != null ? stack.getDisplayName() : fluid.getFluid().getLocalizedName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/Mekanism.java b/src/main/java/modtweaker/mods/mekanism/Mekanism.java new file mode 100644 index 0000000..81cbd23 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/Mekanism.java @@ -0,0 +1,41 @@ +package modtweaker.mods.mekanism; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.mekanism.gas.GasBracketHandler; +import modtweaker.mods.mekanism.handlers.ChemicalCrystallizer; +import modtweaker.mods.mekanism.handlers.ChemicalDissolution; +import modtweaker.mods.mekanism.handlers.ChemicalInfuser; +import modtweaker.mods.mekanism.handlers.ChemicalInjection; +import modtweaker.mods.mekanism.handlers.ChemicalOxidizer; +import modtweaker.mods.mekanism.handlers.ChemicalWasher; +import modtweaker.mods.mekanism.handlers.Combiner; +import modtweaker.mods.mekanism.handlers.Compressor; +import modtweaker.mods.mekanism.handlers.Crusher; +import modtweaker.mods.mekanism.handlers.Enrichment; +import modtweaker.mods.mekanism.handlers.Infuser; +import modtweaker.mods.mekanism.handlers.Purification; +import modtweaker.mods.mekanism.handlers.Reaction; +import modtweaker.mods.mekanism.handlers.Sawmill; +import modtweaker.mods.mekanism.handlers.Separator; +import modtweaker.util.TweakerPlugin; + +public class Mekanism extends TweakerPlugin { + public Mekanism() { + MineTweakerAPI.registerBracketHandler(new GasBracketHandler()); + MineTweakerAPI.registerClass(Combiner.class); + MineTweakerAPI.registerClass(Compressor.class); + MineTweakerAPI.registerClass(Crusher.class); + MineTweakerAPI.registerClass(Enrichment.class); + MineTweakerAPI.registerClass(Infuser.class); + MineTweakerAPI.registerClass(Purification.class); + MineTweakerAPI.registerClass(Reaction.class); + MineTweakerAPI.registerClass(Sawmill.class); + MineTweakerAPI.registerClass(Separator.class); + MineTweakerAPI.registerClass(ChemicalCrystallizer.class); + MineTweakerAPI.registerClass(ChemicalDissolution.class); + MineTweakerAPI.registerClass(ChemicalInfuser.class); + MineTweakerAPI.registerClass(ChemicalInjection.class); + MineTweakerAPI.registerClass(ChemicalOxidizer.class); + MineTweakerAPI.registerClass(ChemicalWasher.class); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/MekanismHelper.java b/src/main/java/modtweaker/mods/mekanism/MekanismHelper.java new file mode 100644 index 0000000..ccb616a --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/MekanismHelper.java @@ -0,0 +1,27 @@ +package modtweaker.mods.mekanism; + +import mekanism.api.gas.GasRegistry; +import mekanism.api.gas.GasStack; +import minetweaker.api.item.IIngredient; +import modtweaker.mods.mekanism.gas.IGasStack; + +public class MekanismHelper { + private MekanismHelper() {} + + public static GasStack toGas(IGasStack iStack) { + if (iStack == null) { + return null; + } else return new GasStack(GasRegistry.getGas(iStack.getName()), iStack.getAmount()); + } + + public static GasStack[] toGases(IIngredient[] input) { + return toGases((IGasStack[]) input); + } + + public static GasStack[] toGases(IGasStack[] iStack) { + GasStack[] stack = new GasStack[iStack.length]; + for (int i = 0; i < stack.length; i++) + stack[i] = toGas(iStack[i]); + return stack; + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/gas/GasBracketHandler.java b/src/main/java/modtweaker/mods/mekanism/gas/GasBracketHandler.java new file mode 100644 index 0000000..614d0ec --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/gas/GasBracketHandler.java @@ -0,0 +1,85 @@ +package modtweaker.mods.mekanism.gas; + +import java.util.List; + +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasRegistry; +import mekanism.api.gas.GasStack; +import minetweaker.IBracketHandler; +import minetweaker.MineTweakerAPI; +import minetweaker.annotations.BracketHandler; +import minetweaker.api.item.IngredientAny; +import stanhebben.zenscript.compiler.IEnvironmentGlobal; +import stanhebben.zenscript.expression.ExpressionCallStatic; +import stanhebben.zenscript.expression.ExpressionString; +import stanhebben.zenscript.expression.partial.IPartialExpression; +import stanhebben.zenscript.parser.Token; +import stanhebben.zenscript.symbols.IZenSymbol; +import stanhebben.zenscript.type.natives.IJavaMethod; +import stanhebben.zenscript.util.ZenPosition; + +@BracketHandler(priority = 100) +public class GasBracketHandler implements IBracketHandler { + public static IGasStack getGas(String name) { + Gas gas = GasRegistry.getGas(name); + if (gas != null) { + return new MCGasStack(new GasStack(gas, 1)); + } else { + return null; + } + } + + private final IZenSymbol symbolAny; + private final IJavaMethod method; + + public GasBracketHandler() { + symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE"); + method = MineTweakerAPI.getJavaMethod(GasBracketHandler.class, "getGas", String.class); + } + + @Override + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { + // any symbol + if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) { + return symbolAny; + } + + if (tokens.size() > 2) { + if (tokens.get(0).getValue().equals("gas") && tokens.get(1).getValue().equals(":")) { + return find(environment, tokens, 2, tokens.size()); + } + } + + return null; + } + + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex) { + StringBuilder valueBuilder = new StringBuilder(); + for (int i = startIndex; i < endIndex; i++) { + Token token = tokens.get(i); + valueBuilder.append(token.getValue()); + } + + Gas gas = GasRegistry.getGas(valueBuilder.toString()); + if (gas != null) { + return new GasReferenceSymbol(environment, valueBuilder.toString()); + } + + return null; + } + + private class GasReferenceSymbol implements IZenSymbol { + private final IEnvironmentGlobal environment; + private final String name; + + public GasReferenceSymbol(IEnvironmentGlobal environment, String name) { + this.environment = environment; + this.name = name; + } + + @Override + public IPartialExpression instance(ZenPosition position) { + return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name)); + } + } +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/mekanism/gas/GasLogger.java b/src/main/java/modtweaker/mods/mekanism/gas/GasLogger.java new file mode 100644 index 0000000..355fceb --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/gas/GasLogger.java @@ -0,0 +1,38 @@ +package modtweaker.mods.mekanism.gas; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasRegistry; +import minetweaker.MineTweakerAPI; +import minetweaker.MineTweakerImplementationAPI; +import minetweaker.api.player.IPlayer; +import minetweaker.api.server.ICommandFunction; + +public class GasLogger implements ICommandFunction { + public static final Comparator COMPARATOR = new Compare(); + + private static class Compare implements Comparator { + @Override + public int compare(Gas o1, Gas o2) { + return o1.getName().compareTo(o2.getName()); + } + } + + @Override + public void execute(String[] arguments, IPlayer player) { + List gases = GasRegistry.getRegisteredGasses(); + System.out.println("Gases: " + GasRegistry.getRegisteredGasses().size()); + Collections.sort(gases, COMPARATOR); + for (Gas gas : gases) { + System.out.println("Gas " + gas.getName()); + MineTweakerAPI.logCommand("<" + gas.getName() + "> -- " + gas.getLocalizedName()); + } + + if (player != null) { + player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir")); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/gas/IGasDefinition.java b/src/main/java/modtweaker/mods/mekanism/gas/IGasDefinition.java new file mode 100644 index 0000000..689a189 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/gas/IGasDefinition.java @@ -0,0 +1,18 @@ +package modtweaker.mods.mekanism.gas; + +import stanhebben.zenscript.annotations.OperatorType; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenOperator; + +@ZenClass("modtweaker.gas.IGasDefinition") +public interface IGasDefinition { + @ZenOperator(OperatorType.MUL) + public IGasStack asStack(int millibuckets); + + @ZenGetter("name") + public String getName(); + + @ZenGetter("displayName") + public String getDisplayName(); +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/mekanism/gas/IGasStack.java b/src/main/java/modtweaker/mods/mekanism/gas/IGasStack.java new file mode 100644 index 0000000..1cf2759 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/gas/IGasStack.java @@ -0,0 +1,28 @@ +package modtweaker.mods.mekanism.gas; + +import stanhebben.zenscript.annotations.OperatorType; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.ZenOperator; + +@ZenClass("modtweaker.gas.IGasStack") +public interface IGasStack { + @ZenGetter("definition") + public IGasDefinition getDefinition(); + + @ZenGetter("name") + public String getName(); + + @ZenGetter("displayName") + public String getDisplayName(); + + @ZenGetter("amount") + public int getAmount(); + + @ZenOperator(OperatorType.MUL) + @ZenMethod + public IGasStack withAmount(int amount); + + public Object getInternal(); +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/mekanism/gas/MCGasDefinition.java b/src/main/java/modtweaker/mods/mekanism/gas/MCGasDefinition.java new file mode 100644 index 0000000..aa53b58 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/gas/MCGasDefinition.java @@ -0,0 +1,27 @@ +package modtweaker.mods.mekanism.gas; + +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; + +public class MCGasDefinition implements IGasDefinition { + private final Gas gas; + + public MCGasDefinition(Gas gas) { + this.gas = gas; + } + + @Override + public String getName() { + return gas.getName(); + } + + @Override + public String getDisplayName() { + return gas.getLocalizedName(); + } + + @Override + public IGasStack asStack(int millibuckets) { + return new MCGasStack(new GasStack(gas, millibuckets)); + } +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/mekanism/gas/MCGasStack.java b/src/main/java/modtweaker/mods/mekanism/gas/MCGasStack.java new file mode 100644 index 0000000..78e1d1b --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/gas/MCGasStack.java @@ -0,0 +1,42 @@ +package modtweaker.mods.mekanism.gas; + +import mekanism.api.gas.GasStack; + +public class MCGasStack implements IGasStack { + private final GasStack stack; + + public MCGasStack(GasStack stack) { + this.stack = stack; + } + + @Override + public IGasDefinition getDefinition() { + return new MCGasDefinition(stack.getGas()); + } + + @Override + public String getName() { + return stack.getGas().getName(); + } + + @Override + public String getDisplayName() { + return stack.getGas().getLocalizedName(); + } + + @Override + public int getAmount() { + return stack.amount; + } + + @Override + public IGasStack withAmount(int amount) { + GasStack result = new GasStack(stack.getGas(), amount); + return new MCGasStack(result); + } + + @Override + public Object getInternal() { + return stack; + } +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalCrystallizer.java b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalCrystallizer.java new file mode 100644 index 0000000..ddd6aa0 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalCrystallizer.java @@ -0,0 +1,25 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.mods.mekanism.MekanismHelper.toGas; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.chemical.Crystallizer") +public class ChemicalCrystallizer { + @ZenMethod + public static void addRecipe(IGasStack input, IItemStack output) { + MineTweakerAPI.apply(new AddMekanismRecipe("CHEMICAL_CRYSTALLIZER", Recipe.CHEMICAL_CRYSTALLIZER.get(), toGas(input), toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("CHEMICAL_CRYSTALLIZER", Recipe.CHEMICAL_CRYSTALLIZER.get(), toStack(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalDissolution.java b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalDissolution.java new file mode 100644 index 0000000..a6d95d5 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalDissolution.java @@ -0,0 +1,78 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import static modtweaker.mods.mekanism.MekanismHelper.toGas; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import mekanism.api.gas.GasStack; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.oredict.IOreDictEntry; +import modtweaker.helpers.InputHelper; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.chemical.Dissolution") +public class ChemicalDissolution { + @ZenMethod + public static void addRecipe(IItemStack input, IGasStack output) { + MineTweakerAPI.apply(new AddMekanismRecipe("CHEMICAL_DISSOLUTION_CHAMBER", Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), toStack(input), toGas(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove("CHEMICAL_DISSOLUTION_CHAMBER", Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), toStack(input))); + } + + @ZenMethod + public static void removeRecipe(IOreDictEntry input) { + List stacks = OreDictionary.getOres(InputHelper.toString(input)); + for (ItemStack stack : stacks) { + MineTweakerAPI.apply(new Remove("CHEMICAL_DISSOLUTION_CHAMBER", Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), stack)); + } + } + + @ZenMethod + public static void removeRecipe(IGasStack input) { + MineTweakerAPI.apply(new Remove("CHEMICAL_DISSOLUTION_CHAMBER", Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get(), toGas(input))); + } + + private static class Remove extends RemoveMekanismRecipe { + public Remove(String string, Map map, Object key) { + super(string, map, key); + } + + @Override + public void apply() { + Iterator it = map.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry) it.next(); + ItemStack key = (ItemStack) pairs.getKey(); + GasStack value = (GasStack) pairs.getValue(); + if (key != null) { + if (this.key instanceof ItemStack && areEqual(key, (ItemStack) this.key)) { + this.key = key; + break; + } else if (this.key instanceof GasStack && value.isGasEqual((GasStack) this.key)) { + this.key = key; + break; + } + } + + } + + recipe = map.get(key); + map.remove(key); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalInfuser.java b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalInfuser.java new file mode 100644 index 0000000..f88294e --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalInfuser.java @@ -0,0 +1,25 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.mods.mekanism.MekanismHelper.toGas; +import mekanism.api.ChemicalPair; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.chemical.Infuser") +public class ChemicalInfuser { + @ZenMethod + public static void addRecipe(IGasStack left, IGasStack right, IGasStack out) { + ChemicalPair pair = new ChemicalPair(toGas(left), toGas(right)); + MineTweakerAPI.apply(new AddMekanismRecipe("CHEMICAL_INFUSER", Recipe.CHEMICAL_INFUSER.get(), pair, toGas(out))); + } + + @ZenMethod + public static void removeRecipe(IGasStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("CHEMICAL_INFUSER", Recipe.CHEMICAL_INFUSER.get(), toGas(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalInjection.java b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalInjection.java new file mode 100644 index 0000000..cc7c268 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalInjection.java @@ -0,0 +1,27 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.mods.mekanism.MekanismHelper.toGas; +import mekanism.api.AdvancedInput; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.chemical.Injection") +public class ChemicalInjection { + @ZenMethod + public static void addRecipe(IItemStack input, IGasStack gas, IItemStack output) { + AdvancedInput aInput = new AdvancedInput(toStack(input), toGas(gas).getGas()); + MineTweakerAPI.apply(new AddMekanismRecipe("CHEMICAL_INJECTION_CHAMBER", Recipe.CHEMICAL_INJECTION_CHAMBER.get(), aInput, toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("CHEMICAL_INJECTION_CHAMBER", Recipe.CHEMICAL_INJECTION_CHAMBER.get(), toStack(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalOxidizer.java b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalOxidizer.java new file mode 100644 index 0000000..67dde0b --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalOxidizer.java @@ -0,0 +1,25 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.mods.mekanism.MekanismHelper.toGas; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.chemical.Oxidizer") +public class ChemicalOxidizer { + @ZenMethod + public static void addRecipe(IItemStack input, IGasStack output) { + MineTweakerAPI.apply(new AddMekanismRecipe("CHEMICAL_OXIDIZER", Recipe.CHEMICAL_OXIDIZER.get(), toStack(input), toGas(output))); + } + + @ZenMethod + public static void removeRecipe(IGasStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("CHEMICAL_OXIDIZER", Recipe.CHEMICAL_OXIDIZER.get(), toGas(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalWasher.java b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalWasher.java new file mode 100644 index 0000000..29e9970 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/ChemicalWasher.java @@ -0,0 +1,54 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.mods.mekanism.MekanismHelper.toGas; + +import java.util.Iterator; +import java.util.Map; + +import mekanism.api.gas.GasStack; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.chemical.Washer") +public class ChemicalWasher { + @ZenMethod + public static void addRecipe(IGasStack input, IGasStack output) { + MineTweakerAPI.apply(new AddMekanismRecipe("CHEMICAL_WASHER", Recipe.CHEMICAL_WASHER.get(), toGas(input), toGas(output))); + } + + @ZenMethod + public static void removeRecipe(IGasStack output) { + MineTweakerAPI.apply(new Remove("CHEMICAL_WASHER", Recipe.CHEMICAL_WASHER.get(), toGas(output))); + } + + private static class Remove extends RemoveMekanismRecipe { + public Remove(String string, Map map, Object key) { + super(string, map, key); + } + + @Override + public void apply() { + Iterator it = map.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry) it.next(); + GasStack key = (GasStack) pairs.getKey(); + GasStack value = (GasStack) pairs.getValue(); + if (key != null) { + if (this.key instanceof GasStack && value.isGasEqual((GasStack) this.key)) { + this.key = key; + break; + } + } + + } + + recipe = map.get(key); + map.remove(key); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Combiner.java b/src/main/java/modtweaker/mods/mekanism/handlers/Combiner.java new file mode 100644 index 0000000..bf4e43f --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Combiner.java @@ -0,0 +1,26 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import mekanism.api.AdvancedInput; +import mekanism.api.gas.GasRegistry; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Combiner") +public class Combiner { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + AdvancedInput aInput = new AdvancedInput(toStack(input), GasRegistry.getGas("liquidStone")); + MineTweakerAPI.apply(new AddMekanismRecipe("COMBINER", Recipe.COMBINER.get(), aInput, toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("COMBINER", Recipe.COMBINER.get(), toStack(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Compressor.java b/src/main/java/modtweaker/mods/mekanism/handlers/Compressor.java new file mode 100644 index 0000000..789a5a1 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Compressor.java @@ -0,0 +1,26 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import mekanism.api.AdvancedInput; +import mekanism.api.gas.GasRegistry; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Compressor") +public class Compressor { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + AdvancedInput aInput = new AdvancedInput(toStack(input), GasRegistry.getGas("liquidOsmium")); + MineTweakerAPI.apply(new AddMekanismRecipe("OSMIUM_COMPRESSOR", Recipe.OSMIUM_COMPRESSOR.get(), aInput, toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("OSMIUM_COMPRESSOR", Recipe.OSMIUM_COMPRESSOR.get(), toStack(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Crusher.java b/src/main/java/modtweaker/mods/mekanism/handlers/Crusher.java new file mode 100644 index 0000000..ed353ef --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Crusher.java @@ -0,0 +1,23 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Crusher") +public class Crusher { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new AddMekanismRecipe("CRUSHER", Recipe.CRUSHER.get(), toStack(input), toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("CRUSHER", Recipe.CRUSHER.get(), toStack(output))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Enrichment.java b/src/main/java/modtweaker/mods/mekanism/handlers/Enrichment.java new file mode 100644 index 0000000..671cb81 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Enrichment.java @@ -0,0 +1,23 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Enrichment") +public class Enrichment { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new AddMekanismRecipe("ENRICHMENT_CHAMBER", Recipe.ENRICHMENT_CHAMBER.get(), toStack(input), toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new RemoveMekanismRecipe("ENRICHMENT_CHAMBER", Recipe.ENRICHMENT_CHAMBER.get(), toStack(input))); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Infuser.java b/src/main/java/modtweaker/mods/mekanism/handlers/Infuser.java new file mode 100644 index 0000000..44d7ac3 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Infuser.java @@ -0,0 +1,59 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.Iterator; +import java.util.Map; + +import mekanism.api.infuse.InfuseRegistry; +import mekanism.api.infuse.InfusionInput; +import mekanism.api.infuse.InfusionOutput; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Infuser") +public class Infuser { + @ZenMethod + public static void addRecipe(String type, int infuse, IItemStack input, IItemStack output) { + InfusionInput infuseIn = new InfusionInput(InfuseRegistry.get(type), infuse, toStack(input)); + InfusionOutput infuseOut = new InfusionOutput(infuseIn, toStack(output)); + MineTweakerAPI.apply(new AddMekanismRecipe("METALLURGIC_INFUSER", Recipe.METALLURGIC_INFUSER.get(), infuseIn, infuseOut)); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove("METALLURGIC_INFUSER", Recipe.METALLURGIC_INFUSER.get(), new InfusionOutput(null, toStack(output)))); + } + + private static class Remove extends RemoveMekanismRecipe { + public Remove(String string, Map map, Object key) { + super(string, map, key); + } + + @Override + public void apply() { + Iterator it = map.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry) it.next(); + InfusionInput key = (InfusionInput) pairs.getKey(); + InfusionOutput value = (InfusionOutput) pairs.getValue(); + if (key != null) { + if (this.key instanceof InfusionOutput && areEqual(value.resource, ((InfusionOutput) this.key).resource)) { + this.key = key; + break; + } + } + + } + + recipe = map.get(key); + map.remove(key); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Purification.java b/src/main/java/modtweaker/mods/mekanism/handlers/Purification.java new file mode 100644 index 0000000..7a17499 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Purification.java @@ -0,0 +1,50 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.Map; + +import mekanism.api.AdvancedInput; +import mekanism.api.gas.GasRegistry; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Purification") +public class Purification { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + AdvancedInput aInput = new AdvancedInput(toStack(input), GasRegistry.getGas("oxygen")); + MineTweakerAPI.apply(new AddMekanismRecipe("PURIFICATION_CHAMBER", Recipe.PURIFICATION_CHAMBER.get(), aInput, toStack(output))); + } + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseMapRemoval { + public Remove(ItemStack stack) { + super("Purification Chamber", Recipe.PURIFICATION_CHAMBER.get(), stack); + } + + //We must search through the recipe entries so that we can assign the correct key for removal + @Override + public void apply() { + for (Map.Entry entry : ((Map) map).entrySet()) { + if (entry.getValue() != null && areEqual(entry.getValue(), (ItemStack) stack)) { + key = entry.getKey(); + break; + } + } + + super.apply(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Reaction.java b/src/main/java/modtweaker/mods/mekanism/handlers/Reaction.java new file mode 100644 index 0000000..334e707 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Reaction.java @@ -0,0 +1,33 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.mods.mekanism.MekanismHelper.toGas; +import mekanism.api.PressurizedProducts; +import mekanism.api.PressurizedReactants; +import mekanism.api.PressurizedRecipe; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.mods.mekanism.util.RemoveMekanismRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Reaction") +public class Reaction { + @ZenMethod + public static void addRecipe(IItemStack solid, ILiquidStack liquid, IGasStack gas, IItemStack outItem, IGasStack outGas, double energy, int ticks) { + PressurizedReactants input = new PressurizedReactants(toStack(solid), toFluid(liquid), toGas(gas)); + PressurizedRecipe recipe = new PressurizedRecipe(input, energy, new PressurizedProducts(toStack(outItem), toGas(outGas)), ticks); + MineTweakerAPI.apply(new AddMekanismRecipe("PRESSURIZED_REACTION_CHAMBER", Recipe.PRESSURIZED_REACTION_CHAMBER.get(), input, recipe)); + } + + @ZenMethod + public static void removeRecipe(IItemStack outItem, IGasStack outGas) { + PressurizedProducts output = new PressurizedProducts(toStack(outItem), toGas(outGas)); + MineTweakerAPI.apply(new RemoveMekanismRecipe("PRESSURIZED_REACTION_CHAMBER", Recipe.PRESSURIZED_REACTION_CHAMBER.get(), output)); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Sawmill.java b/src/main/java/modtweaker/mods/mekanism/handlers/Sawmill.java new file mode 100644 index 0000000..a60dfb2 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Sawmill.java @@ -0,0 +1,50 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.Map; + +import mekanism.api.ChanceOutput; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Sawmill") +public class Sawmill { + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output1, @Optional IItemStack output2, @Optional double chance) { + ChanceOutput chanceOutput = new ChanceOutput(toStack(output1), toStack(output2), chance); + MineTweakerAPI.apply(new AddMekanismRecipe("PRECISION_SAWMILL", Recipe.PRECISION_SAWMILL.get(), toStack(input), chanceOutput)); + } + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove extends BaseMapRemoval { + public Remove(ItemStack stack) { + super("Precision Sawmill", Recipe.PRECISION_SAWMILL.get(), stack); + } + + //We must search through the recipe entries so that we can assign the correct key for removal + @Override + public void apply() { + for (Map.Entry entry : ((Map) map).entrySet()) { + if (entry.getKey() != null && areEqual(entry.getKey(), (ItemStack) stack)) { + key = entry.getKey(); + break; + } + } + + super.apply(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/handlers/Separator.java b/src/main/java/modtweaker/mods/mekanism/handlers/Separator.java new file mode 100644 index 0000000..a4be2fb --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/handlers/Separator.java @@ -0,0 +1,50 @@ +package modtweaker.mods.mekanism.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.mods.mekanism.MekanismHelper.toGas; + +import java.util.Map; + +import mekanism.api.ChemicalPair; +import mekanism.common.recipe.RecipeHandler.Recipe; +import minetweaker.MineTweakerAPI; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.mods.mekanism.gas.IGasStack; +import modtweaker.mods.mekanism.util.AddMekanismRecipe; +import modtweaker.util.BaseMapRemoval; +import net.minecraftforge.fluids.FluidStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.Separator") +public class Separator { + @ZenMethod + public static void addRecipe(ILiquidStack input, IGasStack gas1, IGasStack gas2) { + ChemicalPair pair = new ChemicalPair(toGas(gas1), toGas(gas2)); + MineTweakerAPI.apply(new AddMekanismRecipe("ELECTROLYTIC_SEPARATOR", Recipe.ELECTROLYTIC_SEPARATOR.get(), toFluid(input), pair)); + } + + @ZenMethod + public static void removeRecipe(ILiquidStack input) { + MineTweakerAPI.apply(new Remove(toFluid(input))); + } + + private static class Remove extends BaseMapRemoval { + public Remove(FluidStack stack) { + super("Electrolytic Separator", Recipe.ELECTROLYTIC_SEPARATOR.get(), stack); + } + + //We must search through the recipe entries so that we can assign the correct key for removal + @Override + public void apply() { + for (Map.Entry entry : ((Map) map).entrySet()) { + if (entry.getKey() != null && entry.getKey().isFluidEqual((FluidStack) stack)) { + key = entry.getKey(); + break; + } + } + + super.apply(); + } + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/util/AddMekanismRecipe.java b/src/main/java/modtweaker/mods/mekanism/util/AddMekanismRecipe.java new file mode 100644 index 0000000..fbaf1ee --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/util/AddMekanismRecipe.java @@ -0,0 +1,42 @@ +package modtweaker.mods.mekanism.util; + +import java.util.Map; + +import mekanism.api.ChanceOutput; +import mekanism.api.ChemicalPair; +import mekanism.api.PressurizedReactants; +import mekanism.api.gas.GasStack; +import mekanism.api.infuse.InfusionOutput; +import modtweaker.util.BaseMapAddition; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class AddMekanismRecipe extends BaseMapAddition { + public AddMekanismRecipe(String str, Map map, Object key, Object recipe) { + super(str.toLowerCase(), map, key, recipe); + } + + @Override + public String describe() { + if (recipe instanceof ItemStack) return "Adding " + description + " Recipe for : " + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Adding " + description + " Recipe for : " + ((FluidStack) recipe).getFluid().getLocalizedName(); + else if (recipe instanceof ChemicalPair) return "Adding " + description + " Recipe for : " + ((ChemicalPair) recipe).leftGas.getGas().getLocalizedName(); + else if (recipe instanceof ChanceOutput) return "Adding " + description + " Recipe for : " + ((ChanceOutput) recipe).primaryOutput.getDisplayName(); + else if (recipe instanceof GasStack) return "Adding " + description + " Recipe for : " + ((GasStack) recipe).getGas().getLocalizedName(); + else if (recipe instanceof PressurizedReactants) return "Adding " + description + " Recipe for : " + ((PressurizedReactants) recipe).getSolid().getDisplayName(); + else if (recipe instanceof InfusionOutput) return "Adding " + description + " Recipe for : " + ((InfusionOutput) recipe).resource.getDisplayName(); + else return super.getRecipeInfo(); + } + + @Override + public String describeUndo() { + if (recipe instanceof ItemStack) return "Removing " + description + " Recipe for : " + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Removing " + description + " Recipe for : " + ((FluidStack) recipe).getFluid().getLocalizedName(); + else if (recipe instanceof ChemicalPair) return "Removing " + description + " Recipe for : " + ((ChemicalPair) recipe).leftGas.getGas().getLocalizedName(); + else if (recipe instanceof ChanceOutput) return "Removing " + description + " Recipe for : " + ((ChanceOutput) recipe).primaryOutput.getDisplayName(); + else if (recipe instanceof GasStack) return "Removing " + description + " Recipe for : " + ((GasStack) recipe).getGas().getLocalizedName(); + else if (recipe instanceof PressurizedReactants) return "Removing " + description + " Recipe for : " + ((PressurizedReactants) recipe).getSolid().getDisplayName(); + else if (recipe instanceof InfusionOutput) return "Removing " + description + " Recipe for : " + ((InfusionOutput) recipe).resource.getDisplayName(); + else return super.getRecipeInfo(); + } +} diff --git a/src/main/java/modtweaker/mods/mekanism/util/RemoveMekanismRecipe.java b/src/main/java/modtweaker/mods/mekanism/util/RemoveMekanismRecipe.java new file mode 100644 index 0000000..25344b6 --- /dev/null +++ b/src/main/java/modtweaker/mods/mekanism/util/RemoveMekanismRecipe.java @@ -0,0 +1,131 @@ +package modtweaker.mods.mekanism.util; + +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.Iterator; +import java.util.Map; + +import mekanism.api.ChanceOutput; +import mekanism.api.ChemicalPair; +import mekanism.api.PressurizedProducts; +import mekanism.api.PressurizedReactants; +import mekanism.api.PressurizedRecipe; +import mekanism.api.gas.GasStack; +import mekanism.api.infuse.InfusionOutput; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class RemoveMekanismRecipe extends BaseMapRemoval { + private Object tmp; + + public RemoveMekanismRecipe(String string, Map map, Object key) { + super(string.toLowerCase().replace('_', ' '), map, key, null); + this.tmp = key; + } + + @Override + public void apply() { + try { + Iterator it = map.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry) it.next(); + Object value = pairs.getValue(); + if (value != null) { + if (tmp instanceof ItemStack && value instanceof ItemStack) { + if (areEqual(((ItemStack) tmp), (ItemStack) value)) { + key = pairs.getKey(); + break; + } + } + + if (tmp instanceof FluidStack && value instanceof FluidStack) { + if (((FluidStack) tmp).isFluidEqual((FluidStack) value)) { + key = pairs.getKey(); + break; + } + } + + if (tmp instanceof GasStack && value instanceof GasStack) { + if (((GasStack) tmp).isGasEqual((GasStack) value)) { + key = pairs.getKey(); + break; + } + } + + if (tmp instanceof ItemStack && value instanceof InfusionOutput) { + if (areEqual(((ItemStack) tmp), ((InfusionOutput) value).resource)) { + key = pairs.getKey(); + break; + } + } + + if (tmp instanceof ChemicalPair && value instanceof ChemicalPair) { + ChemicalPair par1 = (ChemicalPair) tmp; + ChemicalPair par2 = (ChemicalPair) value; + if (par1.leftGas.isGasEqual(par2.leftGas) && par1.rightGas.isGasEqual(par2.rightGas)) { + key = pairs.getKey(); + break; + } + } + + if (tmp instanceof ChanceOutput && value instanceof ChanceOutput) { + ChanceOutput par1 = (ChanceOutput) tmp; + ChanceOutput par2 = (ChanceOutput) value; + if (areEqual(par1.primaryOutput, par2.primaryOutput)) { + if (par1.secondaryOutput == null || (par1.secondaryOutput != null && par2.secondaryOutput != null && areEqual(par1.secondaryOutput, par2.secondaryOutput))) { + key = pairs.getKey(); + break; + } + } + } + + if (tmp instanceof PressurizedProducts && value instanceof PressurizedRecipe) { + PressurizedProducts par1 = (PressurizedProducts) tmp; + PressurizedProducts par2 = ((PressurizedRecipe) value).products; + if (areEqual(par1.getItemOutput(), (par2.getItemOutput()))) { + if (par1.getGasOutput().isGasEqual(par2.getGasOutput())) { + key = pairs.getKey(); + break; + + } + } + } + } + + it.remove(); + } + + recipe = map.get(key); + + } catch (Exception e) { + e.printStackTrace(); + } + + map.remove(key); + } + + @Override + public String describe() { + if (tmp instanceof ItemStack) return "Removing " + description + " Recipe for : " + ((ItemStack) tmp).getDisplayName(); + else if (tmp instanceof FluidStack) return "Removing " + description + " Recipe for : " + ((FluidStack) tmp).getFluid().getLocalizedName(); + else if (tmp instanceof ChemicalPair) return "Removing " + description + " Recipe for : " + ((ChemicalPair) tmp).leftGas.getGas().getLocalizedName(); + else if (tmp instanceof ChanceOutput) return "Removing " + description + " Recipe for : " + ((ChanceOutput) tmp).primaryOutput.getDisplayName(); + else if (tmp instanceof GasStack) return "Removing " + description + " Recipe for : " + ((GasStack) tmp).getGas().getLocalizedName(); + else if (tmp instanceof PressurizedReactants) return "Removing " + description + " Recipe for : " + ((PressurizedReactants) tmp).getSolid().getDisplayName(); + else if (tmp instanceof InfusionOutput) return "Removing " + description + " Recipe for : " + ((InfusionOutput) tmp).resource.getDisplayName(); + else return super.getRecipeInfo(); + } + + @Override + public String describeUndo() { + if (tmp instanceof ItemStack) return "Restoring " + description + " Recipe for : " + ((ItemStack) tmp).getDisplayName(); + else if (tmp instanceof FluidStack) return "Restoring " + description + " Recipe for : " + ((FluidStack) tmp).getFluid().getLocalizedName(); + else if (tmp instanceof ChemicalPair) return "Restoring " + description + " Recipe for : " + ((ChemicalPair) tmp).leftGas.getGas().getLocalizedName(); + else if (tmp instanceof ChanceOutput) return "Restoring " + description + " Recipe for : " + ((ChanceOutput) tmp).primaryOutput.getDisplayName(); + else if (tmp instanceof GasStack) return "Restoring " + description + " Recipe for : " + ((GasStack) tmp).getGas().getLocalizedName(); + else if (tmp instanceof PressurizedReactants) return "Restoring " + description + " Recipe for : " + ((PressurizedReactants) tmp).getSolid().getDisplayName(); + else if (tmp instanceof InfusionOutput) return "Restoring " + description + " Recipe for : " + ((InfusionOutput) tmp).resource.getDisplayName(); + else return super.getRecipeInfo(); + } +} diff --git a/src/main/java/modtweaker/mods/metallurgy/Metallurgy.java b/src/main/java/modtweaker/mods/metallurgy/Metallurgy.java new file mode 100644 index 0000000..ce92f6b --- /dev/null +++ b/src/main/java/modtweaker/mods/metallurgy/Metallurgy.java @@ -0,0 +1,12 @@ +package modtweaker.mods.metallurgy; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.metallurgy.handlers.Alloyer; +import modtweaker.mods.metallurgy.handlers.Crusher; + +public class Metallurgy { + public Metallurgy() { + MineTweakerAPI.registerClass(Alloyer.class); + MineTweakerAPI.registerClass(Crusher.class); + } +} diff --git a/src/main/java/modtweaker/mods/metallurgy/MetallurgyHelper.java b/src/main/java/modtweaker/mods/metallurgy/MetallurgyHelper.java new file mode 100644 index 0000000..589e725 --- /dev/null +++ b/src/main/java/modtweaker/mods/metallurgy/MetallurgyHelper.java @@ -0,0 +1,44 @@ +package modtweaker.mods.metallurgy; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.HashMap; + +import modtweaker.helpers.ReflectionHelper; +import net.minecraft.item.ItemStack; + +import com.teammetallurgy.metallurgy.recipes.AlloyerRecipes; +import com.teammetallurgy.metallurgy.recipes.AlloyerRecipes.AlloyRecipe; +import com.teammetallurgy.metallurgy.recipes.CrusherRecipes; + +public class MetallurgyHelper { + public static ArrayList alloyerRecipes = null; + public static HashMap crusherMetaList = null; + public static HashMap crusherInputList = null; + + static { + try { + alloyerRecipes = ReflectionHelper.getFinalObject(AlloyerRecipes.getInstance(), "recipes"); + crusherMetaList = ReflectionHelper.getFinalObject(CrusherRecipes.getInstance(), "metaList"); + crusherInputList = ReflectionHelper.getFinalObject(CrusherRecipes.getInstance(), "inputList"); + } catch (Exception e) {} + } + + private MetallurgyHelper() {} + + public static String getCrusherKey(ItemStack input) { + return input.getUnlocalizedName(); + } + + //Returns a Drying Recipe, using reflection as the constructor is not visible + public static AlloyRecipe getAlloyRecipe(ItemStack first, ItemStack base, ItemStack result) { + try { + Constructor constructor = AlloyRecipe.class.getDeclaredConstructor(ItemStack.class, ItemStack.class, ItemStack.class); + constructor.setAccessible(true); + return (AlloyRecipe) constructor.newInstance(first, base, result); + } catch (Exception e) { + e.printStackTrace(); + throw new NullPointerException("Failed to instantiate AlloyRecipe"); + } + } +} diff --git a/src/main/java/modtweaker/mods/metallurgy/handlers/Alloyer.java b/src/main/java/modtweaker/mods/metallurgy/handlers/Alloyer.java new file mode 100644 index 0000000..ab3fd41 --- /dev/null +++ b/src/main/java/modtweaker/mods/metallurgy/handlers/Alloyer.java @@ -0,0 +1,68 @@ +package modtweaker.mods.metallurgy.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.metallurgy.MetallurgyHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +import com.teammetallurgy.metallurgy.recipes.AlloyerRecipes.AlloyRecipe; + +@ZenClass("mods.metallurgy.Alloyer") +public class Alloyer { + //Adding a Metallurgy Alloyer recipe + @ZenMethod + public static void addRecipe(IItemStack first, IItemStack base, IItemStack result) { + MineTweakerAPI.apply(new Add(MetallurgyHelper.getAlloyRecipe(toStack(first), toStack(base), toStack(result)))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(AlloyRecipe recipe) { + super("Metallurgy Alloyer", MetallurgyHelper.alloyerRecipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((AlloyRecipe) recipe).getCraftingResult().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Metallurgy Alloyer recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Metallurgy Alloyer", MetallurgyHelper.alloyerRecipes, stack); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (AlloyRecipe r : MetallurgyHelper.alloyerRecipes) { + if (r.getCraftingResult() != null && areEqual(r.getCraftingResult(), stack)) { + recipe = r; + break; + } + } + + MetallurgyHelper.alloyerRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/metallurgy/handlers/Crusher.java b/src/main/java/modtweaker/mods/metallurgy/handlers/Crusher.java new file mode 100644 index 0000000..15bae7e --- /dev/null +++ b/src/main/java/modtweaker/mods/metallurgy/handlers/Crusher.java @@ -0,0 +1,114 @@ +package modtweaker.mods.metallurgy.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.metallurgy.MetallurgyHelper; +import modtweaker.util.BaseMapAddition; +import modtweaker.util.BaseMapRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.metallurgy.Crusher") +public class Crusher { + //Adding a Metallurgy Crusher Recipe + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(toStack(input), toStack(output))); + } + + private static class Add extends BaseMapAddition { + private final ItemStack stack; + + public Add(ItemStack input, ItemStack output) { + super("Metallurgy Crusher", MetallurgyHelper.crusherMetaList, MetallurgyHelper.getCrusherKey(input), output); + this.stack = input; + } + + @Override + public void apply() { + super.apply(); + addToInput(stack, (ItemStack) recipe); + } + + @Override + public void undo() { + super.undo(); + removeFromInput(stack, (ItemStack) recipe); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a Metallurgy Crusher recipe + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove extends BaseMapRemoval { + public Remove(ItemStack stack) { + super("Metallurgy Crusher", MetallurgyHelper.crusherMetaList, MetallurgyHelper.getCrusherKey(stack), stack); + } + + @Override + public String getRecipeInfo() { + return ((ItemStack) stack).getDisplayName(); + } + + @Override + public void apply() { + super.apply(); + removeFromInput(((ItemStack) stack), (ItemStack) recipe); + } + + @Override + public void undo() { + super.undo(); + addToInput(((ItemStack) stack), (ItemStack) recipe); + } + } + + //Helper Methods + private static void addToInput(ItemStack input, ItemStack output) { + ItemStack[] inputList = MetallurgyHelper.crusherInputList.get(output.getUnlocalizedName()); + if (inputList == null) { + inputList = new ItemStack[1]; + inputList[0] = input; + } else { + ItemStack[] newList = new ItemStack[inputList.length + 1]; + for (int i = 0; i < inputList.length; i++) { + newList[i] = inputList[i]; + } + + newList[inputList.length] = input; + + inputList = newList; + } + + MetallurgyHelper.crusherInputList.put(output.getUnlocalizedName(), inputList); + } + + private static void removeFromInput(ItemStack input, ItemStack output) { + boolean switched = false; + ItemStack[] inputList = MetallurgyHelper.crusherInputList.get(output.getUnlocalizedName()); + ItemStack[] newList = new ItemStack[inputList.length - 1]; + if (newList.length >= 1) { + for (int i = 0; i < inputList.length; i++) { + if (switched || (areEqual(inputList[i], input))) { + switched = true; + newList[i] = inputList[i + 1]; + } else newList[i] = inputList[i]; + } + } else newList = null; + + inputList = newList; + if (inputList == null || inputList.length <= 0) { + MetallurgyHelper.crusherInputList.remove(output.getUnlocalizedName()); + } else { + MetallurgyHelper.crusherInputList.put(output.getUnlocalizedName(), inputList); + } + } +} diff --git a/src/main/java/modtweaker/mods/pneumaticcraft/PneumaticCraft.java b/src/main/java/modtweaker/mods/pneumaticcraft/PneumaticCraft.java new file mode 100644 index 0000000..a06912b --- /dev/null +++ b/src/main/java/modtweaker/mods/pneumaticcraft/PneumaticCraft.java @@ -0,0 +1,12 @@ +package modtweaker.mods.pneumaticcraft; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.pneumaticcraft.handlers.Assembly; +import modtweaker.mods.pneumaticcraft.handlers.Pressure; + +public class PneumaticCraft { + public PneumaticCraft() { + MineTweakerAPI.registerClass(Assembly.class); + MineTweakerAPI.registerClass(Pressure.class); + } +} diff --git a/src/main/java/modtweaker/mods/pneumaticcraft/handlers/Assembly.java b/src/main/java/modtweaker/mods/pneumaticcraft/handlers/Assembly.java new file mode 100644 index 0000000..70349a2 --- /dev/null +++ b/src/main/java/modtweaker/mods/pneumaticcraft/handlers/Assembly.java @@ -0,0 +1,84 @@ +package modtweaker.mods.pneumaticcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.List; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import pneumaticCraft.api.recipe.AssemblyRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.pneumaticcraft.Assembly") +public class Assembly { + @ZenMethod + public static void addDrillRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new AssemblyRecipe(toStack(input), toStack(output)), AssemblyRecipe.drillRecipes)); + } + + @ZenMethod + public static void addLaserRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new AssemblyRecipe(toStack(input), toStack(output)), AssemblyRecipe.laserRecipes)); + } + + @ZenMethod + public static void addLaserDrillRecipe(IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(new AssemblyRecipe(toStack(input), toStack(output)), AssemblyRecipe.drillLaserRecipes)); + } + + private static class Add extends BaseListAddition { + public Add(AssemblyRecipe recipe, List list) { + super("Pneumaticraft Assembly", list, recipe); + } + + @Override + public String getRecipeInfo() { + return ((AssemblyRecipe) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeDrillRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), AssemblyRecipe.drillRecipes)); + } + + @ZenMethod + public static void removeLaserRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), AssemblyRecipe.laserRecipes)); + } + + @ZenMethod + public static void removeLaserDrillRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output), AssemblyRecipe.drillLaserRecipes)); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack, List list) { + super("Pneumaticraft Assembly", list, stack); + } + + @Override + public void apply() { + for (AssemblyRecipe r : (List) list) { + if (r.getOutput() != null && areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/pneumaticcraft/handlers/Pressure.java b/src/main/java/modtweaker/mods/pneumaticcraft/handlers/Pressure.java new file mode 100644 index 0000000..c94a68e --- /dev/null +++ b/src/main/java/modtweaker/mods/pneumaticcraft/handlers/Pressure.java @@ -0,0 +1,75 @@ +package modtweaker.mods.pneumaticcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStacks; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import pneumaticCraft.api.recipe.PressureChamberRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.pneumaticcraft.Pressure") +public class Pressure { + @ZenMethod + public static void addRecipe(IItemStack[] input, double pressure, IItemStack[] output, boolean asBlock) { + MineTweakerAPI.apply(new Add(new PressureChamberRecipe(toStacks(input), (float) pressure, toStacks(output), asBlock))); + } + + private static class Add extends BaseListAddition { + private ItemStack stack; + + public Add(PressureChamberRecipe recipe) { + super("Pneumaticraft Pressure Chamber", PressureChamberRecipe.chamberRecipes, recipe); + this.stack = recipe.output[0]; + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack[] output) { + MineTweakerAPI.apply(new Remove(toStacks(output))); + } + + private static class Remove extends BaseListRemoval { + private final ItemStack[] stacks; + + public Remove(ItemStack[] stacks) { + super("Pneumaticraft Pressure Chamber", PressureChamberRecipe.chamberRecipes, stacks[0]); + this.stacks = stacks; + } + + @Override + public void apply() { + for (PressureChamberRecipe r : PressureChamberRecipe.chamberRecipes) { + boolean matches = true; + for (int i = 0; i < stacks.length; i++) { + if (!areEqual(stacks[i], r.output[i])) { + matches = false; + break; + } + } + + if (matches) { + recipe = r; + break; + } + } + + PressureChamberRecipe.chamberRecipes.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/railcraft/Railcraft.java b/src/main/java/modtweaker/mods/railcraft/Railcraft.java new file mode 100644 index 0000000..74a1bc9 --- /dev/null +++ b/src/main/java/modtweaker/mods/railcraft/Railcraft.java @@ -0,0 +1,16 @@ +package modtweaker.mods.railcraft; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.railcraft.handlers.BlastFurnace; +import modtweaker.mods.railcraft.handlers.CokeOven; +import modtweaker.mods.railcraft.handlers.RockCrusher; +import modtweaker.mods.railcraft.handlers.RollingMachine; + +public class Railcraft { + public Railcraft() { + MineTweakerAPI.registerClass(BlastFurnace.class); + MineTweakerAPI.registerClass(CokeOven.class); + MineTweakerAPI.registerClass(RockCrusher.class); + MineTweakerAPI.registerClass(RollingMachine.class); + } +} diff --git a/src/main/java/modtweaker/mods/railcraft/RailcraftHelper.java b/src/main/java/modtweaker/mods/railcraft/RailcraftHelper.java new file mode 100644 index 0000000..3c94944 --- /dev/null +++ b/src/main/java/modtweaker/mods/railcraft/RailcraftHelper.java @@ -0,0 +1,62 @@ +package modtweaker.mods.railcraft; + +import java.lang.reflect.Constructor; +import java.util.List; + +import mods.railcraft.api.crafting.IBlastFurnaceRecipe; +import mods.railcraft.api.crafting.ICokeOvenRecipe; +import mods.railcraft.api.crafting.IRockCrusherRecipe; +import mods.railcraft.api.crafting.RailcraftCraftingManager; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.fluids.FluidStack; + +public class RailcraftHelper { + public static List furnace = null; + public static List oven = null; + public static List crusher = null; + public static List rolling = null; + static { + try { + furnace = RailcraftCraftingManager.blastFurnace.getRecipes(); + oven = RailcraftCraftingManager.cokeOven.getRecipes(); + crusher = RailcraftCraftingManager.rockCrusher.getRecipes(); + rolling = RailcraftCraftingManager.rollingMachine.getRecipeList(); + } catch (Exception e) {} + } + + private RailcraftHelper() {} + + public static IBlastFurnaceRecipe getBlastFurnaceRecipe(ItemStack input, boolean matchDamage, boolean matchNBT, int cookTime, ItemStack output) { + try { + Class clazz = Class.forName("mods.railcraft.common.util.crafting.BlastFurnaceCraftingManager$BlastFurnaceRecipe"); + Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, boolean.class, boolean.class, int.class, ItemStack.class); + constructor.setAccessible(true); + return (IBlastFurnaceRecipe) constructor.newInstance(input, matchDamage, matchNBT, cookTime, output); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate BlastFurnaceRecipe"); + } + } + + public static ICokeOvenRecipe getCokeOvenRecipe(ItemStack input, boolean matchDamage, boolean matchNBT, ItemStack output, FluidStack fluidOutput, int cookTime) { + try { + Class clazz = Class.forName("mods.railcraft.common.util.crafting.CokeOvenCraftingManager$CokeOvenRecipe"); + Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, boolean.class, boolean.class, ItemStack.class, FluidStack.class, int.class); + constructor.setAccessible(true); + return (ICokeOvenRecipe) constructor.newInstance(input, matchDamage, matchNBT, output, fluidOutput, cookTime); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate CokeOvenRecipe"); + } + } + + public static IRockCrusherRecipe getRockCrusherRecipe(ItemStack stack, boolean matchDamage, boolean matchNBT) { + try { + Class clazz = Class.forName("mods.railcraft.common.util.crafting.RockCrusherCraftingManager$CrusherRecipe"); + Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, boolean.class, boolean.class); + constructor.setAccessible(true); + return (IRockCrusherRecipe) constructor.newInstance(stack, matchDamage, matchNBT); + } catch (Exception e) { + throw new NullPointerException("Failed to instantiate CrusherRecipe"); + } + } +} diff --git a/src/main/java/modtweaker/mods/railcraft/handlers/BlastFurnace.java b/src/main/java/modtweaker/mods/railcraft/handlers/BlastFurnace.java new file mode 100644 index 0000000..ba22ea9 --- /dev/null +++ b/src/main/java/modtweaker/mods/railcraft/handlers/BlastFurnace.java @@ -0,0 +1,64 @@ +package modtweaker.mods.railcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import mods.railcraft.api.crafting.IBlastFurnaceRecipe; +import modtweaker.mods.railcraft.RailcraftHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.railcraft.BlastFurnace") +public class BlastFurnace { + @ZenMethod + public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, int cookTime, IItemStack output) { + MineTweakerAPI.apply(new Add(RailcraftHelper.getBlastFurnaceRecipe(toStack(input), matchDamage, matchNBT, cookTime, toStack(output)))); + } + + private static class Add extends BaseListAddition { + public Add(IBlastFurnaceRecipe recipe) { + super("Blast Furnace", RailcraftHelper.furnace, recipe); + } + + @Override + public String getRecipeInfo() { + return ((IBlastFurnaceRecipe) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Blast Furnace", RailcraftHelper.furnace, stack); + } + + @Override + public void apply() { + for (IBlastFurnaceRecipe r : RailcraftHelper.furnace) { + if (r != null) { + if (r.getOutput() != null && areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + } + + RailcraftHelper.furnace.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/railcraft/handlers/CokeOven.java b/src/main/java/modtweaker/mods/railcraft/handlers/CokeOven.java new file mode 100644 index 0000000..7d374d5 --- /dev/null +++ b/src/main/java/modtweaker/mods/railcraft/handlers/CokeOven.java @@ -0,0 +1,64 @@ +package modtweaker.mods.railcraft.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import mods.railcraft.api.crafting.ICokeOvenRecipe; +import modtweaker.mods.railcraft.RailcraftHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.railcraft.CokeOven") +public class CokeOven { + @ZenMethod + public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack output, ILiquidStack fluidOutput, int cookTime) { + MineTweakerAPI.apply(new Add(RailcraftHelper.getCokeOvenRecipe(toStack(input), matchDamage, matchNBT, toStack(output), toFluid(fluidOutput), cookTime))); + } + + private static class Add extends BaseListAddition { + public Add(ICokeOvenRecipe recipe) { + super("Coke Oven", RailcraftHelper.oven, recipe); + } + + @Override + public String getRecipeInfo() { + return ((ICokeOvenRecipe) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Coke Oven", RailcraftHelper.oven, stack); + } + + @Override + public void apply() { + for (ICokeOvenRecipe r : RailcraftHelper.oven) { + if (r.getOutput() != null && areEqual(r.getOutput(), stack)) { + recipe = r; + break; + } + } + + RailcraftHelper.oven.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/railcraft/handlers/RockCrusher.java b/src/main/java/modtweaker/mods/railcraft/handlers/RockCrusher.java new file mode 100644 index 0000000..fc252b7 --- /dev/null +++ b/src/main/java/modtweaker/mods/railcraft/handlers/RockCrusher.java @@ -0,0 +1,65 @@ +package modtweaker.mods.railcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import mods.railcraft.api.crafting.IRockCrusherRecipe; +import modtweaker.mods.railcraft.RailcraftHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.railcraft.RockCrusher") +public class RockCrusher { + @ZenMethod + public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack[] output, double[] chances) { + IRockCrusherRecipe recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), matchDamage, matchNBT); + for (int i = 0; i < output.length; i++) + recipe.addOutput(toStack(output[i]), (float) chances[i]); + MineTweakerAPI.apply(new Add(recipe)); + } + + private static class Add extends BaseListAddition { + public Add(IRockCrusherRecipe recipe) { + super("Rock Crusher", RailcraftHelper.crusher, recipe); + } + + @Override + public String getRecipeInfo() { + return ((IRockCrusherRecipe) recipe).getInput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Rock Crusher", RailcraftHelper.crusher, stack); + } + + @Override + public void apply() { + for (IRockCrusherRecipe r : RailcraftHelper.crusher) { + if (r.getInput() != null && areEqual(r.getInput(), stack)) { + recipe = r; + break; + } + } + + RailcraftHelper.crusher.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/railcraft/handlers/RollingMachine.java b/src/main/java/modtweaker/mods/railcraft/handlers/RollingMachine.java new file mode 100644 index 0000000..736eb93 --- /dev/null +++ b/src/main/java/modtweaker/mods/railcraft/handlers/RollingMachine.java @@ -0,0 +1,57 @@ +package modtweaker.mods.railcraft.handlers; + +import static modtweaker.helpers.InputHelper.toObjects; +import static modtweaker.helpers.InputHelper.toShapedObjects; +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import mods.railcraft.api.crafting.RailcraftCraftingManager; +import modtweaker.mods.railcraft.RailcraftHelper; +import modtweaker.util.BaseCraftingAddition; +import modtweaker.util.BaseCraftingRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.railcraft.Rolling") +public class RollingMachine { + @ZenMethod + public static void addShaped(IItemStack output, IIngredient[][] ingredients) { + MineTweakerAPI.apply(new Add(false, toStack(output), toShapedObjects(ingredients))); + } + + @ZenMethod + public static void addShapeless(IItemStack output, IIngredient[] ingredients) { + MineTweakerAPI.apply(new Add(true, toStack(output), toObjects(ingredients))); + } + + private static class Add extends BaseCraftingAddition { + public Add(boolean shapeless, ItemStack output, Object... recipe) { + super("Rolling Machine", shapeless, RailcraftHelper.rolling, output, recipe); + } + + @Override + public void applyShaped() { + RailcraftCraftingManager.rollingMachine.addRecipe(output, recipe); + } + + @Override + public void applyShapeless() { + RailcraftCraftingManager.rollingMachine.addShapelessRecipe(output, recipe); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseCraftingRemoval { + public Remove(ItemStack stack) { + super("Rolling Machine", RailcraftHelper.rolling, stack); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/MaterialLogger.java b/src/main/java/modtweaker/mods/tconstruct/MaterialLogger.java new file mode 100644 index 0000000..d8488e1 --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/MaterialLogger.java @@ -0,0 +1,36 @@ +package modtweaker.mods.tconstruct; + +import static modtweaker.helpers.LogHelper.logPrinted; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.player.IPlayer; +import minetweaker.api.server.ICommandFunction; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.tools.ToolMaterial; + +public class MaterialLogger implements ICommandFunction { + private static ArrayList materials = new ArrayList(); + static { + materials = new ArrayList(); + for (Map.Entry entry : TConstructRegistry.toolMaterialStrings.entrySet()) { + materials.add(entry.getKey()); + } + + Collections.sort(materials); + } + + @Override + public void execute(String[] arguments, IPlayer player) { + System.out.println("Materials: " + materials.size()); + for (String s : materials) { + System.out.println("Material " + s); + MineTweakerAPI.logCommand("<" + s + "> -- "); + } + + logPrinted(player); + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/TConstruct.java b/src/main/java/modtweaker/mods/tconstruct/TConstruct.java new file mode 100644 index 0000000..4e1138f --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/TConstruct.java @@ -0,0 +1,18 @@ +package modtweaker.mods.tconstruct; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.tconstruct.handlers.Casting; +import modtweaker.mods.tconstruct.handlers.Drying; +import modtweaker.mods.tconstruct.handlers.Smeltery; +import modtweaker.mods.tconstruct.handlers.TiCTweaks; +import modtweaker.mods.tconstruct.handlers.ToolStats; + +public class TConstruct { + public TConstruct() { + MineTweakerAPI.registerClass(Casting.class); + MineTweakerAPI.registerClass(Drying.class); + MineTweakerAPI.registerClass(Smeltery.class); + MineTweakerAPI.registerClass(TiCTweaks.class); + MineTweakerAPI.registerClass(ToolStats.class); + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/TConstructHelper.java b/src/main/java/modtweaker/mods/tconstruct/TConstructHelper.java new file mode 100644 index 0000000..256f691 --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/TConstructHelper.java @@ -0,0 +1,85 @@ +package modtweaker.mods.tconstruct; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import mantle.utils.ItemMetaWrapper; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.AlloyMix; +import tconstruct.library.crafting.CastingRecipe; +import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe; +import tconstruct.library.crafting.ModifyBuilder; +import tconstruct.library.crafting.PatternBuilder.ItemKey; +import tconstruct.library.modifier.ItemModifier; +import tconstruct.library.tools.ToolMaterial; + +public class TConstructHelper { + public static HashMap mappings = new HashMap(); + public static List alloys = null; + public static ArrayList basinCasting = null; + public static ArrayList tableCasting = null; + public static Map smeltingList = null; + public static Map temperatureList = null; + public static Map renderIndex = null; + public static List modifiers = null; + public static List modifiers_clone = null; + + static { + try { + alloys = tconstruct.library.crafting.Smeltery.getAlloyList(); + smeltingList = tconstruct.library.crafting.Smeltery.getSmeltingList(); + temperatureList = tconstruct.library.crafting.Smeltery.getTemperatureList(); + renderIndex = tconstruct.library.crafting.Smeltery.getRenderIndex(); + basinCasting = TConstructRegistry.getBasinCasting().getCastingRecipes(); + tableCasting = TConstructRegistry.getTableCasting().getCastingRecipes(); + modifiers = ModifyBuilder.instance.itemModifiers; + modifiers_clone = new ArrayList(modifiers); + + for (Map.Entry entry : TConstructRegistry.toolMaterials.entrySet()) { + mappings.put(entry.getValue().materialName, entry.getKey()); + } + + } catch (Exception e) {} + } + + private TConstructHelper() {} + + public static int getIDFromString(String material) { + if (!mappings.containsKey(material)) { + return -1; + } else return mappings.get(material); + } + + //Returns a Drying Recipe, using reflection as the constructor is not visible + public static DryingRecipe getDryingRecipe(ItemStack input, int time, ItemStack output) { + try { + Constructor constructor = DryingRecipe.class.getDeclaredConstructor(ItemStack.class, int.class, ItemStack.class); + constructor.setAccessible(true); + return (DryingRecipe) constructor.newInstance(input, time, output); + } catch (Exception e) { + e.printStackTrace(); + throw new NullPointerException("Failed to instantiate DryingRecipe"); + } + } + + public static String getMaterialFromID(int id) { + return TConstructRegistry.toolMaterials.get(id).materialName; + } + + public static ItemKey getItemKey(Item item, int damage, int value, String material) { + try { + Constructor constructor = ItemKey.class.getDeclaredConstructor(ItemStack.class, int.class, int.class, String.class); + constructor.setAccessible(true); + return (ItemKey) constructor.newInstance(item, damage, value, material); + } catch (Exception e) { + e.printStackTrace(); + throw new NullPointerException("Failed to instantiate ItemKey"); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker/mods/tconstruct/handlers/Casting.java new file mode 100644 index 0000000..80138a8 --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/handlers/Casting.java @@ -0,0 +1,83 @@ +package modtweaker.mods.tconstruct.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.ArrayList; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.mods.tconstruct.TConstructHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import tconstruct.library.crafting.CastingRecipe; + +@ZenClass("mods.tconstruct.Casting") +public class Casting { + //Adding a TConstruct Casting recipe + @ZenMethod + public static void addBasinRecipe(IItemStack output, ILiquidStack metal, @Optional IItemStack cast, @Optional boolean consume, int delay) { + MineTweakerAPI.apply(new Add(new CastingRecipe(toStack(output), toFluid(metal), toStack(cast), consume, delay, null), TConstructHelper.basinCasting)); + } + + @ZenMethod + public static void addTableRecipe(IItemStack output, ILiquidStack metal, @Optional IItemStack cast, @Optional boolean consume, int delay) { + MineTweakerAPI.apply(new Add(new CastingRecipe(toStack(output), toFluid(metal), toStack(cast), consume, delay, null), TConstructHelper.tableCasting)); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(CastingRecipe recipe, ArrayList list) { + super("TConstruct Casting", list, recipe); + } + + @Override + public String getRecipeInfo() { + return ((CastingRecipe) recipe).output.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a TConstruct Casting recipe + @ZenMethod + public static void removeBasinRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting)); + } + + @ZenMethod + public static void removeTableRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting)); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack output, ArrayList list) { + super("TConstruct Casting", list, output); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (CastingRecipe r : (ArrayList) list) { + if (r.output != null && areEqual(r.output, stack)) { + recipe = r; + break; + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/handlers/Drying.java b/src/main/java/modtweaker/mods/tconstruct/handlers/Drying.java new file mode 100644 index 0000000..de268bb --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/handlers/Drying.java @@ -0,0 +1,71 @@ +package modtweaker.mods.tconstruct.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.ArrayList; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.tconstruct.TConstructHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import tconstruct.library.crafting.DryingRackRecipes; +import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe; + +@ZenClass("mods.tconstruct.Drying") +public class Drying { + //Adding a TConstruct Drying Rack recipe + @ZenMethod + public static void addRecipe(IItemStack input, IItemStack output, int time) { + MineTweakerAPI.apply(new Add(TConstructHelper.getDryingRecipe(toStack(input), time, toStack(output)))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class Add extends BaseListAddition { + public Add(DryingRecipe recipe) { + super("TConstruct Drying Rack", DryingRackRecipes.recipes, recipe); + } + + @Override + public String getRecipeInfo() { + return ((DryingRecipe) recipe).result.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a TConstruct Drying Rack recipe + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove((toStack(output)))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + public Remove(ItemStack output) { + super("TConstruct Drying Rack", DryingRackRecipes.recipes, output); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (DryingRecipe r : (ArrayList) list) { + if (r.result != null && areEqual(r.result, stack)) { + recipe = r; + break; + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/handlers/Modifiers.java b/src/main/java/modtweaker/mods/tconstruct/handlers/Modifiers.java new file mode 100644 index 0000000..320933c --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/handlers/Modifiers.java @@ -0,0 +1,40 @@ +package modtweaker.mods.tconstruct.handlers; + +import java.util.List; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.tconstruct.TConstructHelper; +import modtweaker.util.BaseListRemoval; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import tconstruct.library.modifier.ItemModifier; + +@ZenClass("mods.tconstruct.Modifiers") +public class Modifiers { + @ZenMethod + public static void remove(String mod) { + MineTweakerAPI.apply(new Remove(mod)); + } + + //Searches through the modifiers and removes the first valid entry + private static class Remove extends BaseListRemoval { + private final String check; + + public Remove(String check) { + super("Modifier", TConstructHelper.modifiers); + this.check = check; + } + + @Override + public void apply() { + for (ItemModifier m : (List) list) { + if (m.key.equals(check)) { + recipe = m; + break; + } + } + + list.remove(recipe); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/handlers/Smeltery.java b/src/main/java/modtweaker/mods/tconstruct/handlers/Smeltery.java new file mode 100644 index 0000000..0554a72 --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/handlers/Smeltery.java @@ -0,0 +1,195 @@ +package modtweaker.mods.tconstruct.handlers; + +import static modtweaker.helpers.InputHelper.isABlock; +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toFluids; +import static modtweaker.helpers.InputHelper.toStack; + +import java.util.ArrayList; +import java.util.Arrays; + +import mantle.utils.ItemMetaWrapper; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import minetweaker.api.minecraft.MineTweakerMC; +import minetweaker.api.oredict.IOreDictEntry; +import modtweaker.mods.tconstruct.TConstructHelper; +import modtweaker.util.BaseDescriptionAddition; +import modtweaker.util.BaseDescriptionRemoval; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import tconstruct.library.crafting.AlloyMix; + +@ZenClass("mods.tconstruct.Smeltery") +public class Smeltery { + + /********************************************** TConstruct Alloy Recipes **********************************************/ + + //Adding a TConstruct Alloy recipe + @ZenMethod + public static void addAlloy(ILiquidStack output, ILiquidStack[] input) { + MineTweakerAPI.apply(new AddAlloy(new AlloyMix(toFluid(output), new ArrayList(Arrays.asList(toFluids(input)))))); + } + + //Passes the list to the base list implementation, and adds the recipe + private static class AddAlloy extends BaseListAddition { + public AddAlloy(AlloyMix recipe) { + super("Smeltery - Alloy", TConstructHelper.alloys, recipe); + } + + @Override + public String getRecipeInfo() { + return ((AlloyMix) recipe).result.getFluid().getName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a TConstruct Alloy recipe + @ZenMethod + public static void removeAlloy(ILiquidStack output) { + MineTweakerAPI.apply(new RemoveAlloy((toFluid(output)))); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class RemoveAlloy extends BaseListRemoval { + public RemoveAlloy(FluidStack output) { + super("Smeltery - Alloy", TConstructHelper.alloys, output); + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (AlloyMix r : TConstructHelper.alloys) { + if (r.result != null && r.result.isFluidStackIdentical(fluid)) { + recipe = r; + break; + } + } + + TConstructHelper.alloys.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return fluid.getFluid().getName(); + } + } + + /********************************************** TConstruct Melting Recipes **********************************************/ + + //Adding a TConstruct Melting recipe + @ZenMethod + public static void addMelting(IItemStack input, ILiquidStack output, int temp, @Optional IItemStack block) { + if (block == null) block = input; + if (isABlock(block)) { + Block theBlock = Block.getBlockFromItem(toStack(block).getItem()); + int theMeta = toStack(block).getItemDamage(); + MineTweakerAPI.apply(new AddMelting(toStack(input), theBlock, theMeta, temp, toFluid(output))); + } + } + + @ZenMethod + public static void addMelting(IOreDictEntry input, ILiquidStack output, int temp, @Optional IItemStack block) { + for (ItemStack stack : OreDictionary.getOres(input.getName())) { + addMelting(MineTweakerMC.getIItemStack(stack), output, temp, block); + } + } + + //Takes all the variables and saves them in place + private static class AddMelting extends BaseDescriptionAddition { + private final ItemStack input; + private final Block block; + private final int meta; + private final int temp; + private final FluidStack output; + + public AddMelting(ItemStack input, Block block, int meta, int temp, FluidStack output) { + super("Smeltery - Melting"); + this.input = input; + this.block = block; + this.meta = meta; + this.temp = temp; + this.output = output; + } + + //Adds the Melting recipe + @Override + public void apply() { + tconstruct.library.crafting.Smeltery.instance.addMelting(input, block, meta, temp, output); + } + + //Removes the Melting recipe from the hashmaps + @Override + public void undo() { + ItemMetaWrapper in = new ItemMetaWrapper(input); + TConstructHelper.smeltingList.remove(in); + TConstructHelper.temperatureList.remove(in); + TConstructHelper.renderIndex.remove(in); + } + + @Override + public String getRecipeInfo() { + return input.getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Removing a TConstruct Melting recipe + @ZenMethod + public static void removeMelting(IItemStack input) { + MineTweakerAPI.apply(new RemoveMelting((toStack(input)))); + } + + @ZenMethod + public static void removeMelting(IOreDictEntry input) { + for (ItemStack stack : OreDictionary.getOres(input.getName())) { + removeMelting(MineTweakerMC.getIItemStack(stack)); + } + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class RemoveMelting extends BaseDescriptionRemoval { + private final ItemStack input; + private FluidStack fluid; + private Integer temp; + private ItemStack renderer; + + public RemoveMelting(ItemStack input) { + super("Smeltery - Melting"); + this.input = input; + } + + //Gets the current values, and saves, them removes them from the hashmaps + @Override + public void apply() { + ItemMetaWrapper in = new ItemMetaWrapper(input); + fluid = TConstructHelper.smeltingList.get(in); + temp = TConstructHelper.temperatureList.get(in); + renderer = TConstructHelper.renderIndex.get(in); + TConstructHelper.smeltingList.remove(in); + TConstructHelper.temperatureList.remove(in); + TConstructHelper.renderIndex.remove(in); + } + + //Readds the Melting recipe + @Override + public void undo() { + tconstruct.library.crafting.Smeltery.instance.addMelting(input, Block.getBlockFromItem(renderer.getItem()), renderer.getItemDamage(), temp, fluid); + } + + @Override + public String getRecipeInfo() { + return input.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/handlers/TiCTweaks.java b/src/main/java/modtweaker/mods/tconstruct/handlers/TiCTweaks.java new file mode 100644 index 0000000..471f7de --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/handlers/TiCTweaks.java @@ -0,0 +1,151 @@ +package modtweaker.mods.tconstruct.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.tconstruct.TConstructHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import modtweaker.util.BaseSetVar; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import tconstruct.library.crafting.PatternBuilder; +import tconstruct.library.crafting.PatternBuilder.ItemKey; +import tconstruct.library.tools.ToolCore; +import tconstruct.tools.TinkerTools; + +@ZenClass("mods.tconstruct.Tweaks") +public class TiCTweaks { + //Set the maximum RF + @ZenMethod + public static void setRFCapacity(String tool, int capacity) { + MineTweakerAPI.apply(new AdjustRF(tool, capacity)); + } + + private static class AdjustRF extends BaseSetVar { + public AdjustRF(String tool, int newValue) { + super("RF Maximum for Tinkers Tools", ToolCore.class, ReflectionHelper.getStaticObject(TinkerTools.class, tool), "capacity", 400000, newValue); + } + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** Disabling for 0.5, will do this properly for 0.6 **/ + //Tweaks for enabling / disabling Patterns + /* @ZenMethod + public static void removePattern(IItemStack stack) { + MineTweakerAPI.apply(new DisablePattern(toStack(stack))); + } + + private static class DisablePattern implements IUndoableAction { + private String key; + private MaterialSet set; + private List list; + private ItemStack stack; + private final ItemStack disable; + + public DisablePattern(ItemStack disable) { + this.disable = disable; + } + + //Loops through the pattern mappings to find an entry with the same material name + @Override + public void apply() { + for (Entry entry : TConstructRegistry.patternPartMapping.entrySet()) { + ItemStack check = entry.getValue(); + if (check.isItemEqual(disable)) { + list = entry.getKey(); + stack = entry.getValue(); + break; + } + } + + TConstructRegistry.patternPartMapping.remove(list); + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + TConstructRegistry.patternPartMapping.put(list, stack); + } + + @Override + public String describe() { + return "Disabling creation of the pattern for: " + disable.getDisplayName(); + } + + @Override + public String describeUndo() { + return "Enabling creation of the pattern for: " + disable.getDisplayName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } */ + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void addRepairMaterial(IItemStack stack, String material, int value) { + ItemStack input = toStack(stack); + MineTweakerAPI.apply(new Add(TConstructHelper.getItemKey(input.getItem(), input.getItemDamage(), value, material))); + } + + //Tweaks for setting repair materials + private static class Add extends BaseListAddition { + public Add(ItemKey recipe) { + super("Repair Material", PatternBuilder.instance.materials, recipe); + } + + @Override + public String getRecipeInfo() { + return new ItemStack(((ItemKey) recipe).item, 1, ((ItemKey) recipe).damage).getDisplayName(); + } + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + @ZenMethod + public static void removeRepairMaterial(IItemStack output, @Optional String material) { + MineTweakerAPI.apply(new Remove(toStack(output), material)); + } + + //Removes a recipe, apply is never the same for anything, so will always need to override it + private static class Remove extends BaseListRemoval { + private final String material; + + public Remove(ItemStack stack, String material) { + super("Repair Material", PatternBuilder.instance.materials, stack); + this.material = material; + } + + //Loops through the registry, to find the item that matches, saves that recipe then removes it + @Override + public void apply() { + for (ItemKey r : PatternBuilder.instance.materials) { + ItemStack clone = new ItemStack(r.item, 1, r.damage); + if ((material != null && material.equalsIgnoreCase(r.key)) || (material == null)) { + if (clone.isItemEqual(stack)) { + recipe = r; + break; + } + } + } + + PatternBuilder.instance.materials.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/tconstruct/handlers/ToolStats.java b/src/main/java/modtweaker/mods/tconstruct/handlers/ToolStats.java new file mode 100644 index 0000000..367dd31 --- /dev/null +++ b/src/main/java/modtweaker/mods/tconstruct/handlers/ToolStats.java @@ -0,0 +1,246 @@ +package modtweaker.mods.tconstruct.handlers; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import modtweaker.helpers.ReflectionHelper; +import modtweaker.mods.tconstruct.TConstructHelper; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.tools.ArrowMaterial; +import tconstruct.library.tools.BowMaterial; +import tconstruct.library.tools.ToolMaterial; + +@ZenClass("mods.tconstruct.ToolStats") +public class ToolStats { + @ZenMethod + public static void set(String material, @Optional String name, int level, int durability, int speed, int damage, double handle, int reinforced, double stonebound, String style, String ability) { + if (name == null) name = material + " "; + MineTweakerAPI.apply(new SetToolStats(material, "", new ToolMaterial(material, name, level, durability, speed, damage, (float) handle, reinforced, (float) stonebound, style, ability))); + } + + @ZenMethod + public static void setDisplayName(String material, String name) { + MineTweakerAPI.apply(new SetToolStats(material, "displayName", name)); + } + + @ZenMethod + public static void setHarvestLevel(String material, int value) { + MineTweakerAPI.apply(new SetToolStats(material, "harvestLevel", value)); + } + + @ZenMethod + public static void setDurability(String material, int value) { + MineTweakerAPI.apply(new SetToolStats(material, "durability", value)); + } + + @ZenMethod + public static void setSpeed(String material, int value) { + MineTweakerAPI.apply(new SetToolStats(material, "miningspeed", value)); + } + + @ZenMethod + public static void setDamage(String material, int value) { + MineTweakerAPI.apply(new SetToolStats(material, "attack", value)); + } + + @ZenMethod + public static void setHandleModifier(String material, double value) { + MineTweakerAPI.apply(new SetToolStats(material, "handleModifier", (float) value)); + } + + @ZenMethod + public static void setReinforcedLevel(String material, int value) { + MineTweakerAPI.apply(new SetToolStats(material, "reinforced", value)); + } + + @ZenMethod + public static void setStoneboundLevel(String material, double value) { + MineTweakerAPI.apply(new SetToolStats(material, "stonebound", (float) value)); + } + + @ZenMethod + public static void setStyle(String material, String name) { + MineTweakerAPI.apply(new SetToolStats(material, "tipStyle", name)); + } + + @ZenMethod + public static void setAbility(String material, String name) { + MineTweakerAPI.apply(new SetToolStats(material, "ability", name)); + } + + //Sets various variables with reflection, making my life partially easier :D + private static class SetToolStats implements IUndoableAction { + protected int id; + protected Object old; + protected Object fresh; + protected final String material; + protected final String field; + protected final Object value; + + public SetToolStats(String material, String field, Object value) { + this.material = material; + this.field = field; + this.value = value; + } + + @Override + public void apply() { + old = TConstructRegistry.toolMaterialStrings.get(material); + id = TConstructHelper.getIDFromString(material); + if (id != -1 && old != null) { + if (value instanceof ToolMaterial) { + fresh = (ToolMaterial) value; + } else { + ToolMaterial t = (ToolMaterial) old; + fresh = new ToolMaterial(t.materialName, t.displayName, t.harvestLevel, t.durability, t.miningspeed, t.attack, t.handleModifier, t.reinforced, t.stonebound, t.tipStyle, t.ability); + ReflectionHelper.setPrivateValue(ToolMaterial.class, fresh, field, value); + } + + TConstructRegistry.toolMaterials.put(id, (ToolMaterial) fresh); + TConstructRegistry.toolMaterialStrings.put(material, (ToolMaterial) fresh); + } + } + + @Override + public boolean canUndo() { + return TConstructRegistry.toolMaterialStrings != null && id != -1 && old != null; + } + + @Override + public void undo() { + TConstructRegistry.toolMaterials.put(id, (ToolMaterial) old); + TConstructRegistry.toolMaterialStrings.put(material, (ToolMaterial) old); + } + + @Override + public String describe() { + return "Changing material stats field : + " + field + " for " + material; + } + + @Override + public String describeUndo() { + return "Undoing change of material stats field : + " + field + " for " + material; + } + + @Override + public Object getOverrideKey() { + return null; + } + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Bow Stats + @ZenMethod + public static void setBowStats(String material, int durability, int drawspeed, double flightspeed) { + MineTweakerAPI.apply(new SetBowStats(material, "", new BowMaterial(durability, drawspeed, (float) flightspeed))); + } + + @ZenMethod + public static void setBowDurability(String material, int value) { + MineTweakerAPI.apply(new SetBowStats(material, "durability", value)); + } + + @ZenMethod + public static void setBowDrawspeed(String material, int value) { + MineTweakerAPI.apply(new SetBowStats(material, "drawspeed", value)); + } + + @ZenMethod + public static void setBowFlightSpeed(String material, double value) { + MineTweakerAPI.apply(new SetBowStats(material, "flightSpeedMax", (float) value)); + } + + // Bow Stats + private static class SetBowStats extends SetToolStats { + public SetBowStats(String material, String field, Object value) { + super(material, field, value); + } + + @Override + public void apply() { + id = TConstructHelper.getIDFromString(material); + old = TConstructRegistry.bowMaterials.get(id); + if (id != -1 && old != null) { + if (value instanceof BowMaterial) { + fresh = (BowMaterial) value; + } else { + BowMaterial b = (BowMaterial) old; + fresh = new BowMaterial(b.durability, b.drawspeed, b.flightSpeedMax); + ReflectionHelper.setPrivateValue(BowMaterial.class, fresh, field, value); + } + + TConstructRegistry.bowMaterials.put(id, (BowMaterial) fresh); + } + } + + @Override + public boolean canUndo() { + return TConstructRegistry.bowMaterials != null && id != -1 && old != null; + } + + @Override + public void undo() { + TConstructRegistry.bowMaterials.put(id, (BowMaterial) old); + } + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + //Arrow Stats + @ZenMethod + public static void setArrowStats(String material, double mass, double breakChance, double accuracy) { + MineTweakerAPI.apply(new SetArrowStats(material, "", new ArrowMaterial((float) mass, (float) breakChance, (float) accuracy))); + } + + @ZenMethod + public static void setArrowMass(String material, double value) { + MineTweakerAPI.apply(new SetArrowStats(material, "mass", (float) value)); + } + + @ZenMethod + public static void setArrowBreakChance(String material, double value) { + MineTweakerAPI.apply(new SetArrowStats(material, "breakChance", (float) value)); + } + + @ZenMethod + public static void setArrowAccuracy(String material, double value) { + MineTweakerAPI.apply(new SetArrowStats(material, "accuracy", (float) value)); + } + + // Bow Stats + private static class SetArrowStats extends SetToolStats { + public SetArrowStats(String material, String field, Object value) { + super(material, field, value); + } + + @Override + public void apply() { + id = TConstructHelper.getIDFromString(material); + old = TConstructRegistry.arrowMaterials.get(id); + if (id != -1 && old != null) { + if (value instanceof ArrowMaterial) { + fresh = (ArrowMaterial) value; + } else { + ArrowMaterial a = (ArrowMaterial) old; + fresh = new ArrowMaterial(a.mass, a.breakChance, a.accuracy); + ReflectionHelper.setPrivateValue(ArrowMaterial.class, fresh, field, value); + } + + TConstructRegistry.arrowMaterials.put(id, (ArrowMaterial) fresh); + } + } + + @Override + public boolean canUndo() { + return TConstructRegistry.arrowMaterials != null && id != -1 && old != null; + } + + @Override + public void undo() { + TConstructRegistry.arrowMaterials.put(id, (ArrowMaterial) old); + } + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/Thaumcraft.java b/src/main/java/modtweaker/mods/thaumcraft/Thaumcraft.java new file mode 100644 index 0000000..8a31d12 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/Thaumcraft.java @@ -0,0 +1,21 @@ +package modtweaker.mods.thaumcraft; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.thaumcraft.handlers.Arcane; +import modtweaker.mods.thaumcraft.handlers.Aspects; +import modtweaker.mods.thaumcraft.handlers.Crucible; +import modtweaker.mods.thaumcraft.handlers.Infusion; +import modtweaker.mods.thaumcraft.handlers.Research; +import modtweaker.mods.thaumcraft.handlers.Warp; + +public class Thaumcraft { + public Thaumcraft() { + MineTweakerAPI.registerClass(Arcane.class); + MineTweakerAPI.registerClass(Aspects.class); + MineTweakerAPI.registerClass(Crucible.class); + MineTweakerAPI.registerClass(Infusion.class); + MineTweakerAPI.registerClass(Research.class); + MineTweakerAPI.registerClass(Warp.class); + + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/ThaumcraftHelper.java b/src/main/java/modtweaker/mods/thaumcraft/ThaumcraftHelper.java new file mode 100644 index 0000000..ba42734 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/ThaumcraftHelper.java @@ -0,0 +1,63 @@ +package modtweaker.mods.thaumcraft; + +import java.util.ArrayList; +import java.util.HashMap; + +import modtweaker.helpers.ReflectionHelper; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.research.ResearchCategories; + +public class ThaumcraftHelper { + public static ArrayList recipes = null; + public static HashMap warpList; + + static { + try { + recipes = ReflectionHelper.getStaticObject(ThaumcraftApi.class, "recipes"); + warpList = ReflectionHelper.getStaticObject(ThaumcraftApi.class, "warpMap"); + } catch (Exception e) {} + } + + private ThaumcraftHelper() {} + + public static AspectList parseAspects(String aspects) { + return parseAspects(new AspectList(), aspects); + } + + public static AspectList parseAspects(AspectList list, String str) { + if (list == null) list = new AspectList(); + if (str == null || str.equals("")) return list; + String[] aspects = str.split(","); + for (String aspect : aspects) { + if (aspect.startsWith(" ")) aspect = aspect.replaceFirst(" ", ""); + String[] aspct = aspect.split("\\s+"); + if (aspct.length == 2) list.add(Aspect.aspects.get(aspct[0]), Integer.parseInt(aspct[1])); + } + + return list; + } + + public static AspectList removeAspects(AspectList list, String str) { + String[] aspects = str.split(","); + for (String aspect : aspects) { + if (aspect.startsWith(" ")) aspect = aspect.replaceFirst(" ", ""); + String[] aspct = aspect.split("\\s+"); + if (aspct.length == 2) { + list.remove(Aspect.aspects.get(aspct[0]), Integer.parseInt(aspct[1])); + } + } + + return list; + } + + public static String getResearchTab(String key) { + for (String tab : ResearchCategories.researchCategories.keySet()) { + for (String research : ResearchCategories.researchCategories.get(tab).research.keySet()) { + if (research.equals(key)) return tab; + } + } + return null; + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/handlers/Arcane.java b/src/main/java/modtweaker/mods/thaumcraft/handlers/Arcane.java new file mode 100644 index 0000000..d313dae --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/handlers/Arcane.java @@ -0,0 +1,79 @@ +package modtweaker.mods.thaumcraft.handlers; + +import static modtweaker.helpers.InputHelper.toObjects; +import static modtweaker.helpers.InputHelper.toShapedObjects; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.crafting.IArcaneRecipe; +import thaumcraft.api.crafting.ShapedArcaneRecipe; +import thaumcraft.api.crafting.ShapelessArcaneRecipe; + +@ZenClass("mods.thaumcraft.Arcane") +public class Arcane { + @ZenMethod + public static void addShaped(String key, IItemStack output, String aspects, IIngredient[][] ingredients) { + MineTweakerAPI.apply(new Add(new ShapedArcaneRecipe(key, toStack(output), ThaumcraftHelper.parseAspects(aspects), toShapedObjects(ingredients)))); + } + + @ZenMethod + public static void addShapeless(String key, IItemStack output, String aspects, IIngredient[] ingredients) { + MineTweakerAPI.apply(new Add(new ShapelessArcaneRecipe(key, toStack(output), ThaumcraftHelper.parseAspects(aspects), toObjects(ingredients)))); + } + + private static class Add extends BaseListAddition { + public Add(IArcaneRecipe recipe) { + super("Thaumcraft Arcane Worktable", ThaumcraftApi.getCraftingRecipes(), recipe); + } + + @Override + public String getRecipeInfo() { + Object out = ((IArcaneRecipe) recipe).getRecipeOutput(); + if (out instanceof ItemStack) { + return ((ItemStack) out).getDisplayName(); + } else return super.getRecipeInfo(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Thaumcraft Infusion", ThaumcraftApi.getCraftingRecipes(), stack); + } + + @Override + public void apply() { + for (Object o : ThaumcraftApi.getCraftingRecipes()) { + if (o instanceof IArcaneRecipe) { + IArcaneRecipe r = (IArcaneRecipe) o; + if (r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && areEqual((ItemStack) r.getRecipeOutput(), stack)) { + recipe = r; + break; + } + } + } + + ThaumcraftApi.getCraftingRecipes().remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/handlers/Aspects.java b/src/main/java/modtweaker/mods/thaumcraft/handlers/Aspects.java new file mode 100644 index 0000000..a63b8c1 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/handlers/Aspects.java @@ -0,0 +1,111 @@ +package modtweaker.mods.thaumcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; + +import java.util.Arrays; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import modtweaker.util.BaseDescriptionAddition; +import modtweaker.util.BaseDescriptionRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.ThaumcraftApiHelper; +import thaumcraft.api.aspects.AspectList; + +@ZenClass("mods.thaumcraft.Aspects") +public class Aspects { + /** Add/Remove/Set Aspects for items **/ + @ZenMethod + public static void add(IItemStack stack, String aspects) { + MineTweakerAPI.apply(new Add(toStack(stack), aspects, false)); + } + + @ZenMethod + public static void set(IItemStack stack, String aspects) { + MineTweakerAPI.apply(new Add(toStack(stack), aspects, true)); + } + + //Adds or sets Aspects + private static class Add extends BaseDescriptionAddition { + private final ItemStack stack; + private final String aspects; + private final boolean replace; + private AspectList oldList; + private AspectList newList; + + public Add(ItemStack stack, String aspects, boolean replace) { + super("Aspects"); + this.stack = stack; + this.aspects = aspects; + this.replace = replace; + } + + @Override + public void apply() { + oldList = ThaumcraftApiHelper.getObjectAspects(stack); + if (!replace) newList = ThaumcraftHelper.parseAspects(oldList, aspects); + else newList = ThaumcraftHelper.parseAspects(aspects); + ThaumcraftApi.objectTags.put(Arrays.asList(stack.getItem(), stack.getItemDamage()), newList); + } + + @Override + public void undo() { + if (oldList == null) { + ThaumcraftApi.objectTags.remove(Arrays.asList(stack.getItem(), stack.getItemDamage())); + } else ThaumcraftApi.objectTags.put(Arrays.asList(stack.getItem(), stack.getItemDamage()), oldList); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + ////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void remove(IItemStack stack, String aspects) { + MineTweakerAPI.apply(new Remove(toStack(stack), aspects)); + } + + private static class Remove extends BaseDescriptionRemoval { + private final ItemStack stack; + private final String aspects; + private AspectList oldList; + private AspectList newList; + + public Remove(ItemStack stack, String aspects) { + super("Aspects"); + this.stack = stack; + this.aspects = aspects; + } + + @Override + public void apply() { + oldList = ThaumcraftApiHelper.getObjectAspects(stack); + if (oldList != null) { + newList = ThaumcraftHelper.removeAspects(oldList, aspects); + ThaumcraftApi.objectTags.put(Arrays.asList(stack.getItem(), stack.getItemDamage()), newList); + } + } + + @Override + public boolean canUndo() { + return oldList != null; + } + + @Override + public void undo() { + ThaumcraftApi.objectTags.put(Arrays.asList(stack.getItem(), stack.getItemDamage()), oldList); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/handlers/Crucible.java b/src/main/java/modtweaker/mods/thaumcraft/handlers/Crucible.java new file mode 100644 index 0000000..d8715d6 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/handlers/Crucible.java @@ -0,0 +1,68 @@ +package modtweaker.mods.thaumcraft.handlers; + +import static modtweaker.helpers.InputHelper.toObject; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.crafting.CrucibleRecipe; + +@ZenClass("mods.thaumcraft.Crucible") +public class Crucible { + @ZenMethod + public static void addRecipe(String key, IItemStack result, IIngredient catalyst, String aspects) { + MineTweakerAPI.apply(new Add(new CrucibleRecipe(key, toStack(result), toObject(catalyst), ThaumcraftHelper.parseAspects(aspects)))); + } + + private static class Add extends BaseListAddition { + public Add(CrucibleRecipe recipe) { + super("Thaumcraft Crucible", ThaumcraftApi.getCraftingRecipes(), recipe); + } + + @Override + public String getRecipeInfo() { + return ((CrucibleRecipe) recipe).getRecipeOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Thaumcraft Crucible", ThaumcraftApi.getCraftingRecipes(), stack); + } + + @Override + public void apply() { + for (Object o : ThaumcraftApi.getCraftingRecipes()) { + if (o instanceof CrucibleRecipe) { + CrucibleRecipe r = (CrucibleRecipe) o; + if (r.getRecipeOutput() != null && areEqual(r.getRecipeOutput(), stack)) { + recipe = r; + break; + } + } + } + + ThaumcraftApi.getCraftingRecipes().remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/handlers/Infusion.java b/src/main/java/modtweaker/mods/thaumcraft/handlers/Infusion.java new file mode 100644 index 0000000..c8430b2 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/handlers/Infusion.java @@ -0,0 +1,175 @@ +package modtweaker.mods.thaumcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.helpers.InputHelper.toStacks; +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import modtweaker.mods.thaumcraft.recipe.MTInfusionRecipe; +import modtweaker.util.BaseListAddition; +import modtweaker.util.BaseListRemoval; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.crafting.InfusionEnchantmentRecipe; +import thaumcraft.api.crafting.InfusionRecipe; + +@ZenClass("mods.thaumcraft.Infusion") +public class Infusion { + @ZenMethod + public static void addRecipe(String key, IItemStack input, IItemStack[] recipe, String aspects, IItemStack result, int instability) { + MineTweakerAPI.apply(new Add(new InfusionRecipe(key, toStack(result), instability, ThaumcraftHelper.parseAspects(aspects), toStack(input), toStacks(recipe)))); + } + + //A version that allows you to specify whether the detection should be fuzzy or not + @ZenMethod + public static void addRecipe(String key, IItemStack input, IItemStack[] recipe, String aspects, IItemStack result, int instability, boolean fuzzyCentre, boolean[] fuzzyRecipe) { + MineTweakerAPI.apply(new Add(new MTInfusionRecipe(key, toStack(result), instability, ThaumcraftHelper.parseAspects(aspects), toStack(input), toStacks(recipe), fuzzyCentre, fuzzyRecipe))); + } + + @ZenMethod + public static void addEnchantment(String key, int enchantID, int instability, String aspects, IItemStack[] recipe) { + MineTweakerAPI.apply(new AddEnchant(new InfusionEnchantmentRecipe(key, Enchantment.enchantmentsList[enchantID], instability, ThaumcraftHelper.parseAspects(aspects), toStacks(recipe)))); + } + + private static class Add extends BaseListAddition { + public Add(InfusionRecipe recipe) { + super("Thaumcraft Infusion", ThaumcraftApi.getCraftingRecipes(), recipe); + } + + @Override + public String getRecipeInfo() { + Object out = ((InfusionRecipe) recipe).getRecipeOutput(); + if (out instanceof ItemStack) { + return ((ItemStack) out).getDisplayName(); + } else return super.getRecipeInfo(); + } + } + + private static class AddEnchant implements IUndoableAction { + InfusionEnchantmentRecipe recipe; + + public AddEnchant(InfusionEnchantmentRecipe inp) { + recipe = inp; + } + + @Override + public void apply() { + ThaumcraftApi.getCraftingRecipes().add(recipe); + } + + @Override + public String describe() { + return "Adding Infusion Enchantment Recipe: " + recipe.enchantment.getName(); + } + + @Override + public boolean canUndo() { + return recipe != null; + } + + @Override + public void undo() { + ThaumcraftApi.getCraftingRecipes().remove(recipe); + } + + @Override + public String describeUndo() { + return "Removing Infusion Enchantment Recipe: " + recipe.enchantment.getName(); + } + + @Override + public String getOverrideKey() { + return null; + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack output) { + MineTweakerAPI.apply(new Remove(toStack(output))); + } + + @ZenMethod + public static void removeEnchant(int id) { + MineTweakerAPI.apply(new RemoveEnchant(Enchantment.enchantmentsList[id])); + } + + private static class Remove extends BaseListRemoval { + public Remove(ItemStack stack) { + super("Thaumcraft Infusion", ThaumcraftApi.getCraftingRecipes(), stack); + } + + @Override + public void apply() { + for (Object o : ThaumcraftApi.getCraftingRecipes()) { + if (o instanceof InfusionRecipe) { + InfusionRecipe r = (InfusionRecipe) o; + if (r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && areEqual((ItemStack) r.getRecipeOutput(), stack)) { + recipe = r; + break; + } + } + } + + ThaumcraftApi.getCraftingRecipes().remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + private static class RemoveEnchant implements IUndoableAction { + Enchantment enchant; + InfusionEnchantmentRecipe removed; + + public RemoveEnchant(Enchantment ench) { + enchant = ench; + } + + @Override + public void apply() { + for (Object recipe : ThaumcraftApi.getCraftingRecipes()) { + if (recipe instanceof InfusionEnchantmentRecipe) { + InfusionEnchantmentRecipe enchRecipe = (InfusionEnchantmentRecipe) recipe; + if (enchRecipe.getEnchantment() == enchant) { + removed = enchRecipe; + ThaumcraftApi.getCraftingRecipes().remove(enchRecipe); + } + } + } + } + + @Override + public String describe() { + return "Removing Infusion Enchantment Recipe: " + enchant.getName(); + } + + @Override + public boolean canUndo() { + return removed != null; + } + + @Override + public void undo() { + ThaumcraftApi.getCraftingRecipes().add(removed); + } + + @Override + public String describeUndo() { + return "Restoring Infusion Enchantment Recipe: " + enchant.getName(); + } + + @Override + public String getOverrideKey() { + return null; + } + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/handlers/Research.java b/src/main/java/modtweaker/mods/thaumcraft/handlers/Research.java new file mode 100644 index 0000000..f1f7f64 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/handlers/Research.java @@ -0,0 +1,199 @@ +package modtweaker.mods.thaumcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.player.IPlayer; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import modtweaker.mods.thaumcraft.research.AddPage; +import modtweaker.mods.thaumcraft.research.AddPrereq; +import modtweaker.mods.thaumcraft.research.AddResearch; +import modtweaker.mods.thaumcraft.research.AddSibling; +import modtweaker.mods.thaumcraft.research.AddTab; +import modtweaker.mods.thaumcraft.research.ClearPages; +import modtweaker.mods.thaumcraft.research.ClearPrereqs; +import modtweaker.mods.thaumcraft.research.ClearSiblings; +import modtweaker.mods.thaumcraft.research.Difficulty; +import modtweaker.mods.thaumcraft.research.MoveResearch; +import modtweaker.mods.thaumcraft.research.OrphanResearch; +import modtweaker.mods.thaumcraft.research.RefreshResearch; +import modtweaker.mods.thaumcraft.research.RemoveResearch; +import modtweaker.mods.thaumcraft.research.RemoveTab; +import modtweaker.mods.thaumcraft.research.SetAspects; +import modtweaker.mods.thaumcraft.research.SetResearch; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.util.ResourceLocation; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.ThaumcraftApiHelper; +import thaumcraft.api.research.ResearchItem; +import thaumcraft.api.research.ResearchPage.PageType; + +@ZenClass("mods.thaumcraft.Research") +public class Research { + private static final ResourceLocation defaultBackground = new ResourceLocation("thaumcraft", "textures/gui/gui_researchback.png"); + + @ZenMethod + public static void addTab(String key, String iconDomain, String iconPath) { + addTab(key, iconDomain, iconPath, null, null); + } + + @ZenMethod + public static void addTab(String key, String iconDomain, String iconPath, String backDomain, String backPath) { + ResourceLocation icon = new ResourceLocation(iconDomain, iconPath); + ResourceLocation background; + if (backPath == null) background = defaultBackground; + else background = new ResourceLocation(backDomain, backPath); + addTab(key, icon, background); + } + + private static void addTab(String key, ResourceLocation icon, ResourceLocation background) { + MineTweakerAPI.apply(new AddTab(key, icon, background)); + } + + @ZenMethod + public static void removeTab(String tab) { + MineTweakerAPI.apply(new RemoveTab(tab)); + } + + @ZenMethod + public static void removeResearch(String research) { + MineTweakerAPI.apply(new RemoveResearch(research)); + } + + @ZenMethod + public static void orphanResearch(String research) { + MineTweakerAPI.apply(new OrphanResearch(research)); + } + + @ZenMethod + public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, String domain, String path) { + MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, new ResourceLocation(domain, path)))); + } + + @ZenMethod + public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, IItemStack item) { + MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)))); + } + + @ZenMethod + public static void addPage(String key, String unlocalized) { + MineTweakerAPI.apply(new AddPage(key, PageType.TEXT, unlocalized)); + } + + @ZenMethod + public static void addCraftingPage(String key, IItemStack item) { + MineTweakerAPI.apply(new AddPage(key, PageType.NORMAL_CRAFTING, toStack(item))); + } + + @ZenMethod + public static void addCruciblePage(String key, IItemStack item) { + MineTweakerAPI.apply(new AddPage(key, PageType.CRUCIBLE_CRAFTING, toStack(item))); + } + + @ZenMethod + public static void addArcanePage(String key, IItemStack item) { + MineTweakerAPI.apply(new AddPage(key, PageType.ARCANE_CRAFTING, toStack(item))); + } + + @ZenMethod + public static void addInfusionPage(String key, IItemStack item) { + MineTweakerAPI.apply(new AddPage(key, PageType.INFUSION_CRAFTING, toStack(item))); + } + + @ZenMethod + public static void addEnchantmentPage(String key, int i) { + MineTweakerAPI.apply(new AddPage(key, PageType.INFUSION_ENCHANTMENT, Enchantment.enchantmentsList[i])); + } + + @ZenMethod + public static void clearPages(String key) { + MineTweakerAPI.apply(new ClearPages(key)); + } + + @ZenMethod + public static void addPrereq(String key, String req, @Optional boolean hidden) { + MineTweakerAPI.apply(new AddPrereq(key, req, hidden)); + } + + @ZenMethod + public static void clearPrereqs(String key) { + MineTweakerAPI.apply(new ClearPrereqs(key)); + } + + @ZenMethod + public static void addSibling(String key, String sibling) { + MineTweakerAPI.apply(new AddSibling(key, sibling)); + } + + @ZenMethod + public static void clearSiblings(String key) { + MineTweakerAPI.apply(new ClearSiblings(key)); + } + + @ZenMethod + public static void setRound(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.ROUND)); + } + + @ZenMethod + public static void setSpikey(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.SPIKE)); + } + + @ZenMethod + public static void setStub(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.STUB)); + } + + @ZenMethod + public static void setSecondary(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.SECONDARY)); + } + + @ZenMethod + public static void setVirtual(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.VIRTUAL)); + } + + @ZenMethod + public static void setAutoUnlock(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.AUTO)); + } + + @ZenMethod + public static void setConcealed(String key, boolean flag) { + MineTweakerAPI.apply(new SetResearch(key, flag, SetType.CONCEAL)); + } + + @ZenMethod + public static void setAspects(String key, String aspects) { + MineTweakerAPI.apply(new SetAspects(key, ThaumcraftHelper.parseAspects(aspects))); + } + + @ZenMethod + public static void setComplexity(String key, int complexity) { + MineTweakerAPI.apply(new Difficulty(key, complexity)); + } + + @ZenMethod + public static void refreshResearchRecipe(String key) { + MineTweakerAPI.apply(new RefreshResearch(key)); + } + + @ZenMethod + public static void moveResearch(String key, String destination, int x, int y) { + MineTweakerAPI.apply(new MoveResearch(key, destination, x, y)); + } + + @ZenMethod + public static boolean hasResearched(IPlayer player, String key) { + return ThaumcraftApiHelper.isResearchComplete(player.getName(), key); + } + + public static enum SetType { + AUTO, ROUND, SPIKE, SECONDARY, STUB, VIRTUAL, CONCEAL + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/handlers/Warp.java b/src/main/java/modtweaker/mods/thaumcraft/handlers/Warp.java new file mode 100644 index 0000000..91dbb42 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/handlers/Warp.java @@ -0,0 +1,209 @@ +package modtweaker.mods.thaumcraft.handlers; + +import static modtweaker.helpers.InputHelper.toStack; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thaumcraft.api.ThaumcraftApi; + +@ZenClass("mods.thaumcraft.Warp") +public class Warp { + + @ZenMethod + public static void addToResearch(String key, int warp) { + MineTweakerAPI.apply(new Add(key, warp)); + } + + @ZenMethod + public static void addToItem(IItemStack stack, int warp) { + MineTweakerAPI.apply(new Add(toStack(stack), warp)); + } + + private static class Add implements IUndoableAction { + Object target; + int warp; + + public Add(Object targ, int amount) { + target = targ; + warp = amount; + } + + public void apply() { + if (target instanceof String) ThaumcraftApi.addWarpToResearch((String) target, warp); + else if (target instanceof ItemStack) ThaumcraftApi.addWarpToItem((ItemStack) target, warp); + } + + public boolean canUndo() { + return ThaumcraftApi.getWarp(target) > 0; + } + + public String describe() { + String desc = "Adding " + warp + " warp to "; + if (target instanceof String) desc += (String) target; + else if (target instanceof ItemStack) desc += ((ItemStack) target).getDisplayName(); + return desc; + } + + public void undo() { + if (target instanceof String) ThaumcraftHelper.warpList.remove(target); + else if (target instanceof ItemStack) ThaumcraftHelper.warpList.remove(Arrays.asList(((ItemStack) target).getItem(), ((ItemStack) target).getItemDamage())); + } + + public String describeUndo() { + String desc = "Removing warp from "; + if (target instanceof String) desc += (String) target; + else if (target instanceof ItemStack) desc += ((ItemStack) target).getDisplayName(); + return desc; + } + + public Object getOverrideKey() { + return null; + } + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeFromResearch(String key) { + MineTweakerAPI.apply(new Remove(key)); + } + + @ZenMethod + public static void removeFromItem(IItemStack stack) { + MineTweakerAPI.apply(new Remove(toStack(stack))); + } + + @ZenMethod + public static void removeAll() { + MineTweakerAPI.apply(new MassRemove(RemoveType.BOTH)); + } + + @ZenMethod + public static void removeAllResearch() { + MineTweakerAPI.apply(new MassRemove(RemoveType.RESEARCH)); + } + + @ZenMethod + public static void removeAllItems() { + MineTweakerAPI.apply(new MassRemove(RemoveType.ITEMS)); + } + + private static class Remove implements IUndoableAction { + Object target; + int warp; + + public Remove(Object targ) { + target = targ; + } + + public void apply() { + if (target instanceof String) warp = ThaumcraftHelper.warpList.remove(target); + else if (target instanceof ItemStack) warp = ThaumcraftHelper.warpList.remove(Arrays.asList(((ItemStack) target).getItem(), ((ItemStack) target).getItemDamage())); + } + + public boolean canUndo() { + return warp > 0; + } + + public String describe() { + String desc = "Removing warp from "; + if (target instanceof String) desc += (String) target; + else if (target instanceof ItemStack) desc += ((ItemStack) target).getDisplayName(); + return desc; + } + + public void undo() { + if (target instanceof String) ThaumcraftApi.addWarpToResearch((String) target, warp); + else if (target instanceof ItemStack) ThaumcraftApi.addWarpToItem((ItemStack) target, warp); + } + + public String describeUndo() { + String desc = "Restoring " + warp + " warp to "; + if (target instanceof String) desc += (String) target; + else if (target instanceof ItemStack) desc += ((ItemStack) target).getDisplayName(); + return desc; + } + + public Object getOverrideKey() { + return null; + } + + } + + public static enum RemoveType { + RESEARCH, ITEMS, BOTH + } + + private static class MassRemove implements IUndoableAction { + HashMap oldMap = new HashMap(); + RemoveType type; + + public MassRemove(RemoveType typ) { + type = typ; + } + + public void apply() { + if (type == RemoveType.BOTH) { + for (Object key : ThaumcraftHelper.warpList.keySet()) { + oldMap.put(key, ThaumcraftHelper.warpList.get(key)); + } + ThaumcraftHelper.warpList.clear(); + } else if (type == RemoveType.ITEMS) { + for (Object key : ThaumcraftHelper.warpList.keySet()) { + if (key instanceof List) { + oldMap.put(key, ThaumcraftHelper.warpList.get(key)); + } + } + for (Object key : oldMap.keySet()) { + ThaumcraftHelper.warpList.remove(key); + } + } else if (type == RemoveType.RESEARCH) { + for (Object key : ThaumcraftHelper.warpList.keySet()) { + if (key instanceof String) { + oldMap.put(key, ThaumcraftHelper.warpList.get(key)); + } + } + for (Object key : oldMap.keySet()) { + ThaumcraftHelper.warpList.remove(key); + } + } + } + + public boolean canUndo() { + return oldMap.size() > 0; + } + + public String describe() { + if (type == RemoveType.RESEARCH) return "Clearing All Research Warp"; + else if (type == RemoveType.ITEMS) return "Clearing All Item Warp"; + else return "Clearing All Warp"; + } + + public void undo() { + for (Object key : oldMap.keySet()) { + ThaumcraftHelper.warpList.put(key, oldMap.get(key)); + } + } + + public String describeUndo() { + if (type == RemoveType.RESEARCH) return "Restoring All Research Warp"; + else if (type == RemoveType.ITEMS) return "Restoring All Item Warp"; + else return "Restoring All Warp"; + } + + public Object getOverrideKey() { + return null; + } + + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/recipe/MTInfusionRecipe.java b/src/main/java/modtweaker/mods/thaumcraft/recipe/MTInfusionRecipe.java new file mode 100644 index 0000000..d686282 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/recipe/MTInfusionRecipe.java @@ -0,0 +1,63 @@ +package modtweaker.mods.thaumcraft.recipe; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +import thaumcraft.api.ThaumcraftApiHelper; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.crafting.InfusionRecipe; + +public class MTInfusionRecipe extends InfusionRecipe { + private final boolean fuzzyCentre; + private final boolean[] fuzzyRecipe; + + public MTInfusionRecipe(String research, Object output, int inst, AspectList aspects2, ItemStack input, ItemStack[] recipe, boolean fuzzyCentre, boolean[] fuzzyRecipe) { + super(research, output, inst, aspects2, input, recipe); + this.fuzzyCentre = fuzzyCentre; + this.fuzzyRecipe = fuzzyRecipe; + } + + @Override + public boolean matches(ArrayList input, ItemStack central, World world, EntityPlayer player) { + if (getRecipeInput() == null) return false; + + if (research.length() > 0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) { + return false; + } + + ItemStack i2 = central.copy(); + if (getRecipeInput().getItemDamage() == OreDictionary.WILDCARD_VALUE) { + i2.setItemDamage(OreDictionary.WILDCARD_VALUE); + } + + if (!areItemStacksEqual(i2, getRecipeInput(), fuzzyCentre)) return false; + + ArrayList ii = new ArrayList(); + for (ItemStack is : input) { + ii.add(is.copy()); + } + + for (int j = 0; j < getComponents().length; j++) { + ItemStack comp = getComponents()[j]; + boolean b = false; + for (int a = 0; a < ii.size(); a++) { + i2 = ii.get(a).copy(); + if (comp.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + i2.setItemDamage(OreDictionary.WILDCARD_VALUE); + } + + if (areItemStacksEqual(i2, comp, fuzzyRecipe[j])) { + ii.remove(a); + b = true; + break; + } + } + if (!b) return false; + } + + return ii.size() == 0 ? true : false; + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/AddPage.java b/src/main/java/modtweaker/mods/thaumcraft/research/AddPage.java new file mode 100644 index 0000000..045e635 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/AddPage.java @@ -0,0 +1,126 @@ +package modtweaker.mods.thaumcraft.research; + +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.crafting.CrucibleRecipe; +import thaumcraft.api.crafting.IArcaneRecipe; +import thaumcraft.api.crafting.InfusionEnchantmentRecipe; +import thaumcraft.api.crafting.InfusionRecipe; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchPage; +import thaumcraft.api.research.ResearchPage.PageType; + +public class AddPage implements IUndoableAction { + String key; + String tab; + ResearchPage page; + ResearchPage[] oldPages; + PageType type; + ItemStack target; + Enchantment enchant; + + public AddPage(String res, PageType a, Object b) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + type = a; + if (type == PageType.TEXT) page = new ResearchPage((String) b); + else if (type == PageType.INFUSION_ENCHANTMENT) enchant = (Enchantment) b; + if (b instanceof ItemStack) target = (ItemStack) b; + } + + @Override + public void apply() { + if (type == PageType.NORMAL_CRAFTING) { + for (Object craft : CraftingManager.getInstance().getRecipeList()) { + if (craft instanceof IRecipe) { + IRecipe theCraft = (IRecipe) craft; + if (theCraft.getRecipeOutput() != null && areEqual(theCraft.getRecipeOutput(), target)) { + page = new ResearchPage(theCraft); + break; + } + } + } + } else if (type == PageType.ARCANE_CRAFTING) { + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof IArcaneRecipe) { + IArcaneRecipe theCraft = (IArcaneRecipe) craft; + if (theCraft.getRecipeOutput() != null && areEqual(theCraft.getRecipeOutput(), target)) { + page = new ResearchPage(theCraft); + break; + } + } + } + } else if (type == PageType.CRUCIBLE_CRAFTING) { + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof CrucibleRecipe) { + CrucibleRecipe theCraft = (CrucibleRecipe) craft; + if (theCraft.getRecipeOutput() != null && areEqual(theCraft.getRecipeOutput(), target)) { + page = new ResearchPage(theCraft); + break; + } + } + } + } else if (type == PageType.INFUSION_CRAFTING) { + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof InfusionRecipe) { + InfusionRecipe theCraft = (InfusionRecipe) craft; + if (theCraft.getRecipeOutput() != null && theCraft.getRecipeOutput() instanceof ItemStack && areEqual(((ItemStack) (theCraft.getRecipeOutput())), target)) { + page = new ResearchPage(theCraft); + break; + } + } + } + } else if (type == PageType.INFUSION_ENCHANTMENT) { + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof InfusionEnchantmentRecipe) { + InfusionEnchantmentRecipe theCraft = (InfusionEnchantmentRecipe) craft; + if (theCraft.getEnchantment() != null && theCraft.getEnchantment() == enchant) { + page = new ResearchPage(theCraft); + break; + } + } + } + } + if (page == null) return; + oldPages = ResearchCategories.researchCategories.get(tab).research.get(key).getPages(); + if (oldPages == null) oldPages = new ResearchPage[0]; + ResearchPage[] newPages = new ResearchPage[oldPages.length + 1]; + for (int x = 0; x < oldPages.length; x++) { + newPages[x] = oldPages[x]; + } + newPages[oldPages.length] = page; + ResearchCategories.researchCategories.get(tab).research.get(key).setPages(newPages); + } + + @Override + public String describe() { + return "Adding Research Page to " + key; + } + + @Override + public boolean canUndo() { + return oldPages != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.get(key).setPages(oldPages); + } + + @Override + public String describeUndo() { + return "Removing Page from " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/AddPrereq.java b/src/main/java/modtweaker/mods/thaumcraft/research/AddPrereq.java new file mode 100644 index 0000000..d73868e --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/AddPrereq.java @@ -0,0 +1,70 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; + +public class AddPrereq implements IUndoableAction { + String key; + String tab; + String prereq; + String[] oldPrereqs; + boolean hidden; + + public AddPrereq(String res, String req, boolean secret) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + prereq = req; + hidden = secret; + } + + @Override + public void apply() { + if (!hidden) { + oldPrereqs = ResearchCategories.researchCategories.get(tab).research.get(key).parents; + if (oldPrereqs == null) oldPrereqs = new String[0]; + String[] newPrereqs = new String[oldPrereqs.length + 1]; + for (int x = 0; x < oldPrereqs.length; x++) { + newPrereqs[x] = oldPrereqs[x]; + } + newPrereqs[oldPrereqs.length] = prereq; + ResearchCategories.researchCategories.get(tab).research.get(key).setParents(newPrereqs); + } else { + oldPrereqs = ResearchCategories.researchCategories.get(tab).research.get(key).parentsHidden; + if (oldPrereqs == null) oldPrereqs = new String[0]; + String[] newPrereqs = new String[oldPrereqs.length + 1]; + for (int x = 0; x < oldPrereqs.length; x++) { + newPrereqs[x] = oldPrereqs[x]; + } + newPrereqs[oldPrereqs.length] = prereq; + ResearchCategories.researchCategories.get(tab).research.get(key).setParentsHidden(newPrereqs); + } + } + + @Override + public String describe() { + return "Adding Prerequisites to " + key; + } + + @Override + public boolean canUndo() { + return oldPrereqs != null; + } + + @Override + public void undo() { + if (!hidden) ResearchCategories.researchCategories.get(tab).research.get(key).setParents(oldPrereqs); + else ResearchCategories.researchCategories.get(tab).research.get(key).setParentsHidden(oldPrereqs); + } + + @Override + public String describeUndo() { + return "Restoring Prerequisites for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/AddResearch.java b/src/main/java/modtweaker/mods/thaumcraft/research/AddResearch.java new file mode 100644 index 0000000..9e98112 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/AddResearch.java @@ -0,0 +1,48 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; + +public class AddResearch implements IUndoableAction { + String key; + String tab; + ResearchItem research; + + public AddResearch(ResearchItem res) { + research = res; + tab = research.category; + key = research.key; + } + + @Override + public void apply() { + research.registerResearchItem(); + } + + @Override + public String describe() { + return "Registering Research: " + key; + } + + @Override + public boolean canUndo() { + return tab != null && key != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.remove(key); + } + + @Override + public String describeUndo() { + return "Removing Research: " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/AddSibling.java b/src/main/java/modtweaker/mods/thaumcraft/research/AddSibling.java new file mode 100644 index 0000000..792f275 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/AddSibling.java @@ -0,0 +1,56 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; + +public class AddSibling implements IUndoableAction { + String key; + String tab; + String sibling; + String[] oldSiblings; + + public AddSibling(String res, String sib) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + sibling = sib; + } + + @Override + public void apply() { + oldSiblings = ResearchCategories.researchCategories.get(tab).research.get(key).siblings; + if (oldSiblings == null) oldSiblings = new String[0]; + String[] newSiblings = new String[oldSiblings.length + 1]; + for (int x = 0; x < oldSiblings.length; x++) { + newSiblings[x] = oldSiblings[x]; + } + newSiblings[oldSiblings.length] = sibling; + ResearchCategories.researchCategories.get(tab).research.get(key).setSiblings(sibling); + } + + @Override + public String describe() { + return "Adding Sibling to " + key; + } + + @Override + public boolean canUndo() { + return oldSiblings != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.get(key).setSiblings(oldSiblings); + } + + @Override + public String describeUndo() { + return "Restoring Siblings for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/AddTab.java b/src/main/java/modtweaker/mods/thaumcraft/research/AddTab.java new file mode 100644 index 0000000..77750c5 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/AddTab.java @@ -0,0 +1,48 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import net.minecraft.util.ResourceLocation; +import thaumcraft.api.research.ResearchCategories; + +public class AddTab implements IUndoableAction { + String tab; + ResourceLocation icon; + ResourceLocation background; + + public AddTab(String research, ResourceLocation pic, ResourceLocation back) { + icon = pic; + background = back; + tab = research; + } + + @Override + public void apply() { + ResearchCategories.registerCategory(tab, icon, background); + } + + @Override + public String describe() { + return "Registering Research Tab: " + tab; + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.remove(tab); + } + + @Override + public String describeUndo() { + return "Removing Research Tab: " + tab; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/ClearPages.java b/src/main/java/modtweaker/mods/thaumcraft/research/ClearPages.java new file mode 100644 index 0000000..f904013 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/ClearPages.java @@ -0,0 +1,49 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchPage; + +public class ClearPages implements IUndoableAction { + String key; + String tab; + ResearchPage[] oldPages; + + public ClearPages(String res) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + } + + @Override + public void apply() { + oldPages = ResearchCategories.researchCategories.get(tab).research.get(key).getPages(); + ResearchCategories.researchCategories.get(tab).research.get(key).setPages(new ResearchPage[0]); + } + + @Override + public String describe() { + return "Clearing Research Pages from " + key; + } + + @Override + public boolean canUndo() { + return oldPages != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.get(key).setPages(oldPages); + } + + @Override + public String describeUndo() { + return "Restoring Pages to " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/ClearPrereqs.java b/src/main/java/modtweaker/mods/thaumcraft/research/ClearPrereqs.java new file mode 100644 index 0000000..fae4fae --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/ClearPrereqs.java @@ -0,0 +1,52 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; + +public class ClearPrereqs implements IUndoableAction { + String key; + String tab; + String[] prereqs; + String[] secretPrereqs; + + public ClearPrereqs(String res) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + } + + @Override + public void apply() { + prereqs = ResearchCategories.researchCategories.get(tab).research.get(key).parents; + secretPrereqs = ResearchCategories.researchCategories.get(tab).research.get(key).parentsHidden; + ResearchCategories.researchCategories.get(tab).research.get(key).setParents(new String[0]); + ResearchCategories.researchCategories.get(tab).research.get(key).setParentsHidden(new String[0]); + } + + @Override + public String describe() { + return "Clearing Prerequisites for " + key; + } + + @Override + public boolean canUndo() { + return prereqs != null || secretPrereqs != null; + } + + @Override + public void undo() { + if (prereqs != null) ResearchCategories.researchCategories.get(tab).research.get(key).setParents(prereqs); + if (secretPrereqs != null) ResearchCategories.researchCategories.get(tab).research.get(key).setParentsHidden(secretPrereqs); + } + + @Override + public String describeUndo() { + return "Restoring Prerequisites for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/ClearSiblings.java b/src/main/java/modtweaker/mods/thaumcraft/research/ClearSiblings.java new file mode 100644 index 0000000..51057c0 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/ClearSiblings.java @@ -0,0 +1,48 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; + +public class ClearSiblings implements IUndoableAction { + String key; + String tab; + String[] siblings; + + public ClearSiblings(String res) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + } + + @Override + public void apply() { + siblings = ResearchCategories.researchCategories.get(tab).research.get(key).siblings; + ResearchCategories.researchCategories.get(tab).research.get(key).setSiblings(new String[0]); + } + + @Override + public String describe() { + return "Clearing Siblings for " + key; + } + + @Override + public boolean canUndo() { + return siblings != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.get(key).setSiblings(siblings); + } + + @Override + public String describeUndo() { + return "Restoring Siblings for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/Difficulty.java b/src/main/java/modtweaker/mods/thaumcraft/research/Difficulty.java new file mode 100644 index 0000000..5fb297c --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/Difficulty.java @@ -0,0 +1,69 @@ +package modtweaker.mods.thaumcraft.research; + +import java.lang.reflect.Field; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; + +public class Difficulty implements IUndoableAction { + String key; + String tab; + int difficulty; + int oldDif; + boolean applied = false; + + public Difficulty(String res, int dif) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + difficulty = dif; + } + + @Override + public void apply() { + ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key); + oldDif = research.getComplexity(); + try { + Field complexity = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("complexity"); + complexity.setAccessible(true); + complexity.set(research, difficulty); + applied = true; + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public String describe() { + return "Changing Complexity for " + key; + } + + @Override + public boolean canUndo() { + return applied; + } + + @Override + public void undo() { + try { + ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key); + Field complexity = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("complexity"); + complexity.setAccessible(true); + complexity.set(research, oldDif); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public String describeUndo() { + return "Restoring Complexity for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/MoveResearch.java b/src/main/java/modtweaker/mods/thaumcraft/research/MoveResearch.java new file mode 100644 index 0000000..1dbeace --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/MoveResearch.java @@ -0,0 +1,97 @@ +package modtweaker.mods.thaumcraft.research; + +import java.lang.reflect.Field; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; + +public class MoveResearch implements IUndoableAction { + String key; + String newTab; + int x; + int y; + String oldTab; + int oldX; + int oldY; + boolean moved = false; + + public MoveResearch(String research, String destination, int ex, int wy) { + key = research; + oldTab = ThaumcraftHelper.getResearchTab(key); + newTab = destination; + x = ex; + y = wy; + } + + @Override + public void apply() { + if (oldTab != null) { + ResearchItem research = ResearchCategories.researchCategories.get(oldTab).research.get(key); + oldX = research.displayColumn; + oldY = research.displayRow; + try { + Class res = Class.forName("thaumcraft.api.research.ResearchItem"); + Field ex = res.getField("displayColumn"); + ex.setAccessible(true); + ex.setInt(research, x); + Field wy = res.getField("displayRow"); + wy.setAccessible(true); + wy.setInt(research, y); + Field cat = res.getField("category"); + cat.setAccessible(true); + cat.set(research, newTab); + ResearchCategories.researchCategories.get(oldTab).research.remove(key); + research.registerResearchItem(); + moved = true; + + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + public String describe() { + return "Moving Research " + key + " to " + newTab; + } + + @Override + public boolean canUndo() { + return moved; + } + + @Override + public void undo() { + ResearchItem research = ResearchCategories.researchCategories.get(oldTab).research.get(key); + try { + Class res = Class.forName("thaumcraft.api.research.ResearchItem"); + Field ex = res.getField("displayColumn"); + ex.setAccessible(true); + ex.setInt(research, oldX); + Field wy = res.getField("displayRow"); + wy.setAccessible(true); + wy.setInt(research, oldY); + Field cat = res.getField("category"); + cat.setAccessible(true); + cat.set(research, oldTab); + ResearchCategories.researchCategories.get(newTab).research.remove(key); + research.registerResearchItem(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public String describeUndo() { + return "Moving Research " + key + " back to " + oldTab; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/OrphanResearch.java b/src/main/java/modtweaker/mods/thaumcraft/research/OrphanResearch.java new file mode 100644 index 0000000..f7a70ae --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/OrphanResearch.java @@ -0,0 +1,126 @@ +package modtweaker.mods.thaumcraft.research; + +import java.util.ArrayList; +import java.util.HashMap; + +import minetweaker.IUndoableAction; +import thaumcraft.api.research.ResearchCategories; + +public class OrphanResearch implements IUndoableAction { + String key; + HashMap children = new HashMap(); + HashMap secretChildren = new HashMap(); + HashMap siblings = new HashMap(); + + public OrphanResearch(String victim) { + key = victim; + } + + @Override + public void apply() { + for (String tab : ResearchCategories.researchCategories.keySet()) { + for (String research : ResearchCategories.researchCategories.get(tab).research.keySet()) { + String[] prereqs = ResearchCategories.researchCategories.get(tab).research.get(research).parents; + if (prereqs != null) { + for (int x = 0; x < prereqs.length; x++) { + if (prereqs[x] != null && prereqs[x].equals(key)) { + children.put(research, tab); + ArrayList newReqs = new ArrayList(); + for (int y = 0; y < prereqs.length; y++) { + if (y != x) newReqs.add(prereqs[y]); + } + ResearchCategories.researchCategories.get(tab).research.get(research).setParents(newReqs.toArray(new String[prereqs.length - 1])); + break; + } + } + } + prereqs = ResearchCategories.researchCategories.get(tab).research.get(research).parentsHidden; + if (prereqs != null) { + for (int x = 0; x < prereqs.length; x++) { + if (prereqs[x] != null && prereqs[x].equals(key)) { + secretChildren.put(research, tab); + ArrayList newReqs = new ArrayList(); + for (int y = 0; y < prereqs.length; y++) { + if (y != x) newReqs.add(prereqs[y]); + } + ResearchCategories.researchCategories.get(tab).research.get(research).setParentsHidden(newReqs.toArray(new String[prereqs.length - 1])); + break; + } + } + } + prereqs = ResearchCategories.researchCategories.get(tab).research.get(research).siblings; + if (prereqs != null) { + for (int x = 0; x < prereqs.length; x++) { + if (prereqs[x] != null && prereqs[x].equals(key)) { + siblings.put(research, tab); + ArrayList newReqs = new ArrayList(); + for (int y = 0; y < prereqs.length; y++) { + if (y != x) newReqs.add(prereqs[y]); + } + ResearchCategories.researchCategories.get(tab).research.get(research).setSiblings(newReqs.toArray(new String[prereqs.length - 1])); + break; + } + } + } + } + } + } + + @Override + public String describe() { + return "Orphaning Research: " + key; + } + + @Override + public boolean canUndo() { + return children.size() > 0 || secretChildren.size() > 0 || siblings.size() > 0; + } + + @Override + public void undo() { + if (children.size() > 0) { + for (String research : children.keySet()) { + String[] oldPrereqs = ResearchCategories.researchCategories.get(children.get(research)).research.get(research).parents; + String[] newReqs = new String[oldPrereqs.length + 1]; + for (int x = 0; x < oldPrereqs.length; x++) { + newReqs[x] = oldPrereqs[x]; + } + newReqs[oldPrereqs.length] = key; + ResearchCategories.researchCategories.get(children.get(research)).research.get(research).setParents(newReqs); + } + } + if (secretChildren.size() > 0) { + for (String research : secretChildren.keySet()) { + String[] oldPrereqs = ResearchCategories.researchCategories.get(secretChildren.get(research)).research.get(research).parentsHidden; + String[] newReqs = new String[oldPrereqs.length + 1]; + for (int x = 0; x < oldPrereqs.length; x++) { + newReqs[x] = oldPrereqs[x]; + } + newReqs[oldPrereqs.length] = key; + ResearchCategories.researchCategories.get(secretChildren.get(research)).research.get(research).setParentsHidden(newReqs); + } + } + if (siblings.size() > 0) { + for (String research : siblings.keySet()) { + String[] oldPrereqs = ResearchCategories.researchCategories.get(siblings.get(research)).research.get(research).siblings; + String[] newReqs = new String[oldPrereqs.length + 1]; + for (int x = 0; x < oldPrereqs.length; x++) { + newReqs[x] = oldPrereqs[x]; + } + newReqs[oldPrereqs.length] = key; + ResearchCategories.researchCategories.get(siblings.get(research)).research.get(research).setSiblings(newReqs); + } + } + } + + @Override + public String describeUndo() { + return "Reattaching Research: " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/RefreshResearch.java b/src/main/java/modtweaker/mods/thaumcraft/research/RefreshResearch.java new file mode 100644 index 0000000..2c2d8a1 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/RefreshResearch.java @@ -0,0 +1,110 @@ +package modtweaker.mods.thaumcraft.research; + +import static modtweaker.helpers.StackHelper.areEqual; +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import thaumcraft.api.ThaumcraftApi; +import thaumcraft.api.crafting.CrucibleRecipe; +import thaumcraft.api.crafting.IArcaneRecipe; +import thaumcraft.api.crafting.InfusionRecipe; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; +import thaumcraft.api.research.ResearchPage; + +public class RefreshResearch implements IUndoableAction { + String research; + String tab; + + public RefreshResearch(String target) { + research = target; + tab = ThaumcraftHelper.getResearchTab(research); + } + + @Override + public void apply() { + if (tab != null) { + ResearchItem target = ResearchCategories.researchCategories.get(tab).research.get(research); + ResearchPage[] pages = target.getPages(); + for (int x = 0; x < pages.length; x++) { + if (pages[x].recipe != null) { + if (pages[x].recipe instanceof IRecipe) { + IRecipe recipe = (IRecipe) pages[x].recipe; + for (Object craft : CraftingManager.getInstance().getRecipeList()) { + if (craft instanceof IRecipe) { + IRecipe theCraft = (IRecipe) craft; + if (theCraft.getRecipeOutput() != null && areEqual(theCraft.getRecipeOutput(), recipe.getRecipeOutput())) { + pages[x] = new ResearchPage(theCraft); + break; + } + } + } + } else if (pages[x].recipe instanceof IArcaneRecipe) { + IArcaneRecipe recipe = (IArcaneRecipe) pages[x].recipe; + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof IArcaneRecipe) { + IArcaneRecipe theCraft = (IArcaneRecipe) craft; + if (theCraft.getRecipeOutput() != null && areEqual(theCraft.getRecipeOutput(), recipe.getRecipeOutput())) { + pages[x] = new ResearchPage(theCraft); + break; + } + } + } + } else if (pages[x].recipe instanceof CrucibleRecipe) { + CrucibleRecipe recipe = (CrucibleRecipe) pages[x].recipe; + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof CrucibleRecipe) { + CrucibleRecipe theCraft = (CrucibleRecipe) craft; + if (theCraft.getRecipeOutput() != null && areEqual(theCraft.getRecipeOutput(), recipe.getRecipeOutput())) { + pages[x] = new ResearchPage(theCraft); + break; + } + } + } + } else if (pages[x].recipe instanceof InfusionRecipe) { + InfusionRecipe recipe = (InfusionRecipe) pages[x].recipe; + if (recipe.getRecipeOutput() instanceof ItemStack) { + for (Object craft : ThaumcraftApi.getCraftingRecipes()) { + if (craft instanceof InfusionRecipe) { + InfusionRecipe theCraft = (InfusionRecipe) craft; + if (theCraft.getRecipeOutput() != null && theCraft.getRecipeOutput() instanceof ItemStack && areEqual(((ItemStack) theCraft.getRecipeOutput()), (ItemStack) recipe.getRecipeOutput())) { + pages[x] = new ResearchPage(theCraft); + break; + } + } + } + } + } + } + } + } + } + + @Override + public String describe() { + return "Refreshing Research: " + research; + } + + @Override + public boolean canUndo() { + return tab != null; + } + + @Override + public void undo() { + apply(); + } + + @Override + public String describeUndo() { + return "Refreshing Research Again?: " + research; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/RemoveResearch.java b/src/main/java/modtweaker/mods/thaumcraft/research/RemoveResearch.java new file mode 100644 index 0000000..477aaeb --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/RemoveResearch.java @@ -0,0 +1,51 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; + +public class RemoveResearch implements IUndoableAction { + String key; + String tab; + ResearchItem removed; + + public RemoveResearch(String victim) { + key = victim; + tab = ThaumcraftHelper.getResearchTab(key); + } + + @Override + public void apply() { + if (tab != null) { + removed = ResearchCategories.researchCategories.get(tab).research.get(key); + ResearchCategories.researchCategories.get(tab).research.remove(key); + } + } + + @Override + public String describe() { + return "Removing Research: " + key; + } + + @Override + public boolean canUndo() { + return tab != null && removed != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.put(tab, removed); + } + + @Override + public String describeUndo() { + return "Restoring Research: " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/RemoveTab.java b/src/main/java/modtweaker/mods/thaumcraft/research/RemoveTab.java new file mode 100644 index 0000000..21e0915 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/RemoveTab.java @@ -0,0 +1,46 @@ +package modtweaker.mods.thaumcraft.research; + +import minetweaker.IUndoableAction; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchCategoryList; + +public class RemoveTab implements IUndoableAction { + String tab; + ResearchCategoryList list; + + public RemoveTab(String victim) { + tab = victim; + } + + @Override + public void apply() { + list = ResearchCategories.getResearchList(tab); + ResearchCategories.researchCategories.remove(tab); + } + + @Override + public String describe() { + return "Removing Research Tab: " + tab; + } + + @Override + public boolean canUndo() { + return list != null; + } + + @Override + public void undo() { + ResearchCategories.researchCategories.put(tab, list); + } + + @Override + public String describeUndo() { + return "Restoring Research Tab: " + tab; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/ResearchLogger.java b/src/main/java/modtweaker/mods/thaumcraft/research/ResearchLogger.java new file mode 100644 index 0000000..796548c --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/ResearchLogger.java @@ -0,0 +1,35 @@ +package modtweaker.mods.thaumcraft.research; + +import static modtweaker.helpers.LogHelper.log; +import static modtweaker.helpers.LogHelper.logPrinted; +import minetweaker.MineTweakerAPI; +import minetweaker.api.player.IPlayer; +import minetweaker.api.server.ICommandFunction; +import thaumcraft.api.research.ResearchCategories; + +public class ResearchLogger implements ICommandFunction { + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments == null || arguments.length <= 0 || arguments[0] == null) { + System.out.println("Research Categories:"); + MineTweakerAPI.logCommand("Research Categories:"); + for (String tab : ResearchCategories.researchCategories.keySet()) { + System.out.println(tab); + MineTweakerAPI.logCommand(tab); + } + + logPrinted(player); + } else if (arguments[0] != null && ResearchCategories.researchCategories.containsKey(arguments[0])) { + System.out.println("Research Keys for " + arguments[0] + ":"); + MineTweakerAPI.logCommand("Research Keys for " + arguments[0] + ":"); + for (String key : ResearchCategories.researchCategories.get(arguments[0]).research.keySet()) { + System.out.println(key); + MineTweakerAPI.logCommand(key); + } + + logPrinted(player); + } else if (arguments[0] != null && player != null) { + log(player, "Cannot find research category " + arguments[0]); + } + } +} diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/SetAspects.java b/src/main/java/modtweaker/mods/thaumcraft/research/SetAspects.java new file mode 100644 index 0000000..af552b7 --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/SetAspects.java @@ -0,0 +1,70 @@ +package modtweaker.mods.thaumcraft.research; + +import java.lang.reflect.Field; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; + +public class SetAspects implements IUndoableAction { + String key; + String tab; + AspectList oldList; + AspectList list; + boolean applied = false; + + public SetAspects(String res, AspectList asp) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + list = asp; + } + + @Override + public void apply() { + ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key); + oldList = research.tags; + try { + Field tags = Class.forName("thaumcraft.api.research.ResearchItem").getField("tags"); + tags.setAccessible(true); + tags.set(research, list); + applied = true; + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public String describe() { + return "Changing Aspects for " + key; + } + + @Override + public boolean canUndo() { + return applied; + } + + @Override + public void undo() { + try { + ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key); + Field tags = Class.forName("thaumcraft.api.research.ResearchItem").getField("tags"); + tags.setAccessible(true); + tags.set(research, oldList); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public String describeUndo() { + return "Restoring Aspects for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thaumcraft/research/SetResearch.java b/src/main/java/modtweaker/mods/thaumcraft/research/SetResearch.java new file mode 100644 index 0000000..b4d92db --- /dev/null +++ b/src/main/java/modtweaker/mods/thaumcraft/research/SetResearch.java @@ -0,0 +1,111 @@ +package modtweaker.mods.thaumcraft.research; + +import java.lang.reflect.Field; + +import minetweaker.IUndoableAction; +import modtweaker.mods.thaumcraft.ThaumcraftHelper; +import modtweaker.mods.thaumcraft.handlers.Research.SetType; +import thaumcraft.api.research.ResearchCategories; +import thaumcraft.api.research.ResearchItem; + +public class SetResearch implements IUndoableAction { + String key; + String tab; + SetType type; + boolean flag; + boolean applied = false; + + public SetResearch(String res, boolean f, SetType typ) { + key = res; + tab = ThaumcraftHelper.getResearchTab(key); + type = typ; + flag = f; + } + + @Override + public void apply() { + ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key); + if (flag) { + if (type == SetType.AUTO) research.setAutoUnlock(); + else if (type == SetType.ROUND) research.setRound(); + else if (type == SetType.SPIKE) research.setSpecial(); + else if (type == SetType.SECONDARY) research.setSecondary(); + else if (type == SetType.STUB) research.setStub(); + else if (type == SetType.VIRTUAL) research.setVirtual(); + else if (type == SetType.CONCEAL) research.setConcealed(); + applied = true; + } else { + try { + Field target = null; + if (type == SetType.AUTO) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isAutoUnlock"); + else if (type == SetType.ROUND) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isRound"); + else if (type == SetType.SPIKE) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isSpecial"); + else if (type == SetType.SECONDARY) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isSecondary"); + else if (type == SetType.STUB) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isStub"); + else if (type == SetType.VIRTUAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isVirtual"); + else if (type == SetType.CONCEAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isConcealed"); + + if (target != null) { + target.setAccessible(true); + target.setBoolean(research, false); + applied = true; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + public String describe() { + return "Setting tag for " + key; + } + + @Override + public boolean canUndo() { + return applied; + } + + @Override + public void undo() { + ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key); + if (!flag) { + if (type == SetType.AUTO) research.setAutoUnlock(); + else if (type == SetType.ROUND) research.setRound(); + else if (type == SetType.SPIKE) research.setSpecial(); + else if (type == SetType.SECONDARY) research.setSecondary(); + else if (type == SetType.STUB) research.setStub(); + else if (type == SetType.VIRTUAL) research.setVirtual(); + else if (type == SetType.CONCEAL) research.setConcealed(); + } else { + try { + Field target = null; + if (type == SetType.AUTO) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isAutoUnlock"); + else if (type == SetType.ROUND) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isRound"); + else if (type == SetType.SPIKE) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isSpecial"); + else if (type == SetType.SECONDARY) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isSecondary"); + else if (type == SetType.STUB) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isStub"); + else if (type == SetType.VIRTUAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isVirtual"); + else if (type == SetType.CONCEAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isConcealed"); + + if (target != null) { + target.setAccessible(true); + target.setBoolean(research, false); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + public String describeUndo() { + return "Reversing tag for " + key; + } + + @Override + public String getOverrideKey() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/modtweaker/mods/thermalexpansion/ThermalExpansion.java b/src/main/java/modtweaker/mods/thermalexpansion/ThermalExpansion.java new file mode 100644 index 0000000..4ca5d85 --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/ThermalExpansion.java @@ -0,0 +1,20 @@ +package modtweaker.mods.thermalexpansion; + +import minetweaker.MineTweakerAPI; +import modtweaker.mods.thermalexpansion.handlers.Crucible; +import modtweaker.mods.thermalexpansion.handlers.Furnace; +import modtweaker.mods.thermalexpansion.handlers.Pulverizer; +import modtweaker.mods.thermalexpansion.handlers.Sawmill; +import modtweaker.mods.thermalexpansion.handlers.Smelter; +import modtweaker.mods.thermalexpansion.handlers.Transposer; + +public class ThermalExpansion { + public ThermalExpansion() { + MineTweakerAPI.registerClass(Crucible.class); + MineTweakerAPI.registerClass(Furnace.class); + MineTweakerAPI.registerClass(Pulverizer.class); + MineTweakerAPI.registerClass(Sawmill.class); + MineTweakerAPI.registerClass(Smelter.class); + MineTweakerAPI.registerClass(Transposer.class); + } +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/ThermalHelper.java b/src/main/java/modtweaker/mods/thermalexpansion/ThermalHelper.java new file mode 100644 index 0000000..a52f714 --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/ThermalHelper.java @@ -0,0 +1,79 @@ +package modtweaker.mods.thermalexpansion; + +import static modtweaker.helpers.ReflectionHelper.getConstructor; +import static modtweaker.helpers.ReflectionHelper.getStaticObject; + +import java.lang.reflect.Constructor; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import thermalexpansion.util.crafting.SmelterManager.RecipeSmelter; +import thermalexpansion.util.crafting.TransposerManager.RecipeTransposer; +import cofh.lib.inventory.ComparableItemStackSafe; + +public class ThermalHelper { + private static Map smelter; + public static Set smelterValid; + private static Map crucible; + + private static Map transposerFill; + private static Map transposerEmpty; + public static Set transposerValid; + + public static Constructor smelterRecipe; + public static Constructor transposerRecipe; + + static { + try { + smelterRecipe = getConstructor("thermalexpansion.util.crafting.SmelterManager$RecipeSmelter", ItemStack.class, ItemStack.class, ItemStack.class, ItemStack.class, int.class, int.class); + transposerRecipe = getConstructor("thermalexpansion.util.crafting.TransposerManager$RecipeTransposer", ItemStack.class, ItemStack.class, FluidStack.class, int.class, int.class); + } catch (Exception e) {} + } + + /** Need to perform this reflection on the fly as the map is ALWAYS changing, thanks to the way that te handles stuff */ + public static Map getSmelterMap() { + try { + smelter = getStaticObject(Class.forName("thermalexpansion.util.crafting.SmelterManager"), "recipeMap"); + smelterValid = getStaticObject(Class.forName("thermalexpansion.util.crafting.SmelterManager"), "validationSet"); + } catch (Exception e) {} + + return smelter; + } + + public static Map getFillMap() { + try { + transposerFill = getStaticObject(Class.forName("thermalexpansion.util.crafting.TransposerManager"), "recipeMapFill"); + transposerValid = getStaticObject(Class.forName("thermalexpansion.util.crafting.TransposerManager"), "validationSet"); + } catch (Exception e) {} + + return transposerFill; + } + + public static Map getExtractMap() { + try { + transposerEmpty = getStaticObject(Class.forName("thermalexpansion.util.crafting.TransposerManager"), "recipeMapExtraction"); + transposerValid = getStaticObject(Class.forName("thermalexpansion.util.crafting.TransposerManager"), "validationSet"); + } catch (Exception e) {} + + return transposerEmpty; + } + + public static boolean removeCrucibleRecipe(ItemStack input) { + try { + crucible = getStaticObject(Class.forName("thermalexpansion.util.crafting.CrucibleManager"), "recipeMap"); + } catch (Exception e) {} + + return crucible.remove(new ComparableItemStackSafe(input)) != null; + } + + public static Object getTERecipe(Constructor constructor, Object... items) { + try { + return constructor.newInstance(items); + } catch (Exception e) {} + + return null; + } +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/handlers/Crucible.java b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Crucible.java new file mode 100644 index 0000000..cba4e07 --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Crucible.java @@ -0,0 +1,104 @@ +package modtweaker.mods.thermalexpansion.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; +import static modtweaker.mods.thermalexpansion.ThermalHelper.removeCrucibleRecipe; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thermalexpansion.util.crafting.CrucibleManager; +import thermalexpansion.util.crafting.CrucibleManager.RecipeCrucible; + +@ZenClass("mods.thermalexpansion.Crucible") +public class Crucible { + @ZenMethod + public static void addRecipe(int energy, IItemStack input, ILiquidStack output) { + MineTweakerAPI.apply(new Add(energy, toStack(input), toFluid(output))); + } + + private static class Add implements IUndoableAction { + ItemStack input; + FluidStack output; + int energy; + boolean applied = false; + + public Add(int rf, ItemStack inp, FluidStack out) { + energy = rf; + input = inp; + output = out; + } + + public void apply() { + applied = CrucibleManager.addRecipe(energy, input, output); + } + + public boolean canUndo() { + return input != null && applied; + } + + public String describe() { + return "Adding TE Magma Crucible Recipe using " + input.getDisplayName(); + } + + public void undo() { + removeCrucibleRecipe(input); + } + + public String describeUndo() { + return "Removing TE Magma Crucible Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove implements IUndoableAction { + ItemStack input; + RecipeCrucible removed; + + public Remove(ItemStack inp) { + input = inp; + } + + public void apply() { + removed = CrucibleManager.getRecipe(input); + removeCrucibleRecipe(input); + } + + public boolean canUndo() { + return removed != null; + } + + public String describe() { + return "Removing TE Magma Crucible Recipe using " + input.getDisplayName(); + } + + public void undo() { + CrucibleManager.addRecipe(removed.getEnergy(), removed.getInput(), removed.getOutput()); + } + + public String describeUndo() { + return "Restoring TE Magma Crucible Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/handlers/Furnace.java b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Furnace.java new file mode 100644 index 0000000..dcb1209 --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Furnace.java @@ -0,0 +1,133 @@ +package modtweaker.mods.thermalexpansion.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thermalexpansion.util.crafting.FurnaceManager; +import thermalexpansion.util.crafting.FurnaceManager.RecipeFurnace; + +@ZenClass("mods.thermalexpansion.Furnace") +public class Furnace { + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(energy, toStack(input), toStack(output))); + } + + private static class Add implements IUndoableAction { + ItemStack input; + ItemStack output; + int energy; + boolean applied = false; + + public Add(int rf, ItemStack inp, ItemStack out) { + energy = rf; + input = inp; + output = out; + } + + public void apply() { + applied = FurnaceManager.addRecipe(energy, input, output, false); + } + + public boolean canUndo() { + return input != null && applied; + } + + public String describe() { + return "Adding Redstone Furnace Recipe using " + input.getDisplayName(); + } + + public void undo() { + FurnaceManager.removeRecipe(input); + } + + public String describeUndo() { + return "Removing Redstone Furnace Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove implements IUndoableAction { + ItemStack input; + RecipeFurnace removed; + + public Remove(ItemStack inp) { + input = inp; + } + + public void apply() { + removed = FurnaceManager.getRecipe(input); + FurnaceManager.removeRecipe(input); + } + + public boolean canUndo() { + return removed != null; + } + + public String describe() { + return "Removing Redstone Furnace Recipe using " + input.getDisplayName(); + } + + public void undo() { + FurnaceManager.addRecipe(removed.getEnergy(), removed.getInput(), removed.getOutput(), false); + } + + public String describeUndo() { + return "Restoring Redstone Furnace Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void refreshRecipes() { + MineTweakerAPI.apply(new Refresh()); + } + + private static class Refresh implements IUndoableAction { + + public void apply() { + FurnaceManager.loadRecipes(); + } + + public boolean canUndo() { + return false; + } + + public String describe() { + return "Refreshing Redstone Furnace Recipes"; + } + + public void undo() {} + + public String describeUndo() { + return "Can't Undo Redstone Furnace Refresh"; + } + + public Object getOverrideKey() { + return null; + } + + } + +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/handlers/Pulverizer.java b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Pulverizer.java new file mode 100644 index 0000000..dd0151c --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Pulverizer.java @@ -0,0 +1,109 @@ +package modtweaker.mods.thermalexpansion.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thermalexpansion.util.crafting.PulverizerManager; +import thermalexpansion.util.crafting.PulverizerManager.RecipePulverizer; + +@ZenClass("mods.thermalexpansion.Pulverizer") +public class Pulverizer { + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(energy, toStack(input), toStack(output), null, 0)); + } + + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack output, IItemStack secondary, int secondaryChance) { + MineTweakerAPI.apply(new Add(energy, toStack(input), toStack(output), toStack(secondary), secondaryChance)); + } + + private static class Add implements IUndoableAction { + ItemStack input; + ItemStack output; + ItemStack secondary; + int secondaryChance; + int energy; + boolean applied = false; + + public Add(int rf, ItemStack inp, ItemStack out, ItemStack sec, int chance) { + energy = rf; + input = inp; + output = out; + secondary = sec; + secondaryChance = chance; + } + + public void apply() { + applied = PulverizerManager.addRecipe(energy, input, output, secondary, secondaryChance); + } + + public boolean canUndo() { + return input != null && applied; + } + + public String describe() { + return "Adding Pulverizer Recipe using " + input.getDisplayName(); + } + + public void undo() { + PulverizerManager.removeRecipe(input); + } + + public String describeUndo() { + return "Removing Pulverizer Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove implements IUndoableAction { + ItemStack input; + RecipePulverizer removed; + + public Remove(ItemStack inp) { + input = inp; + } + + public void apply() { + removed = PulverizerManager.getRecipe(input); + PulverizerManager.removeRecipe(input); + } + + public boolean canUndo() { + return removed != null; + } + + public String describe() { + return "Removing Pulverizer Recipe using " + input.getDisplayName(); + } + + public void undo() { + PulverizerManager.addRecipe(removed.getEnergy(), removed.getInput(), removed.getPrimaryOutput(), removed.getSecondaryOutput(), removed.getSecondaryOutputChance()); + } + + public String describeUndo() { + return "Restoring Pulverizer Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/handlers/Sawmill.java b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Sawmill.java new file mode 100644 index 0000000..1f5a39b --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Sawmill.java @@ -0,0 +1,109 @@ +package modtweaker.mods.thermalexpansion.handlers; + +import static modtweaker.helpers.InputHelper.toStack; +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thermalexpansion.util.crafting.SawmillManager; +import thermalexpansion.util.crafting.SawmillManager.RecipeSawmill; + +@ZenClass("mods.thermalexpansion.Sawmill") +public class Sawmill { + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack output) { + MineTweakerAPI.apply(new Add(energy, toStack(input), toStack(output), null, 0)); + } + + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack output, IItemStack secondary, int secondaryChance) { + MineTweakerAPI.apply(new Add(energy, toStack(input), toStack(output), toStack(secondary), secondaryChance)); + } + + private static class Add implements IUndoableAction { + ItemStack input; + ItemStack output; + ItemStack secondary; + int secondaryChance; + int energy; + boolean applied = false; + + public Add(int rf, ItemStack inp, ItemStack out, ItemStack sec, int chance) { + energy = rf; + input = inp; + output = out; + secondary = sec; + secondaryChance = chance; + } + + public void apply() { + applied = SawmillManager.addRecipe(energy, input, output, secondary, secondaryChance); + } + + public boolean canUndo() { + return input != null && applied; + } + + public String describe() { + return "Adding Sawmill Recipe using " + input.getDisplayName(); + } + + public void undo() { + SawmillManager.removeRecipe(input); + } + + public String describeUndo() { + return "Removing Sawmill Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input) { + MineTweakerAPI.apply(new Remove(toStack(input))); + } + + private static class Remove implements IUndoableAction { + ItemStack input; + RecipeSawmill removed; + + public Remove(ItemStack inp) { + input = inp; + } + + public void apply() { + removed = SawmillManager.getRecipe(input); + SawmillManager.removeRecipe(input); + } + + public boolean canUndo() { + return removed != null; + } + + public String describe() { + return "Removing Sawmill Recipe using " + input.getDisplayName(); + } + + public void undo() { + SawmillManager.addRecipe(removed.getEnergy(), removed.getInput(), removed.getPrimaryOutput(), removed.getSecondaryOutput(), removed.getSecondaryOutputChance()); + } + + public String describeUndo() { + return "Restoring Sawmill Recipe using " + input.getDisplayName(); + } + + public Object getOverrideKey() { + return null; + } + + } + +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/handlers/Smelter.java b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Smelter.java new file mode 100644 index 0000000..3056cea --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Smelter.java @@ -0,0 +1,134 @@ +package modtweaker.mods.thermalexpansion.handlers; + +import static modtweaker.helpers.InputHelper.toStack; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import modtweaker.mods.thermalexpansion.ThermalHelper; +import modtweaker.util.BaseDescriptionAddition; +import modtweaker.util.BaseDescriptionRemoval; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thermalexpansion.util.crafting.SmelterManager.RecipeSmelter; +import cofh.lib.inventory.ComparableItemStackSafe; + +@ZenClass("mods.thermalexpansion.Smelter") +public class Smelter { + private static boolean removeValidated(ComparableItemStackSafe stack) { + for (Map.Entry entry : ThermalHelper.getSmelterMap().entrySet()) { + RecipeSmelter recipe = (RecipeSmelter) entry.getValue(); + if (stack.equals(new ComparableItemStackSafe(recipe.getPrimaryInput()))) { + return false; + } else if (stack.equals(new ComparableItemStackSafe(recipe.getSecondaryInput()))) { + return false; + } + } + + return ThermalHelper.smelterValid.remove(stack); + } + + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack input2, IItemStack output) { + addRecipe(energy, input, input2, output, null, 0); + } + + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack input2, IItemStack output, IItemStack output2, int chance) { + ItemStack in1 = toStack(input); + ItemStack in2 = toStack(input2); + ItemStack out1 = toStack(output); + ItemStack out2 = toStack(output2); + RecipeSmelter recipe = (RecipeSmelter) ThermalHelper.getTERecipe(ThermalHelper.smelterRecipe, in1, in2, out1, out2, chance, energy); + MineTweakerAPI.apply(new Add(in1, in2, recipe)); + } + + private static class Add extends BaseDescriptionAddition { + private final ComparableItemStackSafe input1; + private final ComparableItemStackSafe input2; + private final List key; + private final RecipeSmelter recipe; + + public Add(ItemStack input1, ItemStack input2, RecipeSmelter recipe) { + super("Induction Smelter"); + this.input1 = new ComparableItemStackSafe(input1); + this.input2 = new ComparableItemStackSafe(input2); + this.key = (Arrays.asList(new ComparableItemStackSafe[] { this.input1, this.input2 })); + this.recipe = recipe; + } + + @Override + public void apply() { + ThermalHelper.getSmelterMap().put(key, recipe); + ThermalHelper.smelterValid.add(input1); + ThermalHelper.smelterValid.add(input2); + } + + @Override + public boolean canUndo() { + return ThermalHelper.getSmelterMap() != null; + } + + @Override + public void undo() { + ThermalHelper.getSmelterMap().remove(key); + removeValidated(input1); + removeValidated(input2); + } + + @Override + public String getRecipeInfo() { + return ((RecipeSmelter) recipe).getPrimaryOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IItemStack input, IItemStack input2) { + MineTweakerAPI.apply(new Remove(toStack(input), toStack(input2))); + } + + private static class Remove extends BaseDescriptionRemoval { + private final ComparableItemStackSafe input1; + private final ComparableItemStackSafe input2; + private final List key; + private RecipeSmelter recipe; + + public Remove(ItemStack input1, ItemStack input2) { + super("Induction Smelter"); + this.input1 = new ComparableItemStackSafe(input1); + this.input2 = new ComparableItemStackSafe(input2); + this.key = (Arrays.asList(new ComparableItemStackSafe[] { this.input1, this.input2 })); + } + + @Override + public void apply() { + recipe = ThermalHelper.getSmelterMap().get(key); + ThermalHelper.getSmelterMap().remove(key); + removeValidated(input1); + removeValidated(input2); + } + + @Override + public boolean canUndo() { + return ThermalHelper.getSmelterMap() != null; + } + + @Override + public void undo() { + ThermalHelper.getSmelterMap().put(key, recipe); + ThermalHelper.smelterValid.add(input1); + ThermalHelper.smelterValid.add(input2); + } + + @Override + public String getRecipeInfo() { + return input1.toItemStack().getDisplayName() + " + " + input2.toItemStack().getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/mods/thermalexpansion/handlers/Transposer.java b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Transposer.java new file mode 100644 index 0000000..51e7752 --- /dev/null +++ b/src/main/java/modtweaker/mods/thermalexpansion/handlers/Transposer.java @@ -0,0 +1,179 @@ +package modtweaker.mods.thermalexpansion.handlers; + +import static modtweaker.helpers.InputHelper.toFluid; +import static modtweaker.helpers.InputHelper.toStack; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import modtweaker.mods.thermalexpansion.ThermalHelper; +import modtweaker.util.BaseDescriptionAddition; +import modtweaker.util.BaseDescriptionRemoval; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import thermalexpansion.util.crafting.TransposerManager.RecipeTransposer; +import cofh.lib.inventory.ComparableItemStackSafe; + +@ZenClass("mods.thermalexpansion.Transposer") +public class Transposer { + private static boolean removeValidated(ComparableItemStackSafe stack) { + //Check if there is a recipe that requires this in the validation set for filling + for (Map.Entry entry : ThermalHelper.getFillMap().entrySet()) { + RecipeTransposer recipe = (RecipeTransposer) entry.getValue(); + if (stack.equals(new ComparableItemStackSafe(recipe.getInput()))) { + return false; + } + } + + //Check if there is a recipe that requires this in the validation set for extracting + for (Map.Entry entry : ThermalHelper.getExtractMap().entrySet()) { + RecipeTransposer recipe = (RecipeTransposer) entry.getValue(); + if (stack.equals(new ComparableItemStackSafe(recipe.getInput()))) { + return false; + } + } + + return ThermalHelper.transposerValid.remove(stack); + } + + @ZenMethod + public static void addFillRecipe(int energy, IItemStack input, IItemStack output, ILiquidStack liquid) { + addRecipe(energy, input, output, liquid, 100, true); + } + + @ZenMethod + public static void addExtractRecipe(int energy, IItemStack input, IItemStack output, ILiquidStack liquid, int chance) { + addRecipe(energy, input, output, liquid, chance, false); + } + + @ZenMethod + public static void addRecipe(int energy, IItemStack input, IItemStack output, ILiquidStack liquid, int chance, boolean isFillRecipe) { + ItemStack in = toStack(input); + ItemStack out = toStack(output); + FluidStack fluid = toFluid(liquid); + RecipeTransposer recipe = (RecipeTransposer) ThermalHelper.getTERecipe(ThermalHelper.transposerRecipe, in, out, fluid, energy, chance); + MineTweakerAPI.apply(new Add(in, fluid, recipe, isFillRecipe)); + } + + private static class Add extends BaseDescriptionAddition { + private List key; + private boolean isFillRecipe; + private final ComparableItemStackSafe input; + private final RecipeTransposer recipe; + + public Add(ItemStack input, FluidStack fluid, RecipeTransposer recipe, boolean isFillRecipe) { + super("Transposer"); + this.isFillRecipe = isFillRecipe; + this.input = new ComparableItemStackSafe(input); + + this.recipe = recipe; + if (this.isFillRecipe) { + this.key = Arrays.asList(new Integer[] { Integer.valueOf(new ComparableItemStackSafe(input).hashCode()), Integer.valueOf(fluid.fluidID) }); + } + } + + @Override + public void apply() { + if (isFillRecipe) { + ThermalHelper.getFillMap().put(key, recipe); + } else { + ThermalHelper.getExtractMap().put(input, recipe); + } + + ThermalHelper.transposerValid.add(input); + } + + @Override + public boolean canUndo() { + return input != null; + } + + @Override + public void undo() { + if (isFillRecipe) { + ThermalHelper.getFillMap().remove(key); + } else { + ThermalHelper.getExtractMap().remove(input); + } + + removeValidated(input); + } + + @Override + public String getRecipeInfo() { + return ((RecipeTransposer) recipe).getOutput().getDisplayName(); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + @ZenMethod + public static void removeFillRecipe(IItemStack input, ILiquidStack liquid) { + removeRecipe(input, liquid, true); + } + + @ZenMethod + public static void removeExtractRecipe(IItemStack input) { + removeRecipe(input, null, false); + } + + @ZenMethod + public static void removeRecipe(IItemStack input, ILiquidStack liquid, boolean isFillRecipe) { + MineTweakerAPI.apply(new Remove(toStack(input), toFluid(liquid), isFillRecipe)); + } + + private static class Remove extends BaseDescriptionRemoval { + private final boolean isFillRecipe; + private final ComparableItemStackSafe input; + private List key; + private RecipeTransposer recipe; + + public Remove(ItemStack input, FluidStack fluid, boolean isFillRecipe) { + super("Transposer"); + this.isFillRecipe = isFillRecipe; + this.input = new ComparableItemStackSafe(input); + if (this.isFillRecipe) { + this.key = Arrays.asList(new Integer[] { Integer.valueOf(new ComparableItemStackSafe(input).hashCode()), Integer.valueOf(fluid.fluidID) }); + } + } + + @Override + public void apply() { + if (isFillRecipe) { + recipe = ThermalHelper.getFillMap().get(key); + ThermalHelper.getFillMap().remove(key); + } else { + recipe = ThermalHelper.getExtractMap().get(input); + ThermalHelper.getExtractMap().remove(input); + } + + removeValidated(input); + } + + @Override + public boolean canUndo() { + return input != null; + } + + @Override + public void undo() { + if (isFillRecipe) { + ThermalHelper.getFillMap().put(key, recipe); + } else { + ThermalHelper.getExtractMap().put(input, recipe); + } + + ThermalHelper.transposerValid.add(input); + } + + @Override + public String getRecipeInfo() { + return input.toItemStack().getDisplayName(); + } + } +} diff --git a/src/main/java/modtweaker/util/BaseCraftingAddition.java b/src/main/java/modtweaker/util/BaseCraftingAddition.java new file mode 100644 index 0000000..bbfc89f --- /dev/null +++ b/src/main/java/modtweaker/util/BaseCraftingAddition.java @@ -0,0 +1,56 @@ +package modtweaker.util; + +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; + +public abstract class BaseCraftingAddition extends BaseDescriptionAddition { + protected final List list; + protected final boolean shapeless; + protected final ItemStack output; + protected final Object[] recipe; + + public BaseCraftingAddition(String name, boolean shapeless, List list, ItemStack output, Object... recipe) { + super(name); + this.shapeless = shapeless; + this.output = output; + this.recipe = recipe; + this.list = list; + } + + @Override + public void apply() { + if (shapeless) applyShapeless(); + else applyShaped(); + } + + public abstract void applyShaped(); + + public abstract void applyShapeless(); + + @Override + public boolean canUndo() { + return list != null; + } + + @Override + public void undo() { + IRecipe remove = null; + for (IRecipe recipe : list) { + if (recipe.getRecipeOutput() != null && areEqual(recipe.getRecipeOutput(), output)) { + remove = recipe; + break; + } + } + + list.remove(remove); + } + + @Override + public String getRecipeInfo() { + return output.getDisplayName(); + } +} diff --git a/src/main/java/modtweaker/util/BaseCraftingRemoval.java b/src/main/java/modtweaker/util/BaseCraftingRemoval.java new file mode 100644 index 0000000..eeb66a5 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseCraftingRemoval.java @@ -0,0 +1,31 @@ +package modtweaker.util; + +import static modtweaker.helpers.StackHelper.areEqual; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; + +public class BaseCraftingRemoval extends BaseListRemoval { + public BaseCraftingRemoval(String name, List list, ItemStack stack) { + super(name, list, stack); + } + + @Override + public void apply() { + for (IRecipe r : (List) list) { + if (r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && areEqual(r.getRecipeOutput(), stack)) { + recipe = r; + break; + } + } + + list.remove(recipe); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } +} diff --git a/src/main/java/modtweaker/util/BaseDescriptionAddition.java b/src/main/java/modtweaker/util/BaseDescriptionAddition.java new file mode 100644 index 0000000..8d4fc99 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseDescriptionAddition.java @@ -0,0 +1,35 @@ +package modtweaker.util; + +import minetweaker.IUndoableAction; + +public abstract class BaseDescriptionAddition implements IUndoableAction { + protected String description; + + public BaseDescriptionAddition(String description) { + this.description = description; + } + + @Override + public boolean canUndo() { + return true; + } + + public String getRecipeInfo() { + return "Unknown Item"; + } + + @Override + public String describe() { + return "Adding " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseDescriptionRemoval.java b/src/main/java/modtweaker/util/BaseDescriptionRemoval.java new file mode 100644 index 0000000..5d916b3 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseDescriptionRemoval.java @@ -0,0 +1,35 @@ +package modtweaker.util; + +import minetweaker.IUndoableAction; + +public abstract class BaseDescriptionRemoval implements IUndoableAction { + protected String description; + + public BaseDescriptionRemoval(String description) { + this.description = description; + } + + @Override + public boolean canUndo() { + return true; + } + + public String getRecipeInfo() { + return "Unknown Item"; + } + + @Override + public String describe() { + return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + return "Restoring " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseListAddition.java b/src/main/java/modtweaker/util/BaseListAddition.java new file mode 100644 index 0000000..769aa26 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseListAddition.java @@ -0,0 +1,61 @@ +package modtweaker.util; + +import java.util.List; + +import minetweaker.IUndoableAction; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public abstract class BaseListAddition implements IUndoableAction { + protected final List list; + protected final Object recipe; + protected String description; + + public BaseListAddition(String description, List list, Object recipe) { + this(list, recipe); + this.description = description; + } + + public BaseListAddition(List list, Object recipe) { + this.list = list; + this.recipe = recipe; + } + + @Override + public void apply() { + list.add(recipe); + } + + @Override + public boolean canUndo() { + return list != null; + } + + @Override + public void undo() { + list.remove(recipe); + } + + public String getRecipeInfo() { + return "Unknown Item"; + } + + @Override + public String describe() { + if (recipe instanceof ItemStack) return "Adding " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Adding " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Adding " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + if (recipe instanceof ItemStack) return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseListRemoval.java b/src/main/java/modtweaker/util/BaseListRemoval.java new file mode 100644 index 0000000..8ca2ea2 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseListRemoval.java @@ -0,0 +1,75 @@ +package modtweaker.util; + +import java.util.List; + +import minetweaker.IUndoableAction; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public abstract class BaseListRemoval implements IUndoableAction { + protected final String description; + protected final List list; + protected final FluidStack fluid; + protected final ItemStack stack; + protected Object recipe; + + public BaseListRemoval(String description, List list, ItemStack stack, FluidStack fluid) { + this.list = list; + this.stack = stack; + this.description = description; + this.fluid = fluid; + } + + public BaseListRemoval(String description, List list, ItemStack stack) { + this(description, list, stack, null); + } + + public BaseListRemoval(String description, List list, FluidStack fluid) { + this(description, list, null, fluid); + } + + public BaseListRemoval(List list, ItemStack stack) { + this(null, list, stack); + } + + public BaseListRemoval(List list, FluidStack stack) { + this(null, list, stack); + } + + public BaseListRemoval(String description, List list) { + this(description, list, null, null); + } + + @Override + public boolean canUndo() { + return list != null; + } + + @Override + public void undo() { + list.add(recipe); + } + + public String getRecipeInfo() { + return "Unknown Item"; + } + + @Override + public String describe() { + if (recipe instanceof ItemStack) return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + if (recipe instanceof ItemStack) return "Restoring " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Restoring " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Restoring " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseMapAddition.java b/src/main/java/modtweaker/util/BaseMapAddition.java new file mode 100644 index 0000000..06f260f --- /dev/null +++ b/src/main/java/modtweaker/util/BaseMapAddition.java @@ -0,0 +1,63 @@ +package modtweaker.util; + +import java.util.Map; + +import minetweaker.IUndoableAction; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public abstract class BaseMapAddition implements IUndoableAction { + protected String description; + protected final Map map; + protected Object key; + protected Object recipe; + + public BaseMapAddition(Map map, Object key, Object recipe) { + this(null, map, key, recipe); + } + + public BaseMapAddition(String description, Map map, Object key, Object recipe) { + this.map = map; + this.key = key; + this.recipe = recipe; + this.description = description; + } + + @Override + public void apply() { + map.put(key, recipe); + } + + @Override + public boolean canUndo() { + return map != null; + } + + @Override + public void undo() { + map.remove(key); + } + + public String getRecipeInfo() { + return "Unknown Item"; + } + + @Override + public String describe() { + if (recipe instanceof ItemStack) return "Adding " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Adding " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Adding " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + if (recipe instanceof ItemStack) return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseMapRemoval.java b/src/main/java/modtweaker/util/BaseMapRemoval.java new file mode 100644 index 0000000..9baecc7 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseMapRemoval.java @@ -0,0 +1,69 @@ +package modtweaker.util; + +import java.util.Map; + +import minetweaker.IUndoableAction; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public abstract class BaseMapRemoval implements IUndoableAction { + protected Object stack; + protected String description; + protected final Map map; + protected Object key; + protected Object recipe; + + public BaseMapRemoval(Object stack, Map map, Object key) { + this(null, map, key, stack); + } + + public BaseMapRemoval(String description, Map map, Object stack) { + this(description, map, null, stack); + } + + public BaseMapRemoval(String description, Map map, Object key, Object stack) { + this.stack = stack; + this.map = map; + this.key = key; + this.description = description; + } + + @Override + public void apply() { + recipe = map.get(key); + map.remove(key); + } + + @Override + public boolean canUndo() { + return map != null; + } + + @Override + public void undo() { + map.put(key, recipe); + } + + public String getRecipeInfo() { + return "Unknown Item"; + } + + @Override + public String describe() { + if (recipe instanceof ItemStack) return "Removing " + description + " Recipe for : " + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Removing " + description + " Recipe for : " + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + if (recipe instanceof ItemStack) return "Restoring " + description + " Recipe for : " + ((ItemStack) recipe).getDisplayName(); + else if (recipe instanceof FluidStack) return "Restoring " + description + " Recipe for : " + ((FluidStack) recipe).getFluid().getLocalizedName(); + else return "Restoring " + description + " Recipe for : " + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseMultipleListRemoval.java b/src/main/java/modtweaker/util/BaseMultipleListRemoval.java new file mode 100644 index 0000000..15a5794 --- /dev/null +++ b/src/main/java/modtweaker/util/BaseMultipleListRemoval.java @@ -0,0 +1,83 @@ +package modtweaker.util; + +import java.util.ArrayList; +import java.util.List; + +import minetweaker.IUndoableAction; + +public abstract class BaseMultipleListRemoval implements IUndoableAction { + public static enum Position { + ALL, FIRST, LAST; + } + + protected final Position pos; + protected final String description; + protected final List list; + protected final Object search; + protected ArrayList recipes; + + public BaseMultipleListRemoval(String description, List list, Object search, Position pos) { + this.pos = pos; + this.description = description; + this.list = list; + this.search = search; + } + + //Return whether the items are equal or not + protected abstract boolean isEqual(Object recipe, Object search); + + @Override + public void apply() { + //Create a new list + recipes = new ArrayList(); + for (Object o : list) { + if (isEqual(o, search)) { + //If we want the last position, reset the array + if (pos == Position.LAST) { + recipes = new ArrayList(); + } + + recipes.add(o); + + //If we want the first position, exit the loop + if (pos == Position.FIRST) { + break; + } + } + } + + //Remove all the recipes that were considered valid for removal + for (Object o : recipes) { + list.remove(o); + } + } + + @Override + public boolean canUndo() { + return recipes != null; + } + + @Override + public void undo() { + for (Object o : recipes) { + list.add(o); + } + } + + public abstract String getRecipeInfo(); + + @Override + public String describe() { + return "Removing " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public String describeUndo() { + return "Restoring " + description + " Recipe for :" + getRecipeInfo(); + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseSetVar.java b/src/main/java/modtweaker/util/BaseSetVar.java new file mode 100644 index 0000000..7914f6b --- /dev/null +++ b/src/main/java/modtweaker/util/BaseSetVar.java @@ -0,0 +1,56 @@ +package modtweaker.util; + +import minetweaker.IUndoableAction; +import modtweaker.helpers.ReflectionHelper; + +public abstract class BaseSetVar implements IUndoableAction { + protected Object object; + protected final String description; + protected final Class clazz; + protected final String field; + protected final int original; + protected final int newValue; + + public BaseSetVar(String description, Class clazz, Object object, String field, int original, int newValue) { + this(description, clazz, field, original, newValue); + this.object = object; + } + + public BaseSetVar(String description, Class clazz, String field, int original, int newValue) { + this.description = description; + this.clazz = clazz; + this.field = field; + this.original = original; + this.newValue = newValue; + } + + @Override + public void apply() { + ReflectionHelper.setPrivateValue(clazz, object, field, newValue); + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + ReflectionHelper.setPrivateValue(clazz, object, field, original); + } + + @Override + public String describe() { + return "Setting " + description + " to " + newValue; + } + + @Override + public String describeUndo() { + return "Setting " + description + " to the default value of " + original; + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/BaseUndoable.java b/src/main/java/modtweaker/util/BaseUndoable.java new file mode 100644 index 0000000..1f581aa --- /dev/null +++ b/src/main/java/modtweaker/util/BaseUndoable.java @@ -0,0 +1,15 @@ +package modtweaker.util; + +import minetweaker.IUndoableAction; + +public abstract class BaseUndoable implements IUndoableAction { + @Override + public boolean canUndo() { + return true; + } + + @Override + public Object getOverrideKey() { + return null; + } +} diff --git a/src/main/java/modtweaker/util/TweakerPlugin.java b/src/main/java/modtweaker/util/TweakerPlugin.java new file mode 100644 index 0000000..7fd404a --- /dev/null +++ b/src/main/java/modtweaker/util/TweakerPlugin.java @@ -0,0 +1,24 @@ +package modtweaker.util; + +import java.util.ArrayList; + +import cpw.mods.fml.common.Loader; + +public class TweakerPlugin { + private static ArrayList isLoaded = new ArrayList(); + + public static void register(String mod, Class clazz) { + if (Loader.isModLoaded(mod)) { + try { + clazz.newInstance(); + isLoaded.add(mod); + } catch (Exception e) { + isLoaded.remove(mod); + } + } + } + + public static boolean isLoaded(String string) { + return isLoaded.contains(string); + } +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..f480667 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,16 @@ +[ +{ + "modid": "examplemod", + "name": "Example Mod", + "description": "Example placeholder mod.", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "", + "updateUrl": "", + "authorList": ["ExampleDude"], + "credits": "The Forge and FML guys, for making this example", + "logoFile": "", + "screenshots": [], + "dependencies": [] +} +]