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;
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations