Search in sources :

Example 1 with IAgriGrowthRequirement

use of com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement in project AgriCraft by AgriCraft.

the class AgriRecipeCategoryGrowthRequirements method draw.

@Override
public void draw(@Nonnull IAgriPlant plant, @Nonnull MatrixStack transforms, double mouseX, double mouseY) {
    // Fetch strength and stage
    PlantRenderState state = this.getState(plant);
    int strength = state.getStrength();
    IAgriGrowthStage stage = state.getStage();
    IAgriGrowthRequirement req = plant.getGrowthRequirement(stage);
    // Tell the renderer to render with a custom growth stage
    AgriIngredientPlant.RENDERER.useGrowthStageForNextRenderCall(plant, stage);
    // Draw increments
    IncrementRenderer.getInstance().renderStrengthIncrements(transforms, strength);
    IncrementRenderer.getInstance().renderGrowthStageIncrements(transforms, stage);
    // Draw light levels
    LightLevelRenderer.getInstance().renderLightLevels(transforms, 32, 26, mouseX, mouseY, light -> req.getLightLevelResponse(light, strength).isFertile());
    // Draw Property icons
    Arrays.stream(IAgriSoil.Humidity.values()).filter(IAgriSoil.Humidity::isValid).filter(humidity -> req.getSoilHumidityResponse(humidity, strength).isFertile()).forEach(humidity -> SoilPropertyIconRenderer.getInstance().drawHumidityIcon(humidity, transforms, 37, 83, mouseX, mouseY));
    Arrays.stream(IAgriSoil.Acidity.values()).filter(IAgriSoil.Acidity::isValid).filter(acidity -> req.getSoilAcidityResponse(acidity, strength).isFertile()).forEach(acidity -> SoilPropertyIconRenderer.getInstance().drawAcidityIcon(acidity, transforms, 37, 96, mouseX, mouseY));
    Arrays.stream(IAgriSoil.Nutrients.values()).filter(IAgriSoil.Nutrients::isValid).filter(nutrients -> req.getSoilNutrientsResponse(nutrients, strength).isFertile()).forEach(nutrients -> SoilPropertyIconRenderer.getInstance().drawNutrientsIcon(nutrients, transforms, 37, 109, mouseX, mouseY));
    // Draw seasons
    SeasonRenderer.getInstance().renderSeasons(transforms, 17, 24, season -> req.getSeasonResponse(season, strength).isFertile());
    // Draw buttons
    state.updateStageButtons(102, 10);
    state.updateStrengthButtons(114, 10);
    state.drawGrowthStageButtons(transforms, mouseX, mouseY);
    state.drawStrengthButtons(transforms, mouseX, mouseY);
    // Draw tooltips
    this.tooltips.forEach(tooltip -> tooltip.drawTooltip(transforms, mouseX, mouseY, state));
}
Also used : java.util(java.util) IRecipeCatalystRegistration(mezz.jei.api.registration.IRecipeCatalystRegistration) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) AgriSeason(com.infinityraider.agricraft.api.v1.requirement.AgriSeason) IDrawable(mezz.jei.api.gui.drawable.IDrawable) IIngredients(mezz.jei.api.ingredients.IIngredients) AgriItemRegistry(com.infinityraider.agricraft.content.AgriItemRegistry) AbstractBlock(net.minecraft.block.AbstractBlock) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) Dist(net.minecraftforge.api.distmarker.Dist) BooleanSupplier(java.util.function.BooleanSupplier) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) AgriToolTips(com.infinityraider.agricraft.reference.AgriToolTips) Minecraft(net.minecraft.client.Minecraft) IRecipeCategory(mezz.jei.api.recipe.category.IRecipeCategory) IRecipeRegistration(mezz.jei.api.registration.IRecipeRegistration) IRenderUtilities(com.infinityraider.infinitylib.render.IRenderUtilities) StringTextComponent(net.minecraft.util.text.StringTextComponent) IAgriSoil(com.infinityraider.agricraft.api.v1.requirement.IAgriSoil) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) AgriCraft(com.infinityraider.agricraft.AgriCraft) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) ImmutableSet(com.google.common.collect.ImmutableSet) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) Predicate(java.util.function.Predicate) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.block.Blocks) AbstractGui(net.minecraft.client.gui.AbstractGui) IAgriGrowthRequirement(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement) ResourceLocation(net.minecraft.util.ResourceLocation) VanillaTypes(mezz.jei.api.constants.VanillaTypes) IAgriGrowthRequirement(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)

Example 2 with IAgriGrowthRequirement

use of com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement in project AgriCraft by AgriCraft.

the class AgriRecipeCategoryGrowthRequirements method setIngredients.

@Override
public void setIngredients(@Nonnull IAgriPlant plant, IIngredients ingredients) {
    // Get current strength and stage
    PlantRenderState state = this.getState(plant);
    int strength = state.getStrength();
    IAgriGrowthStage stage = state.getStage();
    // Determine inputs
    List<ItemStack> seeds = new ImmutableList.Builder<ItemStack>().add(plant.toItemStack()).addAll(plant.getSeedItems()).build();
    List<ItemStack> soils = AgriApi.getSoilRegistry().stream().filter(soil -> {
        IAgriGrowthRequirement req = plant.getGrowthRequirement(stage);
        boolean humidity = req.getSoilHumidityResponse(soil.getHumidity(), strength).isFertile();
        boolean acidity = req.getSoilAcidityResponse(soil.getAcidity(), strength).isFertile();
        boolean nutrients = req.getSoilNutrientsResponse(soil.getNutrients(), strength).isFertile();
        return humidity && acidity && nutrients;
    }).map(IAgriSoil::getVariants).flatMap(Collection::stream).map(AbstractBlock.AbstractBlockState::getBlock).distinct().map(ItemStack::new).collect(Collectors.toList());
    ingredients.setInputLists(VanillaTypes.ITEM, ImmutableList.of(seeds, soils));
    // Determine output
    ingredients.setOutputLists(AgriIngredientPlant.TYPE, ImmutableList.of(ImmutableList.of(plant)));
}
Also used : IAgriGrowthRequirement(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement) ImmutableList(com.google.common.collect.ImmutableList) ItemStack(net.minecraft.item.ItemStack) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) AbstractBlock(net.minecraft.block.AbstractBlock)

Example 3 with IAgriGrowthRequirement

use of com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement in project AgriCraft by AgriCraft.

the class JsonPlant method initGrowthRequirement.

public static IAgriGrowthRequirement initGrowthRequirement(AgriPlant plant) {
    // Run checks
    if (plant == null) {
        return AgriGrowthRequirement.getNone();
    }
    // Initialize utility objects
    IAgriGrowthRequirement.Builder builder = AgriApi.getGrowthRequirementBuilder();
    // Define requirement for humidity
    String humidityString = plant.getRequirement().getHumiditySoilCondition().getCondition();
    IAgriSoil.Humidity humidity = IAgriSoil.Humidity.fromString(humidityString).orElse(IAgriSoil.Humidity.INVALID);
    handleSoilCriterion(humidity, builder::defineHumidity, plant.getRequirement().getHumiditySoilCondition().getType(), plant.getRequirement().getHumiditySoilCondition().getToleranceFactor(), () -> AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has an invalid humidity criterion (\"{1}\")!", plant.getId(), humidityString));
    // Define requirement for acidity
    String acidityString = plant.getRequirement().getAciditySoilCondition().getCondition();
    IAgriSoil.Acidity acidity = IAgriSoil.Acidity.fromString(acidityString).orElse(IAgriSoil.Acidity.INVALID);
    handleSoilCriterion(acidity, builder::defineAcidity, plant.getRequirement().getAciditySoilCondition().getType(), plant.getRequirement().getAciditySoilCondition().getToleranceFactor(), () -> AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has an invalid acidity criterion (\"{1}\")!", plant.getId(), acidityString));
    // Define requirement for nutrients
    String nutrientString = plant.getRequirement().getNutrientSoilCondition().getCondition();
    IAgriSoil.Nutrients nutrients = IAgriSoil.Nutrients.fromString(nutrientString).orElse(IAgriSoil.Nutrients.INVALID);
    handleSoilCriterion(nutrients, builder::defineNutrients, plant.getRequirement().getNutrientSoilCondition().getType(), plant.getRequirement().getNutrientSoilCondition().getToleranceFactor(), () -> AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has an invalid nutrients criterion (\"{1}\")!", plant.getId(), nutrientString));
    // Define requirement for light
    final double f = plant.getRequirement().getLightToleranceFactor();
    final int minLight = plant.getRequirement().getMinLight();
    final int maxLight = plant.getRequirement().getMaxLight();
    builder.defineLightLevel((strength, light) -> {
        int lower = minLight - (int) (f * strength);
        int upper = maxLight + (int) (f * strength);
        return light >= lower && light <= upper ? IAgriGrowthResponse.FERTILE : IAgriGrowthResponse.INFERTILE;
    });
    // Define requirement for nearby blocks
    plant.getRequirement().getConditions().forEach(obj -> {
        BlockPos min = new BlockPos(obj.getMinX(), obj.getMinY(), obj.getMinZ());
        BlockPos max = new BlockPos(obj.getMaxX(), obj.getMaxY(), obj.getMaxZ());
        builder.addCondition(builder.blockStatesNearby(obj.convertAll(BlockState.class), obj.getAmount(), min, max));
    });
    // Define requirement for seasons
    List<AgriSeason> seasons = plant.getRequirement().getSeasons().stream().map(AgriSeason::fromString).filter(Optional::isPresent).map(Optional::get).distinct().collect(Collectors.toList());
    if (seasons.size() > 0) {
        builder.defineSeasonality((str, season) -> {
            if (str >= AgriApi.getStatRegistry().strengthStat().getMax() || seasons.stream().anyMatch(season::matches)) {
                return IAgriGrowthResponse.FERTILE;
            } else {
                return IAgriGrowthResponse.INFERTILE;
            }
        });
    }
    // Define requirement for fluids
    List<Fluid> fluids = plant.getRequirement().getFluid().convertAll(FluidState.class).stream().map(FluidState::getFluid).distinct().collect(Collectors.toList());
    BiFunction<Integer, Fluid, IAgriGrowthResponse> response = (strength, fluid) -> {
        if (fluids.size() > 0) {
            if (fluids.contains(fluid)) {
                return IAgriGrowthResponse.FERTILE;
            }
            return fluid.equals(Fluids.LAVA) ? IAgriGrowthResponse.KILL_IT_WITH_FIRE : IAgriGrowthResponse.LETHAL;
        } else {
            if (fluid.equals(Fluids.LAVA)) {
                return IAgriGrowthResponse.KILL_IT_WITH_FIRE;
            }
            return fluid.equals(Fluids.EMPTY) ? IAgriGrowthResponse.FERTILE : IAgriGrowthResponse.LETHAL;
        }
    };
    builder.defineFluid(response);
    // Build the growth requirement
    IAgriGrowthRequirement req = builder.build();
    // Log warning if no soils exist for this requirement combination
    if (noSoilsMatch(req)) {
        AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has no valid soils to plant on for any strength level!", plant.getId());
    }
    // Return the growth requirements
    return req;
}
Also used : FluidState(net.minecraft.fluid.FluidState) java.util(java.util) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BiFunction(java.util.function.BiFunction) AgriSoilCondition(com.agricraft.agricore.plant.AgriSoilCondition) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) Direction(net.minecraft.util.Direction) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) AgriCore(com.agricraft.agricore.core.AgriCore) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) AgriGrowthRequirement(com.infinityraider.agricraft.impl.v1.requirement.AgriGrowthRequirement) IAgriFertilizer(com.infinityraider.agricraft.api.v1.fertilizer.IAgriFertilizer) com.infinityraider.agricraft.api.v1.requirement(com.infinityraider.agricraft.api.v1.requirement) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Fluids(net.minecraft.fluid.Fluids) AgriCraft(com.infinityraider.agricraft.AgriCraft) Entity(net.minecraft.entity.Entity) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IJsonPlantCallback(com.infinityraider.agricraft.api.v1.plant.IJsonPlantCallback) IncrementalGrowthLogic(com.infinityraider.agricraft.impl.v1.crop.IncrementalGrowthLogic) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) VanillaSeedConversionHandler(com.infinityraider.agricraft.handler.VanillaSeedConversionHandler) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) AgriPlantQuadGenerator(com.infinityraider.agricraft.render.plant.AgriPlantQuadGenerator) BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Consumer(java.util.function.Consumer) IParticleData(net.minecraft.particles.IParticleData) IAgriStatsMap(com.infinityraider.agricraft.api.v1.stat.IAgriStatsMap) AgriPlant(com.agricraft.agricore.plant.AgriPlant) ResourceLocation(net.minecraft.util.ResourceLocation) ParticleType(net.minecraft.particles.ParticleType) Fluid(net.minecraft.fluid.Fluid) ActionResultType(net.minecraft.util.ActionResultType) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) ModelResourceLocation(net.minecraft.client.renderer.model.ModelResourceLocation) Fluid(net.minecraft.fluid.Fluid) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState)

Example 4 with IAgriGrowthRequirement

use of com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement in project AgriCraft by AgriCraft.

the class AgriClocheRecipe method getTime.

@Override
public int getTime(ItemStack seed, ItemStack soilStack) {
    IAgriPlant plant = this.getPlant(seed);
    IAgriSoil soil = this.getSoil(soilStack);
    Optional<IAgriStatsMap> statsOptional = this.getStats(seed);
    if (plant.isPlant() && soil.isSoil() && statsOptional.isPresent()) {
        IAgriStatsMap stats = statsOptional.get();
        IAgriGrowthRequirement req = plant.getGrowthRequirement(plant.getInitialGrowthStage());
        int strength = stats.getStrength();
        if (!req.getSoilHumidityResponse(soil.getHumidity(), strength).isFertile()) {
            return Integer.MAX_VALUE;
        }
        if (!req.getSoilAcidityResponse(soil.getAcidity(), strength).isFertile()) {
            return Integer.MAX_VALUE;
        }
        if (!req.getSoilNutrientsResponse(soil.getNutrients(), strength).isFertile()) {
            return Integer.MAX_VALUE;
        }
        double growthFactor = 1 - stats.getGrowth() * this.getGrowthStatFactor();
        double soilFactor = 2 - soil.getGrowthModifier();
        return Math.max((int) (this.getGrowthTicks() * growthFactor * soilFactor), 1);
    }
    return Integer.MAX_VALUE;
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) IAgriGrowthRequirement(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement) IAgriStatsMap(com.infinityraider.agricraft.api.v1.stat.IAgriStatsMap) IAgriSoil(com.infinityraider.agricraft.api.v1.requirement.IAgriSoil)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 IAgriGrowthStage (com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)3 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)3 IAgriGrowthRequirement (com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement)3 ItemStack (net.minecraft.item.ItemStack)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)2 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)2 IAgriSoil (com.infinityraider.agricraft.api.v1.requirement.IAgriSoil)2 IAgriStatsMap (com.infinityraider.agricraft.api.v1.stat.IAgriStatsMap)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2 AbstractBlock (net.minecraft.block.AbstractBlock)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 Dist (net.minecraftforge.api.distmarker.Dist)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2 AgriCore (com.agricraft.agricore.core.AgriCore)1 AgriPlant (com.agricraft.agricore.plant.AgriPlant)1 AgriSoilCondition (com.agricraft.agricore.plant.AgriSoilCondition)1