Search in sources :

Example 1 with IAgriGrowthStage

use of com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage in project AgriCraft by AgriCraft.

the class TileEntityCropBase method revertGrowthStage.

protected void revertGrowthStage() {
    IAgriGrowthStage current = this.getGrowthStage();
    IAgriGrowthStage previous = current.getPreviousStage(this, this.getRandom());
    if (current.equals(previous)) {
        this.removeGenome();
    } else {
        this.setGrowthStage(previous);
    }
}
Also used : IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)

Example 2 with IAgriGrowthStage

use of com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage 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 3 with IAgriGrowthStage

use of com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage 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 4 with IAgriGrowthStage

use of com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage in project AgriCraft by AgriCraft.

the class MysticalAgricultureCompatClient method bakeQuadsForMystical.

@Nonnull
private static List<BakedQuad> bakeQuadsForMystical(IAgriGrowable growable, IAgriGrowthStage stage, @Nullable Direction face, IntFunction<TextureAtlasSprite> spriteFunc) {
    if (face != null) {
        return ImmutableList.of();
    }
    ITessellator tessellator = AgriPlantQuadGenerator.getInstance().getTessellator();
    TextureAtlasSprite sprite = spriteFunc.apply(0);
    tessellator.startDrawingQuads();
    tessellator.setFace((Direction) null);
    tessellator.pushMatrix();
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, sprite, 4.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, sprite, 3.999F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, sprite, 4.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, sprite, 3.999F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, sprite, 12.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, sprite, 11.999F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, sprite, 12.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, sprite, 11.999F, 0, 0, 16, 16);
    if (stage.isFinal()) {
        IAgriPlant plant = ((IAgriPlant) growable);
        int flowerColor = MysticalAgricultureCompatClient.colorForFlower(plant.getId());
        TextureAtlasSprite flowerSprite = spriteFunc.apply(1);
        if (flowerColor != -1) {
            tessellator.setColorRGB(((flowerColor >> 16) & 0xFF) / 255.0F, ((flowerColor >> 8) & 0xFF) / 255.0F, ((flowerColor) & 0xFF) / 255.0F);
        }
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, flowerSprite, 4.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, flowerSprite, 3.999F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, flowerSprite, 4.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, flowerSprite, 3.999F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, flowerSprite, 12.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, flowerSprite, 11.999F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, flowerSprite, 12.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, flowerSprite, 11.999F, 0, 0, 16, 16);
    }
    tessellator.translate(0, 12.0F / 16.0F, 0);
    tessellator.popMatrix();
    List<BakedQuad> quads = tessellator.getQuads();
    tessellator.draw();
    return quads;
}
Also used : ITessellator(com.infinityraider.infinitylib.render.tessellation.ITessellator) BakedQuad(net.minecraft.client.renderer.model.BakedQuad) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Nonnull(javax.annotation.Nonnull)

Example 5 with IAgriGrowthStage

use of com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage in project AgriCraft by AgriCraft.

the class JsonFertilizer method applyFertilizer.

@Override
public ActionResultType applyFertilizer(World world, BlockPos pos, IAgriFertilizable target, ItemStack stack, Random random, @Nullable LivingEntity entity) {
    if (target instanceof IAgriPlantProvider) {
        IAgriCrop crop = ((IAgriCrop) target);
        String type = "neutral";
        for (int i = 0; i < this.potency; i++) {
            if (fertilizerEffect.isNegativelyAffected(crop.getPlant().getId())) {
                if (fertilizerEffect.canReduceGrowth() && random.nextBoolean()) {
                    type = "negative";
                    IAgriGrowthStage current = crop.getGrowthStage();
                    IAgriGrowthStage previous = current.getPreviousStage(crop, random);
                    if (current.equals(previous)) {
                        if (fertilizerEffect.canKillPlant()) {
                            crop.removeGenome();
                        }
                    } else {
                        crop.setGrowthStage(previous);
                    }
                }
            } else {
                if (crop.hasPlant() && this.fertilizerEffect.canFertilize(crop.getPlant().getId())) {
                    target.applyGrowthTick();
                    type = "positive";
                } else if (crop.isCrossCrop() && this.canTriggerMutation()) {
                    target.applyGrowthTick();
                    type = "positive";
                } else if (this.canTriggerWeeds()) {
                    target.applyGrowthTick();
                    type = "positive";
                }
            }
        }
        this.spawnParticles(world, pos, type, random);
        if ((entity instanceof PlayerEntity) && !(((PlayerEntity) entity).isCreative())) {
            stack.shrink(1);
        }
        return ActionResultType.SUCCESS;
    }
    return ActionResultType.FAIL;
}
Also used : IAgriPlantProvider(com.infinityraider.agricraft.api.v1.plant.IAgriPlantProvider) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IAgriGrowthStage (com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)5 ImmutableList (com.google.common.collect.ImmutableList)2 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)2 IAgriGrowthRequirement (com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthRequirement)2 Nonnull (javax.annotation.Nonnull)2 AbstractBlock (net.minecraft.block.AbstractBlock)2 ItemStack (net.minecraft.item.ItemStack)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 AgriCraft (com.infinityraider.agricraft.AgriCraft)1 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 IAgriPlantProvider (com.infinityraider.agricraft.api.v1.plant.IAgriPlantProvider)1 IAgriWeed (com.infinityraider.agricraft.api.v1.plant.IAgriWeed)1 AgriSeason (com.infinityraider.agricraft.api.v1.requirement.AgriSeason)1 IAgriSoil (com.infinityraider.agricraft.api.v1.requirement.IAgriSoil)1 AgriItemRegistry (com.infinityraider.agricraft.content.AgriItemRegistry)1 AgriToolTips (com.infinityraider.agricraft.reference.AgriToolTips)1 IRenderUtilities (com.infinityraider.infinitylib.render.IRenderUtilities)1 ITessellator (com.infinityraider.infinitylib.render.tessellation.ITessellator)1