Skip to content

Commit

Permalink
Add recipe removal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Choonster committed Sep 6, 2015
1 parent 3b5a9db commit ab7e728
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/choonster/testmod3/TestMod3.java
Expand Up @@ -8,7 +8,6 @@
import com.choonster.testmod3.proxy.CommonProxy;
import com.choonster.testmod3.util.BiomeBlockReplacer;
import com.choonster.testmod3.world.gen.WorldGenOres;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -57,6 +56,8 @@ public void init(FMLInitializationEvent event) {

GameRegistry.registerWorldGenerator(new WorldGenOres(), 0);

ModRecipes.removeCraftingRecipes();

proxy.init();
}

Expand Down
76 changes: 76 additions & 0 deletions src/main/java/com/choonster/testmod3/init/ModRecipes.java
@@ -1,16 +1,25 @@
package com.choonster.testmod3.init;

import com.choonster.testmod3.Logger;
import com.choonster.testmod3.recipe.ShapedArmourUpgradeRecipe;
import com.choonster.testmod3.recipe.ShapelessCuttingRecipe;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPlanks;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.RecipeFireworks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.RecipeSorter;

import java.util.Iterator;
import java.util.List;

import static net.minecraftforge.oredict.RecipeSorter.Category.SHAPED;
import static net.minecraftforge.oredict.RecipeSorter.Category.SHAPELESS;

Expand Down Expand Up @@ -43,4 +52,71 @@ private static void addCraftingRecipes() {

GameRegistry.addRecipe(guardianSpawner, "SSS", "SFS", "SSS", 'S', Items.stick, 'F', Items.fish);
}

public static void removeCraftingRecipes() {
removeRecipeClass(RecipeFireworks.class);
removeRecipe(Items.dye);
removeRecipe(Blocks.stained_hardened_clay);
}

private static void removeRecipe(Block output) {
removeRecipe(Item.getItemFromBlock(output));
}

/**
* Remove all recipes with the specified output Item.
* <p>
* Adapted from Rohzek's code in this post:
* http://www.minecraftforge.net/forum/index.php/topic,33631.0.html
*
* @param output The output Item
*/
@SuppressWarnings("unchecked")
private static void removeRecipe(Item output) {
int recipesRemoved = 0;

List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
Iterator<IRecipe> remover = recipes.iterator();

while (remover.hasNext()) {

ItemStack itemstack = remover.next().getRecipeOutput();

// If the recipe's output Item is the specified Item,
if (itemstack != null && itemstack.getItem() == output) {
// Remove the recipe
remover.remove();
recipesRemoved++;
}
}

Logger.info("Removed %d recipes for %s", recipesRemoved, Item.itemRegistry.getNameForObject(output));
}

/**
* Remove all recipes that are instances of the specified class.
* <p>
* Test for this thread:
* http://www.minecraftforge.net/forum/index.php/topic,33631.0.html
*
* @param recipeClass The recipe class
*/
@SuppressWarnings("unchecked")
private static void removeRecipeClass(Class<? extends IRecipe> recipeClass) {
int recipesRemoved = 0;

List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
Iterator<IRecipe> remover = recipes.iterator();

while (remover.hasNext()) {
// If the recipe is an instance of the specified class,
if (recipeClass.isInstance(remover.next())) {
// Remove the recipe
remover.remove();
recipesRemoved++;
}
}

Logger.info("Removed %d recipes for %s", recipesRemoved, recipeClass);
}
}

0 comments on commit ab7e728

Please sign in to comment.