Search in sources :

Example 1 with MaterialRecipe

use of slimeknights.tconstruct.library.recipe.material.MaterialRecipe in project TinkersConstruct by SlimeKnights.

the class IPartBuilderRecipe method getLeftover.

/**
 * Gets the leftover from performing this recipe
 */
default ItemStack getLeftover(PartBuilderContainerWrapper inventoryWrapper) {
    MaterialRecipe recipe = inventoryWrapper.getMaterial();
    if (recipe != null) {
        int value = recipe.getValue();
        if (value > 1) {
            int remainder = value - getCost() % value;
            if (remainder > 0) {
                ItemStack leftover = recipe.getLeftover();
                leftover.setCount(leftover.getCount() * remainder);
                return leftover;
            }
        }
    }
    return ItemStack.EMPTY;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe)

Example 2 with MaterialRecipe

use of slimeknights.tconstruct.library.recipe.material.MaterialRecipe in project TinkersConstruct by SlimeKnights.

the class MaterialItemList method getItems.

/**
 * Gets a list of items
 * @param material  Materials
 * @return  List of items
 */
public static List<ItemStack> getItems(MaterialVariantId material) {
    List<ItemStack> list = ITEM_LISTS.get(material);
    if (list == null) {
        ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
        for (MaterialRecipe recipe : RECIPE_LIST) {
            if (material.matchesVariant(recipe.getMaterial())) {
                builder.addAll(recipe.getDisplayItems());
            }
        }
        list = builder.build();
        ITEM_LISTS.put(material, list);
    }
    return list;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ItemStack(net.minecraft.world.item.ItemStack) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe)

Example 3 with MaterialRecipe

use of slimeknights.tconstruct.library.recipe.material.MaterialRecipe in project TinkersConstruct by SlimeKnights.

the class PartBuilderScreen method updateDisplay.

@Override
public void updateDisplay() {
    // fixes the case where we added an item and lost recipes
    if (!canScroll()) {
        this.sliderProgress = 0.0F;
        this.recipeIndexOffset = 0;
    }
    // update part recipe cost
    IPartBuilderRecipe partRecipe = this.tile.getPartRecipe();
    if (partRecipe != null) {
        this.infoPanelScreen.setPatternCost(partRecipe.getCost());
    } else {
        this.infoPanelScreen.clearPatternCost();
    }
    // update material
    MaterialRecipe materialRecipe = this.tile.getMaterialRecipe();
    if (materialRecipe != null) {
        this.setDisplayForMaterial(materialRecipe);
    } else {
        // default text
        this.infoPanelScreen.setCaption(this.getTitle());
        this.infoPanelScreen.setText(INFO_TEXT);
        this.infoPanelScreen.clearMaterialValue();
    }
}
Also used : IPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IPartBuilderRecipe) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe)

Example 4 with MaterialRecipe

use of slimeknights.tconstruct.library.recipe.material.MaterialRecipe in project TinkersConstruct by SlimeKnights.

the class TinkerStationContainerWrapper method findMaterialRecipe.

/**
 * Finds a material recipe for the given slot
 * @param stack  Stack in slot
 * @return  Material recipe found, or null if missing
 */
@Nullable
private MaterialRecipe findMaterialRecipe(ItemStack stack) {
    // must have world
    Level world = station.getLevel();
    if (world == null) {
        return null;
    }
    // try last recipe
    ISingleStackContainer inv = () -> stack;
    if (lastMaterialRecipe != null && lastMaterialRecipe.matches(inv, world)) {
        return lastMaterialRecipe;
    }
    // try to find a new recipe
    Optional<MaterialRecipe> newRecipe = world.getRecipeManager().getRecipeFor(RecipeTypes.MATERIAL, inv, world);
    if (newRecipe.isPresent()) {
        lastMaterialRecipe = newRecipe.get();
        return lastMaterialRecipe;
    }
    // if none found, return null
    return null;
}
Also used : ISingleStackContainer(slimeknights.mantle.recipe.container.ISingleStackContainer) Level(net.minecraft.world.level.Level) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe) Nullable(javax.annotation.Nullable)

Example 5 with MaterialRecipe

use of slimeknights.tconstruct.library.recipe.material.MaterialRecipe in project TinkersConstruct by SlimeKnights.

the class PartRecipe method partialMatch.

@Override
public boolean partialMatch(IPartBuilderContainer inv) {
    // first, must have a pattern
    if (!patternItem.test(inv.getPatternStack())) {
        return false;
    }
    // if there is a material item, it must have a valid material and be craftable
    if (!inv.getStack().isEmpty()) {
        MaterialRecipe materialRecipe = inv.getMaterial();
        if (materialRecipe == null) {
            return false;
        }
        MaterialVariant material = materialRecipe.getMaterial();
        return material.get().isCraftable() && output.canUseMaterial(material.getId());
    }
    // no material item? return match in case we get one later
    return true;
}
Also used : MaterialVariant(slimeknights.tconstruct.library.materials.definition.MaterialVariant) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe)

Aggregations

MaterialRecipe (slimeknights.tconstruct.library.recipe.material.MaterialRecipe)9 ItemStack (net.minecraft.world.item.ItemStack)5 ImmutableList (com.google.common.collect.ImmutableList)2 Nullable (javax.annotation.Nullable)2 MaterialVariant (slimeknights.tconstruct.library.materials.definition.MaterialVariant)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)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 IGuiHandlerRegistration (mezz.jei.api.registration.IGuiHandlerRegistration)1 IModIngredientRegistration (mezz.jei.api.registration.IModIngredientRegistration)1