Search in sources :

Example 1 with IRequirement

use of com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirement 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 IRequirement

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

the class RecipeBuilderInternal method addRequirement.

@Override
public IRecipeBuilder addRequirement(IRequirementBuilder matchRequirementBuilder) {
    ResourceLocation location = matchRequirementBuilder.getResourceLocation();
    if (Loader.isModLoaded(matchRequirementBuilder.getRequirementId().toLowerCase())) {
        IRequirement requirement = matchRequirementBuilder.create();
        this.requirementMap.put(location, requirement);
    }
    return this;
}
Also used : IRequirement(com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirement) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 3 with IRequirement

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

the class PluginGameStages method processStagedRecipes.

@SideOnly(Side.CLIENT)
private void processStagedRecipes() {
    if (!FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        return;
    }
    if (PluginJEI.RECIPE_REGISTRY == null) {
        return;
    }
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    Collection<String> unlockedStages = GameStagesHelper.getUnlockedStages(player);
    GameStagesRequirementContext context = (GameStagesRequirementContext) ArtisanAPI.getRequirementContext(new ResourceLocation(ModArtisanWorktables.MOD_ID, "gamestages"));
    context.setUnlockedStages(unlockedStages);
    for (String name : ArtisanAPI.getWorktableNames()) {
        RecipeRegistry registry = ArtisanAPI.getWorktableRecipeRegistry(name);
        if (registry != null) {
            for (EnumTier tier : EnumTier.values()) {
                List<IArtisanRecipe> recipeList = registry.getRecipeListByTier(new ArrayList<>(), tier);
                String uid = PluginJEI.createUID(name, tier);
                for (IArtisanRecipe recipe : recipeList) {
                    IRecipeWrapper recipeWrapper = PluginJEI.RECIPE_REGISTRY.getRecipeWrapper(recipe, uid);
                    if (recipeWrapper == null) {
                        continue;
                    }
                    IRequirement requirement = recipe.getRequirement(GameStagesRequirement.LOCATION);
                    // noinspection unchecked
                    if (requirement == null || requirement.match(context)) {
                        PluginJEI.RECIPE_REGISTRY.unhideRecipe(recipeWrapper);
                    } else {
                        PluginJEI.RECIPE_REGISTRY.hideRecipe(recipeWrapper);
                    }
                }
            }
        }
    }
}
Also used : IRequirement(com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirement) GameStagesRequirementContext(com.codetaylor.mc.artisanworktables.modules.requirement.gamestages.requirement.GameStagesRequirementContext) ResourceLocation(net.minecraft.util.ResourceLocation) IArtisanRecipe(com.codetaylor.mc.artisanworktables.api.recipe.IArtisanRecipe) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EnumTier(com.codetaylor.mc.artisanworktables.api.internal.reference.EnumTier) RecipeRegistry(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeRegistry) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IRequirement (com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirement)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 RecipeRegistry (com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeRegistry)1 EnumTier (com.codetaylor.mc.artisanworktables.api.internal.reference.EnumTier)1 IArtisanRecipe (com.codetaylor.mc.artisanworktables.api.recipe.IArtisanRecipe)1 IRequirementContext (com.codetaylor.mc.artisanworktables.api.recipe.requirement.IRequirementContext)1 GameStagesRequirementContext (com.codetaylor.mc.artisanworktables.modules.requirement.gamestages.requirement.GameStagesRequirementContext)1 IRecipeWrapper (mezz.jei.api.recipe.IRecipeWrapper)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1