Detect the entity the player is looking at

Started by _Ness on

Topic category: Help with modding (Java Edition)

Last seen on 07:12, 23. Jan 2023
Joined Oct 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Detect the entity the player is looking at

Hi, I'm trying to make a procedure that affects the entity a player is looking at, on player tick update, is it possible ? Tell me if I'm not being precise enough, and thank you in advance.

Last seen on 19:13, 24. May 2021
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes that is possible.
Fri, 05/29/2020 - 21:19

Yes that is possible.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Of course it is possible!…
Sun, 05/31/2020 - 01:02

Of course it is possible! Look at raytracing. I believe MCreator has raytracing capabilities. But here is a snippet from one of my mods if you need direction that apply this (1.15.2)

 

if (rayTraceResult.getType() == RayTraceResult.Type.ENTITY) {
                    playercap.addChakra(-chakraAmount * playercap.returnChakraControl());
                    BlockPos pos = ((EntityRayTraceResult) rayTraceResult).getEntity().getPosition();
                    Entity entity = ((EntityRayTraceResult) rayTraceResult).getEntity();
                    System.out.println(entity);
                    entity.setPositionAndUpdate(playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ());
                    playerIn.setPositionAndUpdate(pos.getX(), pos.getY(), pos.getZ());

This "switches" places with you and the entity you look at (that may not be what you need but the point is still there). I get the results using the method below.

RayTraceResult rayTraceResult = Minecraft.getInstance().objectMouseOver;
Last seen on 01:41, 8. Jan 2024
Joined May 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Tbroski, is there a way to…
Wed, 06/10/2020 - 04:49

Tbroski, is there a way to recreate this in procedure form? I'm not familiar with coding, and need to customize it so that my custom mob freezes when I look at it.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't believe so…
Wed, 06/10/2020 - 04:54

I don't believe so punkmonkey, sorry.

Last seen on 04:13, 19. Jun 2023
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I guess you could without…
Wed, 06/10/2020 - 18:09

I guess you could without coding, since there is procedure blocks for "look x y z position - raytrace distance", maybe by coinciding angles from the distance between you and the mob and the mob position and where you are looking you could set the mob in cobweb or setting its speed to 0 0 0. Maybe you do not even have to coincide angles, if where you are looking is coinciding with the mob position it will set its speed to 0 0 0.

Last seen on 01:41, 8. Jan 2024
Joined May 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No problem. :)
Sun, 06/14/2020 - 19:14

No problem. :)

Last seen on 14:47, 27. Mar 2024
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is there a way to do this in…
Wed, 10/06/2021 - 04:20

is there a way to do this in 1.12.2?

 

Last seen on 14:47, 27. Mar 2024
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
what does that mean?
Wed, 10/06/2021 - 17:23

what does that mean?

Last seen on 12:00, 30. Dec 2023
Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
can someone try to make it…
Sat, 05/13/2023 - 15:43

can someone try to make it with procedures?
i can't quite figure it out

Last seen on 16:50, 26. Aug 2023
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try something using this:…
Sat, 08/26/2023 - 10:46

Try something using this:

https://imgur.com/y7OcmJS

It will help a lot