mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-13 16:54:05 +00:00
- Added /mt recipes command
- Added /mt recipes hand command - Removed COMMAND: in front of lines generated from commands
This commit is contained in:
1 parent
f5e467e9a4
commit
9fcf4b9a4e
25 files changed
+617
-42
No files matched your search
@@ -33,6 +33,7 @@ import minetweaker.api.mods.IMod;
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingRecipe;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import minetweaker.api.server.ICommandFunction;
|
||||
@@ -180,6 +181,56 @@ public class MineTweakerImplementationAPI {
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("recipes", new MineTweakerCommand(
|
||||
"recipes",
|
||||
new String[] {
|
||||
"/minetweaker recipes",
|
||||
" Lists all crafting recipes in the game",
|
||||
"/minetweaker recipes hand",
|
||||
" Lists all crafting recipes for the item in your hand",
|
||||
" Also copies the recipes to clipboard"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player)
|
||||
{
|
||||
if (arguments.length == 0) {
|
||||
if (player != null) {
|
||||
player.sendChat("Generating recipe list, this could take a while...");
|
||||
}
|
||||
|
||||
MineTweakerAPI.logCommand("Recipes:");
|
||||
for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else if (arguments[0].equals("hand") && player != null) {
|
||||
IItemStack item = player.getCurrentItem();
|
||||
|
||||
List<ICraftingRecipe> recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount());
|
||||
if (recipes.isEmpty()) {
|
||||
player.sendChat("No crafting recipes found for that item");
|
||||
} else {
|
||||
StringBuilder recipesString = new StringBuilder();
|
||||
|
||||
for (ICraftingRecipe recipe : recipes) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
player.sendChat(recipe.toCommandString());
|
||||
recipesString.append(recipe.toCommandString()).append("\n");
|
||||
}
|
||||
|
||||
copyToClipboard(recipesString.toString());
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendChat("Invalid arguments for recipes command");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("inventory", new MineTweakerCommand(
|
||||
"inventory",
|
||||
new String[] {
|
||||
@@ -201,7 +252,9 @@ public class MineTweakerImplementationAPI {
|
||||
"hand",
|
||||
new String[] {
|
||||
"/minetweaker hand",
|
||||
" Outputs the name of the item in your hand"
|
||||
" Outputs the name of the item in your hand",
|
||||
" Also copies the name to clipboard and prints",
|
||||
" oredict entries"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
|
||||
@@ -157,6 +157,14 @@ public interface IItemStack extends IIngredient {
|
||||
@ZenMethod
|
||||
public IItemStack withAmount(int amount);
|
||||
|
||||
/**
|
||||
* Creates an item stack with wildcard stack size.
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack anyAmount();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the given nbt tag. Ignores existing tags.
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ public class FileLogger implements ILogger {
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write("COMMAND: " + message + "\n");
|
||||
writer.write(message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
|
||||
@@ -23,4 +23,6 @@ public interface ICraftingRecipe {
|
||||
public boolean hasTransformers();
|
||||
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer);
|
||||
|
||||
public String toCommandString();
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
@@ -14,6 +16,23 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeManager")
|
||||
public interface IRecipeManager {
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
public List<ICraftingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes resulting in the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to find
|
||||
* @return crafting recipes for the given item(s)
|
||||
*/
|
||||
@ZenMethod
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Removes all crafting recipes crafting the specified item.
|
||||
*
|
||||
|
||||
@@ -217,6 +217,39 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("recipes.addShaped(");
|
||||
result.append(output);
|
||||
result.append(", [");
|
||||
|
||||
IIngredient[][] ingredientsArray = new IIngredient[height][width];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredientsArray[posy[i]][posx[i]] = ingredients[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < ingredientsArray.length; i++) {
|
||||
if (i > 0) {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
result.append("[");
|
||||
|
||||
for (int j = 0; j < ingredientsArray[i].length; j++) {
|
||||
if (j > 0)
|
||||
result.append(", ");
|
||||
|
||||
result.append(ingredientsArray[i][j]);
|
||||
}
|
||||
|
||||
result.append("]");
|
||||
}
|
||||
|
||||
result.append("]);");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private IItemStack doRecipe(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
|
||||
@@ -80,6 +80,26 @@ public class ShapelessRecipe implements ICraftingRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
result.append("recipes.addShapeless(");
|
||||
result.append(output);
|
||||
result.append(", [");
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (i > 0)
|
||||
result.append(", ");
|
||||
|
||||
result.append(ingredients[i]);
|
||||
}
|
||||
|
||||
result.append("]);");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders ingredients to match the given shapeless recipe.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class UnknownRecipe implements ICraftingRecipe {
|
||||
private final IItemStack output;
|
||||
|
||||
public UnknownRecipe(IItemStack output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return "// unknown recipe type for " + output;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package minetweaker.api.minecraft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -415,6 +416,20 @@ public class MineTweakerMC {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
public static IOreDictEntry getOreDictEntryFromArray(List array) {
|
||||
if (!oreDictArrays.containsKey(array)) {
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictionary.getOres(ore) == array) {
|
||||
oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
@@ -422,12 +437,22 @@ public class MineTweakerMC {
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient instanceof String) {
|
||||
if (ingredient == null) {
|
||||
return null;
|
||||
} else if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else if (ingredient instanceof List) {
|
||||
IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient);
|
||||
|
||||
if (entry == null) {
|
||||
throw new IllegalArgumentException("No matching oredict entry: " + ingredient);
|
||||
}
|
||||
|
||||
return entry;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@Mod(modid = MineTweakerMod.MODID, version = "${version}")
|
||||
@Mod(modid = MineTweakerMod.MODID, version = "3.0.9")
|
||||
@NetworkMod(clientSideRequired = true, serverSideRequired = true, channels = {MCPacketHandler.CHANNEL_SERVERSCRIPT, MCPacketHandler.CHANNEL_OPENBROWSER}, packetHandler = MCPacketHandler.class)
|
||||
public class MineTweakerMod {
|
||||
public static final String MODID = "MineTweaker3";
|
||||
|
||||
@@ -67,6 +67,13 @@ public class MCItemStack implements IItemStack {
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) {
|
||||
stack = itemStack;
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
this.wildcardSize = wildcardSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition getDefinition() {
|
||||
@@ -146,6 +153,13 @@ public class MCItemStack implements IItemStack {
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack anyAmount() {
|
||||
ItemStack result = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withTag(IData tag) {
|
||||
@@ -224,6 +238,9 @@ public class MCItemStack implements IItemStack {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if (item == null)
|
||||
return false;
|
||||
|
||||
ItemStack internal = getItemStack(item);
|
||||
if (internal == null) {
|
||||
throw new RuntimeException("Invalid item: " + item);
|
||||
@@ -238,6 +255,9 @@ public class MCItemStack implements IItemStack {
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
if (ingredient == null)
|
||||
return false;
|
||||
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
if (iitems == null || iitems.size() != 1) return false;
|
||||
return matches(iitems.get(0));
|
||||
|
||||
@@ -187,6 +187,11 @@ public class MCOreDictEntry implements IOreDictEntry {
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<ore:" + OreDictionary.getOreName(id) + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
|
||||
@@ -9,6 +9,7 @@ import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
|
||||
@@ -54,6 +55,32 @@ public class MCRecipeManager implements IRecipeManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
|
||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||
results.add(converted);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getAll() {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||
results.add(converted);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(IIngredient output) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
|
||||
@@ -10,10 +10,21 @@ import minetweaker.api.recipes.ShapedRecipe;
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.api.recipes.ICraftingRecipe;
|
||||
import minetweaker.api.recipes.UnknownRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -121,4 +132,55 @@ public class RecipeConverter {
|
||||
return new ShapedRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static ICraftingRecipe toCraftingRecipe(IRecipe recipe) {
|
||||
IItemStack output = MineTweakerMC.getIItemStack(recipe.getRecipeOutput());
|
||||
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
|
||||
|
||||
IIngredient[] ingredients = new IIngredient[shapeless.recipeItems.size()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.recipeItems.get(i));
|
||||
}
|
||||
|
||||
return new ShapelessRecipe(output, ingredients, null);
|
||||
} else if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes shaped = (ShapedRecipes) recipe;
|
||||
|
||||
IIngredient[][] ingredients = new IIngredient[shaped.recipeHeight][shaped.recipeWidth];
|
||||
for (int i = 0; i < shaped.recipeHeight; i++) {
|
||||
for (int j = 0; j < shaped.recipeWidth; j++) {
|
||||
ingredients[i][j] = MineTweakerMC.getIItemStack(shaped.recipeItems[i * shaped.recipeWidth + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedRecipe(output, ingredients, null, false);
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe shaped = (ShapedOreRecipe) recipe;
|
||||
|
||||
int width = (int) Math.sqrt(recipe.getRecipeSize());
|
||||
int height = recipe.getRecipeSize() / width;
|
||||
|
||||
IIngredient[][] recipeIngredients = new IIngredient[height][width];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
recipeIngredients[i][j] = MineTweakerMC.getIIngredient(shaped.getInput()[i * width + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedRecipe(output, recipeIngredients, null, false);
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
|
||||
|
||||
IIngredient[] ingredients = new IIngredient[shapeless.getRecipeSize()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.getInput().get(i));
|
||||
}
|
||||
|
||||
return new ShapelessRecipe(output, ingredients, null);
|
||||
} else {
|
||||
return new UnknownRecipe(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
-2
@@ -65,8 +65,6 @@ public class AssemblyTable {
|
||||
if (ingredients == null)
|
||||
return true;
|
||||
|
||||
System.out.println("Assembly Table Recipe " + Arrays.deepToString(recipe.input));
|
||||
|
||||
int matchedIngredients = 0;
|
||||
boolean[] matched = new boolean[ingredients.length];
|
||||
checkIngredient: for (int i = 0; i < recipe.input.length; i++) {
|
||||
|
||||
+41
-18
@@ -137,24 +137,6 @@ public class MineTweakerMC {
|
||||
return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
* @param ingredient minecraft ingredient
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] getExamples(IIngredient ingredient) {
|
||||
List<IItemStack> examples = ingredient.getItems();
|
||||
ItemStack[] result = new ItemStack[examples.size()];
|
||||
@@ -427,4 +409,45 @@ public class MineTweakerMC {
|
||||
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
public static IOreDictEntry getOreDictEntryFromArray(List array) {
|
||||
if (!oreDictArrays.containsKey(array)) {
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictionary.getOres(ore) == array) {
|
||||
oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
* @param ingredient minecraft ingredient
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient == null) {
|
||||
return null;
|
||||
} else if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else if (ingredient instanceof List) {
|
||||
IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient);
|
||||
|
||||
if (entry == null) {
|
||||
throw new IllegalArgumentException("No matching oredict entry: " + ingredient);
|
||||
}
|
||||
|
||||
return entry;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,13 @@ public class MCItemStack implements IItemStack {
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) {
|
||||
stack = itemStack;
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
this.wildcardSize = wildcardSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition getDefinition() {
|
||||
@@ -142,6 +149,13 @@ public class MCItemStack implements IItemStack {
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack anyAmount() {
|
||||
ItemStack result = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withAmount(int amount) {
|
||||
|
||||
@@ -188,6 +188,11 @@ public class MCOreDictEntry implements IOreDictEntry {
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<ore:" + OreDictionary.getOreName(id) + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
|
||||
+27
@@ -9,6 +9,7 @@ import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
|
||||
@@ -54,6 +55,32 @@ public class MCRecipeManager implements IRecipeManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
|
||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||
results.add(converted);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getAll() {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||
results.add(converted);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(IIngredient output) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
|
||||
+59
@@ -11,9 +11,17 @@ import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.api.recipes.ICraftingRecipe;
|
||||
import minetweaker.api.recipes.UnknownRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -118,4 +126,55 @@ public class RecipeConverter {
|
||||
return new ShapedRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static ICraftingRecipe toCraftingRecipe(IRecipe recipe) {
|
||||
IItemStack output = MineTweakerMC.getIItemStack(recipe.getRecipeOutput());
|
||||
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
|
||||
|
||||
IIngredient[] ingredients = new IIngredient[shapeless.recipeItems.size()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.recipeItems.get(i));
|
||||
}
|
||||
|
||||
return new ShapelessRecipe(output, ingredients, null);
|
||||
} else if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes shaped = (ShapedRecipes) recipe;
|
||||
|
||||
IIngredient[][] ingredients = new IIngredient[shaped.recipeHeight][shaped.recipeWidth];
|
||||
for (int i = 0; i < shaped.recipeHeight; i++) {
|
||||
for (int j = 0; j < shaped.recipeWidth; j++) {
|
||||
ingredients[i][j] = MineTweakerMC.getIItemStack(shaped.recipeItems[i * shaped.recipeWidth + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedRecipe(output, ingredients, null, false);
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe shaped = (ShapedOreRecipe) recipe;
|
||||
|
||||
int width = (int) Math.sqrt(recipe.getRecipeSize());
|
||||
int height = recipe.getRecipeSize() / width;
|
||||
|
||||
IIngredient[][] recipeIngredients = new IIngredient[height][width];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
recipeIngredients[i][j] = MineTweakerMC.getIIngredient(shaped.getInput()[i * width + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedRecipe(output, recipeIngredients, null, false);
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
|
||||
|
||||
IIngredient[] ingredients = new IIngredient[shapeless.getRecipeSize()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.getInput().get(i));
|
||||
}
|
||||
|
||||
return new ShapelessRecipe(output, ingredients, null);
|
||||
} else {
|
||||
return new UnknownRecipe(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
-18
@@ -398,24 +398,6 @@ public class MineTweakerMC {
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
* @param ingredient minecraft ingredient
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] getExamples(IIngredient ingredient) {
|
||||
List<IItemStack> examples = ingredient.getItems();
|
||||
ItemStack[] result = new ItemStack[examples.size()];
|
||||
@@ -424,4 +406,45 @@ public class MineTweakerMC {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
public static IOreDictEntry getOreDictEntryFromArray(List array) {
|
||||
if (!oreDictArrays.containsKey(array)) {
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictionary.getOres(ore) == array) {
|
||||
oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
* @param ingredient minecraft ingredient
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient == null) {
|
||||
return null;
|
||||
} else if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else if (ingredient instanceof List) {
|
||||
IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient);
|
||||
|
||||
if (entry == null) {
|
||||
throw new IllegalArgumentException("No matching oredict entry: " + ingredient);
|
||||
}
|
||||
|
||||
return entry;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,13 @@ public class MCItemStack implements IItemStack {
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) {
|
||||
stack = itemStack;
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
this.wildcardSize = wildcardSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition getDefinition() {
|
||||
@@ -149,6 +156,13 @@ public class MCItemStack implements IItemStack {
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack anyAmount() {
|
||||
ItemStack result = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withTag(IData tag) {
|
||||
|
||||
@@ -188,6 +188,11 @@ public class MCOreDictEntry implements IOreDictEntry {
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<ore:" + OreDictionary.getOreName(id) + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
|
||||
@@ -9,6 +9,7 @@ import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
|
||||
@@ -54,6 +55,32 @@ public class MCRecipeManager implements IRecipeManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
|
||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||
results.add(converted);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getAll() {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||
results.add(converted);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(IIngredient output) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
|
||||
@@ -11,9 +11,17 @@ import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.api.recipes.ICraftingRecipe;
|
||||
import minetweaker.api.recipes.UnknownRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -118,4 +126,55 @@ public class RecipeConverter {
|
||||
return new ShapedRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static ICraftingRecipe toCraftingRecipe(IRecipe recipe) {
|
||||
IItemStack output = MineTweakerMC.getIItemStack(recipe.getRecipeOutput());
|
||||
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
|
||||
|
||||
IIngredient[] ingredients = new IIngredient[shapeless.recipeItems.size()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.recipeItems.get(i));
|
||||
}
|
||||
|
||||
return new ShapelessRecipe(output, ingredients, null);
|
||||
} else if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes shaped = (ShapedRecipes) recipe;
|
||||
|
||||
IIngredient[][] ingredients = new IIngredient[shaped.recipeHeight][shaped.recipeWidth];
|
||||
for (int i = 0; i < shaped.recipeHeight; i++) {
|
||||
for (int j = 0; j < shaped.recipeWidth; j++) {
|
||||
ingredients[i][j] = MineTweakerMC.getIItemStack(shaped.recipeItems[i * shaped.recipeWidth + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedRecipe(output, ingredients, null, false);
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe shaped = (ShapedOreRecipe) recipe;
|
||||
|
||||
int width = (int) Math.sqrt(recipe.getRecipeSize());
|
||||
int height = recipe.getRecipeSize() / width;
|
||||
|
||||
IIngredient[][] recipeIngredients = new IIngredient[height][width];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
recipeIngredients[i][j] = MineTweakerMC.getIIngredient(shaped.getInput()[i * width + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedRecipe(output, recipeIngredients, null, false);
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
|
||||
|
||||
IIngredient[] ingredients = new IIngredient[shapeless.getRecipeSize()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredients[i] = MineTweakerMC.getIIngredient(shapeless.getInput().get(i));
|
||||
}
|
||||
|
||||
return new ShapelessRecipe(output, ingredients, null);
|
||||
} else {
|
||||
return new UnknownRecipe(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user