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 am trying to determine if a player is looking at a chest or not, I have looked through the Entity and the Look helper but I have not seen anything that helps. Is there anything that helps determine what a player is looking at in the code or do I have to get the player facing direction and eye height and mathematically walk the line of site and test for a block at each point until I hit !air or chest.

 

If so any examples as I am being lazy and my trig is rusty :)

float f = 1.0F;
                        float f1 = p.prevRotationPitch + (p.rotationPitch - p.prevRotationPitch) * f;
                        float f2 = p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * f;
                        double d0 = p.prevPosX + (p.posX - p.prevPosX) * (double)f;
                        double d1 = p.prevPosY + (p.posY - p.prevPosY) * (double)f + 1.62D - (double)p.yOffset;
                        double d2 = p.prevPosZ + (p.posZ - p.prevPosZ) * (double)f;
                        Vec3 vec3 = world.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
                        float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
                        float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
                        float f5 = -MathHelper.cos(-f1 * 0.017453292F);
                        float f6 = MathHelper.sin(-f1 * 0.017453292F);
                        float f7 = f4 * f5;
                        float f8 = f3 * f5;
                        double d3 = 5.0D;
                        Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
                        MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do_do(vec3, vec31, false, true);
                        if (movingobjectposition == null) {
                        	return;
                        }
                        if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
                        {
                            int ix = movingobjectposition.blockX;
                            int iy = movingobjectposition.blockY;
                            int iz = movingobjectposition.blockZ;
                            //block is at ix, iy, iz
                        }

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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

  • Author

Flipin awesome! That saved some math ;)

 

I had a sinking feeling that this would have been needed and I would be pulling out my old 3d math logic :)

 

 

Flipin awesome! That saved some math ;)

 

I had a sinking feeling that this would have been needed and I would be pulling out my old 3d math logic :)

 

TBH, I yoinked that out of the....boat code.

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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

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.