# [1.15.2 | Solved] How to Raytrace from Block to Block and get facing

## Recommended Posts

I am trying to raytrace from the position of a block and i want to find the position of a block in a specific direction but all the raytracing methods i've found need an entity.

I also need to find which way the block is facing (north, east, down, ...).

Edited by Shiranai
Solved
##### Share on other sites

If your raytrace is orthogonal (directly north, directly east, directly SW), just iterate over BlockPos values.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

On 3/1/2020 at 8:49 PM, Draco18s said:

If your raytrace is orthogonal (directly north, directly east, directly SW), just iterate over BlockPos values.

Yeah, i'm doing that at the moment. It does feel kinda hacky though if you have to do it over long distances. I am currently checking in every direction. How can i get the direction the block is facing, so i can check a specific direction?

##### Share on other sites

29 minutes ago, Shiranai said:

How can i get the direction the block is facing

BlockState#get(Property<T>)

30 minutes ago, Shiranai said:

Yeah, i'm doing that at the moment. It does feel kinda hacky though if you have to do it over long distances.

RayTrace() is going to be worse, because instead of checking at 1 unit distances, it checks at 0.1 unit distances.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

2 minutes ago, Draco18s said:

RayTrace() is going to be worse, because instead of checking at 1 unit distances, it checks at 0.1 unit distances.

Oh, i always thought raytracing was a pretty resource sparing thing. Thanks

##### Share on other sites

1 hour ago, Shiranai said:

i always thought raytracing was a pretty resource sparing thing

No, no it is not.

While most "raytracing" things refer to rendering, the same process is applied by physics calculations (of which Minecraft's implementations qualify as). You have to use a very small delta otherwise you're bound to miss corners when moving diagonally at arbitrary angles.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

• 2 months later...

I managed to do it this way. It's kinda messy but hopefully it will help you.

RayTraceUtil.getTargetBlock(player, world, maxdistance)

This should give you the block you are looking at.

I'm new to modding so I'm not shure how correct this is.

Edited by Zagreo

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• ### Posts

• I'm trying to update the Mod Flywheel from 1.20.1 to 1.20.4 and get the following error message: java.lang.VerifyError: Bad type on operand stack Exception Details:   Location:     net/minecraft/client/Minecraft.handler\$zzf000\$flywheel\$onEndManualResourceReload(ZLnet/minecraft/client/Minecraft\$GameLoadCookie;Ljava/lang/Throwable;Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfo;)V @20: invokevirtual   Reason:     Type 'com/jozufozu/flywheel/api/event/EndClientResourceReloadEvent' (current frame, stack[1]) is not assignable to 'net/minecraftforge/eventbus/api/Event'   This error does not make sense as EndClientResourceReloadEvent extends net.minecraftforge.eventbus.api.Event.   Does anyone know what's going on here?   Full Logs: https://paste.ee/p/Ae28w Source code: https://github.com/JulianVennen/Flywheel
• Make a test with another Launcher like MultiMC, AT Launcher or Technic Launcher
• That’s the crash report without mods
• Add the crash-report without mods

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...