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

import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.core.Registry;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.LevelWriter;
import net.minecraft.world.level.block.VineBlock;
import net.minecraft.world.level.LevelSimulatedReader;
import net.minecraft.world.level.levelgen.feature.AbstractTreeFeature;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import java.util.Set;
import net.minecraft.core.BlockPos;
import java.util.List;
import java.util.Random;
import net.minecraft.world.level.LevelAccessor;
import com.mojang.datafixers.Dynamic;

public class TrunkVineDecorator extends TreeDecorator {
    public TrunkVineDecorator() {
        super(TreeDecoratorType.TRUNK_VINE);
    }
    
    public <T> TrunkVineDecorator(final Dynamic<T> dynamic) {
        this();
    }
    
    @Override
    public void place(final LevelAccessor bjx, final Random random, final List<BlockPos> list3, final List<BlockPos> list4, final Set<BlockPos> set, final BoundingBox clb) {
        BlockPos fk2;
        BlockPos fk3;
        BlockPos fk4;
        BlockPos fk5;
        list3.forEach(fk -> {
            if (random.nextInt(3) > 0) {
                fk2 = fk.west();
                if (AbstractTreeFeature.isAir(bjx, fk2)) {
                    this.placeVine(bjx, fk2, VineBlock.EAST, set, clb);
                }
            }
            if (random.nextInt(3) > 0) {
                fk3 = fk.east();
                if (AbstractTreeFeature.isAir(bjx, fk3)) {
                    this.placeVine(bjx, fk3, VineBlock.WEST, set, clb);
                }
            }
            if (random.nextInt(3) > 0) {
                fk4 = fk.north();
                if (AbstractTreeFeature.isAir(bjx, fk4)) {
                    this.placeVine(bjx, fk4, VineBlock.SOUTH, set, clb);
                }
            }
            if (random.nextInt(3) > 0) {
                fk5 = fk.south();
                if (AbstractTreeFeature.isAir(bjx, fk5)) {
                    this.placeVine(bjx, fk5, VineBlock.NORTH, set, clb);
                }
            }
        });
    }
    
    @Override
    public <T> T serialize(final DynamicOps<T> dynamicOps) {
        return (T)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("type"), dynamicOps.createString(Registry.TREE_DECORATOR_TYPES.getKey(this.type).toString())))).getValue();
    }
}
