diff --git a/build.gradle b/build.gradle index 5ee5069..859cdf5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,7 @@ +def MAVEN_URL = System.getenv("maven_url") ?: "" +def MAVEN_USER = System.getenv("maven_user") ?: "" +def MAVEN_PASS = System.getenv("maven_pass") ?: "" + buildscript { repositories { mavenCentral() @@ -16,7 +20,32 @@ buildscript { } repositories { + maven { // The repo from which to get waila + name "Mobius Repo" + url "http://mobiusstrip.eu/maven" + } + maven { // the repo from which to get NEI and stuff + name 'CB Repo' + url "http://chickenbones.net/maven/" + } + maven { + name = "IGW" + url = "http://maven.k-4u.nl/" + } + maven { + name 'OpenComputers' + url = "http://maven.cil.li/" + } + maven { + name 'DVS1 Maven FS' + url 'http://dvs1.progwml6.com/files/maven' + } + // This is a simple flatdir repository for "uploadArchives" when you don't have a remote repo to target + flatDir { + name "fileRepo" + dirs "repo" + } } ext.configFile = file "build.properties" @@ -29,10 +58,12 @@ configFile.withReader { } apply plugin: 'forge' -version = config.mod_version -group = "com.nincraft.nincraftlib" // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = "NincraftLib" +// def versionInfo = getGitVersion() +version = "${config.minecraft_version}-${config.mod_version}+${System.getenv("BUILD_NUMBER") ?: "SNAPSHOT"}" // "${versionInfo['NincraftLib.version']}" + +group = "com.nincraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = "NincraftLib" minecraft { version = config.minecraft_version + "-" + config.forge_version @@ -43,8 +74,6 @@ minecraft { replace "@MOD_VERSION@", "${config.mod_version}+${System.getenv("BUILD_NUMBER") ?: "SNAPSHOT"}" } -version = "${config.minecraft_version}-${config.mod_version}+${System.getenv("BUILD_NUMBER") ?: "SNAPSHOT"}" - dependencies { // you may put jars on which you depend on in ./libs // or you may define them like so.. @@ -58,6 +87,13 @@ dependencies { // for more info... // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html + + compile fileTree(dir: 'lib', include: '*.jar') + compile "codechicken:CodeChickenLib:${config.minecraft_version}-${config.cclib_version}:dev" + compile "codechicken:CodeChickenCore:${config.minecraft_version}-${config.cccore_version}:dev" + compile "codechicken:NotEnoughItems:${config.minecraft_version}-${config.nei_version}:dev" + compile "mcp.mobius.waila:Waila:${config.waila_version}_${config.minecraft_version}" + compile "tconstruct:TConstruct:${config.minecraft_version}-${config.tconstruct_version}:deobf" } processResources @@ -87,4 +123,102 @@ task devJar(type: Jar, dependsOn: 'classes') { extension = 'jar' classifier = 'dev' -} \ No newline at end of file +} + +// Configure an upload task. this is setup for uploading to files.minecraftforge.net. There are other examples around +uploadArchives { + repositories.mavenDeployer { + + dependsOn 'build' + + if (MAVEN_URL) + { + repository(url: MAVEN_URL) { + authentication(userName: MAVEN_USER, password: MAVEN_PASS) + } + } + else + { + // local repo folder. Might want to just use gradle install if you want to send it to maven-local + repository(url: 'file://localhost/' + project.file('repo').getAbsolutePath()) + } + + // This is just the pom data for the maven repo + pom { + groupId = project.group + // Force the maven upload to use the - syntax preferred at files + version = project.version // "${project.minecraft.version}-${project.version}" + artifactId = project.archivesBaseName + project { + name project.archivesBaseName + packaging 'jar' + description 'Nincrafty Things' + url 'https://github.com/Nincraft/NincraftLib' + + scm { + url 'https://github.com/Nincraft/NincraftLib' + connection 'scm:git:git://github.com/Nincraft/NincraftLib.git' + developerConnection 'scm:git:git@github.com:Nincraft/NincraftLib.git' + } + + issueManagement { + system 'github' + url 'https://github.com/Nincraft/NincraftLib/issues' + } + + licenses { + license { + name 'GNU Public License (GPL), Version 3.0' + url 'http://www.gnu.org/licenses/gpl-3.0.txt' + distribution 'repo' + } + } + + developers { + developer { + id 'Nincodedo' + name 'Nincodedo' + roles { role 'developer' } + } + + developer { + id 'Undead_Zeratul' + name 'Undead_Zeratul' + roles { role 'developer' } + } + } + } + } + } +} + +// This is a special task for pulling the version information from git and the environment (for BUILD_NUMBER) +def getGitVersion() +{ + def out = [:] + + // call git command. + def outStream = new ByteArrayOutputStream() + def result = exec { + executable = 'git' + args = [ 'describe', '--long', "--match=[^(jenkins)]*"] + standardOutput = outStream + } + + def fullVersion = outStream.toString().trim() + def matcher = fullVersion =~ /(\d+).(\d+)-(\d+)-(.*)/ + + def maj = matcher[0][1] + def min = matcher[0][2] + def rev = matcher[0][3] + def bn = System.getenv("BUILD_NUMBER") ?: "SNAPSHOT" + + out['NincraftLib.build.major.number'] = maj.toString() + out['NincraftLib.build.minor.number'] = min.toString() + out['NincraftLib.build.revision.number'] = rev.toString() + out['NincraftLib.build.githash'] = matcher[0][4].toString() + out['NincraftLib.build.number' ] = bn.toString() + out['NincraftLib.version' ] = "${maj}.${min}.${rev}.${bn}".toString() + + return out +} diff --git a/build.properties b/build.properties index 06b3945..605d444 100644 --- a/build.properties +++ b/build.properties @@ -1,3 +1,10 @@ minecraft_version=1.7.10 forge_version=10.13.4.1558-1.7.10 -mod_version=0.1.1 \ No newline at end of file +mod_version=0.1.1 + +cccore_version=1.0.6.43 +cclib_version=1.1.1.110 +fmp_version=1.2.0.345 +nei_version=1.0.4.107 +tconstruct_version=1.8.8.build990 +waila_version=1.5.10 diff --git a/src/main/java/com/nincraft/nincraftlib/handler/TConstructHandler.java b/src/main/java/com/nincraft/nincraftlib/handler/TConstructHandler.java new file mode 100644 index 0000000..82e1dcd --- /dev/null +++ b/src/main/java/com/nincraft/nincraftlib/handler/TConstructHandler.java @@ -0,0 +1,233 @@ +package com.nincraft.nincraftlib.handler; + +import static com.nincraft.nincraftlib.utility.StackHelper.isBlock; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.google.common.collect.Sets; + +import mantle.utils.ItemMetaWrapper; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.AlloyMix; +import tconstruct.library.crafting.CastingRecipe; +import tconstruct.library.crafting.LiquidCasting; +import tconstruct.library.crafting.Smeltery; +import tconstruct.library.tools.ToolMaterial; +import tconstruct.smeltery.TinkerSmeltery; +import tconstruct.tools.TinkerTools; +import tconstruct.tools.items.Pattern; + +public class TConstructHandler { + + private static final int INGOT_COST_MB = 144; + + public static void setMeltingTemp(final String fluidName, final int newTemp) { + // If either the input or new temperature are null or invalid, back out. + if (fluidName == null || newTemp <= 0) { + return; + } + + Map meltingTemps = Smeltery.getTemperatureList(); + + // Otherwise, find matching recipe and adjust its melting temperature. + for (ItemMetaWrapper in : getSmeltingInputsByFluid(fluidName)) { + for (ItemMetaWrapper meltingInput : meltingTemps.keySet()) { + if (in.equals(meltingInput)) { + meltingTemps.put(meltingInput, newTemp); + break; + } + } + } + } + + public static void setToolPartCost(final Integer toolPartIndex, final Integer newCost) { + // If either the index or new cost are invalid, back out. + if (toolPartIndex < 0 || newCost < 1) { + return; + } + + // Otherwise, set the new pattern cost (configured to represent ingots, + // patterns represent half-ingots). + Pattern.setPatternCost(toolPartIndex + 1, newCost * 2); + + // Also find the appropriate melting recipes + // and adjust their amounts as well. + for (Entry material : TConstructRegistry.toolMaterials.entrySet()) { + adjustCastingFluidAmounts(new ItemMetaWrapper(TinkerTools.patternOutputs[toolPartIndex], material.getKey()), + toolPartIndex, newCost); + } + } + + public static void addAlloy(final FluidStack output, final FluidStack[] input) { + // If either the input or output passed in are null, we can back out. + if (input == null || output == null) { + return; + } + + // If there exists alloy recipe with the same exact output, back out. + for (AlloyMix alloy : Smeltery.getAlloyList()) { + if (output.isFluidEqual(alloy.result)) { + return; + } + } + + // Otherwise, add a new alloy recipe to the list. + Smeltery.addAlloyMixing(output, input); + } + + public static void removeAlloy(final FluidStack output) { + // If the output passed in is null, back out. + if (output == null) { + return; + } + + List alloys = Smeltery.getAlloyList(); + + // Otherwise, search through the existing alloy list, + // and if we find the one we're looking for, + // remove it. + for (AlloyMix alloy : alloys) { + if (output.isFluidEqual(alloy.result)) { + alloys.remove(alloy); + return; + } + } + } + + public static void addMeltingRecipe(final ItemStack input, final FluidStack output, final int temp, + final ItemStack block) { + // If output or input are null, + // or block isn't a Block, + // or temp is at most 0, back out. + if (output == null || input == null || !isBlock(block) || temp <= 0) { + return; + } + + // If there exists a melting recipe with the same input, back out. + for (ItemMetaWrapper in : Smeltery.getSmeltingList().keySet()) { + if (input.equals(in)) { + return; + } + } + + Smeltery.addMelting(input, Block.getBlockFromItem(block.getItem()), block.getItemDamage(), temp, output); + } + + public static void addMeltingRecipe(final String input, final FluidStack output, final int temp, + final ItemStack block) { + // If the ore dictionary string is null or doesn't actually exist, back + // out. + if (input == null || !OreDictionary.doesOreNameExist(input)) { + return; + } + + // Otherwise, for every enty in the dictionary, add a melting recipe. + for (ItemStack in : OreDictionary.getOres(input)) { + addMeltingRecipe(in, output, temp, block); + } + } + + public static void removeMeltingRecipe(final ItemStack input) { + // If the input passed in is null, back out. + if (input == null) { + return; + } + + // Otherwise, search through the existing smelting list, + // and if we find the one we're looking for, + // remove it. + for (ItemMetaWrapper in : Smeltery.getSmeltingList().keySet()) { + if (in.item == input.getItem() && in.meta == input.getItemDamage()) { + Smeltery.getSmeltingList().remove(in); + Smeltery.getTemperatureList().remove(in); + Smeltery.getRenderIndex().remove(in); + return; + } + } + } + + public static void addBasinRecipe(final ItemStack output, final FluidStack metal, final ItemStack cast, + final boolean isConsumed, final int delay) { + // If the output or molten metal are null, back out. + if (output == null || metal == null) { + return; + } + + // Otherwise, add the basin casting recipe. + TConstructRegistry.getBasinCasting().addCastingRecipe(output, metal, cast, isConsumed, delay, null); + } + + public static void removeBasinRecipe(final FluidStack metal, final ItemStack cast) { + removeCastingRecipe(TConstructRegistry.getBasinCasting().getCastingRecipe(metal, cast), + TConstructRegistry.getBasinCasting()); + } + + public static void addTableRecipe(final ItemStack output, final FluidStack metal, final ItemStack cast, + final boolean isConsumed, final int delay) { + // If the output or molten metal are null, back out. + if (output == null || metal == null) { + return; + } + + // Otherwise, add the table casting recipe. + TConstructRegistry.getTableCasting().addCastingRecipe(output, metal, cast, isConsumed, delay, null); + } + + public static void removeTableRecipe(final FluidStack metal, final ItemStack cast) { + removeCastingRecipe(TConstructRegistry.getBasinCasting().getCastingRecipe(metal, cast), + TConstructRegistry.getTableCasting()); + } + + private static void removeCastingRecipe(final CastingRecipe recipe, final LiquidCasting castingType) { + // If the recipe or casting type is null, back out. + if (recipe == null || castingType == null) { + return; + } + + // Otherwise, remove the casting recipe. + castingType.getCastingRecipes().remove(recipe); + } + + private static Set getSmeltingInputsByFluid(String fluidName) { + Set keys = Sets.newHashSet(); + Map meltingList = Smeltery.getSmeltingList(); + + for (Entry entry : meltingList.entrySet()) { + if (FluidRegistry.getFluidName(entry.getValue()).equalsIgnoreCase(fluidName)) { + keys.add(entry.getKey()); + } + } + + return keys; + } + + private static void adjustCastingFluidAmounts(final ItemMetaWrapper toolPart, final Integer toolPartIndex, + final Integer newCost) { + FluidStack metal = Smeltery.getSmeltingList().get(toolPart); + + // If we find a valid casting recipe, + // adjust its amounts. + if (metal != null) { + metal.amount = newCost * INGOT_COST_MB; + Smeltery.getSmeltingList().put(toolPart, metal.copy()); + + // Find all the casting recipes using this toolpart + // and adjust their required amounts. + CastingRecipe recipe = TConstructRegistry.getTableCasting().getCastingRecipe(metal, + new ItemStack(TinkerSmeltery.metalPattern, 1, toolPartIndex + 1)); + + if (recipe != null) { + recipe.castingMetal.amount = newCost * INGOT_COST_MB; + } + } + } +} diff --git a/src/main/java/com/nincraft/nincraftlib/utility/StackHelper.java b/src/main/java/com/nincraft/nincraftlib/utility/StackHelper.java new file mode 100644 index 0000000..bb26605 --- /dev/null +++ b/src/main/java/com/nincraft/nincraftlib/utility/StackHelper.java @@ -0,0 +1,10 @@ +package com.nincraft.nincraftlib.utility; + +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class StackHelper { + public static boolean isBlock(final ItemStack block) { + return block.getItem() instanceof ItemBlock; + } +}