Hello! I'm trying to raycast between the players eyes and an entity to see if I have line of sight to them before proceding with another action. I'm working in minecraft 1.19.4 and here is the code I'm using:
Box box = client.cameraEntity.getBoundingBox().stretch(5d,5d,5d);
client.world.getEntities().forEach(entity -> {
EntityHitResult hitResult = ProjectileUtil.raycast(player, player.getEyePos(), entity.getEyePos(), box, EntityPredicates.VALID_ENTITY.and(checkEntity->!(checkEntity instanceof PlayerEntity)), maxDistanceToTarget);
For a little more context,
the maxDistanceToTarget is set to clientInteractionManager.getReachDistance(), so about 4.5 blocks.
Also I don't totally understand exactly what the bounding box and EntityPredicates are doing at this point as I have copied some of this code from searching the fabric discord.
Right now,
I think the predicates are a filter for a type of entity that intersects the raycast.
I think the bounding box is the area that an entity's hitbox must intersect with during the raycast and that this bounding box is projected along the length of the raycast until it hits the max distance.
Is this an accurate description of the arguments?
When running, every raycast I do returns null. Even if I'm standing in a pit with zombies all around me, no line of sight obstructions, and no other player entities other than my own character.
Any help/advice is greatly appreciated!