use of net.minecraft.item.crafting.ShapedRecipes in project MC-Prefab by Brian-Wuest.
the class ModRegistry method AddShapedRecipe.
/**
* This should only be used for registering recipes for vanilla objects and not mod-specific objects.
* @param name The name of the recipe. ModID is pre-pended to it.
* @param stack The output of the recipe.
* @param recipeComponents The recipe components.
*/
public static ShapedRecipes AddShapedRecipe(String name, String groupName, ItemStack stack, Object... recipeComponents) {
name = Prefab.MODID.toLowerCase().replace(' ', '_') + ":" + name;
ShapedPrimer primer = CraftingHelper.parseShaped(recipeComponents);
ShapedRecipes shapedrecipes = new ShapedRecipes(groupName, primer.width, primer.height, primer.input, stack);
shapedrecipes.setRegistryName(name);
ForgeRegistries.RECIPES.register(shapedrecipes);
return shapedrecipes;
}
use of net.minecraft.item.crafting.ShapedRecipes in project Galacticraft by micdoodle8.
the class ShapedRecipeHandler method loadCraftingRecipes.
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("crafting") && getClass() == ShapedRecipeHandler.class) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
CachedShapedRecipe recipe = null;
if (irecipe instanceof ShapedRecipes) {
recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
} else if (irecipe instanceof ShapedOreRecipe) {
recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
}
if (recipe == null) {
continue;
}
recipe.computeVisuals();
arecipes.add(recipe);
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project TechReborn by TechReborn.
the class RollingMachineRecipe method addRecipe.
public void addRecipe(ResourceLocation resourceLocation, ItemStack output, Object... components) {
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (components[i] instanceof String[]) {
String[] as = (String[]) components[i++];
for (int l = 0; l < as.length; l++) {
String s2 = as[l];
k++;
j = s2.length();
s = (new StringBuilder()).append(s).append(s2).toString();
}
} else {
while (components[i] instanceof String) {
String s1 = (String) components[i++];
k++;
j = s1.length();
s = (new StringBuilder()).append(s).append(s1).toString();
}
}
HashMap<Character, ItemStack> hashmap = new HashMap<Character, ItemStack>();
for (; i < components.length; i += 2) {
Character character = (Character) components[i];
ItemStack itemstack1 = null;
if (components[i + 1] instanceof Item) {
itemstack1 = new ItemStack((Item) components[i + 1]);
} else if (components[i + 1] instanceof Block) {
itemstack1 = new ItemStack((Block) components[i + 1], 1, -1);
} else if (components[i + 1] instanceof ItemStack) {
itemstack1 = (ItemStack) components[i + 1];
}
hashmap.put(character, itemstack1);
}
NonNullList<Ingredient> recipeArray = NonNullList.create();
for (int i1 = 0; i1 < j * k; i1++) {
char c = s.charAt(i1);
if (hashmap.containsKey(c)) {
recipeArray.set(i1, CraftingHelper.getIngredient(((ItemStack) hashmap.get(c)).copy()));
} else {
recipeArray.set(i1, CraftingHelper.getIngredient(ItemStack.EMPTY));
}
}
recipes.put(resourceLocation, new ShapedRecipes("", j, k, recipeArray, output));
}
use of net.minecraft.item.crafting.ShapedRecipes in project TechReborn by TechReborn.
the class GuiAutoCrafting method renderRecipe.
// Based of vanilla code
public void renderRecipe(IRecipe recipe, int x, int y) {
RenderHelper.enableGUIStandardItemLighting();
GlStateManager.enableAlpha();
mc.getTextureManager().bindTexture(RECIPE_BOOK_TEXTURE);
this.drawTexturedModalRect(x, y, 152, 78, 24, 24);
int recipeWidth = 3;
int recipeHeight = 3;
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shapedrecipes = (ShapedRecipes) recipe;
recipeWidth = shapedrecipes.getWidth();
recipeHeight = shapedrecipes.getHeight();
}
if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe shapedrecipes = (ShapedOreRecipe) recipe;
recipeWidth = shapedrecipes.getRecipeWidth();
recipeHeight = shapedrecipes.getRecipeHeight();
}
Iterator<Ingredient> ingredients = recipe.getIngredients().iterator();
for (int rHeight = 0; rHeight < recipeHeight; ++rHeight) {
int j1 = 3 + rHeight * 7;
for (int rWidth = 0; rWidth < recipeWidth; ++rWidth) {
if (ingredients.hasNext()) {
ItemStack[] aitemstack = ingredients.next().getMatchingStacks();
if (aitemstack.length != 0) {
int l1 = 3 + rWidth * 7;
GlStateManager.pushMatrix();
int i2 = (int) ((float) (x + l1) / 0.42F - 3.0F);
int j2 = (int) ((float) (y + j1) / 0.42F - 3.0F);
GlStateManager.scale(0.42F, 0.42F, 1.0F);
GlStateManager.enableLighting();
mc.getRenderItem().renderItemAndEffectIntoGUI(aitemstack[0], i2, j2);
GlStateManager.disableLighting();
GlStateManager.popMatrix();
}
}
}
}
GlStateManager.disableAlpha();
RenderHelper.disableStandardItemLighting();
}
use of net.minecraft.item.crafting.ShapedRecipes in project ArsMagica2 by Mithion.
the class GuiArcaneCompendium method getAndAnalyzeRecipe.
private void getAndAnalyzeRecipe() {
if (renderStack == null)
return;
if (renderStack.getItem() == ItemsCommonProxy.essence || renderStack.getItem() == ItemsCommonProxy.deficitCrystal) {
RecipeArsMagica essenceRecipe = RecipesEssenceRefiner.essenceRefinement().recipeFor(renderStack);
if (essenceRecipe != null) {
craftingComponents = essenceRecipe.getRecipeItems();
recipeHeight = 2;
} else {
craftingComponents = null;
}
} else if (renderStack.getItem() instanceof ItemSpellPart) {
ISkillTreeEntry part = SkillManager.instance.getSkill(this.entryName);
if (part == null)
return;
ArrayList<Object> recipe = new ArrayList<Object>();
if (part instanceof ISpellPart) {
Object[] recipeItems = ((ISpellPart) part).getRecipeItems();
SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipeItems);
MinecraftForge.EVENT_BUS.post(event);
recipeItems = event.recipeItems;
if (recipeItems != null) {
for (int i = 0; i < recipeItems.length; ++i) {
Object o = recipeItems[i];
boolean matches = false;
if (o instanceof ItemStack) {
recipe.add(o);
} else if (o instanceof Item) {
recipe.add(new ItemStack((Item) o));
} else if (o instanceof Block) {
recipe.add(new ItemStack((Block) o));
} else if (o instanceof String) {
if (((String) o).startsWith("P:")) {
// potion
String s = ((String) o).substring(2);
int pfx = SpellRecipeManager.parsePotionMeta(s);
recipe.add(new ItemStack(Items.potionitem, 1, pfx));
} else if (((String) o).startsWith("E:")) {
// essence
String s = ((String) o);
try {
int[] types = SpellRecipeManager.ParseEssenceIDs(s);
int type = 0;
for (int t : types) type |= t;
int amount = (Integer) recipeItems[++i];
recipe.add(new ItemStack(ItemsCommonProxy.essence, amount, ItemsCommonProxy.essence.META_MAX + type));
} catch (Throwable t) {
continue;
}
} else {
recipe.add(OreDictionary.getOres((String) o));
}
}
}
}
}
craftingComponents = recipe.toArray();
} else {
IRecipe recipe = RecipeUtilities.getRecipeFor(renderStack);
if (recipe != null) {
renderStack = recipe.getRecipeOutput();
if (recipe instanceof ShapedRecipes) {
recipeWidth = ((ShapedRecipes) recipe).recipeWidth;
recipeHeight = ((ShapedRecipes) recipe).recipeHeight;
craftingComponents = ((ShapedRecipes) recipe).recipeItems;
} else if (recipe instanceof ShapedOreRecipe) {
recipeWidth = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "width");
recipeHeight = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "height");
craftingComponents = ((ShapedOreRecipe) recipe).getInput();
} else if (recipe instanceof ShapelessRecipes) {
recipeWidth = ((ShapelessRecipes) recipe).getRecipeSize();
recipeHeight = -1;
craftingComponents = ((ShapelessRecipes) recipe).recipeItems.toArray();
} else if (recipe instanceof ShapelessOreRecipe) {
recipeWidth = ((ShapelessOreRecipe) recipe).getRecipeSize();
recipeHeight = -1;
craftingComponents = ((ShapelessOreRecipe) recipe).getInput().toArray();
} else {
craftingComponents = null;
}
} else {
craftingComponents = null;
}
}
}
Aggregations