use of net.minecraft.item.crafting.IRecipe in project Engine by VoltzEngine-Project.
the class RecipeUtility method removeRecipes.
/**
* Removes all recipes found that has this output. You may use this with Forge Ore Dictionary to
* remove all recipes with the FoD ID.
*
* @return True if successful
*/
public static boolean removeRecipes(ItemStack... itemStacks) {
boolean didRemove = false;
for (Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext(); ) {
Object obj = itr.next();
if (obj != null) {
if (obj instanceof IRecipe) {
if (((IRecipe) obj).getRecipeOutput() != null) {
for (ItemStack itemStack : itemStacks) {
if (((IRecipe) obj).getRecipeOutput().isItemEqual(itemStack)) {
itr.remove();
didRemove = true;
break;
}
}
}
}
}
}
return didRemove;
}
use of net.minecraft.item.crafting.IRecipe in project Engine by VoltzEngine-Project.
the class JsonContentLoader method handlePostCalls.
/**
* Called to handle post call code on generated objects.
* <p>
* Separated from {@link #postInit()} due to other processors
* having special handling.
*
* @param generatedObjects
*/
public void handlePostCalls(List<IJsonGenObject> generatedObjects) {
if (generatedObjects != null && !generatedObjects.isEmpty()) {
for (IJsonGenObject obj : generatedObjects) {
debug.start("Handling: " + obj);
if (obj instanceof IPostInit) {
((IPostInit) obj).onPostInit();
}
if (obj instanceof IRecipeContainer) {
List<IRecipe> recipes = new ArrayList();
((IRecipeContainer) obj).genRecipes(recipes);
if (recipes.size() > 0) {
debug.start("Adding recipes from gen object:");
for (IRecipe recipe : recipes) {
if (recipe != null) {
if (recipe.getRecipeOutput() != null) {
GameRegistry.addRecipe(recipe);
} else {
debug.log("Null recipe output detected");
}
} else {
debug.log("Null recipe detected");
}
}
debug.end();
}
}
debug.end();
}
}
}
use of net.minecraft.item.crafting.IRecipe 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.minecraft.item.crafting.IRecipe in project Engine by VoltzEngine-Project.
the class CommandDebugRecipes method handleConsoleCommand.
@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
String modID = args[0];
if (Loader.isModLoaded(modID)) {
sender.addChatMessage(new ChatComponentText("Checking data...."));
List<Item> items = InventoryUtility.getItemsForMod(modID);
if (items != null && !items.isEmpty()) {
HashMap<Item, List<IRecipe>> itemToRecipes = new HashMap();
sender.addChatMessage(new ChatComponentText("Found " + items.size() + " items for the mod " + modID + " moving on to processing recipes"));
for (Item item : items) {
List<IRecipe> recipes = InventoryUtility.getRecipesWithOutput(item);
if (recipes != null && recipes.size() > 0) {
itemToRecipes.put(item, recipes);
}
}
sender.addChatMessage(new ChatComponentText("Mapped " + itemToRecipes.size() + " entries with recipes"));
if (args.length == 1 || args[1].equalsIgnoreCase("conflict")) {
sender.addChatMessage(new ChatComponentText("Not implemented yet"));
return true;
} else if (args[1].equalsIgnoreCase("missing")) {
//TODO add handling for subtypes
for (Item item : items) {
if (!itemToRecipes.containsKey(item)) {
if (item instanceof ItemBlock) {
Block block = ((ItemBlock) item).field_150939_a;
if (block instanceof BlockTile) {
sender.addChatMessage(new ChatComponentText("Tile[" + ((BlockTile) block).staticTile.name + "] has no recipes for any subtype"));
} else {
sender.addChatMessage(new ChatComponentText("Block[" + block.getLocalizedName() + "] has no recipes for any subtype"));
}
} else {
sender.addChatMessage(new ChatComponentText("Item[" + item.getItemStackDisplayName(new ItemStack(item)) + "] has no recipes for any subtype"));
}
}
}
}
} else {
sender.addChatMessage(new ChatComponentText("No items are mapped for the mod[" + modID + "]"));
}
return true;
} else {
//TODO maybe show closest spelling
sender.addChatMessage(new ChatComponentText("Failed to find mod[" + modID + "]"));
return true;
}
}
return handleHelp(sender, args);
}
use of net.minecraft.item.crafting.IRecipe in project BetterWithAddons by DaedalusGame.
the class InteractionDecoAddon method modifyPaneRecipe.
public void modifyPaneRecipe() {
List<IRecipe> craftingList = CraftingManager.getInstance().getRecipeList();
for (Iterator<IRecipe> craftingIterator = craftingList.iterator(); craftingIterator.hasNext(); ) {
IRecipe recipe = craftingIterator.next();
ItemStack output = recipe.getRecipeOutput();
Block block = Block.getBlockFromItem(output.getItem());
if (block == Blocks.GLASS_PANE || block == Blocks.STAINED_GLASS_PANE) {
output.setCount((output.getCount() * 3) / 4);
}
}
}
Aggregations