package net.minecraft.commands.arguments.blocks;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.entity.BlockEntity;
import java.util.Iterator;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtUtils;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.state.properties.Property;
import java.util.Set;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
import java.util.function.Predicate;

public class BlockInput implements Predicate<BlockInWorld> {
    private final BlockState state;
    private final Set<Property<?>> properties;
    @Nullable
    private final CompoundTag tag;
    
    public BlockInput(final BlockState cfj, final Set<Property<?>> set, @Nullable final CompoundTag le) {
        this.state = cfj;
        this.properties = set;
        this.tag = le;
    }
    
    public BlockState getState() {
        return this.state;
    }
    
    @Override
    public boolean test(final BlockInWorld cfn) {
        final BlockState cfj3 = cfn.getState();
        if (!cfj3.is(this.state.getBlock())) {
            return false;
        }
        for (final Property<?> cgl5 : this.properties) {
            if (cfj3.getValue(cgl5) != this.state.getValue(cgl5)) {
                return false;
            }
        }
        if (this.tag != null) {
            final BlockEntity cdl4 = cfn.getEntity();
            return cdl4 != null && NbtUtils.compareNbt(this.tag, cdl4.save(new CompoundTag()), true);
        }
        return true;
    }
    
    public boolean place(final ServerLevel zd, final BlockPos fu, final int integer) {
        BlockState cfj5 = Block.updateFromNeighbourShapes(this.state, zd, fu);
        if (cfj5.isAir()) {
            cfj5 = this.state;
        }
        if (!zd.setBlock(fu, cfj5, integer)) {
            return false;
        }
        if (this.tag != null) {
            final BlockEntity cdl6 = zd.getBlockEntity(fu);
            if (cdl6 != null) {
                final CompoundTag le7 = this.tag.copy();
                le7.putInt("x", fu.getX());
                le7.putInt("y", fu.getY());
                le7.putInt("z", fu.getZ());
                cdl6.load(cfj5, le7);
            }
        }
        return true;
    }
}
