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
Vector3d eyeVec = playerIn.getEyePosition(1.0F);
Vector3d lookVec = playerIn.getLook(1.0F);
final double distance = 20.0D;
Vector3d finVec = eyeVec.add(lookVec.getX() * distance, lookVec.getY() * distance, lookVec.getZ() * distance);
AxisAlignedBB axisalignedbb = playerIn.getBoundingBox().expand(lookVec.scale(distance)).grow(1.0D, 1.0D, 1.0D);
double d1 = distance * distance;
if (Minecraft.getInstance().objectMouseOver != null) {
	d1 = Minecraft.getInstance().objectMouseOver.getHitVec().squareDistanceTo(eyeVec);
}

EntityRayTraceResult entityRayTraceResult = ProjectileHelper.rayTraceEntities(playerIn, eyeVec, finVec, axisalignedbb, (p_215312_0_) -> {
	return !p_215312_0_.isSpectator() && p_215312_0_.canBeCollidedWith();
}, d1);

I tried to get the entity beyond the line of sight of playerIn with this code, but I can only get up to about 3 blocks. In the first place, I'm not sure what each argument of rayTraceEntities of ProjectileHelper represents. For example, which parameter should I use to get the entity in the line of sight (within 20 blocks from the player)?

I think it goes only up to 3 blocks because thats the reach of a regular PlayerEntity, might be wrong though/

 

I think your question is how to find entities on a line from one Vector3d to another. Now I know this isnt really your question but there is another way to trace entities. 

You create an AABB (AxisAlignedBoundingBox) starting at your start vector and ending at the end vector and using the world object you are raytracing in you use getEntitiesWithinAABB to get the entities that are in the cube with a vertex at the start vector and the opposite vertex at the end vector. You then iterate over the entities and use Entity#getBoundingBox#rayTrace to check if the entity is on the line.

The parameters of AABB are the top corner and the opposite corner.

The parameters of getEntitiesWithinAABB are a class object which determines which entities the function is checking for in the bounding box, i.e if you give it ProjectileEntity.class it will only return a list of entities that extend ProjectileEntity, and the bounding box AABB.

The parameters of rayTrace are the start and end vector that define the line you are checking for.

 

If you just want to know if a line goes through the boundingBox of an entity entity.getBoundingBox.rayTrace(start, end) should do it.

 

You can also use  something like World#getEntitiesWithinAABBExcluding to exclude the shooter.

 

I must say aswell, looking at it now ProjectileHelper#rayTraceEntities seems to do that ^ ish and take  the same parameters needed there so hope it explained that too.

 

Hope this was helpful and answered your question 

Edited by Iron1601

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.