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 created an item that i can use to check if the player can see the center of a specific block like this:

 

public static boolean lineOfSight(int maxRange, Entity player, BlockPos pos)
    {
        Vec3 vec3 = player.getEyePosition();
        Vec3 vec31 = pos.getCenter();
        if (vec31.distanceTo(vec3) > maxRange) { return false; }
        else
        {
            BlockHitResult result = player.level().clip(new ClipContext(vec3, vec31, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, player));
            return result.getBlockPos().getCenter().equals(pos.getCenter());
        }
    }

 This works as far as i need it.

 

Now i wanted to create a block that can do the same. In this case: If the block can see the center of a specific block. I tried it in a similar way:

    public static boolean lineOfSight(int maxRange, Level pLevel, Vec3 posFrom, BlockPos posTo)
    {
        Vec3 vec31 = posTo.getCenter();
        if (vec31.distanceTo(posFrom) > maxRange) { return false; }
        else
        {
            BlockHitResult result = pLevel.clip(new ClipContext(posFrom, vec31, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null));
            return result.getBlockPos().getCenter().equals(posTo.getCenter());
        }
    }

But obviously this does not work, because this method always returns false. The explanation is simple: The block only can see itself, because i raycast/clip from inside of my block.

 

Is there a simple way to use clip and skip this initial block where the raycast is coming from?

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.