(1.16.5) raycast an entity at any distance i want

Started by ElTotisPro50 on Mon, 04/18/2022 - 22:44

Topic category: Help with modding (Java Edition)

Last seen on 22:22, 21. Apr 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
(1.16.5) raycast an entity at any distance i want
Mon, 04/18/2022 - 22:44

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