Detect the entity the player is looking at

Started by _Ness on

Topic category: Help with Minecraft modding (Java Edition)

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.

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.

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;
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.

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.

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.

Joined May 2017
Points:

User statistics:

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

No problem. :)

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?

 

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?

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