diff --git a/build.gradle b/build.gradle index abc284f6..6b7b083a 100644 --- a/build.gradle +++ b/build.gradle @@ -129,8 +129,7 @@ processResources // Add Coremod Manifest jar { manifest { - attributes 'FMLCorePlugin': 'tconstruct.preloader.TConstructLoaderContainer' - attributes 'FMLCorePluginContainsFMLMod': 'true' + attributes 'FMLAT': 'TConstruct_at.cfg' } } @@ -139,8 +138,7 @@ task deobfJar(type: Jar) { from sourceSets.main.output classifier = 'deobf' manifest { - attributes 'FMLCorePlugin': 'tconstruct.preloader.TConstructLoaderContainer' - attributes 'FMLCorePluginContainsFMLMod': 'true' + attributes 'FMLAT': 'TConstruct_at.cfg' } } diff --git a/src/main/java/tconstruct/library/tools/ToolCore.java b/src/main/java/tconstruct/library/tools/ToolCore.java index dafe2aa5..72bd81c9 100644 --- a/src/main/java/tconstruct/library/tools/ToolCore.java +++ b/src/main/java/tconstruct/library/tools/ToolCore.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Random; +import cpw.mods.fml.common.Optional; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -24,7 +25,6 @@ import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.ToolBuilder; import tconstruct.library.modifier.IModifyable; import tconstruct.library.modifier.ItemModifier; -import tconstruct.tools.TinkerTools; import tconstruct.tools.entity.FancyEntityItem; import cofh.api.energy.IEnergyContainerItem; import cpw.mods.fml.relauncher.Side; @@ -54,13 +54,9 @@ import cpw.mods.fml.relauncher.SideOnly; * @see ItemModifier */ +@Optional.Interface(modid = "CoFHLib", iface = "cofh.api.energy.IEnergyContainerItem") public abstract class ToolCore extends Item implements IEnergyContainerItem, IModifyable { - // TE power constants. These are only for backup if the lookup of the real value somehow fails! - protected int capacity = 400000; - protected int maxReceive = 400000; - protected int maxExtract = 80; - protected Random random = new Random(); protected int damageVsEntity; public static IIcon blankSprite; @@ -785,8 +781,14 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo // TE support section -- from COFH core API reference section + // TE power constants. These are only for backup if the lookup of the real value somehow fails! + protected int capacity = 400000; + protected int maxReceive = 400000; + protected int maxExtract = 80; + /* IEnergyContainerItem */ @Override + @Optional.Method(modid = "CoFHLib") public int receiveEnergy (ItemStack container, int maxReceive, boolean simulate) { NBTTagCompound tags = container.getTagCompound(); @@ -808,6 +810,7 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo } @Override + @Optional.Method(modid = "CoFHLib") public int extractEnergy (ItemStack container, int maxExtract, boolean simulate) { NBTTagCompound tags = container.getTagCompound(); @@ -830,6 +833,7 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo } @Override + @Optional.Method(modid = "CoFHLib") public int getEnergyStored (ItemStack container) { NBTTagCompound tags = container.getTagCompound(); @@ -841,6 +845,7 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo } @Override + @Optional.Method(modid = "CoFHLib") public int getMaxEnergyStored (ItemStack container) { NBTTagCompound tags = container.getTagCompound(); diff --git a/src/main/java/tconstruct/preloader/ASMInterfaceRepair.java b/src/main/java/tconstruct/preloader/ASMInterfaceRepair.java deleted file mode 100644 index b5fb7722..00000000 --- a/src/main/java/tconstruct/preloader/ASMInterfaceRepair.java +++ /dev/null @@ -1,177 +0,0 @@ -package tconstruct.preloader; - -/* - * ASMInterfaceRepair is derived from code graciously provided by AlgorithmX2 of Applied Energistics. - * The code was adapted for this loader by Sunstrike. Any queries should be directed to him, not AlgorithmX2. - */ - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import net.minecraft.launchwrapper.IClassTransformer; - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.signature.SignatureReader; -import org.objectweb.asm.signature.SignatureVisitor; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; - -import tconstruct.preloader.helpers.PropertyManager; - -public class ASMInterfaceRepair implements IClassTransformer -{ - - public static Map APIInterfaces = new HashMap(); - - @Override - public byte[] transform (String name, String transformedName, byte[] bytes) - { - if (name.startsWith("tconstruct.") && !isBlacklisted(name)) - { - ClassReader cr = new ClassReader(bytes); - ClassNode cn = new ClassNode(); - cr.accept(cn, 0); - - boolean changed = false; - - if (this.verifyAPI(cn)) - changed = true; - - if (changed) - { - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); - cn.accept(cw); - bytes = cw.toByteArray(); - log("Altering definition of " + transformedName); - } - } - - return bytes; - } - - private boolean isInternal (String path) - { - return path.startsWith("java/") || path.startsWith("cpw/mods/fml/") || path.startsWith("tconstruct/") || path.startsWith("com/google/") || path.startsWith("net/minecraftforge/") - || path.startsWith("net/minecraft/"); - } - - // Used in transform() above. - private boolean isBlacklisted (String path) - { - return path.startsWith("tconstruct.plugins.") || path.startsWith("tconstruct.preloader."); - } - - private boolean isClassAvailable (String inf) - { - if (APIInterfaces.containsKey(inf)) - return APIInterfaces.get(inf); - - boolean isAvailable = false; - Class obj = null; - - try - { - obj = Class.forName(inf.replace("/", ".")); - // obj = ReflectionHelper.getClass( getClass().getClassLoader(), - // inf.replace( "/", "." ) ); - } - catch (Throwable _) - { - } - - // java.io.InputStream is = this.getClass().getResourceAsStream( "/" + - // inf + ".class" ); - APIInterfaces.put(inf, isAvailable = (obj != null)); - return isAvailable; - } - - class SigChecker extends SignatureVisitor - { - - private ASMInterfaceRepair asmTransformer; - public boolean isAvailable = true; - - public SigChecker(int api, ASMInterfaceRepair t) - { - super(api); - asmTransformer = t; - } - - @Override - public void visitInnerClassType (String name) - { - visitTypeVariable(name); - } - - @Override - public void visitClassType (String name) - { - visitTypeVariable(name); - } - - @Override - public void visitTypeVariable (String className) - { - if (isInternal(className)) - return; - isAvailable = isAvailable && asmTransformer.isClassAvailable(className); - log(className + " is " + (isAvailable ? "available" : "not available")); - } - - } - - private boolean verifyAPI (ClassNode cn) - { - boolean changed = false; - - log("Examining " + cn.name); - - Iterator mn = cn.methods.iterator(); - while (mn.hasNext()) - { - MethodNode meth = mn.next(); - - SigChecker sc = new SigChecker(1, this); - (new SignatureReader(meth.desc)).accept(sc); - - boolean isAvailable = sc.isAvailable; - - if (!isAvailable) - { - mn.remove(); - changed = true; - } - } - - Iterator i = cn.interfaces.iterator(); - while (i.hasNext()) - { - String inf = i.next(); - - if (isInternal(inf)) - continue; - - boolean isAvailable = isClassAvailable(inf); - log(inf + " is " + (isAvailable ? "available" : "not available")); - - if (!isAvailable) - { - i.remove(); - changed = true; - } - } - - return changed; - } - - private void log (String string) - { - if (PropertyManager.asmInterfaceRepair_verboseLog) - { - TConstructLoaderContainer.logger.info(string); - } - } - -} diff --git a/src/main/java/tconstruct/preloader/AccessTransformers.java b/src/main/java/tconstruct/preloader/AccessTransformers.java deleted file mode 100644 index 1423373e..00000000 --- a/src/main/java/tconstruct/preloader/AccessTransformers.java +++ /dev/null @@ -1,13 +0,0 @@ -package tconstruct.preloader; - -import java.io.IOException; - -import cpw.mods.fml.common.asm.transformers.AccessTransformer; - -public class AccessTransformers extends AccessTransformer -{ - public AccessTransformers() throws IOException - { - super("TConstruct_at.cfg"); - } -} \ No newline at end of file diff --git a/src/main/java/tconstruct/preloader/TConstructLoaderContainer.java b/src/main/java/tconstruct/preloader/TConstructLoaderContainer.java deleted file mode 100644 index a91fae0b..00000000 --- a/src/main/java/tconstruct/preloader/TConstructLoaderContainer.java +++ /dev/null @@ -1,136 +0,0 @@ -package tconstruct.preloader; - -/* - * TConstructLoaderContainer is derived from code graciously provided by AlgorithmX2 of Applied Energistics. - * The code was adapted for this loader by Sunstrike. Any queries should be directed to him, not AlgorithmX2. - */ - -import java.util.Arrays; -import java.util.Map; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import tconstruct.preloader.helpers.PropertyManager; -import tconstruct.preloader.helpers.PropertyManager.PropAccessException; - -import com.google.common.eventbus.EventBus; - -import cpw.mods.fml.common.DummyModContainer; -import cpw.mods.fml.common.LoadController; -import cpw.mods.fml.common.ModMetadata; -import cpw.mods.fml.relauncher.IFMLLoadingPlugin; - -public class TConstructLoaderContainer extends DummyModContainer implements IFMLLoadingPlugin -{ - - private final String[] asmTransformers = new String[] { "tconstruct.preloader.ASMInterfaceRepair", "tconstruct.preloader.AccessTransformers" }; - private final ModMetadata md = new ModMetadata(); - - public static Logger logger = LogManager.getLogger("TCorestruct"); - - public TConstructLoaderContainer() - { - //logger.setParent(FMLLog.getLogger()); - logger.info("Scalpel. Suction. Lumber axe. CLEAR! *zap*"); - logger.info("Constructing preloader (Modules: " + Arrays.toString(asmTransformers) + ")"); - try - { - PropertyManager.getOrCreateProps(); - } - catch (PropAccessException ex) - { - logger.error("Could not get or create properties file! Assuming defaults."); - logger.error(Arrays.toString(ex.getStackTrace())); - } - - if (PropertyManager.preloaderContainer_verboseLog) - { - // Log ALL the things. - logger.warn("The preloader will now log absolutely everything. To disable this, either change preloaderContainer_verboseLog"); - logger.warn("in (or delete the config file) '" + PropertyManager.propFileName + "'."); - //logger.setLevel(Level.ALL); - } - - if (PropertyManager.asmInterfaceRepair_verboseLog) - { - logger.warn("ASM Interface Repair is set to be verbose, this is NOT GOOD FOR SERVERS, as it will spam the logs!"); - logger.warn("The debug mode is for debug use only. Turn it off unless instructed otherwise by a TCon developer."); - logger.warn("To reset advanced settings to default, delete the '" + PropertyManager.propFileName + "' file from the config folder."); - } - - md.autogenerated = true; - md.credits = "AlgorithmX2 and Sunstrike"; - md.modId = getModId(); - md.version = getVersion(); - md.name = getName(); - md.authorList = Arrays.asList("AlgorithmX2", "Sunstrike"); - } - - @Override - public String getModId () - { - return "TConstruct-Preloader"; - } - - @Override - public String getName () - { - return "Tinkers Corestruct"; - } - - @Override - public String getVersion () - { - return "0.1.1"; - } - - @Override - public String getDisplayVersion () - { - return getVersion(); - } - - @Override - public ModMetadata getMetadata () - { - return md; - } - - @Override - public boolean registerBus (EventBus bus, LoadController controller) - { - bus.register(this); - return true; - } - - @Override - public String[] getASMTransformerClass () - { - return asmTransformers; - } - - @Override - public String getModContainerClass () - { - return "tconstruct.preloader.TConstructLoaderContainer"; - } - - @Override - public String getSetupClass () - { - return null; - } - - @Override - public void injectData (Map data) - { - } - - //TODO IMPLEMENT THIS - @Override - public String getAccessTransformerClass () - { - return "tconstruct.preloader.AccessTransformers"; - } -} diff --git a/src/main/java/tconstruct/preloader/helpers/PropertyManager.java b/src/main/java/tconstruct/preloader/helpers/PropertyManager.java deleted file mode 100644 index 4dc03efd..00000000 --- a/src/main/java/tconstruct/preloader/helpers/PropertyManager.java +++ /dev/null @@ -1,117 +0,0 @@ -package tconstruct.preloader.helpers; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -import tconstruct.preloader.TConstructLoaderContainer; - -/** - * TCon Preloader properties file helper. - * - * We need this as at an early stage as we don't have access to Forge's - * Configuration object. - * - * @author Sunstrike - */ -public class PropertyManager -{ - - private PropertyManager() - { - } // Singleton - - //TODO 1.8 rename to TCorestruct.cfg - public static final String propFileName = "TConPreloader.cfg"; - - private static String[] vars = new String[] { "preloaderContainer_verboseLog", "asmInterfaceRepair_verboseLog" }; - public static boolean preloaderContainer_verboseLog = false; - public static boolean asmInterfaceRepair_verboseLog = false; - - /** - * Gets or creates the TCorestruct properties file. - * - * @throws PropAccessException - * Thrown if a properties file wasn't found and could not be - * created. Should be treated as a SEVERE log message. - * @return True if loaded from disk, false if file created instead. - */ - public static boolean getOrCreateProps () throws PropAccessException - { - File fp = new File("config/" + propFileName); - Properties props = new Properties(); - if (fp.exists()) - { - // Attempt read - try - { - TConstructLoaderContainer.logger.info("Found a properties file. Attempting load..."); - props.load(new FileInputStream(fp)); - - for (String var : vars) - { - if (!props.containsKey(var)) - throw new NullPointerException(); - } - - preloaderContainer_verboseLog = props.getProperty("preloaderContainer_verboseLog", "false").equalsIgnoreCase("true"); - asmInterfaceRepair_verboseLog = props.getProperty("asmInterfaceRepair_verboseLog", "false").equalsIgnoreCase("true"); - - TConstructLoaderContainer.logger.info("Loaded properties successfully. Using specified settings."); - } - catch (IOException ex) - { - throw new PropAccessException(); - } - catch (NullPointerException ex) - { - TConstructLoaderContainer.logger.warn("Preloader config structure has changed; attempting to recreate."); - attemptCreate(fp, props); - } - } - else - { - TConstructLoaderContainer.logger.info("Preloader config not found. Attempting to make a new one."); - attemptCreate(fp, props); - } - - return false; - } - - private static void attemptCreate (File fp, Properties props) throws PropAccessException - { - // Attempt (re)creation - try - { - if (fp.exists()) - fp.delete(); - - if (fp.createNewFile()) - { - TConstructLoaderContainer.logger.info("Creating new properties file, as none found..."); - - props.setProperty("asmInterfaceRepair_verboseLog", "false"); - props.setProperty("preloaderContainer_verboseLog", "false"); - - props.store(new FileOutputStream(fp), null); - TConstructLoaderContainer.logger.info("Created properties file; using defaults this run."); - } - else - { - throw new PropAccessException(); - } - } - catch (IOException ex) - { - ex.printStackTrace(); - throw new PropAccessException(); - } - } - - public static class PropAccessException extends Exception - { - } - -}