use of net.minecraftforge.oredict.ShapedOreRecipe in project BluePower by Qmunity.
the class SlotCircuitTableCrafting method getCraftingComponents.
private static List<ItemStack> getCraftingComponents(ItemStack gate) {
List<ItemStack> requiredItems = new ArrayList<ItemStack>();
List recipeList = CraftingManager.getInstance().getRecipeList();
for (IRecipe r : (List<IRecipe>) recipeList) {
ItemStack result = r.getRecipeOutput();
if (result != null && result.isItemEqual(gate)) {
if (r instanceof ShapedOreRecipe) {
ShapedOreRecipe recipe = (ShapedOreRecipe) r;
for (Object o : recipe.getInput()) {
if (o != null) {
ItemStack stack;
if (o instanceof ItemStack) {
stack = (ItemStack) o;
} else {
List<ItemStack> list = (List<ItemStack>) o;
stack = list.size() > 0 ? list.get(0) : null;
}
if (stack != null) {
boolean needsAdding = true;
for (ItemStack listStack : requiredItems) {
if (listStack.isItemEqual(stack)) {
listStack.stackSize++;
needsAdding = false;
break;
}
}
if (needsAdding)
requiredItems.add(stack.copy());
}
}
}
return requiredItems;
} else if (r instanceof ShapedRecipes) {
ShapedRecipes recipe = (ShapedRecipes) r;
for (ItemStack stack : recipe.recipeItems) {
if (stack != null) {
boolean needsAdding = true;
for (ItemStack listStack : requiredItems) {
if (listStack.isItemEqual(stack)) {
listStack.stackSize++;
needsAdding = false;
break;
}
}
if (needsAdding)
requiredItems.add(stack.copy());
}
}
return requiredItems;
}
}
}
return new ArrayList<ItemStack>();
}
use of net.minecraftforge.oredict.ShapedOreRecipe in project BluePower by Qmunity.
the class AlloyFurnaceRegistry method generateRecyclingRecipes.
@SuppressWarnings("unchecked")
public void generateRecyclingRecipes() {
Collections.addAll(blacklist, Config.alloyFurnaceBlacklist);
List<Item> blacklist = new ArrayList<Item>();
for (String configString : this.blacklist) {
Item item = GameData.getItemRegistry().getObject(configString);
if (item != null) {
blacklist.add(item);
} else {
BluePower.log.info("Config entry \"" + configString + "\" not an existing item/block name! Will not be added to the blacklist");
}
}
List<ItemStack> registeredRecycledItems = new ArrayList<ItemStack>();
List<ItemStack> registeredResultItems = new ArrayList<ItemStack>();
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe recipe : recipes) {
int recyclingAmount = 0;
ItemStack currentlyRecycledInto = null;
for (ItemStack recyclingItem : bufferedRecyclingItems) {
try {
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shaped = (ShapedRecipes) recipe;
if (shaped.recipeItems != null) {
for (ItemStack input : shaped.recipeItems) {
if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
}
}
}
} else if (recipe instanceof ShapelessRecipes) {
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
if (shapeless.recipeItems != null) {
for (ItemStack input : (List<ItemStack>) shapeless.recipeItems) {
if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
}
}
}
} else if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
if (shapedOreRecipe.getInput() != null) {
for (Object input : shapedOreRecipe.getInput()) {
if (input != null) {
List<ItemStack> itemList;
if (input instanceof ItemStack) {
itemList = new ArrayList<ItemStack>();
itemList.add((ItemStack) input);
} else {
itemList = (List<ItemStack>) input;
}
for (ItemStack item : itemList) {
if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
break;
}
}
}
}
}
} else if (recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
for (Object input : shapeless.getInput()) {
if (input != null) {
List<ItemStack> itemList;
if (input instanceof ItemStack) {
itemList = new ArrayList<ItemStack>();
itemList.add((ItemStack) input);
} else {
itemList = (List<ItemStack>) input;
}
for (ItemStack item : itemList) {
if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
break;
}
}
}
}
}
} catch (Throwable e) {
BluePower.log.error("Error when generating an Alloy Furnace recipe for item " + recyclingItem.getDisplayName() + ", recipe output: " + recipe.getRecipeOutput().getDisplayName());
e.printStackTrace();
}
}
if (recyclingAmount > 0 && recipe.getRecipeOutput().stackSize > 0) {
boolean shouldAdd = true;
for (int i = 0; i < registeredRecycledItems.size(); i++) {
if (ItemStackUtils.isItemFuzzyEqual(registeredRecycledItems.get(i), recipe.getRecipeOutput())) {
if (registeredResultItems.get(i).stackSize < recyclingAmount) {
shouldAdd = false;
break;
} else {
registeredResultItems.remove(i);
registeredRecycledItems.remove(i);
i--;
}
}
}
if (shouldAdd) {
if (blacklist.contains(recipe.getRecipeOutput().getItem())) {
BluePower.log.info("Skipped adding item/block " + recipe.getRecipeOutput().getDisplayName() + " to the Alloy Furnace recipes.");
continue;
}
ItemStack resultItem = new ItemStack(currentlyRecycledInto.getItem(), Math.min(64, recyclingAmount), currentlyRecycledInto.getItemDamage());
registeredResultItems.add(resultItem);
registeredRecycledItems.add(recipe.getRecipeOutput());
}
}
}
for (int i = 0; i < registeredResultItems.size(); i++) {
addRecipe(registeredResultItems.get(i), registeredRecycledItems.get(i));
}
}
use of net.minecraftforge.oredict.ShapedOreRecipe in project Engine by VoltzEngine-Project.
the class CommandJsonRecipe method handleConsoleCommand.
@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
if (args[0].equals("generate") || args[0].equals("gen")) {
if (args.length > 1) {
String entryID = args[1];
ItemStack stack = new JsonCraftingRecipeData(null, null, null, false, false).toStack(entryID);
if (stack != null) {
List<IRecipe> recipes = entryID.contains("#") ? InventoryUtility.getRecipesWithOutput(stack) : InventoryUtility.getRecipesWithOutput(stack.getItem());
if (recipes != null) {
sender.addChatMessage(new ChatComponentText("Found " + recipes.size() + " for '" + entryID + "' saving to external json file"));
File writeFile = new File(JsonContentLoader.INSTANCE.externalContentFolder.getParent(), "json-gen/" + (entryID + "-recipes.json").replace(":", "_"));
if (!writeFile.getParentFile().exists()) {
writeFile.getParentFile().mkdirs();
}
try {
JsonObject object = new JsonObject();
int index = 0;
for (IRecipe recipe : recipes) {
try {
if (recipe instanceof ShapedOreRecipe) {
int width = 0;
int height = 0;
Object[] recipeItems = null;
Field field = ShapedOreRecipe.class.getDeclaredField("input");
field.setAccessible(true);
recipeItems = (Object[]) field.get(recipe);
field = ShapedOreRecipe.class.getDeclaredField("width");
field.setAccessible(true);
width = field.getInt(recipe);
field = ShapedOreRecipe.class.getDeclaredField("height");
field.setAccessible(true);
height = field.getInt(recipe);
Pair<String, HashMap<String, JsonElement>> itemSet = generateItemData(recipeItems, width, height);
//Build data
if (itemSet != null) {
JsonObject recipeObject = new JsonObject();
recipeObject.add("type", new JsonPrimitive("shaped"));
recipeObject.add("output", toItemJson(recipe.getRecipeOutput()));
recipeObject.add("grid", new JsonPrimitive(itemSet.left()));
JsonObject itemEntry = new JsonObject();
for (Map.Entry<String, JsonElement> entry : itemSet.right().entrySet()) {
itemEntry.add(entry.getKey(), entry.getValue());
}
recipeObject.add("items", itemEntry);
object.add("craftingGridRecipe:" + (index++), recipeObject);
} else {
sender.addChatMessage(new ChatComponentText("Failed to map recipe items for '" + recipe + "'"));
}
} else if (recipe instanceof ShapedRecipes) {
Pair<String, HashMap<String, JsonElement>> itemSet = generateItemData(((ShapedRecipes) recipe).recipeItems, ((ShapedRecipes) recipe).recipeWidth, ((ShapedRecipes) recipe).recipeHeight);
//Build data
if (itemSet != null) {
JsonObject recipeObject = new JsonObject();
recipeObject.add("type", new JsonPrimitive("shaped"));
recipeObject.add("output", toItemJson(recipe.getRecipeOutput()));
recipeObject.add("grid", new JsonPrimitive(itemSet.left()));
JsonObject itemEntry = new JsonObject();
for (Map.Entry<String, JsonElement> entry : itemSet.right().entrySet()) {
itemEntry.add(entry.getKey(), entry.getValue());
}
recipeObject.add("items", itemEntry);
object.add("craftingGridRecipe:" + (index++), recipeObject);
} else {
sender.addChatMessage(new ChatComponentText("Failed to map recipe items for '" + recipe + "'"));
}
} else {
sender.addChatMessage(new ChatComponentText("Failed to ID recipe type of '" + recipe + "'"));
}
} catch (Exception e) {
sender.addChatMessage(new ChatComponentText("Error processing recipe '" + recipe + "', see logs for details."));
e.printStackTrace();
}
}
if (object.entrySet().size() > 0) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
try (FileWriter file = new FileWriter(writeFile)) {
file.write(gson.toJson(object));
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
sender.addChatMessage(new ChatComponentText("Failed to locate recipes for '" + entryID + "'"));
}
} else {
sender.addChatMessage(new ChatComponentText("Failed to locate entry for '" + entryID + "'"));
}
return true;
}
}
}
return handleHelp(sender, args);
}
use of net.minecraftforge.oredict.ShapedOreRecipe in project Railcraft by Railcraft.
the class RollingMachineCraftingManager method addRecipe.
@Override
public void addRecipe(@Nullable ItemStack result, Object... recipeArray) {
CraftingPlugin.ProcessedRecipe processedRecipe;
try {
processedRecipe = CraftingPlugin.processRecipe(CraftingPlugin.RecipeType.SHAPED, result, recipeArray);
} catch (InvalidRecipeException ex) {
Game.logTrace(Level.WARN, ex.getRawMessage());
return;
}
if (processedRecipe.isOreRecipe) {
IRecipe recipe = new ShapedOreRecipe(processedRecipe.result, processedRecipe.recipeArray);
addRecipe(recipe);
} else
addRecipe(CraftingPlugin.makeVanillaShapedRecipe(processedRecipe.result, processedRecipe.recipeArray));
}
use of net.minecraftforge.oredict.ShapedOreRecipe in project ICBM-Classic by BuiltBrokenModding.
the class ICBMClassic method loadRecipes.
@Override
public void loadRecipes(ModManager manager) {
/** LOAD. */
ArrayList dustCharcoal = OreDictionary.getOres("dustCharcoal");
ArrayList dustCoal = OreDictionary.getOres("dustCoal");
// Sulfur
//GameRegistry.addSmelting(blockSulfurOre, new ItemStack(itemSulfurDust, 4), 0.8f);
GameRegistry.addSmelting(Items.reeds, new ItemStack(itemSulfurDust, 4, 1), 0f);
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(Items.gunpowder, 2), "dustSulfur", "dustSaltpeter", Items.coal));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(Items.gunpowder, 2), "dustSulfur", "dustSaltpeter", new ItemStack(Items.coal, 1, 1)));
if (dustCharcoal != null && dustCharcoal.size() > 0) {
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(Items.gunpowder, 2), "dustSulfur", "dustSaltpeter", "dustCharcoal"));
}
if (dustCoal != null && dustCoal.size() > 0) {
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(Items.gunpowder, 2), "dustSulfur", "dustSaltpeter", "dustCoal"));
}
GameRegistry.addRecipe(new ShapedOreRecipe(Blocks.tnt, "@@@", "@R@", "@@@", '@', Items.gunpowder, 'R', Items.redstone));
// Poison Powder
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(itemPoisonPowder, 3), Items.spider_eye, Items.rotten_flesh));
// Glass Pressure Plate
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockGlassPlate, 1, 0), "##", '#', Blocks.glass));
// Glass Button
GameRegistry.addRecipe(new ItemStack(blockGlassButton, 2), "G", "G", 'G', Blocks.glass);
// Proximity Detector
GameRegistry.addRecipe(new ShapedOreRecipe(blockProximityDetector, "SSS", "S?S", "SSS", 'S', Items.iron_ingot, '?', itemTracker));
// Signal Disrupter
GameRegistry.addRecipe(new ShapedOreRecipe(itemSignalDisrupter, "WWW", "SCS", "SSS", 'S', Items.iron_ingot, 'C', UniversalRecipe.CIRCUIT_T1.get(), 'W', UniversalRecipe.WIRE.get()));
// Antidote
OreDictionary.registerOre("seeds", Items.wheat_seeds);
OreDictionary.registerOre("seeds", Items.pumpkin_seeds);
OreDictionary.registerOre("seeds", Items.melon_seeds);
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemAntidote, 6), "@@@", "@@@", "@@@", '@', "seeds"));
// Reinforced rails
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCombatRail, 16, 0), new Object[] { "C C", "CIC", "C C", 'I', new ItemStack(blockConcrete, 1, 0), 'C', Items.iron_ingot }));
// Reinforced Glass
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockReinforcedGlass, 8), new Object[] { "IGI", "GIG", "IGI", 'G', Blocks.glass, 'I', Items.iron_ingot }));
// Rocket Launcher
GameRegistry.addRecipe(new ShapedOreRecipe(itemRocketLauncher, "SCR", "SB ", 'R', itemRadarGun, 'C', new ItemStack(blockCruiseLauncher), 'B', Blocks.stone_button, 'S', UniversalRecipe.PRIMARY_METAL.get()));
// Radar Gun
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemRadarGun), "@#!", " $!", " !", '@', Blocks.glass, '!', UniversalRecipe.PRIMARY_METAL.get(), '#', UniversalRecipe.CIRCUIT_T1.get(), '$', Blocks.stone_button));
// Remote
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemRemoteDetonator), "?@@", "@#$", "@@@", '@', UniversalRecipe.PRIMARY_METAL.get(), '?', Items.redstone, '#', UniversalRecipe.CIRCUIT_T2.get(), '$', Blocks.stone_button));
// Laser Designator
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemLaserDesignator), "! ", " ? ", " @", '@', itemRemoteDetonator, '?', UniversalRecipe.CIRCUIT_T3.get(), '!', itemRadarGun));
// Defuser
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemDefuser), "I ", " W ", " C", 'C', UniversalRecipe.CIRCUIT_T2.get(), 'W', UniversalRecipe.WRENCH.get(), 'I', UniversalRecipe.WIRE.get()));
// Missile module
GameRegistry.addRecipe(new ShapedOreRecipe(Explosives.MISSILE.getItemStack(), " @ ", "@#@", "@?@", '@', UniversalRecipe.PRIMARY_METAL.get(), '?', Items.flint_and_steel, '#', UniversalRecipe.CIRCUIT_T1.get()));
// Homing
GameRegistry.addRecipe(new ShapedOreRecipe(Explosives.MISSILE_HOMING.getItemStack(), " B ", " C ", "BMB", 'M', Explosives.MISSILE.getItemStack(), 'C', UniversalRecipe.CIRCUIT_T1.get(), 'B', UniversalRecipe.SECONDARY_METAL.get()));
// Anti-ballistic
GameRegistry.addRecipe(new ShapedOreRecipe(Explosives.MISSILE_ANTI.getItemStack(), "!", "?", "@", '@', Explosives.MISSILE.getItemStack(), '?', new ItemStack(blockExplosive, 1, 0), '!', UniversalRecipe.CIRCUIT_T1.get()));
// Cluster
GameRegistry.addRecipe(new ShapedOreRecipe(Explosives.MISSILE_CLUSTER.getItemStack(), " ! ", " ? ", "!@!", '@', Explosives.MISSILE.getItemStack(), '?', Explosives.FRAGMENTATION.getItemStack(), '!', new ItemStack(itemMissile, 1, 0)));
// Nuclear Cluster
GameRegistry.addRecipe(new ShapedOreRecipe(Explosives.MISSILE_CLUSTER_NUKE.getItemStack(), " N ", "NCN", 'C', Explosives.MISSILE_CLUSTER.getItemStack(), 'N', Explosives.NUCLEAR.getItemStack()));
for (Explosives ex : Explosives.values()) {
Explosive explosive = ex.handler;
explosive.init();
if (!(explosive instanceof Missile)) {
// Missile
RecipeUtility.addRecipe(new ShapelessOreRecipe(new ItemStack(itemMissile, 1, ex.ordinal()), Explosives.MISSILE.getItemStack(), new ItemStack(blockExplosive, 1, ex.ordinal())), explosive.getUnlocalizedName() + " Missile", getConfig(), true);
if (explosive.getTier() < 2) {
// Grenade
RecipeUtility.addRecipe(new ShapedOreRecipe(new ItemStack(itemGrenade, 1, ex.ordinal()), "?", "@", '@', new ItemStack(blockExplosive, 1, ex.ordinal()), '?', Items.string), explosive.getUnlocalizedName() + " Grenade", getConfig(), true);
}
if (explosive.getTier() < 3) {
// Minecart
RecipeUtility.addRecipe(new ShapedOreRecipe(new ItemStack(itemBombCart, 1, ex.ordinal()), "?", "@", '?', new ItemStack(blockExplosive, 1, ex.ordinal()), '@', Items.minecart), explosive.getUnlocalizedName() + " Minecart", getConfig(), true);
}
}
}
}
Aggregations