package net.minecraft.world.level.levelgen.feature.trunkplacers;

import com.mojang.datafixers.kinds.Applicative;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Vec3i;
import com.google.common.collect.ImmutableList;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;
import java.util.List;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import java.util.Set;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.LevelSimulatedRW;
import com.mojang.serialization.Codec;

public class GiantTrunkPlacer extends TrunkPlacer {
    public static final Codec<GiantTrunkPlacer> CODEC;
    
    public GiantTrunkPlacer(final int integer1, final int integer2, final int integer3) {
        super(integer1, integer2, integer3);
    }
    
    @Override
    protected TrunkPlacerType<?> type() {
        return TrunkPlacerType.GIANT_TRUNK_PLACER;
    }
    
    @Override
    public List<FoliagePlacer.FoliageAttachment> placeTrunk(final LevelSimulatedRW bqf, final Random random, final int integer, final BlockPos fu, final Set<BlockPos> set, final BoundingBox ctd, final TreeConfiguration cou) {
        final BlockPos fu2 = fu.below();
        TrunkPlacer.setDirtAt(bqf, fu2);
        TrunkPlacer.setDirtAt(bqf, fu2.east());
        TrunkPlacer.setDirtAt(bqf, fu2.south());
        TrunkPlacer.setDirtAt(bqf, fu2.south().east());
        final BlockPos.MutableBlockPos a10 = new BlockPos.MutableBlockPos();
        for (int integer2 = 0; integer2 < integer; ++integer2) {
            placeLogIfFreeWithOffset(bqf, random, a10, set, ctd, cou, fu, 0, integer2, 0);
            if (integer2 < integer - 1) {
                placeLogIfFreeWithOffset(bqf, random, a10, set, ctd, cou, fu, 1, integer2, 0);
                placeLogIfFreeWithOffset(bqf, random, a10, set, ctd, cou, fu, 1, integer2, 1);
                placeLogIfFreeWithOffset(bqf, random, a10, set, ctd, cou, fu, 0, integer2, 1);
            }
        }
        return ImmutableList.<FoliagePlacer.FoliageAttachment>of(new FoliagePlacer.FoliageAttachment(fu.above(integer), 0, true));
    }
    
    private static void placeLogIfFreeWithOffset(final LevelSimulatedRW bqf, final Random random, final BlockPos.MutableBlockPos a, final Set<BlockPos> set, final BoundingBox ctd, final TreeConfiguration cou, final BlockPos fu, final int integer8, final int integer9, final int integer10) {
        a.setWithOffset(fu, integer8, integer9, integer10);
        TrunkPlacer.placeLogIfFree(bqf, random, a, set, ctd, cou);
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> TrunkPlacer.<TrunkPlacer>trunkPlacerParts((RecordCodecBuilder.Instance<TrunkPlacer>)instance).apply(instance, GiantTrunkPlacer::new));
    }
}
