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