use of net.minecraft.item.crafting.Ingredient in project Totemic by TeamTotemic.
the class PageCraftingRecipe method renderCraftingRecipe.
@SideOnly(Side.CLIENT)
private void renderCraftingRecipe(IGuiLexiconEntry gui) {
int x = 0;
int y = 0;
for (Ingredient ingredient : recipe.getIngredients()) {
if (ingredient != Ingredient.EMPTY) {
ItemStack[] stacks = ingredient.getMatchingStacks();
renderItemAtGridPos(gui, 1 + x, 1 + y, stacks[recipeIndex % stacks.length], true);
}
x++;
if (x >= recipeWidth) {
x = 0;
y++;
}
}
renderItemAtGridPos(gui, 2, 0, recipe.getRecipeOutput(), false);
}
use of net.minecraft.item.crafting.Ingredient in project GregTech by GregTechCE.
the class MetaItemShapedRecipeFactory method parse.
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
String group = JsonUtils.getString(json, "group", "");
Map<Character, Ingredient> ingMap = Maps.newHashMap();
for (Entry<String, JsonElement> entry : JsonUtils.getJsonObject(json, "key").entrySet()) {
if (entry.getKey().length() != 1)
throw new JsonSyntaxException("Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only).");
if (" ".equals(entry.getKey()))
throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
ingMap.put(entry.getKey().toCharArray()[0], CraftingHelper.getIngredient(entry.getValue(), context));
}
ingMap.put(' ', Ingredient.EMPTY);
JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern");
if (patternJ.size() == 0)
throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
String[] pattern = new String[patternJ.size()];
for (int x = 0; x < pattern.length; ++x) {
String line = JsonUtils.getString(patternJ.get(x), "pattern[" + x + "]");
if (x > 0 && pattern[0].length() != line.length())
throw new JsonSyntaxException("Invalid pattern: each row must be the same imageWidth");
pattern[x] = line;
}
ShapedPrimer primer = new ShapedPrimer();
primer.width = pattern[0].length();
primer.height = pattern.length;
primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
primer.input = NonNullList.withSize(primer.width * primer.height, Ingredient.EMPTY);
Set<Character> keys = Sets.newHashSet(ingMap.keySet());
keys.remove(' ');
int x = 0;
for (String line : pattern) {
for (char chr : line.toCharArray()) {
Ingredient ing = ingMap.get(chr);
if (ing == null)
throw new JsonSyntaxException("Pattern references symbol '" + chr + "' but it's not defined in the key");
primer.input.set(x++, ing);
keys.remove(chr);
}
}
if (!keys.isEmpty())
throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + keys);
JsonObject result = JsonUtils.getJsonObject(json, "result");
String name = JsonUtils.getString(result, "name");
int amount = JsonUtils.getInt(result, "amount", 1);
ItemStack stack = ItemStack.EMPTY;
for (MetaItem<?> item : MetaItems.ITEMS) {
MetaItem<?>.MetaValueItem value = item.getItem(name);
if (value != null) {
stack = value.getStackForm(amount);
}
}
return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), stack, primer);
}
use of net.minecraft.item.crafting.Ingredient in project GregTech by GregTechCE.
the class MetaItemShapelessRecipeFactory method parse.
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ings = NonNullList.create();
for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context));
if (ings.isEmpty())
throw new JsonParseException("No ingredients for shapeless recipe");
JsonObject result = JsonUtils.getJsonObject(json, "result");
String name = JsonUtils.getString(result, "name");
int amount = JsonUtils.getInt(result, "amount", 1);
ItemStack stack = ItemStack.EMPTY;
for (MetaItem<?> item : MetaItems.ITEMS) {
MetaItem<?>.MetaValueItem value = item.getItem(name);
if (value != null) {
stack = value.getStackForm(amount);
}
}
return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, stack);
}
use of net.minecraft.item.crafting.Ingredient in project RFToolsDimensions by McJty.
the class NBTMatchingRecipe method checkMatch.
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting inventoryCrafting, int x, int y, boolean reversed) {
for (int col = 0; col < 3; ++col) {
for (int row = 0; row < 3; ++row) {
int i1 = col - x;
int j1 = row - y;
ItemStack itemstack = ItemStack.EMPTY;
String[] nbt = null;
if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight) {
int idx;
if (reversed) {
idx = this.recipeWidth - i1 - 1 + j1 * this.recipeWidth;
} else {
idx = i1 + j1 * this.recipeWidth;
}
Ingredient ingredient = this.recipeItems.get(idx);
if (ingredient.getMatchingStacks().length > 0) {
// @todo recipes most likely wrong!
itemstack = ingredient.getMatchingStacks()[0];
} else {
itemstack = ItemStack.EMPTY;
}
nbt = this.matchingNBTs[idx];
}
ItemStack itemstack1 = inventoryCrafting.getStackInRowAndColumn(col, row);
if (!itemstack1.isEmpty() || !itemstack.isEmpty()) {
if (itemstack1.isEmpty() || itemstack.isEmpty()) {
return false;
}
if (itemstack.getItem() != itemstack1.getItem()) {
return false;
}
if (itemstack.getMetadata() != 32767 && itemstack.getMetadata() != itemstack1.getMetadata()) {
return false;
}
NBTTagCompound compound = itemstack.getTagCompound();
NBTTagCompound compound1 = itemstack1.getTagCompound();
if (nbt != null) {
if (compound == null && compound1 != null) {
return false;
}
if (compound != null && compound1 == null) {
return false;
}
if (compound != null) {
for (String tagName : nbt) {
NBTBase tag = compound.getTag(tagName);
NBTBase tag1 = compound1.getTag(tagName);
if (tag == null && tag1 != null) {
return false;
}
if (tag != null && tag1 == null) {
return false;
}
if (tag != null) {
if (!tag.equals(tag1)) {
return false;
}
}
}
}
}
}
}
}
return true;
}
use of net.minecraft.item.crafting.Ingredient in project SilentGems by SilentChaos512.
the class ItemToolSoul method addRecipes.
@Override
public void addRecipes(RecipeMaker recipes) {
if (ModRecipes.ADD_SOUL_RECIPES) {
// FIXME? JEI only shows wheat souls?
NonNullList<ItemStack> listSouls = NonNullList.create();
ModItems.soulGem.getSubItems(ModItems.soulGem.getCreativeTab(), listSouls);
Ingredient ingSouls = Ingredient.fromStacks(listSouls.toArray(new ItemStack[listSouls.size()]));
recipe = recipes.addShaped("tool_soul", new ItemStack(this), " s ", "scs", " s ", 's', ingSouls, 'c', ModItems.craftingMaterial.soulShell);
}
}
Aggregations