Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have tried several different things in order to try to get where the player is looking at such as player.getLookAngle() (which now I realize doesn't have anything to do with that) and a few other methods that I can't remember right now, but the only thing I've found that works is getPlayerPOVHitResult, and that only works in children of the Item class.

Currently, I'm trying to get an entity to spawn where the player is looking at 100 blocks in the air, and I have an item mostly set up to do so, but getPlayerPOVHitResult is not working in this situation.

Here is exactly what I'm doing, if you know how to make this work properly your assistance would be highly appreciated:

        BlockHitResult povHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.ANY);

	if(!level.isClientSide && hand == InteractionHand.MAIN_HAND && !player.isCrouching() && mode == 6 && mode6) {
            DescendingShellEntity descendingShell = new DescendingShellEntity(TMEntityTypes.DESCENDING_SHELL.get(), level);
            descendingShell.setPos(povHitResult.getBlockPos().getX(), povHitResult.getBlockPos().getY() + 100, povHitResult.getBlockPos().getZ());
            level.addFreshEntity(descendingShell);

Here's the GitHub repo if it helps: https://github.com/xCrazyFeline/Turtle-Magic-1.19.2-FORGE-

Edited by xCrazyFeline
Adding GitHub repo link

Sanity is for losers. -Felix

I used the following code:

	public static @NotNull Vec3 clipWithDistance(@NotNull Player player, @NotNull Level level, double clipDistance) {
		double vecX = Math.sin(-player.getYRot() * (Math.PI / 180.0) - Math.PI) * -Math.cos(-player.getXRot() * (Math.PI / 180.0));
		double vecY = Math.sin(-player.getXRot() * (Math.PI / 180.0));
		double vecZ = Math.cos(-player.getYRot() * (Math.PI / 180.0) - Math.PI) * -Math.cos(-player.getXRot() * (Math.PI / 180.0));
		return level.clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(vecX * clipDistance, vecY * clipDistance, vecZ * clipDistance), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getLocation();
	}

Note if you also want to recognise Fluid as a block, you have to change ClipContext.Fluid.

  • Author

That works! Thank you! I'll add your name to the mod's credits for your assistance.
(I really can not thank you enough for this, I've been working on it for weeks, and it also helped me with something else I was going to have to fix)

Edited by xCrazyFeline

Sanity is for losers. -Felix

  • xCrazyFeline changed the title to [SOLVED] How to get the block the player's looking at

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.

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.