Skip to content

How get block side which one is looking player #2449

Discussion options

You must be logged in to vote

It depends where you are in the code and what kind of raycast/HitResult you find acceptable.

If your HitResult is hitting a block you will have a BlockHitResult which has a getSide().

Assuming where you are in the code doesn't have a HitResult parameter:

On the client there is MinecraftClient.crosshairTarget which may or may not be a BlockHitResult
See MinecraftClient.doItemUse() for example.

You can do the calculation from scratch using something like:

		HitResult hit = entity.raycast(20, 0, false); // 20 is distance used by the DebugHud for "looking at block", false means ignore fluids
		if (hit.getType() == HitResult.Type.BLOCK) {
			BlockHitResult blockHit = (BlockHitResult) hit;
			i…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Intezium
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants