Skip to content

Instantly share code, notes, and snippets.

@kindlich
Last active February 25, 2018 20:23
Show Gist options
  • Select an option

  • Save kindlich/b9d3ddf7ec2dd1ddd88e271c017e98b8 to your computer and use it in GitHub Desktop.

Select an option

Save kindlich/b9d3ddf7ec2dd1ddd88e271c017e98b8 to your computer and use it in GitHub Desktop.
import mods.modularmachinery.RecipePrimer;
import mods.modularmachinery.RecipeBuilder;
import crafttweaker.item.IItemStack;
import crafttweaker.item.IIngredient;
import crafttweaker.liquid.ILiquidStack;
import crafttweaker.oredict.IOreDictEntry;
import crafttweaker.data.IData;
/*
//Only because I don't have those OD's here...
<ore:partShaft>.add(<modularmachinery:blockcasing:3>);
<ore:partGear>.add(<modularmachinery:blockcasing:2>);
<ore:partMagnet>.add(<modularmachinery:itemmodularium>);
<ore:partBearing>.add(<modularmachinery:blockcasing:1>);
<ore:dustAshes>.add(<minecraft:coal>);
*/
//These ingredients will differ for the sifferent stirling recipes
val mapStirlingSolid as IData[IIngredient][string][IData] = {
{recipeName : "stick_blazepowder", recipeTickTime : 800/*, recipeEnergyOutput : 45*/} : {
itemInputs : {<item:minecraft:stick> : 1, <minecraft:blaze_rod> : 1},
fluidOutputs : {<liquid:water> : 50},
itemOutputs : {<ore:stone> : 1, <minecraft:stick>: [1, 0.5]}
},
{recipeName : "stick_redstone", recipeTickTime : 800, recipeEnergyOutput : 45} : {
itemInputs : {<item:minecraft:stick> : 1, <minecraft:redstone> : [1, 0.5]},
fluidInputs: {<liquid:water> : 100},
itemOutputs : {<ore:stone> : 1, <minecraft:stick>: [1, 0.5]}
}
};
//This will be the same for all stirling recipes
val mapStirlingSolidConsistent as IData[IIngredient][string] = {
itemInputs : {
<ore:partShaft> : [1, 0.004f],
<ore:partGear> : [1, 0.004f],
<ore:partMagnet> : [1, 0.004f],
<ore:partBearing> : [1, 0.004f]
},
itemOutputs : {
<ore:dustAshes> : [2, 0.04f]
}
};
//Now create the recipes.
for recipeData, changingIngredients in mapStirlingSolid {
createRecipe(recipeData, changingIngredients, mapStirlingSolidConsistent, "stirling_solid");
}
/**
* Creates a recipe using the given parameters
* recipeData: Contains the 'recipeName', 'recipeTickTime', 'recipeEnergyInput','recipeEnergyOutput','recipeBurnTime'
* Latter three are optional
* changingIngredients: The ingredients for that recipe, given in a map with 'itemInputs','fluidInputs','itemOutputs','fluidOutputs' as outer keys,
* followed by the ingredient, and lastly either the amount or [amount, chance] as innermost value.
* Due to how internals work, some ingredients won't work if multiplied, so use the IData to give them the amount
* consistentIngredients: Same as changingIngredients, can be null if not needed. Used to facilitate ingredients that are the same for
* multiple recipes.
* machineName: The Registry Name of the machine.
*
*/
function createRecipe(recipeData as IData, changingIngredients as IData[IIngredient][string], consistentIngredients as IData[IIngredient][string], machineName as string) as void {
if (isNull(machineName) | machineName.isEmpty) {
logger.logError("Cannot create recipe for empty machine name");
return;
}
if (isNull(recipeData)) {
logger.logError("recipeData must notbe null");
return;
}
if (!(recipeData has "recipeName") | recipeData.recipeName.asString().isEmpty) {
logger.logError("Cannot create recipe with empty recipe name");
return;
}
if (!(recipeData has "recipeTickTime") | recipeData.recipeTickTime.asInt() == 0) {
logger.logError("Cannot create recipe with no or 0 recipe tick time");
return;
}
var primer as RecipePrimer = RecipeBuilder.newBuilder(recipeData.recipeName.asString(), machineName, recipeData.recipeTickTime.asInt());
if (recipeData has "recipeEnergyInput" && recipeData.recipeEnergyInput.asInt() != 0)
primer.addEnergyPerTickInput(recipeData.recipeEnergyInput.asInt());
if (recipeData has "recipeEnergyOutput" && recipeData.recipeEnergyOutput.asInt() != 0)
primer.addEnergyPerTickOutput(recipeData.recipeEnergyOutput.asInt());
if (recipeData has "recipeBurnTime" && recipeData.recipeBurnTime.asInt() != 0)
primer.addFuelItemInout(recipeData.recipeBurnTime.asInt());
if (changingIngredients has "itemInputs") {
addItemInputs(changingIngredients.itemInputs, primer);
}
if (changingIngredients has "fluidInputs") {
addFluidInputs(changingIngredients.fluidInputs, primer);
}
if (changingIngredients has "itemOutputs") {
addItemOutputs(changingIngredients.itemOutputs, primer);
}
if (changingIngredients has "fluidOutputs") {
addFluidOutputs(changingIngredients.fluidOutputs, primer);
}
//consistentIngredients
if (isNull(consistentIngredients)) {
primer.build();
return;
}
if (consistentIngredients has "itemInputs") {
print("has itemInputs");
addItemInputs(consistentIngredients.itemInputs, primer);
}
if (consistentIngredients has "fluidInputs") {
print("has fluidInputs");
addFluidInputs(consistentIngredients.fluidInputs, primer);
}
if (consistentIngredients has "itemOutputs") {
print("has itemOutputs");
addItemOutputs(consistentIngredients.itemOutputs, primer);
}
if (consistentIngredients has "fluidOutputs") {
print("has fluidOutputs");
addFluidOutputs(consistentIngredients.fluidOutputs, primer);
}
primer.build();
}
/**
* Adds the given ingredients as item inputs to the recipePrimer
* The keys need to be either IItemStack or IOreDictEntry objects
* The values need to be either a whole number which will represent the ingredient amount
* Alternatively, the value can be a list of two numbers, of which the first will represent the amount.
* The second will represent the chance of the item being consumed.
*
* The function returns nothing because the primer stays modified after execution.
*/
function addItemInputs(inputs as IData[IIngredient], primer as RecipePrimer) as void {
for itemInput, inputData in inputs {
if (itemInput instanceof IItemStack) {
val item as IItemStack = itemInput;
if (inputData.length == 0)
primer.addItemInput(item * inputData.asInt());
else if (inputData.length > 1) {
primer.addItemInput(item * inputData[0].asInt());
primer.setChance(inputData[1].asFloat());
}
} else if (itemInput instanceof IOreDictEntry) {
val oreDict as IOreDictEntry = itemInput;
if (inputData.length == 0)
primer.addItemInput(oreDict, inputData.asInt());
else if (inputData.length > 1) {
primer.addItemInput(oreDict, inputData[0].asInt());
primer.setChance(inputData[1].asFloat());
}
} else {
logger.logError("Cannot find origin of item with data " ~ inputData.asString());
}
}
return;
}
/**
* Adds the given ingredients as item outputs to the recipePrimer
* The keys need to be either IItemStack or IOreDictEntry objects
* The values need to be either a whole number which will represent the ingredient amount
* Alternatively, the value can be a list of two numbers, of which the first will represent the amount.
* The second will represent the chance of the item being created.
*
* The function returns nothing because the primer stays modified after execution.
*/
function addItemOutputs(outputs as IData[IIngredient], primer as RecipePrimer) as void {
for itemOutput, outputData in outputs {
if (itemOutput instanceof IItemStack) {
val item as IItemStack = itemOutput;
if (outputData.length == 0)
primer.addItemOutput(item * outputData.asInt());
else if (outputData.length > 1) {
primer.addItemOutput(item * outputData[0].asInt());
primer.setChance(outputData[1].asFloat());
}
} else if (itemOutput instanceof IOreDictEntry) {
val oreDict as IOreDictEntry = itemOutput;
if (outputData.length == 0)
primer.addItemOutput(oreDict, outputData.asInt());
else if (outputData.length > 1) {
primer.addItemOutput(oreDict, outputData[0].asInt());
primer.setChance(outputData[1].asFloat());
}
} else {
logger.logError("Cannot find origin of item with data " ~ outputData.asString());
}
}
return;
}
/**
* Adds the given ingredients as fluid inputs to the recipePrimer
* The keys need to be an ILiquidStack object
* The values need to be either a whole number which will represent the liquid amount in millibuckets
* Alternatively, the value can be a list of two numbers, of which the first will represent the amount.
* The second will represent the chance of the liquid being consumed.
*
* The function returns nothing because the primer stays modified after execution.
*/
function addFluidInputs(inputs as IData[IIngredient], primer as RecipePrimer) as void {
for fluidInput, inputData in inputs {
if (fluidInput instanceof ILiquidStack) {
val fluid as ILiquidStack = fluidInput;
if (inputData.length == 0)
primer.addFluidInput(fluid * inputData.asInt());
else if (inputData.length > 1) {
primer.addFluidInput(fluid * inputData[0].asInt());
primer.setChance(inputData[1].asFloat());
}
} else {
logger.logError("Cannot find origin of fluid with data " ~ inputData.asString());
}
}
return;
}
/**
* Adds the given ingredients as fluid outputs to the recipePrimer
* The keys need to be an ILiquidStack object
* The values need to be either a whole number which will represent the liquid amount in millibuckets
* Alternatively, the value can be a list of two numbers, of which the first will represent the amount.
* The second will represent the chance of the liquid being created.
*
* The function returns nothing because the primer stays modified after execution.
*/
function addFluidOutputs(outputs as IData[IIngredient], primer as RecipePrimer) as void {
for fluidOutput, outputData in outputs {
if (fluidOutput instanceof ILiquidStack) {
val fluid as ILiquidStack = fluidOutput;
if (outputData.length == 0)
primer.addFluidOutput(fluid * outputData.asInt());
else if (outputData.length > 1) {
primer.addFluidOutput(fluid * outputData[0].asInt());
primer.setChance(outputData[1].asFloat());
}
} else {
logger.logError("Cannot find origin of fluid with data " ~ outputData.asString());
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment