(1.16.5) raycast an entity at any distance i want

Started by ElTotisPro50 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(1.16.5) raycast an entity at any distance i want

i know that for raycasting blocks you use this code:

 

double rayCastDistance = 20;
RayTraceResult result = player.pick(rayCastDistance ,0.0F,false);
 if(result.getType() == RayTraceResult.Type.BLOCK)
 {
        BlockPos lookPos = ((BlockRayTraceResult) result).getPos(); //This changes too but i know what goes here
        BlockState state = world.getBlockState(lookPos); //and here

}

 

and for entities you change  .Type.BLOCK to .Type.ENTITY and player.pick to Minecraft.getInstance().objectMouseOver but that doesnt let me change the ray cast distance, objectMouseOver only works a few meters away from the entity you want to raycast, but i want to make you can raycast an entity 50 blocks away or anything i want

how can i do that? (raycast the entity im looking at)

PD: code or procedures is ok