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

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.core.Registry;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.JigsawBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import com.google.common.collect.Lists;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import java.util.List;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import com.mojang.datafixers.Dynamic;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;

public class FeaturePoolElement extends StructurePoolElement {
    private final ConfiguredFeature<?, ?> feature;
    private final CompoundTag defaultJigsawNBT;
    
    @Deprecated
    public FeaturePoolElement(final ConfiguredFeature<?, ?> cdc) {
        this(cdc, StructureTemplatePool.Projection.RIGID);
    }
    
    public FeaturePoolElement(final ConfiguredFeature<?, ?> cdc, final StructureTemplatePool.Projection a) {
        super(a);
        this.feature = cdc;
        this.defaultJigsawNBT = this.fillDefaultJigsawNBT();
    }
    
    public <T> FeaturePoolElement(final Dynamic<T> dynamic) {
        super(dynamic);
        this.feature = ConfiguredFeature.deserialize((com.mojang.datafixers.Dynamic<Object>)dynamic.get("feature").orElseEmptyMap());
        this.defaultJigsawNBT = this.fillDefaultJigsawNBT();
    }
    
    public CompoundTag fillDefaultJigsawNBT() {
        final CompoundTag jt2 = new CompoundTag();
        jt2.putString("target_pool", "minecraft:empty");
        jt2.putString("attachement_type", "minecraft:bottom");
        jt2.putString("final_state", "minecraft:air");
        return jt2;
    }
    
    public BlockPos getSize(final StructureManager cmo, final Rotation btu) {
        return BlockPos.ZERO;
    }
    
    @Override
    public List<StructureTemplate.StructureBlockInfo> getShuffledJigsawBlocks(final StructureManager cmo, final BlockPos fk, final Rotation btu, final Random random) {
        final List<StructureTemplate.StructureBlockInfo> list6 = Lists.newArrayList();
        list6.add(new StructureTemplate.StructureBlockInfo(fk, ((AbstractStateHolder<O, BlockState>)Blocks.JIGSAW.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)JigsawBlock.FACING, Direction.DOWN), this.defaultJigsawNBT));
        return list6;
    }
    
    @Override
    public BoundingBox getBoundingBox(final StructureManager cmo, final BlockPos fk, final Rotation btu) {
        final BlockPos fk2 = this.getSize(cmo, btu);
        return new BoundingBox(fk.getX(), fk.getY(), fk.getZ(), fk.getX() + fk2.getX(), fk.getY() + fk2.getY(), fk.getZ() + fk2.getZ());
    }
    
    @Override
    public boolean place(final StructureManager cmo, final LevelAccessor bjx, final ChunkGenerator<?> caa, final BlockPos fk, final Rotation btu, final BoundingBox clb, final Random random) {
        return this.feature.place(bjx, caa, random, fk);
    }
    
    public <T> Dynamic<T> getDynamic(final DynamicOps<T> dynamicOps) {
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)ImmutableMap.of(dynamicOps.createString("feature"), this.feature.<T>serialize(dynamicOps).getValue())));
    }
    
    @Override
    public StructurePoolElementType getType() {
        return StructurePoolElementType.FEATURE;
    }
    
    @Override
    public String toString() {
        return "Feature[" + Registry.FEATURE.getKey(this.feature.feature) + "]";
    }
}
