package net.minecraft.world.entity.ai.behavior;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.entity.ai.memory.WalkTarget;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import com.google.common.collect.Lists;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.item.ItemEntity;
import java.util.List;
import net.minecraft.world.entity.npc.Villager;

public class PickUpItems extends Behavior<Villager> {
    private List<ItemEntity> items;
    
    public PickUpItems() {
        super(ImmutableMap.<MemoryModuleType<PositionWrapper>, MemoryStatus>of(MemoryModuleType.LOOK_TARGET, MemoryStatus.VALUE_ABSENT, (MemoryModuleType<PositionWrapper>)MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT));
        this.items = Lists.newArrayList();
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel xd, final Villager axw) {
        this.items = xd.<ItemEntity>getEntitiesOfClass(ItemEntity.class, axw.getBoundingBox().inflate(4.0, 2.0, 4.0));
        return !this.items.isEmpty();
    }
    
    @Override
    protected void start(final ServerLevel xd, final Villager axw, final long long3) {
        final ItemEntity awb6 = this.items.get(xd.random.nextInt(this.items.size()));
        if (axw.wantToPickUp(awb6.getItem().getItem())) {
            final Vec3 cvl7 = awb6.position();
            axw.getBrain().<BlockPosWrapper>setMemory((MemoryModuleType<BlockPosWrapper>)MemoryModuleType.LOOK_TARGET, new BlockPosWrapper(new BlockPos(cvl7)));
            axw.getBrain().<WalkTarget>setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(cvl7, 0.5f, 0));
        }
    }
}
