use a compound oreingredient for paper & cardboard box json recipes

This commit is contained in:
Xander committed 2018-03-24 20:24:59 +08:00
1 parent 3482390f27
commit d8a497216e
5 files changed
+69 -6

No files matched your search

@@ -0,0 +1,54 @@
package mekanism.common.recipe;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.CompoundIngredient;
import net.minecraftforge.common.crafting.IIngredientFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.oredict.OreIngredient;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Created by Thiakil on 24/03/2018.
*/
@SuppressWarnings("unused")
public class MultiOredictIngredient extends CompoundIngredient
{
MultiOredictIngredient(String... ores){
super(getOreIngredients(ores));
}
private static Collection<Ingredient> getOreIngredients(String... ores){
if (ores == null || ores.length < 2){
throw new IllegalArgumentException("ores must contain at least 2 values");
}
List<Ingredient> children = new ArrayList<>(ores.length);
for (String ore : ores){
children.add(new OreIngredient(ore));
}
return children;
}
public static class Factory implements IIngredientFactory{
@Nonnull
@Override
public Ingredient parse(JsonContext context, JsonObject json)
{
JsonArray oreJsonArray = JsonUtils.getJsonArray(json, "ores");
if (oreJsonArray.size() < 2){
throw new JsonSyntaxException("ores must contain at least 2 values");
}
ArrayList<String> ores = new ArrayList<>(oreJsonArray.size());
oreJsonArray.forEach(el->ores.add(el.getAsString()));
return new MultiOredictIngredient(ores.toArray(new String[ores.size()]));
}
}
}
@@ -102,8 +102,9 @@ public class MekanismRecipes {
recipeGenerator.addShapedRecipe(MachineType.CHEMICAL_INJECTION_CHAMBER.getStack(), "RCR", "GPG", "RCR", 'C', MekanismUtils.getControlCircuit(BaseTier.ELITE), 'R', "alloyElite", 'G', "ingotGold", 'P', MachineType.PURIFICATION_CHAMBER.getStack());
recipeGenerator.addShapedRecipe(MachineType.ELECTROLYTIC_SEPARATOR.getStack(), "IRI", "ECE", "IRI", 'I', "ingotIron", 'R', "dustRedstone", 'E', MekanismItems.EnrichedAlloy, 'C', MekanismItems.ElectrolyticCore);
recipeGenerator.addShapedRecipe(new ItemStack(MekanismItems.ElectrolyticCore), "EPE", "IEG", "EPE", 'E', MekanismItems.EnrichedAlloy, 'P', "dustOsmium", 'I', "dustIron", 'G', "dustGold");
recipeGenerator.addShapedRecipe(new ItemStack(MekanismBlocks.CardboardBox), "SS", "SS", 'S', "pulpWood");
recipeGenerator.addShapedRecipe(new ItemStack(Items.PAPER, 6), "SSS", 'S', MekanismItems.Sawdust);
//NB: custom json
//recipeGenerator.addShapedRecipe(new ItemStack(MekanismBlocks.CardboardBox), "SS", "SS", 'S', "pulpWood");
//recipeGenerator.addShapedRecipe(new ItemStack(Items.PAPER, 6), "SSS", 'S', MekanismItems.Sawdust);
recipeGenerator.addShapedRecipe(MachineType.PRECISION_SAWMILL.getStack(), "ICI", "ASA", "ICI", 'I', "ingotIron", 'C', MekanismUtils.getControlCircuit(BaseTier.BASIC), 'A', MekanismItems.EnrichedAlloy, 'S', new ItemStack(MekanismBlocks.BasicBlock, 1, 8));
recipeGenerator.addShapedRecipe(new ItemStack(MekanismBlocks.BasicBlock, 1, 14), "CGC", "IBI", "III", 'C', MekanismUtils.getControlCircuit(BaseTier.ADVANCED), 'G', "paneGlass", 'I', new ItemStack(MekanismBlocks.BasicBlock2, 1, 0), 'B', Items.BUCKET);
recipeGenerator.addShapedRecipe(new ItemStack(MekanismBlocks.BasicBlock, 1, 15), " I ", "ICI", " I ", 'I', new ItemStack(MekanismBlocks.BasicBlock2, 1, 0), 'C', MekanismUtils.getControlCircuit(BaseTier.ADVANCED));