From 7f684de9c64243709c5c9309198a93edf1848cbb Mon Sep 17 00:00:00 2001 From: p455w0rd Date: Sat, 7 May 2016 11:52:01 -0400 Subject: [PATCH] Fixed #14 #24 - Implemented #25 #26 #27 #28 --- build.gradle | 94 +++ gradle.properties | 11 + gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++++ gradlew.bat | 90 +++ .../cofh/api/energy/IEnergyContainerItem.java | 5 + src/java/ic2/api/item/IElectricItem.java | 57 ++ .../ic2/api/item/IElectricItemManager.java | 95 +++ .../ic2/api/item/ISpecialElectricItem.java | 13 + src/java/ic2/api/item/package-info.java | 4 + .../api/package-info.java | 2 + .../gui/GuiWirelessCraftingTerminal.java | 3 +- .../client/gui/WCTBaseGui.java | 750 +++++++----------- .../common/WirelessCraftingTerminal.java | 10 +- .../core/crash/BaseCrashEnhancement.java | 28 - .../crash/IntegrationCrashEnhancement.java | 11 - .../handlers/ConfigHandler.java | 9 +- .../integration/IntegrationHelper.java | 4 +- .../integration/IntegrationRegistry.java | 76 +- .../integration/IntegrationType.java | 4 +- .../integration/modules/IC2.java | 47 ++ .../items/ItemMagnet.java | 5 +- .../items/ItemWirelessCraftingTerminal.java | 212 ++++- .../proxy/ClientProxy.java | 11 +- .../proxy/CommonProxy.java | 4 - .../reference/Reference.java | 2 +- .../transformer/Integration.java | 34 - .../transformer/MissingCoreMod.java | 82 -- .../transformer/WCTCore.java | 136 ---- .../transformer/annotations/Integration.java | 34 - .../transformer/asm/ASMIntegration.java | 182 ----- src/resources/META-INF/MANIFEST.MF | 4 + src/resources/mcmod.info | 4 +- 33 files changed, 1127 insertions(+), 1066 deletions(-) create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 src/java/ic2/api/item/IElectricItem.java create mode 100644 src/java/ic2/api/item/IElectricItemManager.java create mode 100644 src/java/ic2/api/item/ISpecialElectricItem.java create mode 100644 src/java/ic2/api/item/package-info.java create mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/api/package-info.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/BaseCrashEnhancement.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/IntegrationCrashEnhancement.java create mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/IC2.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/transformer/Integration.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/transformer/MissingCoreMod.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/transformer/WCTCore.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/transformer/annotations/Integration.java delete mode 100644 src/java/net/p455w0rd/wirelesscraftingterminal/transformer/asm/ASMIntegration.java create mode 100644 src/resources/META-INF/MANIFEST.MF diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..56b9172 --- /dev/null +++ b/build.gradle @@ -0,0 +1,94 @@ +buildscript { + repositories { + mavenCentral() + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + maven { + name = "sonatype" + url = "https://oss.sonatype.org/content/repositories/snapshots/" + } + maven { + name "ChickenBones" + url "http://chickenbones.net/maven/" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' + } +} + +apply plugin: 'forge' +targetCompatibility=7 +sourceCompatibility=7 + +version = minecraft_version + "-" + aeversion + "-" + wctbuild + "" + wctchannel +group = wctgroup +archivesBaseName = wctbasename + +minecraft { + version = minecraft_version + "-" + forge_version + runDir = "run" + + replaceIn "Reference.java" + replaceIn "package-info.java" + + replace "@version@", project.version +} + +jar { + include "net/p455w0rd/wirelesscraftingterminal/**" + include "cofh/api/**" + include "assets/**" + include "ic2/**" + include "mcmod.info" + include "pack.mcmeta" +} + +task deobfJar(type: Jar) { // Generate deobfuscated + from sourceSets.main.output + classifier = 'deobf' +} +task sourceJar(type: Jar) { // Generate sources + from sourceSets.main.allSource + classifier = 'sources' +} +tasks.build.dependsOn('sourceJar', 'deobfJar') +artifacts { + archives deobfJar + archives sourceJar + archives jar +} + +dependencies { + compile("appeng:appliedenergistics2:rv3-beta-5:dev") { + transitive = false + } +} + +sourceSets { + main { + java { + srcDir "src/java/" + + } + + resources { + srcDir "src/resources/" + include "assets/ae2wct/lang/*.lang", + "assets/ae2wct/textures/gui/*", + "assets/ae2wct/textures/items/*", + "mcmod.info", + "pack.mcmeta" + } + } +} + +processResources { + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version': project.version, 'mcversion': minecraft_version + } +} + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..82ef722 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,11 @@ +aeversion=rv3 +wctchannel=b +wctbuild=1.7 +wctgroup=net.p455w0rd.wirelesscraftingterminal +wctbasename=WirelessCraftingTerminal + +######################################################### +# Versions # +######################################################### +minecraft_version=1.7.10 +forge_version=10.13.4.1614-1.7.10 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..c00f2ae --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat Apr 30 08:13:30 EDT 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/java/cofh/api/energy/IEnergyContainerItem.java b/src/java/cofh/api/energy/IEnergyContainerItem.java index c28455b..959427a 100644 --- a/src/java/cofh/api/energy/IEnergyContainerItem.java +++ b/src/java/cofh/api/energy/IEnergyContainerItem.java @@ -1,5 +1,8 @@ package cofh.api.energy; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; /** @@ -49,4 +52,6 @@ public interface IEnergyContainerItem { */ int getMaxEnergyStored(ItemStack container); + void addInformation(ItemStack is, EntityPlayer player, List list, boolean displayMore); + } diff --git a/src/java/ic2/api/item/IElectricItem.java b/src/java/ic2/api/item/IElectricItem.java new file mode 100644 index 0000000..4f546d5 --- /dev/null +++ b/src/java/ic2/api/item/IElectricItem.java @@ -0,0 +1,57 @@ +package ic2.api.item; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +/** + * Provides the ability to store energy on the implementing item. + * + * The item should have a maximum damage of 13. + */ +public interface IElectricItem { + /** + * Determine if the item can be used in a machine or as an armor part to supply energy. + * + * @return Whether the item can supply energy + */ + boolean canProvideEnergy(ItemStack itemStack); + + /** + * Get the item ID to use for a charge energy greater than 0. + * + * @return Item ID to use + */ + Item getChargedItem(ItemStack itemStack); + + /** + * Get the item ID to use for a charge energy of 0. + * + * @return Item ID to use + */ + Item getEmptyItem(ItemStack itemStack); + + /** + * Get the item's maximum charge energy in EU. + * + * @return Maximum charge energy + */ + double getMaxCharge(ItemStack itemStack); + + /** + * Get the item's tier, lower tiers can't send energy to higher ones. + * + * Batteries are Tier 1, Advanced Batteries are Tier 2, Energy Crystals are Tier 3, Lapotron + * Crystals are Tier 4. + * + * @return Item's tier + */ + int getTier(ItemStack itemStack); + + /** + * Get the item's transfer limit in EU per transfer operation. + * + * @return Transfer limit + */ + double getTransferLimit(ItemStack itemStack); +} + diff --git a/src/java/ic2/api/item/IElectricItemManager.java b/src/java/ic2/api/item/IElectricItemManager.java new file mode 100644 index 0000000..5de43d7 --- /dev/null +++ b/src/java/ic2/api/item/IElectricItemManager.java @@ -0,0 +1,95 @@ +package ic2.api.item; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * This interface specifies a manager to handle the various tasks for electric items. + * + * The default implementation does the following: + * - store and retrieve the charge + * - handle charging, taking amount, tier, transfer limit, canProvideEnergy and simulate into account + * - replace item IDs if appropriate (getChargedItemId() and getEmptyItemId()) + * - update and manage the damage value for the visual charge indicator + * + * @note If you're implementing your own variant (ISpecialElectricItem), you can delegate to the + * default implementations through ElectricItem.rawManager. The default implementation is designed + * to minimize its dependency on its own constraints/structure and delegates most work back to the + * more atomic features in the gateway manager. + */ +public interface IElectricItemManager { + /** + * Charge an item with a specified amount of energy. + * + * @param itemStack electric item's stack + * @param amount amount of energy to charge in EU + * @param tier tier of the charging device, has to be at least as high as the item to charge + * @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit() + * @param simulate don't actually change the item, just determine the return value + * @return Energy transferred into the electric item + */ + double charge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate); + + /** + * Discharge an item by a specified amount of energy + * + * @param itemStack electric item's stack + * @param amount amount of energy to discharge in EU + * @param tier tier of the discharging device, has to be at least as high as the item to discharge + * @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit() + * @param externally use the supplied item externally, i.e. to power something else as if it was a battery + * @param simulate don't actually discharge the item, just determine the return value + * @return Energy retrieved from the electric item + */ + double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate); + + /** + * Determine the charge level for the specified item. + * + * @param itemStack ItemStack containing the electric item + * @return charge level in EU + */ + double getCharge(ItemStack stack); + + /** + * Determine if the specified electric item has at least a specific amount of EU. + * This is supposed to be used in the item code during operation, for example if you want to implement your own electric item. + * BatPacks are not taken into account. + * + * @param itemStack electric item's stack + * @param amount minimum amount of energy required + * @return true if there's enough energy + */ + boolean canUse(ItemStack stack, double amount); + + /** + * Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack. + * This is supposed to be used in the item code during operation, for example if you want to implement your own electric item. + * + * @param itemStack electric item's stack + * @param amount amount of energy to discharge in EU + * @param entity entity holding the item + * @return true if the operation succeeded + */ + boolean use(ItemStack stack, double amount, EntityLivingBase entity); + + /** + * Charge an item from the BatPack a player is wearing. + * This is supposed to be used in the item code during operation, for example if you want to implement your own electric item. + * use() already contains this functionality. + * + * @param itemStack electric item's stack + * @param entity entity holding the item + */ + void chargeFromArmor(ItemStack stack, EntityLivingBase entity); + + /** + * Get the tool tip to display for electric items. + * + * @param itemStack ItemStack to determine the tooltip for + * @return tool tip string or null for none + */ + String getToolTip(ItemStack stack); + + // TODO: add tier getter +} diff --git a/src/java/ic2/api/item/ISpecialElectricItem.java b/src/java/ic2/api/item/ISpecialElectricItem.java new file mode 100644 index 0000000..a7302f5 --- /dev/null +++ b/src/java/ic2/api/item/ISpecialElectricItem.java @@ -0,0 +1,13 @@ +package ic2.api.item; + +import net.minecraft.item.ItemStack; + +public interface ISpecialElectricItem extends IElectricItem { + /** + * Supply a custom IElectricItemManager. + * + * @param itemStack ItemStack to get the manager for + * @return IElectricItemManager instance + */ + IElectricItemManager getManager(ItemStack itemStack); +} diff --git a/src/java/ic2/api/item/package-info.java b/src/java/ic2/api/item/package-info.java new file mode 100644 index 0000000..44ecdce --- /dev/null +++ b/src/java/ic2/api/item/package-info.java @@ -0,0 +1,4 @@ +@API(apiVersion="1.0", owner="IC2", provides="IC2API") +package ic2.api.item; +import cpw.mods.fml.common.API; + diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/api/package-info.java b/src/java/net/p455w0rd/wirelesscraftingterminal/api/package-info.java new file mode 100644 index 0000000..df22606 --- /dev/null +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/api/package-info.java @@ -0,0 +1,2 @@ +@API( apiVersion = "1.7.10-rv3-1.6b", owner = "ae2wct", provides = "ae2wct|API" ) package net.p455w0rd.wirelesscraftingterminal.api; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java index 7fe9298..cf8477a 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiWirelessCraftingTerminal.java @@ -38,6 +38,7 @@ import appeng.core.localization.GuiText; import appeng.helpers.InventoryAction; import appeng.util.IConfigManagerHost; import appeng.util.Platform; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ObfuscationReflectionHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; @@ -299,7 +300,7 @@ public class GuiWirelessCraftingTerminal extends GuiContainer implements ISortSo Keyboard.enableRepeatEvents(true); this.maxRows = this.getMaxRows(); this.perRow = AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ( ( this.width - this.standardSize ) / 18 ); - this.isNEIEnabled = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI); + this.isNEIEnabled = Loader.isModLoaded("NotEnoughItems"); int top = isNEIEnabled ? 22 : 0; final int magicNumber = 114 + 1; final int extraSpace = this.height - magicNumber - 0 - top - this.reservedSpace; diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java b/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java index 6d3af64..b142bba 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/client/gui/WCTBaseGui.java @@ -51,6 +51,7 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots; import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ObfuscationReflectionHelper; import appeng.api.storage.data.IAEItemStack; @@ -58,9 +59,7 @@ import appeng.client.gui.widgets.ITooltip; import appeng.container.slot.SlotRestrictedInput; import appeng.helpers.InventoryAction; - -public abstract class WCTBaseGui extends GuiContainer -{ +public abstract class WCTBaseGui extends GuiContainer { private static boolean switchingGuis; private final List meSlots = new LinkedList(); // drag y @@ -73,97 +72,78 @@ public abstract class WCTBaseGui extends GuiContainer private Slot bl_clicked; private boolean subGui; - public WCTBaseGui( final Container container ) - { - super( container ); + public WCTBaseGui(final Container container) { + super(container); this.subGui = switchingGuis; switchingGuis = false; } - protected static String join( final Collection toolTip, final String delimiter ) - { - final Joiner joiner = Joiner.on( delimiter ); + protected static String join(final Collection toolTip, final String delimiter) { + final Joiner joiner = Joiner.on(delimiter); - return joiner.join( toolTip ); + return joiner.join(toolTip); } - protected int getQty( final GuiButton btn ) - { - try - { - final DecimalFormat df = new DecimalFormat( "+#;-#" ); - return df.parse( btn.displayString ).intValue(); + protected int getQty(final GuiButton btn) { + try { + final DecimalFormat df = new DecimalFormat("+#;-#"); + return df.parse(btn.displayString).intValue(); } - catch( final ParseException e ) - { + catch (final ParseException e) { return 0; } } - public boolean isSubGui() - { + public boolean isSubGui() { return this.subGui; } @Override - public void initGui() - { + public void initGui() { super.initGui(); final List slots = this.getInventorySlots(); final Iterator i = slots.iterator(); - while( i.hasNext() ) - { - if( i.next() instanceof SlotME ) - { + while (i.hasNext()) { + if (i.next() instanceof SlotME) { i.remove(); } } - for( final InternalSlotME me : this.meSlots ) - { - slots.add( new SlotME( me ) ); + for (final InternalSlotME me : this.meSlots) { + slots.add(new SlotME(me)); } } - @SuppressWarnings( "unchecked" ) - private List getInventorySlots() - { + @SuppressWarnings("unchecked") + private List getInventorySlots() { return this.inventorySlots.inventorySlots; } @Override - public void drawScreen( final int mouseX, final int mouseY, final float btn ) - { - super.drawScreen( mouseX, mouseY, btn ); + public void drawScreen(final int mouseX, final int mouseY, final float btn) { + super.drawScreen(mouseX, mouseY, btn); - final boolean hasClicked = Mouse.isButtonDown( 0 ); - if( hasClicked && this.scrollBar != null ) - { - this.scrollBar.click( this, mouseX - this.guiLeft, mouseY - this.guiTop ); + final boolean hasClicked = Mouse.isButtonDown(0); + if (hasClicked && this.scrollBar != null) { + this.scrollBar.click(this, mouseX - this.guiLeft, mouseY - this.guiTop); } - for( final Object c : this.buttonList ) - { - if( c instanceof ITooltip ) - { + for (final Object c : this.buttonList) { + if (c instanceof ITooltip) { final ITooltip tooltip = (ITooltip) c; final int x = tooltip.xPos(); // ((GuiImgButton) c).xPosition; int y = tooltip.yPos(); // ((GuiImgButton) c).yPosition; - if( x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible() ) - { - if( y < mouseY && y + tooltip.getHeight() > mouseY ) - { - if( y < 15 ) - { + if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) { + if (y < mouseY && y + tooltip.getHeight() > mouseY) { + if (y < 15) { y = 15; } final String msg = tooltip.getMessage(); - if( msg != null ) - { - this.drawTooltip( x + 11, y + 4, 0, msg ); + if (msg != null) { + this.drawTooltip(x + 11, y + 4, 0, msg); } } } @@ -171,27 +151,23 @@ public abstract class WCTBaseGui extends GuiContainer } } - public void drawTooltip( final int par2, final int par3, final int forceWidth, final String message ) - { - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glDisable( GL12.GL_RESCALE_NORMAL ); + public void drawTooltip(final int par2, final int par3, final int forceWidth, final String message) { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); RenderHelper.disableStandardItemLighting(); - GL11.glDisable( GL11.GL_LIGHTING ); - GL11.glDisable( GL11.GL_DEPTH_TEST ); - final String[] var4 = message.split( "\n" ); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + final String[] var4 = message.split("\n"); - if( var4.length > 0 ) - { + if (var4.length > 0) { int var5 = 0; int var6; int var7; - for( var6 = 0; var6 < var4.length; ++var6 ) - { - var7 = this.fontRendererObj.getStringWidth( var4[var6] ); + for (var6 = 0; var6 < var4.length; ++var6) { + var7 = this.fontRendererObj.getStringWidth(var4[var6]); - if( var7 > var5 ) - { + if (var7 > var5) { var5 = var7; } } @@ -200,53 +176,46 @@ public abstract class WCTBaseGui extends GuiContainer var7 = par3 - 12; int var9 = 8; - if( var4.length > 1 ) - { - var9 += 2 + ( var4.length - 1 ) * 10; + if (var4.length > 1) { + var9 += 2 + (var4.length - 1) * 10; } - if( this.guiTop + var7 + var9 + 6 > this.height ) - { + if (this.guiTop + var7 + var9 + 6 > this.height) { var7 = this.height - var9 - this.guiTop - 6; } - if( forceWidth > 0 ) - { + if (forceWidth > 0) { var5 = forceWidth; } this.zLevel = 300.0F; itemRender.zLevel = 300.0F; final int var10 = -267386864; - this.drawGradientRect( var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10 ); - this.drawGradientRect( var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10 ); - this.drawGradientRect( var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10 ); - this.drawGradientRect( var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10 ); - this.drawGradientRect( var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10 ); + this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); + this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); + this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); + this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); final int var11 = 1347420415; - final int var12 = ( var11 & 16711422 ) >> 1 | var11 & -16777216; - this.drawGradientRect( var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12 ); - this.drawGradientRect( var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12 ); - this.drawGradientRect( var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11 ); - this.drawGradientRect( var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12 ); + final int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; + this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); + this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); + this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); - for( int var13 = 0; var13 < var4.length; ++var13 ) - { + for (int var13 = 0; var13 < var4.length; ++var13) { String var14 = var4[var13]; - if( var13 == 0 ) - { - var14 = '\u00a7' + Integer.toHexString( 15 ) + var14; + if (var13 == 0) { + var14 = '\u00a7' + Integer.toHexString(15) + var14; } - else - { + else { var14 = "\u00a77" + var14; } - this.fontRendererObj.drawStringWithShadow( var14, var6, var7, -1 ); + this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); - if( var13 == 0 ) - { + if (var13 == 0) { var7 += 2; } @@ -260,49 +229,41 @@ public abstract class WCTBaseGui extends GuiContainer } @Override - protected final void drawGuiContainerForegroundLayer( final int x, final int y ) - { + protected final void drawGuiContainerForegroundLayer(final int x, final int y) { final int ox = this.guiLeft; // (width - xSize) / 2; final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - if( this.scrollBar != null ) - { - this.scrollBar.draw( this ); + if (this.scrollBar != null) { + this.scrollBar.draw(this); } - this.drawFG( ox, oy, x, y ); + this.drawFG(ox, oy, x, y); } - public abstract void drawFG( int offsetX, int offsetY, int mouseX, int mouseY ); + public abstract void drawFG(int offsetX, int offsetY, int mouseX, int mouseY); @Override - protected final void drawGuiContainerBackgroundLayer( final float f, final int x, final int y ) - { + protected final void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) { final int ox = this.guiLeft; // (width - xSize) / 2; final int oy = this.guiTop; // (height - ySize) / 2; - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); - this.drawBG( ox, oy, x, y ); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawBG(ox, oy, x, y); final List slots = this.getInventorySlots(); - for( final Slot slot : slots ) - { - if( slot instanceof OptionalSlotFake ) - { + for (final Slot slot : slots) { + if (slot instanceof OptionalSlotFake) { final OptionalSlotFake fs = (OptionalSlotFake) slot; - if( fs.renderDisabled() ) - { - if( fs.isEnabled() ) - { - this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18 ); + if (fs.renderDisabled()) { + if (fs.isEnabled()) { + this.drawTexturedModalRect(ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18); } - else - { - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 0.4F ); - GL11.glEnable( GL11.GL_BLEND ); - this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18 ); - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); + else { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F); + GL11.glEnable(GL11.GL_BLEND); + this.drawTexturedModalRect(ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.getSourceX() - 1, fs.getSourceY() - 1, 18, 18); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopAttrib(); } } @@ -311,235 +272,197 @@ public abstract class WCTBaseGui extends GuiContainer } @Override - protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) - { + protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { this.drag_click.clear(); - if( btn == 1 ) - { - for( final Object o : this.buttonList ) - { + if (btn == 1) { + for (final Object o : this.buttonList) { final GuiButton guibutton = (GuiButton) o; - if( guibutton.mousePressed( this.mc, xCoord, yCoord ) ) - { - super.mouseClicked( xCoord, yCoord, 0 ); + if (guibutton.mousePressed(this.mc, xCoord, yCoord)) { + super.mouseClicked(xCoord, yCoord, 0); return; } } } - super.mouseClicked( xCoord, yCoord, btn ); + super.mouseClicked(xCoord, yCoord, btn); } @Override - protected void mouseClickMove( final int x, final int y, final int c, final long d ) - { - final Slot slot = this.getSlot( x, y ); + protected void mouseClickMove(final int x, final int y, final int c, final long d) { + final Slot slot = this.getSlot(x, y); final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); - if( slot instanceof SlotFake && itemstack != null ) - { - this.drag_click.add( slot ); - if( this.drag_click.size() > 1 ) - { - for( final Slot dr : this.drag_click ) - { - final PacketInventoryAction p = new PacketInventoryAction( c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, dr.slotNumber, 0 ); - NetworkHandler.instance.sendToServer( p ); + if (slot instanceof SlotFake && itemstack != null) { + this.drag_click.add(slot); + if (this.drag_click.size() > 1) { + for (final Slot dr : this.drag_click) { + final PacketInventoryAction p = new PacketInventoryAction(c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, dr.slotNumber, 0); + NetworkHandler.instance.sendToServer(p); } } } - else - { - super.mouseClickMove( x, y, c, d ); + else { + super.mouseClickMove(x, y, c, d); } } @Override - protected void handleMouseClick( final Slot slot, final int slotIdx, final int ctrlDown, final int key ) - { + protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int key) { final EntityPlayer player = Minecraft.getMinecraft().thePlayer; - if( slot instanceof SlotFake ) - { + if (slot instanceof SlotFake) { final InventoryAction action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - if( this.drag_click.size() > 1 ) - { + if (this.drag_click.size() > 1) { return; } - final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 ); - NetworkHandler.instance.sendToServer( p ); + final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); + NetworkHandler.instance.sendToServer(p); return; } - if( slot instanceof SlotCraftingTerm ) - { - if( key == 6 ) - { + if (slot instanceof SlotCraftingTerm) { + if (key == 6) { return; // prevent weird double clicks.. } InventoryAction action = null; - if( key == 1 ) - { + if (key == 1) { action = InventoryAction.CRAFT_SHIFT; } - else - { + else { action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM; } - final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 ); - NetworkHandler.instance.sendToServer( p ); + final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0); + NetworkHandler.instance.sendToServer(p); return; } - if( Keyboard.isKeyDown( Keyboard.KEY_SPACE ) ) - { - if( this.enableSpaceClicking() ) - { + if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { + if (this.enableSpaceClicking()) { IAEItemStack stack = null; - if( slot instanceof SlotME ) - { - stack = ( (SlotME) slot ).getAEStack(); + if (slot instanceof SlotME) { + stack = ((SlotME) slot).getAEStack(); } int slotNum = this.getInventorySlots().size(); - if( !( slot instanceof SlotME ) && slot != null ) - { + if (!(slot instanceof SlotME) && slot != null) { slotNum = slot.slotNumber; } - ( (WCTBaseContainer) this.inventorySlots ).setTargetStack( stack ); - final PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, slotNum, 0 ); - NetworkHandler.instance.sendToServer( p ); + ((WCTBaseContainer) this.inventorySlots).setTargetStack(stack); + final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0); + NetworkHandler.instance.sendToServer(p); return; } } - if( slot instanceof SlotDisconnected ) - { + if (slot instanceof SlotDisconnected) { InventoryAction action = null; - switch( key ) - { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - break; + switch (key) { + case 0: // pickup / set-down. + action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; + break; + case 1: + action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; + break; - case 3: // creative dupe: + case 3: // creative dupe: - if( player.capabilities.isCreativeMode ) - { - action = InventoryAction.CREATIVE_DUPLICATE; - } + if (player.capabilities.isCreativeMode) { + action = InventoryAction.CREATIVE_DUPLICATE; + } - break; + break; - default: - case 4: // drop item: - case 6: + default: + case 4: // drop item: + case 6: } - if( action != null ) - { - final PacketInventoryAction p = new PacketInventoryAction( action, slot.getSlotIndex(), ( (SlotDisconnected) slot ).getSlot().getId() ); - NetworkHandler.instance.sendToServer( p ); + if (action != null) { + final PacketInventoryAction p = new PacketInventoryAction(action, slot.getSlotIndex(), ((SlotDisconnected) slot).getSlot().getId()); + NetworkHandler.instance.sendToServer(p); } return; } - if( slot instanceof SlotME ) - { + if (slot instanceof SlotME) { InventoryAction action = null; IAEItemStack stack = null; - switch( key ) - { - case 0: // pickup / set-down. - action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; - stack = ( (SlotME) slot ).getAEStack(); + switch (key) { + case 0: // pickup / set-down. + action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN; + stack = ((SlotME) slot).getAEStack(); - if( stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0 && player.inventory.getItemStack() == null ) - { - action = InventoryAction.AUTO_CRAFT; + if (stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0 && player.inventory.getItemStack() == null) { + action = InventoryAction.AUTO_CRAFT; + } + + break; + case 1: + action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; + stack = ((SlotME) slot).getAEStack(); + break; + + case 3: // creative dupe: + + stack = ((SlotME) slot).getAEStack(); + if (stack != null && stack.isCraftable()) { + action = InventoryAction.AUTO_CRAFT; + } + else if (player.capabilities.isCreativeMode) { + final IAEItemStack slotItem = ((SlotME) slot).getAEStack(); + if (slotItem != null) { + action = InventoryAction.CREATIVE_DUPLICATE; } + } + break; - break; - case 1: - action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK; - stack = ( (SlotME) slot ).getAEStack(); - break; - - case 3: // creative dupe: - - stack = ( (SlotME) slot ).getAEStack(); - if( stack != null && stack.isCraftable() ) - { - action = InventoryAction.AUTO_CRAFT; - } - else if( player.capabilities.isCreativeMode ) - { - final IAEItemStack slotItem = ( (SlotME) slot ).getAEStack(); - if( slotItem != null ) - { - action = InventoryAction.CREATIVE_DUPLICATE; - } - } - break; - - default: - case 4: // drop item: - case 6: + default: + case 4: // drop item: + case 6: } - if( action != null ) - { - ( (WCTBaseContainer) this.inventorySlots ).setTargetStack( stack ); - final PacketInventoryAction p = new PacketInventoryAction( action, this.getInventorySlots().size(), 0 ); - NetworkHandler.instance.sendToServer( p ); + if (action != null) { + ((WCTBaseContainer) this.inventorySlots).setTargetStack(stack); + final PacketInventoryAction p = new PacketInventoryAction(action, this.getInventorySlots().size(), 0); + NetworkHandler.instance.sendToServer(p); } return; } - if( !this.disableShiftClick && isShiftKeyDown() ) - { + if (!this.disableShiftClick && isShiftKeyDown()) { this.disableShiftClick = true; - if( this.dbl_whichItem == null || this.bl_clicked != slot || this.dbl_clickTimer.elapsed( TimeUnit.MILLISECONDS ) > 150 ) - { + if (this.dbl_whichItem == null || this.bl_clicked != slot || this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) { // some simple double click logic. this.bl_clicked = slot; this.dbl_clickTimer = Stopwatch.createStarted(); - if( slot != null ) - { + if (slot != null) { this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null; } - else - { + else { this.dbl_whichItem = null; } } - else if( this.dbl_whichItem != null ) - { + else if (this.dbl_whichItem != null) { // a replica of the weird broken vanilla feature. final List slots = this.getInventorySlots(); - for( final Slot inventorySlot : slots ) - { - if( inventorySlot != null && inventorySlot.canTakeStack( this.mc.thePlayer ) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.func_94527_a( inventorySlot, this.dbl_whichItem, true ) ) - { - this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, ctrlDown, 1 ); + for (final Slot inventorySlot : slots) { + if (inventorySlot != null && inventorySlot.canTakeStack(this.mc.thePlayer) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) { + this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1); } } } @@ -547,53 +470,40 @@ public abstract class WCTBaseGui extends GuiContainer this.disableShiftClick = false; } - super.handleMouseClick( slot, slotIdx, ctrlDown, key ); + super.handleMouseClick(slot, slotIdx, ctrlDown, key); } @Override - protected boolean checkHotbarKeys( final int keyCode ) - { + protected boolean checkHotbarKeys(final int keyCode) { final Slot theSlot; - try - { - theSlot = ObfuscationReflectionHelper.getPrivateValue( GuiContainer.class, this, "theSlot", "field_147006_u", "f" ); + try { + theSlot = ObfuscationReflectionHelper.getPrivateValue(GuiContainer.class, this, "theSlot", "field_147006_u", "f"); } - catch( final Throwable t ) - { + catch (final Throwable t) { return false; } - if( this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null ) - { - for( int j = 0; j < 9; ++j ) - { - if( keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode() ) - { + if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) { + for (int j = 0; j < 9; ++j) { + if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) { final List slots = this.getInventorySlots(); - for( final Slot s : slots ) - { - if( s.getSlotIndex() == j && s.inventory == ( (WCTBaseContainer) this.inventorySlots ).getPlayerInv() ) - { - if( !s.canTakeStack( ( (WCTBaseContainer) this.inventorySlots ).getPlayerInv().player ) ) - { + for (final Slot s : slots) { + if (s.getSlotIndex() == j && s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) { + if (!s.canTakeStack(((WCTBaseContainer) this.inventorySlots).getPlayerInv().player)) { return false; } } } - if( theSlot.getSlotStackLimit() == 64 ) - { - this.handleMouseClick( theSlot, theSlot.slotNumber, j, 2 ); + if (theSlot.getSlotStackLimit() == 64) { + this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2); return true; } - else - { - for( final Slot s : slots ) - { - if( s.getSlotIndex() == j && s.inventory == ( (WCTBaseContainer) this.inventorySlots ).getPlayerInv() ) - { - NetworkHandler.instance.sendToServer( new PacketSwapSlots( s.slotNumber, theSlot.slotNumber ) ); + else { + for (final Slot s : slots) { + if (s.getSlotIndex() == j && s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) { + NetworkHandler.instance.sendToServer(new PacketSwapSlots(s.slotNumber, theSlot.slotNumber)); return true; } } @@ -606,20 +516,16 @@ public abstract class WCTBaseGui extends GuiContainer } @Override - public void onGuiClosed() - { + public void onGuiClosed() { super.onGuiClosed(); this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI ) } - protected Slot getSlot( final int mouseX, final int mouseY ) - { + protected Slot getSlot(final int mouseX, final int mouseY) { final List slots = this.getInventorySlots(); - for( final Slot slot : slots ) - { + for (final Slot slot : slots) { // isPointInRegion - if( this.func_146978_c( slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY ) ) - { + if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) { return slot; } } @@ -627,291 +533,243 @@ public abstract class WCTBaseGui extends GuiContainer return null; } - public abstract void drawBG( int offsetX, int offsetY, int mouseX, int mouseY ); + public abstract void drawBG(int offsetX, int offsetY, int mouseX, int mouseY); @Override - public void handleMouseInput() - { + public void handleMouseInput() { super.handleMouseInput(); final int i = Mouse.getEventDWheel(); - if( i != 0 && isShiftKeyDown() ) - { + if (i != 0 && isShiftKeyDown()) { final int x = Mouse.getEventX() * this.width / this.mc.displayWidth; final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - this.mouseWheelEvent( x, y, i / Math.abs( i ) ); + this.mouseWheelEvent(x, y, i / Math.abs(i)); } - else if( i != 0 && this.scrollBar != null ) - { - this.scrollBar.wheel( i ); + else if (i != 0 && this.scrollBar != null) { + this.scrollBar.wheel(i); } } - private void mouseWheelEvent( final int x, final int y, final int wheel ) - { - final Slot slot = this.getSlot( x, y ); - if( slot instanceof SlotME ) - { - final IAEItemStack item = ( (SlotME) slot ).getAEStack(); - if( item != null ) - { - ( (WCTBaseContainer) this.inventorySlots ).setTargetStack( item ); + private void mouseWheelEvent(final int x, final int y, final int wheel) { + final Slot slot = this.getSlot(x, y); + if (slot instanceof SlotME) { + final IAEItemStack item = ((SlotME) slot).getAEStack(); + if (item != null) { + ((WCTBaseContainer) this.inventorySlots).setTargetStack(item); final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP; - final int times = Math.abs( wheel ); + final int times = Math.abs(wheel); final int inventorySize = this.getInventorySlots().size(); - for( int h = 0; h < times; h++ ) - { - final PacketInventoryAction p = new PacketInventoryAction( direction, inventorySize, 0 ); - NetworkHandler.instance.sendToServer( p ); + for (int h = 0; h < times; h++) { + final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0); + NetworkHandler.instance.sendToServer(p); } } } } - protected boolean enableSpaceClicking() - { + protected boolean enableSpaceClicking() { return true; } - public void bindTexture( final String base, final String file ) - { - final ResourceLocation loc = new ResourceLocation( base, "textures/" + file ); - this.mc.getTextureManager().bindTexture( loc ); + public void bindTexture(final String base, final String file) { + final ResourceLocation loc = new ResourceLocation(base, "textures/" + file); + this.mc.getTextureManager().bindTexture(loc); } - protected void drawItem( final int x, final int y, final ItemStack is ) - { + protected void drawItem(final int x, final int y, final ItemStack is) { this.zLevel = 100.0F; itemRender.zLevel = 100.0F; - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glEnable( GL11.GL_LIGHTING ); - GL11.glEnable( GL12.GL_RESCALE_NORMAL ); - GL11.glEnable( GL11.GL_DEPTH_TEST ); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_DEPTH_TEST); RenderHelper.enableGUIStandardItemLighting(); - itemRender.renderItemAndEffectIntoGUI( this.fontRendererObj, this.mc.renderEngine, is, x, y ); + itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.renderEngine, is, x, y); GL11.glPopAttrib(); itemRender.zLevel = 0.0F; this.zLevel = 0.0F; } - protected String getGuiDisplayName( final String in ) - { + protected String getGuiDisplayName(final String in) { return this.hasCustomInventoryName() ? this.getInventoryName() : in; } - private boolean hasCustomInventoryName() - { - if( this.inventorySlots instanceof WCTBaseContainer ) - { - return ( (WCTBaseContainer) this.inventorySlots ).getCustomName() != null; + private boolean hasCustomInventoryName() { + if (this.inventorySlots instanceof WCTBaseContainer) { + return ((WCTBaseContainer) this.inventorySlots).getCustomName() != null; } return false; } - private String getInventoryName() - { - return ( (WCTBaseContainer) this.inventorySlots ).getCustomName(); + private String getInventoryName() { + return ((WCTBaseContainer) this.inventorySlots).getCustomName(); } - private void drawSlot( final Slot s ) - { - if( s instanceof SlotME ) - { - final RenderItem pIR = this.setItemRender( this.aeRenderItem ); - try - { + private void drawSlot(final Slot s) { + if (s instanceof SlotME) { + final RenderItem pIR = this.setItemRender(this.aeRenderItem); + try { this.zLevel = 100.0F; itemRender.zLevel = 100.0F; - if( !this.isPowered() ) - { - GL11.glDisable( GL11.GL_LIGHTING ); - drawRect( s.xDisplayPosition, s.yDisplayPosition, 16 + s.xDisplayPosition, 16 + s.yDisplayPosition, 0x66111111 ); - GL11.glEnable( GL11.GL_LIGHTING ); + if (!this.isPowered()) { + GL11.glDisable(GL11.GL_LIGHTING); + drawRect(s.xDisplayPosition, s.yDisplayPosition, 16 + s.xDisplayPosition, 16 + s.yDisplayPosition, 0x66111111); + GL11.glEnable(GL11.GL_LIGHTING); } this.zLevel = 0.0F; itemRender.zLevel = 0.0F; - this.aeRenderItem.setAeStack( ( (SlotME) s ).getAEStack() ); + this.aeRenderItem.setAeStack(((SlotME) s).getAEStack()); - this.safeDrawSlot( s ); + this.safeDrawSlot(s); } - catch( final Exception err ) - { - WCTLog.warning( "WCT prevented crash while drawing slot: " + err.toString() ); + catch (final Exception err) { + WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); } - this.setItemRender( pIR ); + this.setItemRender(pIR); return; } - else - { - try - { + else { + try { final ItemStack is = s.getStack(); - if( s instanceof AppEngSlot && ( ( (AppEngSlot) s ).renderIconWithItem() || is == null ) && ( ( (AppEngSlot) s ).shouldDisplay() ) ) - { + if (s instanceof AppEngSlot && (((AppEngSlot) s).renderIconWithItem() || is == null) && (((AppEngSlot) s).shouldDisplay())) { final AppEngSlot aes = (AppEngSlot) s; - if( aes.getIcon() >= 0 ) - { - this.bindTexture( "guis/states.png" ); + if (aes.getIcon() >= 0) { + this.bindTexture("guis/states.png"); - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); final Tessellator tessellator = Tessellator.instance; - try - { - final int uv_y = (int) Math.floor( aes.getIcon() / 16 ); + try { + final int uv_y = (int) Math.floor(aes.getIcon() / 16); final int uv_x = aes.getIcon() - uv_y * 16; - GL11.glEnable( GL11.GL_BLEND ); - GL11.glDisable( GL11.GL_LIGHTING ); - GL11.glEnable( GL11.GL_TEXTURE_2D ); - GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); - GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); final float par1 = aes.xDisplayPosition; final float par2 = aes.yDisplayPosition; final float par3 = uv_x * 16; final float par4 = uv_y * 16; tessellator.startDrawingQuads(); - tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() ); + tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon()); final float f1 = 0.00390625F; final float f = 0.00390625F; final float par6 = 16; - tessellator.addVertexWithUV( par1 + 0, par2 + par6, this.zLevel, ( par3 + 0 ) * f, ( par4 + par6 ) * f1 ); + tessellator.addVertexWithUV(par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, (par4 + par6) * f1); final float par5 = 16; - tessellator.addVertexWithUV( par1 + par5, par2 + par6, this.zLevel, ( par3 + par5 ) * f, ( par4 + par6 ) * f1 ); - tessellator.addVertexWithUV( par1 + par5, par2 + 0, this.zLevel, ( par3 + par5 ) * f, ( par4 + 0 ) * f1 ); - tessellator.addVertexWithUV( par1 + 0, par2 + 0, this.zLevel, ( par3 + 0 ) * f, ( par4 + 0 ) * f1 ); - tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, 1.0f ); + tessellator.addVertexWithUV(par1 + par5, par2 + par6, this.zLevel, (par3 + par5) * f, (par4 + par6) * f1); + tessellator.addVertexWithUV(par1 + par5, par2 + 0, this.zLevel, (par3 + par5) * f, (par4 + 0) * f1); + tessellator.addVertexWithUV(par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f, (par4 + 0) * f1); + tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, 1.0f); tessellator.draw(); } - catch( final Exception err ) - { + catch (final Exception err) { } GL11.glPopAttrib(); } } - if( is != null && s instanceof AppEngSlot ) - { - if( ( (AppEngSlot) s ).getIsValid() == hasCalculatedValidness.NotAvailable ) - { - boolean isValid = s.isItemValid( is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected; - if( isValid && s instanceof SlotRestrictedInput ) - { - try - { - isValid = ( (SlotRestrictedInput) s ).isValid( is, this.mc.theWorld ); + if (is != null && s instanceof AppEngSlot) { + if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) { + boolean isValid = s.isItemValid(is) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected; + if (isValid && s instanceof SlotRestrictedInput) { + try { + isValid = ((SlotRestrictedInput) s).isValid(is, this.mc.theWorld); } - catch( final Exception err ) - { - WCTLog.debug( err.getMessage() ); + catch (final Exception err) { + WCTLog.debug(err.getMessage()); } } - ( (AppEngSlot) s ).setIsValid( isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid ); + ((AppEngSlot) s).setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid); } - if( ( (AppEngSlot) s ).getIsValid() == hasCalculatedValidness.Invalid ) - { + if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) { this.zLevel = 100.0F; itemRender.zLevel = 100.0F; - GL11.glDisable( GL11.GL_LIGHTING ); - drawRect( s.xDisplayPosition, s.yDisplayPosition, 16 + s.xDisplayPosition, 16 + s.yDisplayPosition, 0x66ff6666 ); - GL11.glEnable( GL11.GL_LIGHTING ); + GL11.glDisable(GL11.GL_LIGHTING); + drawRect(s.xDisplayPosition, s.yDisplayPosition, 16 + s.xDisplayPosition, 16 + s.yDisplayPosition, 0x66ff6666); + GL11.glEnable(GL11.GL_LIGHTING); this.zLevel = 0.0F; itemRender.zLevel = 0.0F; } } - if( s instanceof AppEngSlot ) - { - ( (AppEngSlot) s ).setDisplay( true ); - this.safeDrawSlot( s ); + if (s instanceof AppEngSlot) { + ((AppEngSlot) s).setDisplay(true); + this.safeDrawSlot(s); } - else - { - this.safeDrawSlot( s ); + else { + this.safeDrawSlot(s); } return; } - catch( final Exception err ) - { - WCTLog.warning( "WCT prevented crash while drawing slot: " + err.toString() ); + catch (final Exception err) { + WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString()); } } // do the usual for non-ME Slots. - this.safeDrawSlot( s ); + this.safeDrawSlot(s); } - private RenderItem setItemRender( final RenderItem item ) - { - if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.NEI ) ) - { - return ( (INEI) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.NEI ) ).setItemRender( item ); + private RenderItem setItemRender(final RenderItem item) { + if (Loader.isModLoaded("NotEnoughItems")) { + return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); } - else - { + else { final RenderItem ri = itemRender; itemRender = item; return ri; } } - protected boolean isPowered() - { + protected boolean isPowered() { return true; } - private void safeDrawSlot( final Slot s ) - { - try - { - GuiContainer.class.getDeclaredMethod( "func_146977_a_original", Slot.class ).invoke( this, s ); + private void safeDrawSlot(final Slot s) { + try { + GuiContainer.class.getDeclaredMethod("func_146977_a_original", Slot.class).invoke(this, s); } - catch( final Exception err ) - { + catch (final Exception err) { } } - public void bindTexture( final String file ) - { - final ResourceLocation loc = new ResourceLocation( "appliedenergistics2", "textures/" + file ); - this.mc.getTextureManager().bindTexture( loc ); + public void bindTexture(final String file) { + final ResourceLocation loc = new ResourceLocation("appliedenergistics2", "textures/" + file); + this.mc.getTextureManager().bindTexture(loc); } - public void func_146977_a( final Slot s ) - { - this.drawSlot( s ); + public void func_146977_a(final Slot s) { + this.drawSlot(s); } - protected GuiScrollbar getScrollBar() - { + protected GuiScrollbar getScrollBar() { return this.scrollBar; } - protected void setScrollBar( final GuiScrollbar myScrollBar ) - { + protected void setScrollBar(final GuiScrollbar myScrollBar) { this.scrollBar = myScrollBar; } - protected List getMeSlots() - { + protected List getMeSlots() { return this.meSlots; } - public static final synchronized boolean isSwitchingGuis() - { + public static final synchronized boolean isSwitchingGuis() { return switchingGuis; } - public static final synchronized void setSwitchingGuis( final boolean switchingGuis ) - { + public static final synchronized void setSwitchingGuis(final boolean switchingGuis) { WCTBaseGui.switchingGuis = switchingGuis; } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java index b9c9dde..7bb1c94 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/common/WirelessCraftingTerminal.java @@ -11,7 +11,6 @@ import java.io.File; import appeng.api.AEApi; import appeng.api.features.IWirelessTermHandler; import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.core.crash.IntegrationCrashEnhancement; import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler; import net.p455w0rd.wirelesscraftingterminal.creativetab.CreativeTabWCT; import net.p455w0rd.wirelesscraftingterminal.handlers.AchievementHandler; @@ -22,7 +21,8 @@ import net.p455w0rd.wirelesscraftingterminal.proxy.CommonProxy; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; -@Mod(modid = Reference.MODID, acceptedMinecraftVersions = "[1.7.10]", name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, dependencies = "required-after:Forge@[" +@Mod(modid = Reference.MODID, acceptedMinecraftVersions = "[1.7.10]", name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY, dependencies = "" + + "required-after:Forge@[" + net.minecraftforge.common.ForgeVersion.majorVersion + '.' // majorVersion + net.minecraftforge.common.ForgeVersion.minorVersion + '.' // minorVersion + net.minecraftforge.common.ForgeVersion.revisionVersion + '.' // revisionVersion @@ -42,9 +42,6 @@ public class WirelessCraftingTerminal { @EventHandler public void preInit(FMLPreInitializationEvent event) { - if (!Loader.isModLoaded("wct-core")) { - WirelessCraftingTerminal.proxy.missingCoreMod(); - } long stopwatch = WCTLog.beginSection("PreInit"); WirelessCraftingTerminal.WCTState = LoaderState.PREINITIALIZATION; WirelessCraftingTerminal.INSTANCE = this; @@ -59,9 +56,9 @@ public class WirelessCraftingTerminal { @EventHandler public void init(FMLInitializationEvent event) { long stopwatch = WCTLog.beginSection("Init"); + IntegrationRegistry.INSTANCE.init(); WirelessCraftingTerminal.WCTState = LoaderState.INITIALIZATION; RecipeHandler.addRecipes(true); - IntegrationRegistry.INSTANCE.init(); AchievementHandler.init(); WCTLog.endSection("Init", stopwatch); } @@ -70,7 +67,6 @@ public class WirelessCraftingTerminal { public void postInit(final FMLPostInitializationEvent event) { long stopwatch = WCTLog.beginSection("PostInit"); IntegrationRegistry.INSTANCE.postInit(); - FMLCommonHandler.instance().registerCrashCallable(new IntegrationCrashEnhancement()); NetworkRegistry.INSTANCE.registerGuiHandler(WirelessCraftingTerminal.INSTANCE, new WCTGuiHandler()); NetworkHandler.instance = new NetworkHandler("WCT"); WirelessCraftingTerminal.proxy.removeItemsFromNEI(); diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/BaseCrashEnhancement.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/BaseCrashEnhancement.java deleted file mode 100644 index cc11234..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/BaseCrashEnhancement.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.crash; - -import cpw.mods.fml.common.ICrashCallable; - - -abstract class BaseCrashEnhancement implements ICrashCallable -{ - private final String name; - private final String value; - - public BaseCrashEnhancement( final String name, final String value ) - { - this.name = name; - this.value = value; - } - - @Override - public final String call() throws Exception - { - return this.value; - } - - @Override - public final String getLabel() - { - return this.name; - } -} diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/IntegrationCrashEnhancement.java b/src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/IntegrationCrashEnhancement.java deleted file mode 100644 index 68f702f..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/core/crash/IntegrationCrashEnhancement.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.core.crash; - -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; - -public class IntegrationCrashEnhancement extends BaseCrashEnhancement -{ - public IntegrationCrashEnhancement() - { - super( "AE2 Integration", IntegrationRegistry.INSTANCE.getStatus() ); - } -} diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java index 3d43efc..650559f 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/handlers/ConfigHandler.java @@ -3,13 +3,12 @@ package net.p455w0rd.wirelesscraftingterminal.handlers; import java.io.File; import cpw.mods.fml.client.event.ConfigChangedEvent; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import net.p455w0rd.wirelesscraftingterminal.common.WirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; @@ -115,7 +114,7 @@ public class ConfigHandler { } public static void removeBoosterIcon() { - if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) { + if (Loader.isModLoaded("NotEnoughItems")) { if (!codechicken.nei.api.ItemInfo.hiddenItems.contains(ItemEnum.BOOSTER_ICON.getStack())) { codechicken.nei.api.API.hideItem(ItemEnum.BOOSTER_ICON.getStack()); } @@ -124,14 +123,14 @@ public class ConfigHandler { public static void removeBooster() { if (Reference.WCT_BOOSTER_ENABLED) { - if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) { + if (Loader.isModLoaded("NotEnoughItems")) { if (codechicken.nei.api.ItemInfo.hiddenItems.contains(ItemEnum.BOOSTER_CARD.getStack())) { codechicken.nei.api.ItemInfo.hiddenItems.remove(ItemEnum.BOOSTER_CARD.getStack()); } } ItemEnum.BOOSTER_CARD.getItem().setCreativeTab(WirelessCraftingTerminal.creativeTab); } else { - if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) { + if (Loader.isModLoaded("NotEnoughItems")) { codechicken.nei.api.API.hideItem(ItemEnum.BOOSTER_CARD.getStack()); } ItemEnum.BOOSTER_CARD.getItem().setCreativeTab(null); diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationHelper.java b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationHelper.java index d080b82..01f5ec3 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationHelper.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationHelper.java @@ -3,8 +3,8 @@ package net.p455w0rd.wirelesscraftingterminal.integration; public class IntegrationHelper { - public static void testClassExistence( final Object o, final Class clz ) + public static void testClassExistence( final Object obj, final Class clazz ) { - clz.isInstance( o ); + clazz.isInstance(obj); } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationRegistry.java b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationRegistry.java index 3c75b61..a545b1a 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationRegistry.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationRegistry.java @@ -8,75 +8,64 @@ import javax.annotation.Nonnull; import cpw.mods.fml.relauncher.FMLLaunchHandler; import cpw.mods.fml.relauncher.Side; - -public enum IntegrationRegistry -{ +public enum IntegrationRegistry { INSTANCE; private static final String PACKAGE_PREFIX = "net.p455w0rd.wirelesscraftingterminal.integration.modules."; private final Collection modules = new LinkedList(); - public void add( final IntegrationType type ) - { - if( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER ) - { + public void add(final IntegrationType type) { + if (type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER) { return; } - if( type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT ) - { + if (type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT) { return; } - this.modules.add( new IntegrationNode( type.dspName, type.modID, type, PACKAGE_PREFIX + type.name() ) ); + this.modules.add(new IntegrationNode(type.dspName, type.modID, type, PACKAGE_PREFIX + type.name())); } - public void init() - { - for( final IntegrationNode node : this.modules ) + public void init() { + for (final IntegrationType type : IntegrationType.values()) { - node.call( IntegrationStage.PRE_INIT ); + IntegrationRegistry.INSTANCE.add(type); + } + + for (final IntegrationNode node : this.modules) { + node.call(IntegrationStage.PRE_INIT); } - for( final IntegrationNode node : this.modules ) - { - node.call( IntegrationStage.INIT ); + for (final IntegrationNode node : this.modules) { + node.call(IntegrationStage.INIT); } } - public void postInit() - { - for( final IntegrationNode node : this.modules ) - { - node.call( IntegrationStage.POST_INIT ); + public void postInit() { + for (final IntegrationNode node : this.modules) { + node.call(IntegrationStage.POST_INIT); } } - public String getStatus() - { - final StringBuilder builder = new StringBuilder( this.modules.size() * 3 ); + public String getStatus() { + final StringBuilder builder = new StringBuilder(this.modules.size() * 3); - for( final IntegrationNode node : this.modules ) - { - if( builder.length() != 0 ) - { - builder.append( ", " ); + for (final IntegrationNode node : this.modules) { + if (builder.length() != 0) { + builder.append(", "); } - final String integrationState = node.getShortName() + ":" + ( node.getState() == IntegrationStage.FAILED ? "OFF" : "ON" ); - builder.append( integrationState ); + final String integrationState = node.getShortName() + ":" + (node.getState() == IntegrationStage.FAILED ? "OFF" : "ON"); + builder.append(integrationState); } return builder.toString(); } - public boolean isEnabled( final IntegrationType name ) - { - for( final IntegrationNode node : this.modules ) - { - if( node.getShortName() == name ) - { + public boolean isEnabled(final IntegrationType name) { + for (final IntegrationNode node : this.modules) { + if (node.getShortName() == name) { return node.isActive(); } } @@ -84,17 +73,14 @@ public enum IntegrationRegistry } @Nonnull - public Object getInstance( final IntegrationType name ) - { - for( final IntegrationNode node : this.modules ) - { - if( node.getShortName() == name && node.isActive() ) - { + public Object getInstance(final IntegrationType name) { + for (final IntegrationNode node : this.modules) { + if (node.getShortName() == name && node.isActive()) { return node.getInstance(); } } - throw new IllegalStateException( "integration with " + name.name() + " is disabled." ); + throw new IllegalStateException("integration with " + name.name() + " is disabled."); } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationType.java b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationType.java index c184d93..873ede4 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationType.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/IntegrationType.java @@ -9,7 +9,9 @@ public enum IntegrationType //InvTweaks( IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks" ), - NEI( IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems" ); + NEI( IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems" ), + + IC2( IntegrationSide.BOTH, "Industrial Craft 2", "IC2" ); public final IntegrationSide side; public final String dspName; diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/IC2.java b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/IC2.java new file mode 100644 index 0000000..45d8f3b --- /dev/null +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/integration/modules/IC2.java @@ -0,0 +1,47 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package net.p455w0rd.wirelesscraftingterminal.integration.modules; + +import net.p455w0rd.wirelesscraftingterminal.helpers.Reflected; +import net.p455w0rd.wirelesscraftingterminal.integration.IIntegrationModule; +import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationHelper; + +public class IC2 implements IIntegrationModule +{ + @Reflected + public static IC2 instance; + + @Reflected + public IC2() + { + IntegrationHelper.testClassExistence( this, ic2.api.item.IElectricItem.class ); + IntegrationHelper.testClassExistence( this, ic2.api.item.ISpecialElectricItem.class ); + IntegrationHelper.testClassExistence( this, ic2.api.item.IElectricItemManager.class ); + } + + @Override + public void init() + { + } + + @Override + public void postInit() + { + } +} diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java index 91e7ecc..bc19ec5 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemMagnet.java @@ -197,7 +197,7 @@ public class ItemMagnet extends Item { return; if (player == null) return; - + List filteredList = getFilteredItems(this.getItemStack()); // items Iterator iterator = getEntitiesInRange(EntityItem.class, world, (int) player.posX, (int) player.posY, (int) player.posZ, this.distanceFromPlayer).iterator(); @@ -367,6 +367,9 @@ public class ItemMagnet extends Item { } private boolean hasNetworkAccess(final SecurityPermissions perm, final boolean requirePower, EntityPlayer player, ItemStack wirelessTerm) { + if (player.capabilities.isCreativeMode) { + return true; + } final IGrid g = this.obj.getTargetGrid(); if (g != null) { if (requirePower) { diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java index f3946de..f4e55e0 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/items/ItemWirelessCraftingTerminal.java @@ -13,8 +13,11 @@ import appeng.api.config.Settings; import appeng.api.config.SortDir; import appeng.api.config.SortOrder; import appeng.api.config.ViewItems; +import appeng.api.implementations.items.IAEItemPowerStorage; import appeng.api.util.IConfigManager; -import appeng.items.tools.powered.powersink.AEBasePoweredItem; +import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.items.tools.powered.powersink.AERootPoweredItem; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; @@ -22,8 +25,11 @@ import cofh.api.energy.IEnergyContainerItem; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ic2.api.item.IElectricItemManager; +import ic2.api.item.ISpecialElectricItem; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.Item; @@ -37,20 +43,19 @@ import net.p455w0rd.wirelesscraftingterminal.api.WCTApi; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.handlers.LocaleHandler; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; -import net.p455w0rd.wirelesscraftingterminal.transformer.annotations.Integration.Interface; -@Interface(iface = "cofh.api.energy.IEnergyContainerItem", iname = IntegrationType.RFItem) -public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements IWirelessCraftingTermHandler, IEnergyContainerItem { +public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTermHandler, IAEItemPowerStorage, IAEFeature, IEnergyContainerItem, IElectricItemManager, ISpecialElectricItem +{ private static final String LINK_KEY_STRING = "key"; public static double GLOBAL_POWER_MULTIPLIER = PowerMultiplier.CONFIG.multiplier; private static final String POWER_NBT_KEY = "internalCurrentPower"; private static final String BOOSTER_SLOT_NBT = "BoosterSlot"; private static final String MAGNET_SLOT_NBT = "MagnetSlot"; + private EntityPlayer entityPlayer; public ItemWirelessCraftingTerminal() { - super(Reference.WCT_MAX_POWER, Optional. absent()); + super(Reference.WCT_MAX_POWER, Optional.absent()); setUnlocalizedName("wirelessCraftingTerminal"); setTextureName(Reference.MODID + ":wirelessCraftingTerminal"); setMaxStackSize(1); @@ -100,6 +105,9 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I return; } EntityPlayer p = (EntityPlayer) e; + if (this.entityPlayer == null) { + this.entityPlayer = p; + } ItemStack wirelessTerminal = null; InventoryPlayer inv = p.inventory; wirelessTerminal = RandomUtils.getWirelessTerm(inv); @@ -199,9 +207,11 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I return true; } - @Override + + @SuppressWarnings({ "rawtypes", "unchecked" }) @SideOnly(Side.CLIENT) - public void addCheckedInformation(ItemStack is, EntityPlayer player, List list, boolean displayMore) { + @Override + public void addCheckedInformation(ItemStack is, EntityPlayer player, List list, boolean displayMore) { String shift = LocaleHandler.PressShift.getLocal().replace("Shift", color("yellow") + "" + color("bold") + "" + color("italics") + "Shift" + color("gray")); final NBTTagCompound tag = ensureTagCompound(is); @@ -311,7 +321,11 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I @Override public double extractAEPower(final ItemStack is, final double amt) { - return getInternalBattery(is, batteryOperation.EXTRACT, amt); + int finalAmt = 0; + if (this.entityPlayer != null) { + finalAmt = (int) (this.entityPlayer.capabilities.isCreativeMode ? 0 : amt); + } + return getInternalBattery(is, batteryOperation.EXTRACT, finalAmt); } @Override @@ -319,6 +333,42 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I return Reference.WCT_MAX_POWER; } + private enum batteryOperation { + STORAGE, INJECT, EXTRACT + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean isDamaged(final ItemStack stack) { + return false; + } + + @Override + public boolean isRepairable() { + return false; + } + + @SideOnly(Side.CLIENT) + @Override + public boolean isFull3D() { + return false; + } + + @Override + public int getMaxDamage() { + return 0; + } + + @Override + public int getDamage(ItemStack stack) { + return 0; + } + + //RF Integration @Override public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { if (container == null) { @@ -373,40 +423,132 @@ public class ItemWirelessCraftingTerminal extends AEBasePoweredItem implements I public int getMaxEnergyStored(ItemStack container) { return (int) PowerUnits.AE.convertTo(PowerUnits.RF, getAEMaxPower(container)); } + + //IC2 integration + private double wctInjectExternalPower( final PowerUnits input, final ItemStack is, final double amount, final boolean simulate ) + { + if( simulate ) + { + final int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, this.getAEMaxPower( is ) - this.getAECurrentPower( is ) ); + if( amount < requiredEU ) + { + return 0; + } + return amount - requiredEU; + } + else + { + final double powerRemainder = this.injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) ); + return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder ); + } + } + + @Override + public double charge( final ItemStack is, final double amount, final int tier, final boolean ignoreTransferLimit, final boolean simulate ) + { + double addedAmt = amount; + final double limit = this.getTransferLimit( is ); - private enum batteryOperation { - STORAGE, INJECT, EXTRACT + if( !ignoreTransferLimit && amount > limit ) + { + addedAmt = limit; + } + + return addedAmt - ( (int) this.wctInjectExternalPower( PowerUnits.EU, is, addedAmt, simulate ) ); } @Override - public boolean isDamageable() { - return false; - } - - @Override - public boolean isDamaged(final ItemStack stack) { - return false; - } - - @Override - public boolean isRepairable() { - return false; - } - - @SideOnly(Side.CLIENT) - @Override - public boolean isFull3D() { - return false; - } - - @Override - public int getMaxDamage() { + public double discharge( final ItemStack itemStack, final double amount, final int tier, final boolean ignoreTransferLimit, final boolean externally, final boolean simulate ) + { return 0; } @Override - public int getDamage(ItemStack stack) { - return 0; + public double getCharge( final ItemStack is ) + { + return (int) PowerUnits.AE.convertTo( PowerUnits.EU, this.getAECurrentPower( is ) ); + } + + @Override + public boolean canUse( final ItemStack is, final double amount ) + { + return this.getCharge( is ) > amount; + } + + @Override + public boolean use( final ItemStack is, final double amount, final EntityLivingBase entity ) + { + if( this.canUse( is, amount ) ) + { + // use the power.. + this.extractAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) ); + return true; + } + return false; + } + + @Override + public void chargeFromArmor( final ItemStack itemStack, final EntityLivingBase entity ) + { + // wtf? + } + + @Override + public String getToolTip( final ItemStack itemStack ) + { + return null; + } + + @Override + public boolean canProvideEnergy( final ItemStack itemStack ) + { + return false; + } + + @Override + public Item getChargedItem( final ItemStack itemStack ) + { + return itemStack.getItem(); + } + + @Override + public Item getEmptyItem( final ItemStack itemStack ) + { + return itemStack.getItem(); + } + + @Override + public double getMaxCharge( final ItemStack itemStack ) + { + return PowerUnits.AE.convertTo( PowerUnits.EU, this.getAEMaxPower( itemStack ) ); + } + + @Override + public int getTier( final ItemStack itemStack ) + { + return 1; + } + + @Override + public double getTransferLimit( final ItemStack itemStack ) + { + return Math.max( 32, this.getMaxCharge( itemStack ) / 200 ); + } + + @Override + public IElectricItemManager getManager( final ItemStack itemStack ) + { + return this; + } + + @Override + public IFeatureHandler handler() { + return null; + } + + @Override + public void postInit() { + // X) } } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java index 2c4fcb5..85b3ca5 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/ClientProxy.java @@ -1,13 +1,11 @@ package net.p455w0rd.wirelesscraftingterminal.proxy; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.p455w0rd.wirelesscraftingterminal.handlers.KeybindHandler; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; -import net.p455w0rd.wirelesscraftingterminal.transformer.MissingCoreMod; public class ClientProxy extends CommonProxy { @@ -19,7 +17,7 @@ public class ClientProxy extends CommonProxy { @Override public void removeItemsFromNEI() { - if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) { + if (Loader.isModLoaded("NotEnoughItems")) { codechicken.nei.api.API.hideItem(new ItemStack(ItemEnum.WCT_BOOSTER_BG_ICON.getItem(), 1)); return; } @@ -29,9 +27,4 @@ public class ClientProxy extends CommonProxy { // No renderers...yet =] } - @Override - public void missingCoreMod() { - throw new MissingCoreMod(); - } - } diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java index ef2b5bc..cff3c91 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/proxy/CommonProxy.java @@ -59,10 +59,6 @@ public class CommonProxy { // =P } - public void missingCoreMod() { - throw new IllegalStateException("Unable to Load WCT Core Mod, please verify that WCT is properly install in the mods folder, with a .jar extension."); - } - @SubscribeEvent public void tickEvent(TickEvent.PlayerTickEvent e) { ItemStack wirelessTerm = null; diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/reference/Reference.java b/src/java/net/p455w0rd/wirelesscraftingterminal/reference/Reference.java index ccb64f0..75a14f8 100644 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/reference/Reference.java +++ b/src/java/net/p455w0rd/wirelesscraftingterminal/reference/Reference.java @@ -2,7 +2,7 @@ package net.p455w0rd.wirelesscraftingterminal.reference; public class Reference { public static final String MODID = "ae2wct"; - public static final String VERSION = "1.7.10-rv3-1.6b"; + public static final String VERSION = "@version@"; public static final String NAME = "AE2 Wireless Crafting Terminal"; public static final String SERVER_PROXY_CLASS = "net.p455w0rd.wirelesscraftingterminal.proxy.CommonProxy"; public static final String CLIENT_PROXY_CLASS = "net.p455w0rd.wirelesscraftingterminal.proxy.ClientProxy"; diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/Integration.java b/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/Integration.java deleted file mode 100644 index e614b32..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/Integration.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.transformer; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; - -public @interface Integration -{ - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.TYPE ) - @interface InterfaceList - { - Interface[] value(); - } - - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.TYPE ) - @interface Interface - { - String iface(); - - IntegrationType iname(); - } - - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.METHOD ) - @interface Method - { - IntegrationType iname(); - } -} \ No newline at end of file diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/MissingCoreMod.java b/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/MissingCoreMod.java deleted file mode 100644 index 1a64e31..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/MissingCoreMod.java +++ /dev/null @@ -1,82 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.transformer; - -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiErrorScreen; - -import cpw.mods.fml.client.CustomModLoadingErrorDisplayException; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - - -@SideOnly( Side.CLIENT ) -public final class MissingCoreMod extends CustomModLoadingErrorDisplayException -{ - private static final int SHADOW_WHITE = 0xeeeeee; - private static final int COLOR_WHITE = 0xffffff; - private static final long serialVersionUID = -966774766922821652L; - private static final int SCREEN_OFFSET = 15; - - private boolean deobf = false; - - @Override - public void initGui( final GuiErrorScreen errorScreen, final FontRenderer fontRenderer ) - { - final Class clz = errorScreen.getClass(); - try - { - clz.getField( "mc" ); - this.deobf = true; - } - catch( final Throwable ignored ) - { - - } - } - - @Override - public void drawScreen( final GuiErrorScreen errorScreen, final FontRenderer fontRenderer, final int mouseRelX, final int mouseRelY, final float tickTime ) - { - int offset = 10; - this.drawCenteredString( fontRenderer, "Sorry, couldn't load WCT properly.", errorScreen.width / 2, offset, COLOR_WHITE ); - - offset += SCREEN_OFFSET; - this.drawCenteredString( fontRenderer, "Please make sure that WCT is installed into your mods folder.", errorScreen.width / 2, offset, SHADOW_WHITE ); - - offset += 2 * SCREEN_OFFSET; - - if( this.deobf ) - { - offset += SCREEN_OFFSET; - this.drawCenteredString( fontRenderer, "In a developer environment add the following too your args,", errorScreen.width / 2, offset, COLOR_WHITE ); - - offset += SCREEN_OFFSET; - this.drawCenteredString( fontRenderer, "-Dfml.coreMods.load=net.p455w0rd.wirelesscraftingterminal.transformer.WCTCore", errorScreen.width / 2, offset, SHADOW_WHITE ); - } - else - { - this.drawCenteredString( fontRenderer, "You're launcher may refer to this by different names,", errorScreen.width / 2, offset, COLOR_WHITE ); - - offset += SCREEN_OFFSET + 5; - - this.drawCenteredString( fontRenderer, "MultiMC calls this tab \"Loader Mods\"", errorScreen.width / 2, offset, SHADOW_WHITE ); - - offset += SCREEN_OFFSET; - this.drawCenteredString( fontRenderer, "Magic Launcher calls this tab \"External Mods\"", errorScreen.width / 2, offset, SHADOW_WHITE ); - - offset += SCREEN_OFFSET; - this.drawCenteredString( fontRenderer, "Most other launchers refer to this tab as just \"Mods\"", errorScreen.width / 2, offset, SHADOW_WHITE ); - - offset += 2 * SCREEN_OFFSET; - this.drawCenteredString( fontRenderer, "Also make sure that the WCT file is a .jar, and not a .zip", errorScreen.width / 2, offset, COLOR_WHITE ); - } - } - - private void drawCenteredString( final FontRenderer fontRenderer, final String string, final int x, final int y, final int colour ) - { - final String reEncoded = string.replaceAll( "\\P{InBasic_Latin}", "" ); - final int reEncodedWidth = fontRenderer.getStringWidth( reEncoded ); - final int centeredX = x - reEncodedWidth / 2; - - fontRenderer.drawStringWithShadow( string, centeredX, y, colour ); - } -} \ No newline at end of file diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/WCTCore.java b/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/WCTCore.java deleted file mode 100644 index 106ed01..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/WCTCore.java +++ /dev/null @@ -1,136 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.transformer; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Nullable; - -import com.google.common.collect.Lists; -import com.google.common.eventbus.EventBus; - -import cpw.mods.fml.common.DummyModContainer; -import cpw.mods.fml.common.LoadController; -import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.ModMetadata; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.relauncher.FMLRelaunchLog; -import cpw.mods.fml.relauncher.IFMLLoadingPlugin; -import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion; -import cpw.mods.fml.common.versioning.ArtifactVersion; -import cpw.mods.fml.common.versioning.VersionParser; -import net.p455w0rd.wirelesscraftingterminal.reference.Reference; - - - -@MCVersion( "1.7.10" ) -public final class WCTCore extends DummyModContainer implements IFMLLoadingPlugin -{ - private final ModMetadata metadata = new ModMetadata(); - - public WCTCore() - { - FMLRelaunchLog.info( "[WCT] Core Init" ); - this.metadata.autogenerated = false; - this.metadata.authorList.add( "p455w0rd" ); - this.metadata.credits = "AlgorithmX2"; - this.metadata.modId = this.getModId(); - this.metadata.version = this.getVersion(); - this.metadata.name = this.getName(); - this.metadata.url = "http://p455w0rd.net/mc"; - this.metadata.description = "Embedded Coremod for Wireless Crafting Terminal"; - this.metadata.autogenerated = false; - this.metadata.dependencies=this.getDependencies(); - this.metadata.requiredMods=this.getRequirements(); - } - - @EventHandler - public void load( final FMLInitializationEvent event ) - { - } - - @Override - public List getDependencies() - { - List deps = Lists.newArrayList(); - deps.add(VersionParser.parseVersionReference("appliedenergistics2-core")); - return deps; - } - - @Override - public Set getRequirements() - { - Set reqDeps = new HashSet(); - reqDeps.add(VersionParser.parseVersionReference("appliedenergistics2-core")); - return reqDeps; - } - - - @Override - public String[] getASMTransformerClass() - { - return null; - } - - @Override - public String getModContainerClass() - { - return "net.p455w0rd.wirelesscraftingterminal.transformer.WCTCore"; - } - - @Nullable - @Override - public String getSetupClass() - { - return null; - } - - @Override - public void injectData( final Map data ) - { - - } - - @Override - public String getAccessTransformerClass() - { - return "net.p455w0rd.wirelesscraftingterminal.transformer.asm.ASMIntegration"; - } - - @Override - public ModMetadata getMetadata() - { - return this.metadata; - } - - @Override - public String getModId() - { - return "wct-core"; - } - - @Override - public String getName() - { - return "Wireless Crafting Terminal Core"; - } - - @Override - public String getVersion() - { - return Reference.VERSION; - } - - @Override - public boolean registerBus( final EventBus bus, final LoadController controller ) - { - return true; - } - - @Override - public String getDisplayVersion() - { - return this.getVersion(); - } -} diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/annotations/Integration.java b/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/annotations/Integration.java deleted file mode 100644 index 695a29d..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/annotations/Integration.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.transformer.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; - - -public @interface Integration -{ - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.TYPE ) - @interface InterfaceList - { - Interface[] value(); - } - - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.TYPE ) - @interface Interface - { - String iface(); - - IntegrationType iname(); - } - - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.METHOD ) - @interface Method - { - IntegrationType iname(); - } -} diff --git a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/asm/ASMIntegration.java b/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/asm/ASMIntegration.java deleted file mode 100644 index 9d43305..0000000 --- a/src/java/net/p455w0rd/wirelesscraftingterminal/transformer/asm/ASMIntegration.java +++ /dev/null @@ -1,182 +0,0 @@ -package net.p455w0rd.wirelesscraftingterminal.transformer.asm; - -import java.util.Iterator; - -import javax.annotation.Nullable; - -import org.apache.logging.log4j.Level; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AnnotationNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; - -import net.minecraft.launchwrapper.IClassTransformer; -import net.p455w0rd.wirelesscraftingterminal.helpers.Reflected; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry; -import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType; -import net.p455w0rd.wirelesscraftingterminal.transformer.Integration; -import cpw.mods.fml.relauncher.FMLRelaunchLog; - -@Reflected -public final class ASMIntegration implements IClassTransformer { - @Reflected - public ASMIntegration() { - - /** - * Side, Display Name, ModID ClassPostFix - */ - - for (final IntegrationType type : IntegrationType.values()) { - IntegrationRegistry.INSTANCE.add(type); - } - - } - - @Nullable - @Override - public byte[] transform(final String name, final String transformedName, final byte[] basicClass) { - if (basicClass == null || transformedName.startsWith("net.p455w0rd.wirelesscraftingterminal.transformer")) { - return basicClass; - } - - if (transformedName.startsWith("net.p455w0rd.wirelesscraftingterminal.")) { - final ClassNode classNode = new ClassNode(); - final ClassReader classReader = new ClassReader(basicClass); - classReader.accept(classNode, 0); - - try { - final boolean reWrite = this.removeOptionals(classNode); - - if (reWrite) { - final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); - classNode.accept(writer); - return writer.toByteArray(); - } - } catch (final Throwable t) { - t.printStackTrace(); - } - } - return basicClass; - } - - @SuppressWarnings("rawtypes") - private boolean removeOptionals(final ClassNode classNode) { - boolean changed = false; - - if (classNode.visibleAnnotations != null) { - for (final AnnotationNode an : classNode.visibleAnnotations) { - if (this.hasAnnotation(an, Integration.Interface.class)) { - if (this.stripInterface(classNode, Integration.Interface.class, an)) { - changed = true; - } - } else if (this.hasAnnotation(an, Integration.InterfaceList.class)) { - for (final Object o : ((Iterable) an.values.get(1))) { - if (this.stripInterface(classNode, Integration.InterfaceList.class, (AnnotationNode) o)) { - changed = true; - } - } - } - } - } - - final Iterator i = classNode.methods.iterator(); - while (i.hasNext()) { - final MethodNode mn = i.next(); - - if (mn.visibleAnnotations != null) { - for (final AnnotationNode an : mn.visibleAnnotations) { - if (this.hasAnnotation(an, Integration.Method.class)) { - if (this.stripMethod(classNode, mn, i, Integration.Method.class, an)) { - changed = true; - } - } - } - } - } - - if (changed) { - this.log("Updated " + classNode.name); - } - - return changed; - } - - private boolean hasAnnotation(final AnnotationNode ann, final Class annotation) { - return ann.desc.equals(Type.getDescriptor(annotation)); - } - - private boolean stripInterface(final ClassNode classNode, final Class class1, final AnnotationNode an) { - if (an.values.size() != 4) { - throw new IllegalArgumentException("Unable to handle Interface annotation on " + classNode.name); - } - - String iFace = null; - - if (an.values.get(0).equals("iface")) { - iFace = (String) an.values.get(1); - } else if (an.values.get(2).equals("iface")) { - iFace = (String) an.values.get(3); - } - - String iName = null; - if (an.values.get(0).equals("iname")) { - iName = ((String[]) an.values.get(1))[1]; - } else if (an.values.get(2).equals("iname")) { - iName = ((String[]) an.values.get(3))[1]; - } - - if (iName != null && iFace != null) { - final IntegrationType type = IntegrationType.valueOf(iName); - if (!IntegrationRegistry.INSTANCE.isEnabled(type)) { - this.log("Removing Interface " + iFace + " from " + classNode.name + " because " + iName - + " integration is disabled."); - classNode.interfaces.remove(iFace.replace('.', '/')); - return true; - } else { - this.log("Allowing Interface " + iFace + " from " + classNode.name + " because " + iName - + " integration is enabled."); - } - } else { - throw new IllegalStateException("Unable to handle Method annotation on " + classNode.name); - } - - return false; - } - - @SuppressWarnings("rawtypes") - private boolean stripMethod(final ClassNode classNode, final MethodNode mn, final Iterator i, - final Class class1, final AnnotationNode an) { - if (an.values.size() != 2) { - throw new IllegalArgumentException("Unable to handle Method annotation on " + classNode.name); - } - - String iName = null; - - if (an.values.get(0).equals("iname")) { - iName = ((String[]) an.values.get(1))[1]; - } - - if (iName != null) { - final IntegrationType type = IntegrationType.valueOf(iName); - if (!IntegrationRegistry.INSTANCE.isEnabled(type)) { - this.log("Removing Method " + mn.name + " from " + classNode.name + " because " + iName - + " integration is disabled."); - i.remove(); - return true; - } else { - this.log("Allowing Method " + mn.name + " from " + classNode.name + " because " + iName - + " integration is enabled."); - } - } else { - throw new IllegalStateException("Unable to handle Method annotation on " + classNode.name); - } - - return false; - } - - private void log(final String string) { - FMLRelaunchLog.log("WCT-CORE", Level.INFO, string); - } -} diff --git a/src/resources/META-INF/MANIFEST.MF b/src/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..02ccabc --- /dev/null +++ b/src/resources/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +FMLCorePlugin: net.p455w0rd.wirelesscraftingterminal.transformer.WCTCore +FMLCorePluginContainsFMLMod: true + diff --git a/src/resources/mcmod.info b/src/resources/mcmod.info index a3c0cd0..b25fac6 100644 --- a/src/resources/mcmod.info +++ b/src/resources/mcmod.info @@ -3,8 +3,8 @@ "modid": "ae2wct", "name": "AE2 Wireless Crafting Terminal", "description": "Adds a wireless version of the AE2 Crafting Terminal", - "version": "1.7.10-rv3-1.6b", - "mcversion": "1.7.10", + "version": "${version}", + "mcversion": "${mcversion}", "url": "http://p455w0rd.net/", "updateUrl": "", "authorList": ["TheRealp455w0rd"],