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

import com.google.common.collect.ImmutableList;
import net.minecraft.resources.ResourceLocation;
import java.util.function.Supplier;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator;
import java.util.List;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;

public class SmallTreeConfiguration extends TreeConfiguration {
    public final FoliagePlacer foliagePlacer;
    public final int heightRandA;
    public final int heightRandB;
    public final int trunkHeight;
    public final int trunkHeightRandom;
    public final int trunkTopOffset;
    public final int trunkTopOffsetRandom;
    public final int foliageHeight;
    public final int foliageHeightRandom;
    public final int maxWaterDepth;
    public final boolean ignoreVines;
    
    protected SmallTreeConfiguration(final BlockStateProvider chw1, final BlockStateProvider chw2, final FoliagePlacer chq, final List<TreeDecorator> list, final int integer5, final int integer6, final int integer7, final int integer8, final int integer9, final int integer10, final int integer11, final int integer12, final int integer13, final int integer14, final boolean boolean15) {
        super(chw1, chw2, list, integer5);
        this.foliagePlacer = chq;
        this.heightRandA = integer6;
        this.heightRandB = integer7;
        this.trunkHeight = integer8;
        this.trunkHeightRandom = integer9;
        this.trunkTopOffset = integer10;
        this.trunkTopOffsetRandom = integer11;
        this.foliageHeight = integer12;
        this.foliageHeightRandom = integer13;
        this.maxWaterDepth = integer14;
        this.ignoreVines = boolean15;
    }
    
    @Override
    public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
        final ImmutableMap.Builder<T, T> builder3 = ImmutableMap.<T, T>builder();
        builder3.put((T)dynamicOps.createString("foliage_placer"), this.foliagePlacer.<T>serialize(dynamicOps)).put((T)dynamicOps.createString("height_rand_a"), (T)dynamicOps.createInt(this.heightRandA)).put((T)dynamicOps.createString("height_rand_b"), (T)dynamicOps.createInt(this.heightRandB)).put((T)dynamicOps.createString("trunk_height"), (T)dynamicOps.createInt(this.trunkHeight)).put((T)dynamicOps.createString("trunk_height_random"), (T)dynamicOps.createInt(this.trunkHeightRandom)).put((T)dynamicOps.createString("trunk_top_offset"), (T)dynamicOps.createInt(this.trunkTopOffset)).put((T)dynamicOps.createString("trunk_top_offset_random"), (T)dynamicOps.createInt(this.trunkTopOffsetRandom)).put((T)dynamicOps.createString("foliage_height"), (T)dynamicOps.createInt(this.foliageHeight)).put((T)dynamicOps.createString("foliage_height_random"), (T)dynamicOps.createInt(this.foliageHeightRandom)).put((T)dynamicOps.createString("max_water_depth"), (T)dynamicOps.createInt(this.maxWaterDepth)).put((T)dynamicOps.createString("ignore_vines"), (T)dynamicOps.createBoolean(this.ignoreVines));
        final Dynamic<T> dynamic4 = (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)builder3.build()));
        return (Dynamic<T>)dynamic4.merge((Dynamic)super.<T>serialize(dynamicOps));
    }
    
    public static <T> SmallTreeConfiguration deserialize(final Dynamic<T> dynamic) {
        final TreeConfiguration chl2 = TreeConfiguration.<T>deserialize(dynamic);
        final FoliagePlacerType<?> chr3 = Registry.FOLIAGE_PLACER_TYPES.get(new ResourceLocation(dynamic.get("foliage_placer").get("type").asString().<Throwable>orElseThrow(RuntimeException::new)));
        return new SmallTreeConfiguration(chl2.trunkProvider, chl2.leavesProvider, (FoliagePlacer)chr3.deserialize(dynamic.get("foliage_placer").orElseEmptyMap()), chl2.decorators, chl2.baseHeight, dynamic.get("height_rand_a").asInt(0), dynamic.get("height_rand_b").asInt(0), dynamic.get("trunk_height").asInt(-1), dynamic.get("trunk_height_random").asInt(0), dynamic.get("trunk_top_offset").asInt(0), dynamic.get("trunk_top_offset_random").asInt(0), dynamic.get("foliage_height").asInt(-1), dynamic.get("foliage_height_random").asInt(0), dynamic.get("max_water_depth").asInt(0), dynamic.get("ignore_vines").asBoolean(false));
    }
    
    public static class SmallTreeConfigurationBuilder extends TreeConfigurationBuilder {
        private final FoliagePlacer foliagePlacer;
        private List<TreeDecorator> decorators;
        private int baseHeight;
        private int heightRandA;
        private int heightRandB;
        private int trunkHeight;
        private int trunkHeightRandom;
        private int trunkTopOffset;
        private int trunkTopOffsetRandom;
        private int foliageHeight;
        private int foliageHeightRandom;
        private int maxWaterDepth;
        private boolean ignoreVines;
        
        public SmallTreeConfigurationBuilder(final BlockStateProvider chw1, final BlockStateProvider chw2, final FoliagePlacer chq) {
            super(chw1, chw2);
            this.decorators = ImmutableList.of();
            this.trunkHeight = -1;
            this.foliageHeight = -1;
            this.foliagePlacer = chq;
        }
        
        public SmallTreeConfigurationBuilder decorators(final List<TreeDecorator> list) {
            this.decorators = list;
            return this;
        }
        
        @Override
        public SmallTreeConfigurationBuilder baseHeight(final int integer) {
            this.baseHeight = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder heightRandA(final int integer) {
            this.heightRandA = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder heightRandB(final int integer) {
            this.heightRandB = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder trunkHeight(final int integer) {
            this.trunkHeight = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder trunkHeightRandom(final int integer) {
            this.trunkHeightRandom = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder trunkTopOffset(final int integer) {
            this.trunkTopOffset = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder trunkTopOffsetRandom(final int integer) {
            this.trunkTopOffsetRandom = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder foliageHeight(final int integer) {
            this.foliageHeight = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder foliageHeightRandom(final int integer) {
            this.foliageHeightRandom = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder maxWaterDepth(final int integer) {
            this.maxWaterDepth = integer;
            return this;
        }
        
        public SmallTreeConfigurationBuilder ignoreVines() {
            this.ignoreVines = true;
            return this;
        }
        
        @Override
        public SmallTreeConfiguration build() {
            return new SmallTreeConfiguration(this.trunkProvider, this.leavesProvider, this.foliagePlacer, this.decorators, this.baseHeight, this.heightRandA, this.heightRandB, this.trunkHeight, this.trunkHeightRandom, this.trunkTopOffset, this.trunkTopOffsetRandom, this.foliageHeight, this.foliageHeightRandom, this.maxWaterDepth, this.ignoreVines);
        }
    }
}
