Search in sources :

Example 1 with LeadItem

use of net.minecraft.item.LeadItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAITameAndLeashPet method canUse.

@Override
public boolean canUse() {
    if (!this.entity.canTameEntity()) {
        return false;
    }
    if ((!(this.entity.getHeldItemMainhand().getItem() instanceof LeadItem) && !(this.entity.getMainHandItem().getItem() instanceof LeadItem))) {
        return false;
    }
    if (this.random.nextInt(10) == 0) {
        Vector3d vec1 = this.entity.position().add(PET_SEARCH_RADIUS, PET_SEARCH_RADIUS * 0.5D, PET_SEARCH_RADIUS);
        Vector3d vec2 = this.entity.position().subtract(PET_SEARCH_RADIUS, PET_SEARCH_RADIUS * 0.5D, PET_SEARCH_RADIUS);
        AxisAlignedBB aabb = new AxisAlignedBB(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z);
        List<TameableEntity> possiblePets = this.entity.world.getEntitiesWithinAABB(TameableEntity.class, aabb, input -> TargetUtil.PREDICATE_PETS.apply(input) && this.entity.getSensing().canSee(input));
        if (!possiblePets.isEmpty()) {
            this.entityToTame = TargetUtil.getNearestEntity(this.entity, possiblePets);
            return true;
        }
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vector3d(net.minecraft.util.math.vector.Vector3d) TameableEntity(net.minecraft.entity.passive.TameableEntity) LeadItem(net.minecraft.item.LeadItem)

Aggregations

TameableEntity (net.minecraft.entity.passive.TameableEntity)1 LeadItem (net.minecraft.item.LeadItem)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1