package net.minecraft.world.entity.ai.village.poi;

import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableList;
import net.minecraft.world.level.block.Blocks;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.BedPart;
import net.minecraft.world.level.block.BedBlock;
import net.minecraft.Util;
import java.util.stream.Stream;
import java.util.Optional;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import java.util.Collection;
import com.google.common.collect.ImmutableSet;
import net.minecraft.world.level.block.Block;
import java.util.Map;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Set;
import java.util.function.Predicate;

public class PoiType {
    private static final Predicate<PoiType> ALL_JOBS;
    public static final Predicate<PoiType> ALL;
    private static final Set<BlockState> BEDS;
    private static final Map<BlockState, PoiType> TYPE_BY_STATE;
    public static final PoiType UNEMPLOYED;
    public static final PoiType ARMORER;
    public static final PoiType BUTCHER;
    public static final PoiType CARTOGRAPHER;
    public static final PoiType CLERIC;
    public static final PoiType FARMER;
    public static final PoiType FISHERMAN;
    public static final PoiType FLETCHER;
    public static final PoiType LEATHERWORKER;
    public static final PoiType LIBRARIAN;
    public static final PoiType MASON;
    public static final PoiType NITWIT;
    public static final PoiType SHEPHERD;
    public static final PoiType TOOLSMITH;
    public static final PoiType WEAPONSMITH;
    public static final PoiType HOME;
    public static final PoiType MEETING;
    public static final PoiType BEEHIVE;
    public static final PoiType BEE_NEST;
    public static final PoiType NETHER_PORTAL;
    private final String name;
    private final Set<BlockState> matchingStates;
    private final int maxTickets;
    private final Predicate<PoiType> predicate;
    private final int validRange;
    
    private static Set<BlockState> getBlockStates(final Block bph) {
        return ImmutableSet.copyOf(bph.getStateDefinition().getPossibleStates());
    }
    
    private PoiType(final String string, final Set<BlockState> set, final int integer3, final Predicate<PoiType> predicate, final int integer5) {
        this.name = string;
        this.matchingStates = ImmutableSet.copyOf(set);
        this.maxTickets = integer3;
        this.predicate = predicate;
        this.validRange = integer5;
    }
    
    private PoiType(final String string, final Set<BlockState> set, final int integer3, final int integer4) {
        this.name = string;
        this.matchingStates = ImmutableSet.copyOf(set);
        this.maxTickets = integer3;
        this.predicate = (asu -> asu == this);
        this.validRange = integer4;
    }
    
    public int getMaxTickets() {
        return this.maxTickets;
    }
    
    public Predicate<PoiType> getPredicate() {
        return this.predicate;
    }
    
    public int getValidRange() {
        return this.validRange;
    }
    
    @Override
    public String toString() {
        return this.name;
    }
    
    private static PoiType register(final String string, final Set<BlockState> set, final int integer3, final int integer4) {
        return registerBlockStates(Registry.POINT_OF_INTEREST_TYPE.<PoiType>register(new ResourceLocation(string), new PoiType(string, set, integer3, integer4)));
    }
    
    private static PoiType register(final String string, final Set<BlockState> set, final int integer3, final Predicate<PoiType> predicate, final int integer5) {
        return registerBlockStates(Registry.POINT_OF_INTEREST_TYPE.<PoiType>register(new ResourceLocation(string), new PoiType(string, set, integer3, predicate, integer5)));
    }
    
    private static PoiType registerBlockStates(final PoiType asu) {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: getfield        net/minecraft/world/entity/ai/village/poi/PoiType.matchingStates:Ljava/util/Set;
        //     4: aload_0         /* asu */
        //     5: invokedynamic   BootstrapMethod #1, accept:(Lnet/minecraft/world/entity/ai/village/poi/PoiType;)Ljava/util/function/Consumer;
        //    10: invokeinterface java/util/Set.forEach:(Ljava/util/function/Consumer;)V
        //    15: aload_0         /* asu */
        //    16: areturn        
        //    MethodParameters:
        //  Name  Flags  
        //  ----  -----
        //  asu   
        // 
        // The error that occurred was:
        // 
        // java.lang.IllegalStateException: Could not infer any expression.
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:374)
        //     at com.strobel.decompiler.ast.TypeAnalysis.run(TypeAnalysis.java:96)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:344)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:214)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:782)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:675)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:552)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:519)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:161)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:150)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:125)
        //     at cuchaz.enigma.SourceProvider.getSources(SourceProvider.java:85)
        //     at cuchaz.enigma.EnigmaProject$JarExport.decompileClass(EnigmaProject.java:241)
        //     at cuchaz.enigma.EnigmaProject$JarExport.lambda$decompile$1(EnigmaProject.java:230)
        //     at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        //     at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
        //     at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        //     at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        //     at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:952)
        //     at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:926)
        //     at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
        //     at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
        //     at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        //     at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        //     at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        //     at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        //     at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
    
    public static Optional<PoiType> forState(final BlockState byj) {
        return Optional.<PoiType>ofNullable(PoiType.TYPE_BY_STATE.get(byj));
    }
    
    public static Stream<BlockState> allPoiStates() {
        return PoiType.TYPE_BY_STATE.keySet().stream();
    }
    
    static {
        ALL_JOBS = (asu -> Registry.VILLAGER_PROFESSION.stream().map(VillagerProfession::getJobPoiType).collect(Collectors.toSet()).contains(asu));
        ALL = (asu -> true);
        BEDS = ImmutableList.<Block>of(Blocks.RED_BED, Blocks.BLACK_BED, Blocks.BLUE_BED, Blocks.BROWN_BED, Blocks.CYAN_BED, Blocks.GRAY_BED, Blocks.GREEN_BED, Blocks.LIGHT_BLUE_BED, Blocks.LIGHT_GRAY_BED, Blocks.LIME_BED, Blocks.MAGENTA_BED, Blocks.ORANGE_BED, Blocks.PINK_BED, Blocks.PURPLE_BED, Blocks.WHITE_BED, Blocks.YELLOW_BED).stream().flatMap(bph -> bph.getStateDefinition().getPossibleStates().stream()).filter(byj -> byj.<BedPart>getValue(BedBlock.PART) == BedPart.HEAD).collect(ImmutableSet.toImmutableSet());
        TYPE_BY_STATE = Maps.newHashMap();
        UNEMPLOYED = register("unemployed", ImmutableSet.of(), 1, PoiType.ALL_JOBS, 1);
        ARMORER = register("armorer", getBlockStates(Blocks.BLAST_FURNACE), 1, 1);
        BUTCHER = register("butcher", getBlockStates(Blocks.SMOKER), 1, 1);
        CARTOGRAPHER = register("cartographer", getBlockStates(Blocks.CARTOGRAPHY_TABLE), 1, 1);
        CLERIC = register("cleric", getBlockStates(Blocks.BREWING_STAND), 1, 1);
        FARMER = register("farmer", getBlockStates(Blocks.COMPOSTER), 1, 1);
        FISHERMAN = register("fisherman", getBlockStates(Blocks.BARREL), 1, 1);
        FLETCHER = register("fletcher", getBlockStates(Blocks.FLETCHING_TABLE), 1, 1);
        LEATHERWORKER = register("leatherworker", getBlockStates(Blocks.CAULDRON), 1, 1);
        LIBRARIAN = register("librarian", getBlockStates(Blocks.LECTERN), 1, 1);
        MASON = register("mason", getBlockStates(Blocks.STONECUTTER), 1, 1);
        NITWIT = register("nitwit", ImmutableSet.of(), 1, 1);
        SHEPHERD = register("shepherd", getBlockStates(Blocks.LOOM), 1, 1);
        TOOLSMITH = register("toolsmith", getBlockStates(Blocks.SMITHING_TABLE), 1, 1);
        WEAPONSMITH = register("weaponsmith", getBlockStates(Blocks.GRINDSTONE), 1, 1);
        HOME = register("home", PoiType.BEDS, 1, 1);
        MEETING = register("meeting", getBlockStates(Blocks.BELL), 32, 6);
        BEEHIVE = register("beehive", getBlockStates(Blocks.BEEHIVE), 0, 1);
        BEE_NEST = register("bee_nest", getBlockStates(Blocks.BEE_NEST), 0, 1);
        NETHER_PORTAL = register("nether_portal", getBlockStates(Blocks.NETHER_PORTAL), 0, 1);
    }
}
