Detect the entity the player is looking at

Started by _Ness on Fri, 05/29/2020 - 21:08

Topic category: Help with modding (Java Edition)

Last seen on 15:16, 21. Apr 2021
Joined Oct 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Detect the entity the player is looking at
Fri, 05/29/2020 - 21:08

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:
  • Tracker tickets:
  • 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:
  • Tracker tickets:
  • 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 05:22, 21. Jul 2021
Joined May 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I don't believe so…
Wed, 06/10/2020 - 04:54

I don't believe so punkmonkey, sorry.

Last seen on 23:27, 4. Apr 2021
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 05:22, 21. Jul 2021
Joined May 2017
Points:

User statistics:

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

No problem. :)