// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.adventure.farming.config.modifiers;

import com.hypixel.hytale.builtin.adventure.farming.states.TilledSoilBlock;
import com.hypixel.hytale.math.util.ChunkUtil;
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
import com.hypixel.hytale.server.core.universe.world.chunk.section.ChunkSection;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.asset.type.blocktype.config.farming.GrowthModifierAsset;

public class FertilizerGrowthModifierAsset extends GrowthModifierAsset
{
    public static final BuilderCodec<FertilizerGrowthModifierAsset> CODEC;
    
    @Override
    public double getCurrentGrowthMultiplier(final CommandBuffer<ChunkStore> commandBuffer, final Ref<ChunkStore> sectionRef, final Ref<ChunkStore> blockRef, final int x, final int y, final int z, final boolean initialTick) {
        final ChunkSection chunkSection = commandBuffer.getComponent(sectionRef, ChunkSection.getComponentType());
        final Ref<ChunkStore> chunk = chunkSection.getChunkColumnReference();
        final BlockComponentChunk blockComponentChunk = commandBuffer.getComponent(chunk, BlockComponentChunk.getComponentType());
        final Ref<ChunkStore> blockRefBelow = blockComponentChunk.getEntityReference(ChunkUtil.indexBlockInColumn(x, y - 1, z));
        if (blockRefBelow == null) {
            return 1.0;
        }
        final TilledSoilBlock soil = commandBuffer.getComponent(blockRefBelow, TilledSoilBlock.getComponentType());
        if (soil != null && soil.isFertilized()) {
            return super.getCurrentGrowthMultiplier(commandBuffer, sectionRef, blockRef, x, y, z, initialTick);
        }
        return 1.0;
    }
    
    static {
        CODEC = BuilderCodec.builder(FertilizerGrowthModifierAsset.class, FertilizerGrowthModifierAsset::new, FertilizerGrowthModifierAsset.ABSTRACT_CODEC).build();
    }
}
