mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-28 15:36:06 +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
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user