Playing around with some gradle improvements

This commit is contained in:
Pahimar 2014-05-26 16:03:54 -04:00
parent b1cad58550
commit 39a6db0dce
7 changed files with 209 additions and 29 deletions

View file

@ -17,50 +17,44 @@ buildscript {
apply plugin: 'forge'
version = "1.7.2-0.2.${System.getenv("BUILD_NUMBER") ?: 0}";
ext.configFile = file "build.properties"
configFile.withReader {
def prop = new Properties()
prop.load(it)
project.ext.config = new ConfigSlurper().parse prop
}
version = config.mod_version
group = "com.pahimar.ee3" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "EquivalentExchange3"
minecraft {
version = "1.7.2-10.12.1.1095"
version = config.minecraft_version + "-" + config.forge_version
assetDir = "run/assets"
replaceIn "reference/Reference.java"
replace "@VERSION@", config.mod_version
}
dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"
// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
version = "${config.minecraft_version}-${config.mod_version}.${System.getenv("BUILD_NUMBER") ?: 0}"
processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// exclude xcf files, as they are for development only
exclude '**/*.xcf'
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
include '*.info'
// replace version and mcversion
expand 'version': project.version, 'mcversion': project.minecraft.version
expand 'mod_version': project.version, 'minecraft_version': project.config.minecraft_version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
include '**/*.info'
include '**/*.properties'
}
}

View file

@ -1,5 +1,5 @@
#
#Sat Dec 28 00:14:08 EST 2013
minecraft_version=1.7.2
forge_version=10.12.1.1082
forge_version=10.12.1.1095
mod_version=0.2

View file

@ -20,7 +20,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import java.io.File;
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, certificateFingerprint = Reference.FINGERPRINT, version = "0.2")
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, certificateFingerprint = Reference.FINGERPRINT, version = Reference.VERSION)
public class EquivalentExchange3
{
@Instance(Reference.MOD_ID)

View file

@ -0,0 +1,175 @@
package com.pahimar.ee3.exchange;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import com.pahimar.ee3.reference.Compare;
import com.pahimar.ee3.util.LogHelper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
public class OreStack implements Comparable<OreStack>
{
// Gson serializer for serializing to/deserializing from json
private static final Gson gsonSerializer = new Gson();
private static final int ORE_DICTIONARY_NOT_FOUND = -1;
public String oreName;
public int stackSize;
public static Comparator<OreStack> comparator = new Comparator<OreStack>()
{
@Override
public int compare(OreStack oreStack1, OreStack oreStack2)
{
if (oreStack1 != null)
{
if (oreStack2 != null)
{
if (oreStack1.oreName.equalsIgnoreCase(oreStack2.oreName))
{
return oreStack1.stackSize - oreStack2.stackSize;
}
else
{
return oreStack1.oreName.compareToIgnoreCase(oreStack2.oreName);
}
}
else
{
return Compare.LESSER_THAN;
}
}
else
{
if (oreStack2 != null)
{
return Compare.GREATER_THAN;
}
else
{
return Compare.EQUALS;
}
}
}
};
public OreStack(String oreName, int stackSize)
{
this.oreName = oreName;
this.stackSize = stackSize;
}
public OreStack(String oreName)
{
this(oreName, 1);
}
public OreStack(ItemStack itemStack)
{
this(OreDictionary.getOreName(OreDictionary.getOreID(itemStack)), itemStack.stackSize);
}
public static boolean compareOreNames(OreStack oreStack1, OreStack oreStack2)
{
if (oreStack1 != null && oreStack2 != null)
{
if ((oreStack1.oreName != null) && (oreStack2.oreName != null))
{
return oreStack1.oreName.equalsIgnoreCase(oreStack2.oreName);
}
}
return false;
}
/**
* Deserializes a OreStack object from the given serialized json String
*
* @param jsonOreStack
* Json encoded String representing a OreStack object
*
* @return The OreStack that was encoded as json, or null if a valid OreStack could not be decoded from given String
*/
@SuppressWarnings("unused")
public static OreStack createFromJson(String jsonOreStack)
{
try
{
return gsonSerializer.fromJson(jsonOreStack, OreStack.class);
}
catch (JsonSyntaxException exception)
{
LogHelper.warn(exception.getMessage());
}
catch (JsonParseException exception)
{
LogHelper.warn(exception.getMessage());
}
return null;
}
public static OreStack getOreStackFromList(Object... objects)
{
return getOreStackFromList(Arrays.asList(objects));
}
public static OreStack getOreStackFromList(List<?> objectList)
{
for (Object listElement : objectList)
{
if (listElement instanceof ItemStack)
{
ItemStack stack = (ItemStack) listElement;
if (OreDictionary.getOreID(stack) != ORE_DICTIONARY_NOT_FOUND)
{
return new OreStack(stack);
}
}
}
return null;
}
public static int compare(OreStack oreStack1, OreStack oreStack2)
{
return comparator.compare(oreStack1, oreStack2);
}
@Override
public String toString()
{
return String.format("%sxoreStack.%s", stackSize, oreName);
}
@Override
public boolean equals(Object object)
{
return object instanceof OreStack && (comparator.compare(this, (OreStack) object) == Compare.EQUALS);
}
@Override
public int compareTo(OreStack oreStack)
{
return comparator.compare(this, oreStack);
}
/**
* Returns this OreStack as a json serialized String
*
* @return Json serialized String of this OreStack
*/
@SuppressWarnings("unused")
public String toJson()
{
return gsonSerializer.toJson(this);
}
}

View file

@ -0,0 +1,10 @@
package com.pahimar.ee3.reference;
public class Compare
{
// Comparator stuff
public static final int LESSER_THAN = -1;
public static final int EQUALS = 0;
public static final int GREATER_THAN = 1;
}

View file

@ -5,6 +5,7 @@ public class Reference
public static final String MOD_ID = "EE3";
public static final String MOD_NAME = "Equivalent Exchange 3";
public static final String FINGERPRINT = "@FINGERPRINT@";
public static final String VERSION = "@VERSION@";
public static final String SERVER_PROXY_CLASS = "com.pahimar.ee3.proxy.ServerProxy";
public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.proxy.ClientProxy";
}

View file

@ -3,15 +3,15 @@
"modid": "EE3",
"name": "Equivalent Exchange 3",
"description": "Transmute stuff into other stuff! Become a Minecraft God!",
"version": "${version}",
"mcversion": ${mcversion}",
"version": "${mod_version}",
"mcversion": "${minecraft_version}",
"url": "http://www.minecraftforum.net/topic/1106178-",
"updateUrl": "",
"authorList": [
"pahimar",
"x3n0ph0b3"
],
"credits": "By pahimar, based (loosely) on Equivalent Exchange 1 & 2 by x3n0ph0b3",
"credits": "pahimar and x3n0ph0b3",
"logoFile": "assets/ee3/textures/logo/logo.png",
"screenshots": [
],