HELP Custom Raytrace from Block

Started by Soul of Cinder on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
HELP Custom Raytrace from Block

Hello, I'm working on a custom landmine block that detect nearby players and explode only if the player is actually visible (not behind a wall or solid block). Is there a clean way to perform ray tracing from a block’s position (not from an entity), using only MCreator procedures or plugins? Or at least a more efficient workaround that doesn’t rely on spawning and removing fake entities? or do i have to use custom code? Thanks in advance.

Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
damn, no one know anything…
Tue, 07/01/2025 - 17:19

damn, no one know anything on raycast ? because i have alot of blocks that need it

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There is a way to do this…
Tue, 07/01/2025 - 18:06

There is a way to do this with procedures and not using entities. I am writing this assuming that you are relatively familiar with procedures and don't need a step-by-step walkthrough of how to put different procedure blocks together or create local variables.

You first need the coordinates of the two locations you want to check line of sight between.

Then you need to determine the distance between the two locations ([x1-x2]+[y1-y2]+[z1-z2])

Third you need to determine a set of numbers that I don't know a good term for. Basically they represent a step on the line, and you can use something like x1-x2/distance (or possibly x2-x1/distance I haven't done this in a while) for x, y, and z axis.

Fourth you need to create another number variable as a counter and set it to 1, and a logic variable to return if line of sight is clear, set to true initially.

Fifth you need to repeat distance times, checking if it is air or water at x1+(xLineStep*counter) y1+yLineStep*counter) z1+(zLineStep*counter) if it is air or water, increment counter by 1, if it is not air or water, set the logic variable to false.

That should allow you to determine if one location has line of sight to another. You could use your block as the first position, and the X, Y, and Z positions of the nearest player within a certain radius as the second position, possibly increasing the target Y by 1 to target the middle of the player instead of their feet.

This isn't a perfect solution, and it may get stuck on corners, if you want more accuracy, you can divide the line step by a number and multiply the repetitions by the same number to have more precision, although at the possible cost of performance.

Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
HELLO thanks for your help i…
Thu, 07/03/2025 - 12:45

HELLO thanks for your help i needed some time to understand what you wrote but i finally managed to do it thx a lot!

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm glad I was able to help
Thu, 07/03/2025 - 12:59

I'm glad I was able to help