Search in sources :

Example 1 with MatchSmeltingVanillaItemStack

use of org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack in project SpongeCommon by SpongePowered.

the class MixinFurnaceRecipes method findMatchingRecipe.

@Override
public Optional<SmeltingRecipe> findMatchingRecipe(ItemStackSnapshot ingredient) {
    checkNotNull(ingredient, "ingredient");
    for (SmeltingRecipe customRecipe : this.customRecipes) {
        if (customRecipe.isValid(ingredient)) {
            return Optional.of(customRecipe);
        }
    }
    ItemStack nativeIngredient = ItemStackUtil.fromSnapshotToNative(ingredient);
    for (Map.Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet()) {
        ItemStack nativeIngredientPrecise = entry.getKey();
        if (compareItemStacks(nativeIngredient, nativeIngredientPrecise)) {
            ItemStack nativeExemplaryResult = entry.getValue();
            ItemStackSnapshot result = ItemStackUtil.snapshotOf(nativeExemplaryResult);
            ItemStackSnapshot ingredientPrecise = ItemStackUtil.snapshotOf(nativeIngredientPrecise);
            Predicate<ItemStackSnapshot> ingredientPredicate = new MatchSmeltingVanillaItemStack(ingredientPrecise);
            double experience = this.experienceList.get(nativeExemplaryResult);
            SmeltingRecipe recipe = new SpongeSmeltingRecipe(result, ingredientPrecise, ingredientPredicate, experience);
            return Optional.of(recipe);
        }
    }
    return Optional.empty();
}
Also used : SpongeSmeltingRecipe(org.spongepowered.common.item.recipe.smelting.SpongeSmeltingRecipe) SmeltingRecipe(org.spongepowered.api.item.recipe.smelting.SmeltingRecipe) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SpongeSmeltingRecipe(org.spongepowered.common.item.recipe.smelting.SpongeSmeltingRecipe) ItemStack(net.minecraft.item.ItemStack) MatchSmeltingVanillaItemStack(org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack) MatchSmeltingVanillaItemStack(org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Example 2 with MatchSmeltingVanillaItemStack

use of org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack in project SpongeCommon by SpongePowered.

the class MixinFurnaceRecipes method getRecipes.

@Override
public Collection<SmeltingRecipe> getRecipes() {
    ImmutableList.Builder<SmeltingRecipe> builder = ImmutableList.builder();
    for (Map.Entry<ItemStack, ItemStack> smeltingEntry : this.smeltingList.entrySet()) {
        ItemStack nativeIngredient = smeltingEntry.getKey();
        // If not a custom recipe, add first
        if (!this.nativeIngredientToCustomRecipe.containsKey(nativeIngredient)) {
            ItemStack nativeExemplaryResult = smeltingEntry.getValue();
            ItemStackSnapshot exemplaryResult = ItemStackUtil.snapshotOf(nativeExemplaryResult);
            ItemStackSnapshot exemplaryIngredient = ItemStackUtil.snapshotOf(nativeIngredient);
            Predicate<ItemStackSnapshot> ingredientPredicate = new MatchSmeltingVanillaItemStack(exemplaryIngredient);
            double experience = (double) this.experienceList.get(nativeExemplaryResult);
            builder.add(new SpongeSmeltingRecipe(exemplaryResult, exemplaryIngredient, ingredientPredicate, experience));
        }
    }
    builder.addAll(this.customRecipes);
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SpongeSmeltingRecipe(org.spongepowered.common.item.recipe.smelting.SpongeSmeltingRecipe) SmeltingRecipe(org.spongepowered.api.item.recipe.smelting.SmeltingRecipe) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SpongeSmeltingRecipe(org.spongepowered.common.item.recipe.smelting.SpongeSmeltingRecipe) ItemStack(net.minecraft.item.ItemStack) MatchSmeltingVanillaItemStack(org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack) MatchSmeltingVanillaItemStack(org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 ItemStack (net.minecraft.item.ItemStack)2 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)2 SmeltingRecipe (org.spongepowered.api.item.recipe.smelting.SmeltingRecipe)2 MatchSmeltingVanillaItemStack (org.spongepowered.common.item.recipe.smelting.MatchSmeltingVanillaItemStack)2 SpongeSmeltingRecipe (org.spongepowered.common.item.recipe.smelting.SpongeSmeltingRecipe)2 ImmutableList (com.google.common.collect.ImmutableList)1