use of net.minecraft.item.crafting.IRecipe in project ArsMagica2 by Mithion.
the class RecipeUtilities method getRecipeFor.
public static IRecipe getRecipeFor(ItemStack item) {
if (item == null || item.getItem() == null)
return null;
try {
List list = CraftingManager.getInstance().getRecipeList();
ArrayList possibleRecipes = new ArrayList();
for (Object recipe : list) {
if (recipe instanceof IRecipe) {
ItemStack output = ((IRecipe) recipe).getRecipeOutput();
if (output == null)
continue;
if (output.getItem() == item.getItem() && (output.getItemDamage() == Short.MAX_VALUE || output.getItemDamage() == item.getItemDamage())) {
possibleRecipes.add(recipe);
}
}
}
if (possibleRecipes.size() > 0) {
for (Object recipe : possibleRecipes) {
if (((IRecipe) recipe).getRecipeOutput().getItemDamage() == item.getItemDamage()) {
return (IRecipe) recipe;
}
}
return (IRecipe) possibleRecipes.get(0);
}
} catch (Throwable t) {
}
return null;
}
use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.
the class ThaumcraftApi method getCraftingRecipeKey.
public static Object[] getCraftingRecipeKey(EntityPlayer player, ItemStack stack) {
int[] key = new int[] { Item.getIdFromItem(stack.getItem()), stack.getItemDamage() };
if (keyCache.containsKey(key)) {
if (keyCache.get(key) == null)
return null;
if (ResearchHelper.isResearchComplete(player.getName(), (String) (keyCache.get(key))[0]))
return keyCache.get(key);
else
return null;
}
for (ResearchCategoryList rcl : ResearchCategories.researchCategories.values()) {
for (ResearchItem ri : rcl.research.values()) {
if (ri.getPages() == null)
continue;
for (int a = 0; a < ri.getPages().length; a++) {
ResearchPage page = ri.getPages()[a];
if (page.recipe != null && page.recipe instanceof CrucibleRecipe[]) {
CrucibleRecipe[] crs = (CrucibleRecipe[]) page.recipe;
for (CrucibleRecipe cr : crs) {
if (cr.getRecipeOutput().isItemEqual(stack)) {
keyCache.put(key, new Object[] { ri.key, a });
if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
return new Object[] { ri.key, a };
}
}
} else if (page.recipe != null && page.recipe instanceof InfusionRecipe[]) {
InfusionRecipe[] crs = (InfusionRecipe[]) page.recipe;
for (InfusionRecipe cr : crs) {
if (cr.getRecipeOutput() instanceof ItemStack && ((ItemStack) cr.getRecipeOutput()).isItemEqual(stack)) {
keyCache.put(key, new Object[] { ri.key, a });
if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
return new Object[] { ri.key, a };
}
}
} else if (page.recipe != null && page.recipe instanceof IRecipe[]) {
IRecipe[] crs = (IRecipe[]) page.recipe;
for (IRecipe cr : crs) {
if (cr.getRecipeOutput().isItemEqual(stack)) {
keyCache.put(key, new Object[] { ri.key, a });
if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
return new Object[] { ri.key, a };
}
}
} else if (page.recipeOutput != null && stack != null && (page.recipeOutput instanceof ItemStack && ((ItemStack) page.recipeOutput).isItemEqual(stack)) || (page.recipeOutput instanceof String && ThaumcraftApiHelper.containsMatch(true, new ItemStack[] { stack }, OreDictionary.getOres((String) page.recipeOutput)))) {
keyCache.put(key, new Object[] { ri.key, a });
if (ResearchHelper.isResearchComplete(player.getName(), ri.key))
return new Object[] { ri.key, a };
else
return null;
}
}
}
}
keyCache.put(key, null);
return null;
}
use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.
the class ItemLocomotive method defineRecipes.
@Override
public void defineRecipes() {
IRecipe recipe = new LocomotivePaintingRecipe(new ItemStack(this));
CraftingPlugin.addRecipe(recipe);
}
use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.
the class RollingMachineCraftingManager method addRecipe.
@Override
public void addRecipe(@Nullable ItemStack result, Object... recipeArray) {
CraftingPlugin.ProcessedRecipe processedRecipe;
try {
processedRecipe = CraftingPlugin.processRecipe(CraftingPlugin.RecipeType.SHAPED, result, recipeArray);
} catch (InvalidRecipeException ex) {
Game.logTrace(Level.WARN, ex.getRawMessage());
return;
}
if (processedRecipe.isOreRecipe) {
IRecipe recipe = new ShapedOreRecipe(processedRecipe.result, processedRecipe.recipeArray);
addRecipe(recipe);
} else
addRecipe(CraftingPlugin.makeVanillaShapedRecipe(processedRecipe.result, processedRecipe.recipeArray));
}
use of net.minecraft.item.crafting.IRecipe in project Skree by Skelril.
the class MarketVerifyCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
Task.builder().async().execute(() -> {
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Clause<String, BigDecimal>> profitMargins = new ArrayList<>();
for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
ItemStack output = recipe.getRecipeOutput();
if (output == null) {
continue;
}
Optional<BigDecimal> optResultPrice = service.getPrice(tf(output));
if (!optResultPrice.isPresent()) {
continue;
}
String name = service.getAlias(tf(output)).orElse(output.getItem().getRegistryName().toString());
Collection<ItemStack> items = new ArrayList<>();
if (recipe instanceof ShapedRecipes) {
items.addAll(Lists.newArrayList(((ShapedRecipes) recipe).recipeItems));
} else if (recipe instanceof ShapelessRecipes) {
items.addAll(((ShapelessRecipes) recipe).recipeItems);
} else {
src.sendMessage(Text.of(TextColors.RED, "Unsupported recipe for " + name));
continue;
}
items.removeAll(Collections.singleton(null));
BigDecimal creationCost = BigDecimal.ZERO;
try {
for (ItemStack stack : items) {
creationCost = creationCost.add(service.getPrice(tf(stack)).orElse(BigDecimal.ZERO));
}
} catch (Exception ex) {
src.sendMessage(Text.of(TextColors.RED, "Couldn't complete checks for " + name));
continue;
}
if (creationCost.equals(BigDecimal.ZERO)) {
src.sendMessage(Text.of(TextColors.RED, "No ingredients found on market for " + name));
continue;
}
BigDecimal sellPrice = optResultPrice.get();
sellPrice = sellPrice.multiply(service.getSellFactor(sellPrice));
profitMargins.add(new Clause<>(name, sellPrice.subtract(creationCost)));
}
List<Text> result = profitMargins.stream().sorted((a, b) -> b.getValue().subtract(a.getValue()).intValue()).map(a -> {
boolean profitable = a.getValue().compareTo(BigDecimal.ZERO) >= 0;
return Text.of(profitable ? TextColors.RED : TextColors.GREEN, a.getKey().toUpperCase(), " has a profit margin of ", profitable ? "+" : "", MarketImplUtil.format(a.getValue()));
}).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Profit Margin Report")).padding(Text.of(" ")).sendTo(src);
}).submit(SkreePlugin.inst());
src.sendMessage(Text.of(TextColors.YELLOW, "Verification in progress..."));
return CommandResult.success();
}
Aggregations