Search in sources :

Example 1 with AlloyRecipe

use of slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe in project TinkersConstruct by SlimeKnights.

the class MultiAlloyingModule method iterateRecipes.

/**
 * Runs all the recipes, removing any that no longer match
 * @param predicate  Logic to run for recipes, return true to stop looping
 * @return  True if any recipe returned true
 */
private boolean iterateRecipes(Predicate<AlloyRecipe> predicate) {
    List<AlloyRecipe> recipes = getRecipes();
    if (recipes.isEmpty()) {
        return false;
    }
    Level world = getLevel();
    Iterator<AlloyRecipe> iterator = recipes.iterator();
    while (iterator.hasNext()) {
        // if the recipe no longer matches, remove
        // if it matches, run their function and stop if requested
        AlloyRecipe recipe = iterator.next();
        if (recipe.matches(alloyTank, world)) {
            if (predicate.test(recipe)) {
                return true;
            }
        } else {
            iterator.remove();
        }
    }
    return false;
}
Also used : AlloyRecipe(slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe) Level(net.minecraft.world.level.Level)

Example 2 with AlloyRecipe

use of slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe in project TinkersConstruct by SlimeKnights.

the class SingleAlloyingModule method findRecipe.

/**
 * Finds the recipe to perform
 */
@Nullable
private AlloyRecipe findRecipe() {
    Level world = getLevel();
    if (lastRecipe != null && lastRecipe.canPerform(alloyTank)) {
        return lastRecipe;
    }
    // fetch the first recipe that matches the inputs and fits in the tank
    // means if for some reason two recipes both are vaiud, the tank contents can be used to choose
    Optional<AlloyRecipe> recipe = world.getRecipeManager().byType(RecipeTypes.ALLOYING).values().stream().filter(r -> r instanceof AlloyRecipe).map(r -> (AlloyRecipe) r).filter(r -> alloyTank.canFit(r.getOutput(), 0) && r.canPerform(alloyTank)).findAny();
    // if found, cache and return
    if (recipe.isPresent()) {
        lastRecipe = recipe.get();
        return lastRecipe;
    } else {
        return null;
    }
}
Also used : Objects(java.util.Objects) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Optional(java.util.Optional) Level(net.minecraft.world.level.Level) AlloyRecipe(slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe) IMutableAlloyTank(slimeknights.tconstruct.library.recipe.alloying.IMutableAlloyTank) Nullable(javax.annotation.Nullable) MantleBlockEntity(slimeknights.mantle.block.entity.MantleBlockEntity) RecipeTypes(slimeknights.tconstruct.library.recipe.RecipeTypes) AlloyRecipe(slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe) Level(net.minecraft.world.level.Level) Nullable(javax.annotation.Nullable)

Example 3 with AlloyRecipe

use of slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe in project TinkersConstruct by SlimeKnights.

the class JEIPlugin method registerRecipes.

@Override
public void registerRecipes(IRecipeRegistration register) {
    assert Minecraft.getInstance().level != null;
    RecipeManager manager = Minecraft.getInstance().level.getRecipeManager();
    // casting
    List<IDisplayableCastingRecipe> castingBasinRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.CASTING_BASIN, IDisplayableCastingRecipe.class);
    register.addRecipes(castingBasinRecipes, TConstructRecipeCategoryUid.castingBasin);
    List<IDisplayableCastingRecipe> castingTableRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.CASTING_TABLE, IDisplayableCastingRecipe.class);
    register.addRecipes(castingTableRecipes, TConstructRecipeCategoryUid.castingTable);
    // melting
    List<MeltingRecipe> meltingRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.MELTING, MeltingRecipe.class);
    register.addRecipes(meltingRecipes, TConstructRecipeCategoryUid.melting);
    register.addRecipes(meltingRecipes, TConstructRecipeCategoryUid.foundry);
    MeltingFuelHandler.setMeltngFuels(RecipeHelper.getRecipes(manager, RecipeTypes.FUEL, MeltingFuel.class));
    // entity melting
    List<EntityMeltingRecipe> entityMeltingRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.ENTITY_MELTING, EntityMeltingRecipe.class);
    // generate a "default" recipe for all other entity types
    entityMeltingRecipes.add(new DefaultEntityMeltingRecipe(entityMeltingRecipes));
    register.addRecipes(entityMeltingRecipes, TConstructRecipeCategoryUid.entityMelting);
    // alloying
    List<AlloyRecipe> alloyRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.ALLOYING, AlloyRecipe.class);
    register.addRecipes(alloyRecipes, TConstructRecipeCategoryUid.alloy);
    // molding
    List<MoldingRecipe> moldingRecipes = ImmutableList.<MoldingRecipe>builder().addAll(RecipeHelper.getJEIRecipes(manager, RecipeTypes.MOLDING_TABLE, MoldingRecipe.class)).addAll(RecipeHelper.getJEIRecipes(manager, RecipeTypes.MOLDING_BASIN, MoldingRecipe.class)).build();
    register.addRecipes(moldingRecipes, TConstructRecipeCategoryUid.molding);
    // modifiers
    List<IDisplayModifierRecipe> modifierRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.TINKER_STATION, IDisplayModifierRecipe.class).stream().sorted((r1, r2) -> {
        SlotType t1 = r1.getSlotType();
        SlotType t2 = r2.getSlotType();
        String n1 = t1 == null ? "zzzzzzzzzz" : t1.getName();
        String n2 = t2 == null ? "zzzzzzzzzz" : t2.getName();
        return n1.compareTo(n2);
    }).collect(Collectors.toList());
    register.addRecipes(modifierRecipes, TConstructRecipeCategoryUid.modifiers);
    // beheading
    List<SeveringRecipe> severingRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.SEVERING, SeveringRecipe.class);
    register.addRecipes(severingRecipes, TConstructRecipeCategoryUid.severing);
    // part builder
    List<MaterialRecipe> materialRecipes = RecipeHelper.getRecipes(manager, RecipeTypes.MATERIAL, MaterialRecipe.class);
    MaterialItemList.setRecipes(materialRecipes);
    List<IDisplayPartBuilderRecipe> partRecipes = RecipeHelper.getJEIRecipes(manager, RecipeTypes.PART_BUILDER, IDisplayPartBuilderRecipe.class);
    register.addRecipes(partRecipes, TConstructRecipeCategoryUid.partBuilder);
}
Also used : HeatingStructureScreen(slimeknights.tconstruct.smeltery.client.screen.HeatingStructureScreen) Item(net.minecraft.world.item.Item) MeltingFuel(slimeknights.tconstruct.library.recipe.fuel.MeltingFuel) RecipeHelper(slimeknights.mantle.recipe.helper.RecipeHelper) Config(slimeknights.tconstruct.common.config.Config) UidContext(mezz.jei.api.ingredients.subtypes.UidContext) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) SlotType(slimeknights.tconstruct.library.tools.SlotType) CastItemObject(slimeknights.tconstruct.common.registration.CastItemObject) CastingTableCategory(slimeknights.tconstruct.plugin.jei.casting.CastingTableCategory) ArmorSlotType(slimeknights.tconstruct.tools.item.ArmorSlotType) RecipeType(net.minecraft.world.item.crafting.RecipeType) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) ModList(net.minecraftforge.fml.ModList) IGuiHandlerRegistration(mezz.jei.api.registration.IGuiHandlerRegistration) IGuiContainerHandler(mezz.jei.api.gui.handlers.IGuiContainerHandler) TinkerTools(slimeknights.tconstruct.tools.TinkerTools) AlloyRecipe(slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe) SeveringCategory(slimeknights.tconstruct.plugin.jei.entity.SeveringCategory) IDisplayableCastingRecipe(slimeknights.tconstruct.library.recipe.casting.IDisplayableCastingRecipe) IMaterialItem(slimeknights.tconstruct.library.tools.part.IMaterialItem) IIngredientType(mezz.jei.api.ingredients.IIngredientType) Modifier(slimeknights.tconstruct.library.modifiers.Modifier) FluidStack(net.minecraftforge.fluids.FluidStack) CastingBasinCategory(slimeknights.tconstruct.plugin.jei.casting.CastingBasinCategory) ItemStack(net.minecraft.world.item.ItemStack) MaterialIdNBT(slimeknights.tconstruct.library.tools.nbt.MaterialIdNBT) IRecipeCatalystRegistration(mezz.jei.api.registration.IRecipeCatalystRegistration) IDisplayModifierRecipe(slimeknights.tconstruct.library.recipe.modifiers.adding.IDisplayModifierRecipe) MeltingRecipe(slimeknights.tconstruct.library.recipe.melting.MeltingRecipe) EntityType(net.minecraft.world.entity.EntityType) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ModifierBookmarkIngredientRenderer(slimeknights.tconstruct.plugin.jei.modifiers.ModifierBookmarkIngredientRenderer) TinkerModifiers(slimeknights.tconstruct.tools.TinkerModifiers) IModPlugin(mezz.jei.api.IModPlugin) Container(net.minecraft.world.Container) EntityIngredientRenderer(slimeknights.tconstruct.plugin.jei.entity.EntityIngredientRenderer) IModifiableDisplay(slimeknights.tconstruct.library.tools.item.IModifiableDisplay) IModIngredientRegistration(mezz.jei.api.registration.IModIngredientRegistration) IRecipeTransferRegistration(mezz.jei.api.registration.IRecipeTransferRegistration) CopperCanItem(slimeknights.tconstruct.smeltery.item.CopperCanItem) MeltingCategory(slimeknights.tconstruct.plugin.jei.melting.MeltingCategory) Nullable(javax.annotation.Nullable) RecipeTypes(slimeknights.tconstruct.library.recipe.RecipeTypes) MelterScreen(slimeknights.tconstruct.smeltery.client.screen.MelterScreen) DefaultEntityMeltingRecipe(slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe) Tag(net.minecraft.tags.Tag) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) Pattern(slimeknights.tconstruct.library.recipe.partbuilder.Pattern) IScreenWithFluidTank(slimeknights.tconstruct.smeltery.client.screen.IScreenWithFluidTank) TinkerSmeltery(slimeknights.tconstruct.smeltery.TinkerSmeltery) RetexturedBlockItem(slimeknights.mantle.item.RetexturedBlockItem) MoldingRecipe(slimeknights.tconstruct.library.recipe.molding.MoldingRecipe) ModifierIngredientHelper(slimeknights.tconstruct.plugin.jei.modifiers.ModifierIngredientHelper) ResourceLocation(net.minecraft.resources.ResourceLocation) PatternIngredientHelper(slimeknights.tconstruct.plugin.jei.partbuilder.PatternIngredientHelper) EntityIngredientHelper(slimeknights.tconstruct.plugin.jei.entity.EntityIngredientHelper) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) EntityMeltingRecipeCategory(slimeknights.tconstruct.plugin.jei.entity.EntityMeltingRecipeCategory) Registry(net.minecraft.core.Registry) IIngredientManager(mezz.jei.api.runtime.IIngredientManager) CreativeSlotItem(slimeknights.tconstruct.tools.item.CreativeSlotItem) IDisplayPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IDisplayPartBuilderRecipe) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) MeltingFuelHandler(slimeknights.tconstruct.plugin.jei.melting.MeltingFuelHandler) PartBuilderCategory(slimeknights.tconstruct.plugin.jei.partbuilder.PartBuilderCategory) EntityMeltingRecipe(slimeknights.tconstruct.library.recipe.entitymelting.EntityMeltingRecipe) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) TinkerTables(slimeknights.tconstruct.tables.TinkerTables) TinkerTags(slimeknights.tconstruct.common.TinkerTags) IRecipeCategoryRegistration(mezz.jei.api.registration.IRecipeCategoryRegistration) Collectors(java.util.stream.Collectors) List(java.util.List) FoundryCategory(slimeknights.tconstruct.plugin.jei.melting.FoundryCategory) RecipeManager(net.minecraft.world.item.crafting.RecipeManager) IIngredientSubtypeInterpreter(mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter) ISubtypeRegistration(mezz.jei.api.registration.ISubtypeRegistration) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe) VanillaTypes(mezz.jei.api.constants.VanillaTypes) IJeiRuntime(mezz.jei.api.runtime.IJeiRuntime) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) SeveringRecipe(slimeknights.tconstruct.library.recipe.modifiers.severing.SeveringRecipe) JeiPlugin(mezz.jei.api.JeiPlugin) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) ItemLike(net.minecraft.world.level.ItemLike) IRecipeRegistration(mezz.jei.api.registration.IRecipeRegistration) Fluid(net.minecraft.world.level.material.Fluid) TinkerMaterials(slimeknights.tconstruct.shared.TinkerMaterials) SerializationTags(net.minecraft.tags.SerializationTags) PatternIngredientRenderer(slimeknights.tconstruct.plugin.jei.partbuilder.PatternIngredientRenderer) TinkerFluids(slimeknights.tconstruct.fluids.TinkerFluids) MaterialItemList(slimeknights.tconstruct.plugin.jei.partbuilder.MaterialItemList) SmelteryCompat(slimeknights.tconstruct.smeltery.data.SmelteryCompat) Recipe(net.minecraft.world.item.crafting.Recipe) ModifierRecipeCategory(slimeknights.tconstruct.plugin.jei.modifiers.ModifierRecipeCategory) Comparator(java.util.Comparator) Collections(java.util.Collections) TinkerStationTransferInfo(slimeknights.tconstruct.plugin.jei.transfer.TinkerStationTransferInfo) MeltingFuel(slimeknights.tconstruct.library.recipe.fuel.MeltingFuel) DefaultEntityMeltingRecipe(slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe) EntityMeltingRecipe(slimeknights.tconstruct.library.recipe.entitymelting.EntityMeltingRecipe) IDisplayModifierRecipe(slimeknights.tconstruct.library.recipe.modifiers.adding.IDisplayModifierRecipe) IDisplayableCastingRecipe(slimeknights.tconstruct.library.recipe.casting.IDisplayableCastingRecipe) MoldingRecipe(slimeknights.tconstruct.library.recipe.molding.MoldingRecipe) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe) SlotType(slimeknights.tconstruct.library.tools.SlotType) ArmorSlotType(slimeknights.tconstruct.tools.item.ArmorSlotType) MeltingRecipe(slimeknights.tconstruct.library.recipe.melting.MeltingRecipe) DefaultEntityMeltingRecipe(slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe) EntityMeltingRecipe(slimeknights.tconstruct.library.recipe.entitymelting.EntityMeltingRecipe) AlloyRecipe(slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe) SeveringRecipe(slimeknights.tconstruct.library.recipe.modifiers.severing.SeveringRecipe) RecipeManager(net.minecraft.world.item.crafting.RecipeManager) DefaultEntityMeltingRecipe(slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe) IDisplayPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IDisplayPartBuilderRecipe)

Aggregations

AlloyRecipe (slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe)3 Nullable (javax.annotation.Nullable)2 RecipeTypes (slimeknights.tconstruct.library.recipe.RecipeTypes)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 IModPlugin (mezz.jei.api.IModPlugin)1 JeiPlugin (mezz.jei.api.JeiPlugin)1 VanillaRecipeCategoryUid (mezz.jei.api.constants.VanillaRecipeCategoryUid)1 VanillaTypes (mezz.jei.api.constants.VanillaTypes)1 IGuiContainerHandler (mezz.jei.api.gui.handlers.IGuiContainerHandler)1 IGuiHelper (mezz.jei.api.helpers.IGuiHelper)1 IIngredientType (mezz.jei.api.ingredients.IIngredientType)1 IIngredientSubtypeInterpreter (mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter)1 UidContext (mezz.jei.api.ingredients.subtypes.UidContext)1