use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.
the class PipeBlockRequestTable method cacheRecipe.
public void cacheRecipe() {
ItemIdentifier oldTargetType = targetType;
cache = null;
resultInv.clearInventorySlotContents(0);
AutoCraftingInventory craftInv = new AutoCraftingInventory(null);
for (int i = 0; i < 9; i++) {
craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
List<IRecipe> list = new ArrayList<>();
for (IRecipe r : CraftingUtil.getRecipeList()) {
if (r.matches(craftInv, getWorld())) {
list.add(r);
}
}
if (list.size() == 1) {
cache = list.get(0);
resultInv.setInventorySlotContents(0, cache.getCraftingResult(craftInv));
targetType = null;
} else if (list.size() > 1) {
if (targetType != null) {
for (IRecipe recipe : list) {
craftInv = new AutoCraftingInventory(null);
for (int i = 0; i < 9; i++) {
craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
ItemStack result = recipe.getCraftingResult(craftInv);
if (targetType == ItemIdentifier.get(result)) {
resultInv.setInventorySlotContents(0, result);
cache = recipe;
break;
}
}
}
if (cache == null) {
cache = list.get(0);
ItemStack result = cache.getCraftingResult(craftInv);
resultInv.setInventorySlotContents(0, result);
targetType = ItemIdentifier.get(result);
}
} else {
targetType = null;
}
if (targetType != oldTargetType && !localGuiWatcher.isEmpty() && getWorld() != null && MainProxy.isServer(getWorld())) {
MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(container), localGuiWatcher);
}
}
use of net.minecraft.item.crafting.IRecipe in project ArsMagica2 by Mithion.
the class TileEntityArcaneDeconstructor method getDeconstructionRecipe.
private boolean getDeconstructionRecipe() {
ItemStack checkStack = getStackInSlot(0);
ArrayList<ItemStack> recipeItems = new ArrayList<ItemStack>();
if (checkStack == null)
return false;
if (checkStack.getItem() == ItemsCommonProxy.spell) {
int numStages = SpellUtils.instance.numStages(checkStack);
for (int i = 0; i < numStages; ++i) {
ISpellShape shape = SpellUtils.instance.getShapeForStage(checkStack, i);
Object[] componentParts = shape.getRecipeItems();
if (componentParts != null) {
for (Object o : componentParts) {
ItemStack stack = objectToItemStack(o);
if (stack != null) {
if (stack.getItem() == ItemsCommonProxy.bindingCatalyst) {
stack.setItemDamage(((Binding) SkillManager.instance.getSkill("Binding")).getBindingType(checkStack));
}
recipeItems.add(stack.copy());
}
}
}
ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(checkStack, i);
for (ISpellComponent component : components) {
componentParts = component.getRecipeItems();
if (componentParts != null) {
for (Object o : componentParts) {
ItemStack stack = objectToItemStack(o);
if (stack != null) {
if (stack.getItem() == ItemsCommonProxy.crystalPhylactery) {
ItemsCommonProxy.crystalPhylactery.setSpawnClass(stack, ((Summon) SkillManager.instance.getSkill("Summon")).getSummonType(checkStack));
ItemsCommonProxy.crystalPhylactery.addFill(stack, 100);
}
recipeItems.add(stack.copy());
}
}
}
}
ISpellModifier[] modifiers = SpellUtils.instance.getModifiersForStage(checkStack, i);
for (ISpellModifier modifier : modifiers) {
componentParts = modifier.getRecipeItems();
if (componentParts != null) {
for (Object o : componentParts) {
ItemStack stack = objectToItemStack(o);
if (stack != null)
recipeItems.add(stack.copy());
}
}
}
}
int numShapeGroups = SpellUtils.instance.numShapeGroups(checkStack);
for (int i = 0; i < numShapeGroups; ++i) {
int[] parts = SpellUtils.instance.getShapeGroupParts(checkStack, i);
for (int partID : parts) {
ISkillTreeEntry entry = SkillManager.instance.getSkill(partID);
if (entry != null && entry instanceof ISpellPart) {
Object[] componentParts = ((ISpellPart) entry).getRecipeItems();
if (componentParts != null) {
for (Object o : componentParts) {
ItemStack stack = objectToItemStack(o);
if (stack != null) {
if (stack.getItem() == ItemsCommonProxy.bindingCatalyst) {
stack.setItemDamage(((Binding) SkillManager.instance.getSkill("Binding")).getBindingType(checkStack));
}
recipeItems.add(stack.copy());
}
}
}
}
}
}
deconstructionRecipe = recipeItems.toArray(new ItemStack[recipeItems.size()]);
return true;
} else {
IRecipe recipe = RecipeUtilities.getRecipeFor(checkStack);
if (recipe == null)
return false;
Object[] recipeParts = RecipeUtilities.getRecipeItems(recipe);
if (recipeParts != null && checkStack != null && recipe.getRecipeOutput() != null) {
if (recipe.getRecipeOutput().getItem() == checkStack.getItem() && recipe.getRecipeOutput().getItemDamage() == checkStack.getItemDamage() && recipe.getRecipeOutput().stackSize > 1)
return false;
for (Object o : recipeParts) {
ItemStack stack = objectToItemStack(o);
if (stack != null && !stack.getItem().hasContainerItem(stack)) {
stack.stackSize = 1;
recipeItems.add(stack.copy());
}
}
}
deconstructionRecipe = recipeItems.toArray(new ItemStack[recipeItems.size()]);
return true;
}
}
use of net.minecraft.item.crafting.IRecipe 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;
}
}
}
use of net.minecraft.item.crafting.IRecipe in project VoodooCraft by Mod-DevCafeTeam.
the class TileDeathGlyph method hasRecipe.
/**
* Checks the CraftingManager and the FurnaceRecipes for a recipe for the ItemStack and returns true if it finds one
*/
private static boolean hasRecipe(ItemStack stack) {
if (stack == null)
return false;
//Check crafting recipes
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe r : recipes) if (r.getRecipeOutput() != null && r.getRecipeOutput().isItemEqual(stack))
return true;
//Check furnace recipes
Collection<ItemStack> furnaceResults = FurnaceRecipes.instance().getSmeltingList().values();
for (ItemStack s : furnaceResults) if (s.isItemEqual(stack))
return true;
return false;
}
use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.
the class CraftingPlugin method addShapelessRecipe.
public static void addShapelessRecipe(@Nullable ItemStack result, Object... recipeArray) {
ProcessedRecipe processedRecipe;
try {
processedRecipe = processRecipe(RecipeType.SHAPELESS, result, recipeArray);
} catch (InvalidRecipeException ex) {
Game.logTrace(Level.WARN, ex.getRawMessage());
return;
}
if (processedRecipe.isOreRecipe) {
IRecipe recipe = new ShapelessOreRecipe(processedRecipe.result, processedRecipe.recipeArray);
addRecipe(recipe);
} else
GameRegistry.addShapelessRecipe(processedRecipe.result, processedRecipe.recipeArray);
}
Aggregations