Search in sources :

Example 1 with IRequirementContext

use of com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext in project artisan-worktables by codetaylor.

the class ArtisanRecipe method matchesRequirements.

@Override
public boolean matchesRequirements(Map<ResourceLocation, IRequirementContext> requirementContextMap) {
    // match requirements
    for (IRequirement requirement : this.requirementMap.values()) {
        ResourceLocation location = requirement.getResourceLocation();
        IRequirementContext context = requirementContextMap.get(location);
        if (context == null) {
            return false;
        }
        // noinspection unchecked
        if (!requirement.match(context)) {
            return false;
        }
    }
    return true;
}
Also used : IRequirement(com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirement) ResourceLocation(net.minecraft.util.ResourceLocation) IRequirementContext(com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext)

Example 2 with IRequirementContext

use of com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext in project artisan-worktables by codetaylor.

the class TileEntityBase method getRecipe.

public IArtisanRecipe getRecipe(@Nonnull EntityPlayer player) {
    FluidStack fluidStack = this.getTank().getFluid();
    if (fluidStack != null) {
        fluidStack = fluidStack.copy();
    }
    int playerExperience = EnchantmentHelper.getPlayerExperienceTotal(player);
    int playerLevels = player.experienceLevel;
    boolean isPlayerCreative = player.isCreative();
    IForgeRegistry<RequirementContextSupplier> contextSupplierRegistry = ArtisanRegistries.REQUIREMENT_CONTEXT_SUPPLIER;
    Map<ResourceLocation, IRequirementContext> contextMap = new HashMap<>();
    ICraftingContext craftingContext = this.getCraftingContext(player);
    for (Map.Entry<ResourceLocation, RequirementContextSupplier> entry : contextSupplierRegistry.getEntries()) {
        RequirementContextSupplier contextSupplier = entry.getValue();
        IRequirementContext context = contextSupplier.get();
        context.initialize(craftingContext);
        contextMap.put(entry.getKey(), context);
    }
    return this.getWorktableRecipeRegistry().findRecipe(playerExperience, playerLevels, isPlayerCreative, this.getTools(), this.craftingMatrixHandler, fluidStack, this.getSecondaryIngredientMatcher(), this.getTier(), contextMap);
}
Also used : RequirementContextSupplier(com.codetaylor.mc.artisanworktables.api.recipe.requirement.RequirementContextSupplier) FluidStack(net.minecraftforge.fluids.FluidStack) ResourceLocation(net.minecraft.util.ResourceLocation) IRequirementContext(com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext)

Aggregations

IRequirementContext (com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IRequirement (com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirement)1 RequirementContextSupplier (com.codetaylor.mc.artisanworktables.api.recipe.requirement.RequirementContextSupplier)1 FluidStack (net.minecraftforge.fluids.FluidStack)1