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've been exploring code for the last 4 hours and I can't find a way to make that work. 

 

Also tried the search on the forums but couldn't come up with better keywords, I'm afraid.

 

Is it possible to get the "NORTH; EAST; WEST; UP; DOWN; SOUTH" side  of a block corresponding to the player crosshair?

 

I want to call it inside of onItemUse, or onItemUseFirst.

Pulled this from my code, use/edit freely

 

/**
 * If [4] is -1 , there was no block within reach.
 * @return [0]= BlockId, [1]= BlockX, [2]= BlockY, [3]= BlockZ, [4]= SideHit, [5]= BlockMeta
 */
public static int[] getBlockInfront(World theWorld, EntityPlayer thePlayer, double reach)
{
	int[] blockInfo = { 0, 0, 0, 0, -1, 0 };

	MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(theWorld, thePlayer, true, reach);
	if (movingobjectposition != null) {
		if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
			blockInfo[1] = movingobjectposition.blockX;
			blockInfo[2] = movingobjectposition.blockY;
			blockInfo[3] = movingobjectposition.blockZ;
			blockInfo[4] = movingobjectposition.sideHit;
			blockInfo[5] = theWorld.getBlockMetadata(blockInfo[1], blockInfo[2], blockInfo[3]);
			blockInfo[0] = theWorld.getBlockId(blockInfo[1], blockInfo[2], blockInfo[3]);
		}
	}
	return blockInfo;
}

private static MovingObjectPosition getMovingObjectPositionFromPlayer(World world, EntityPlayer entityplayer, boolean flag, double reach)
{
	float f = 1.0F;
	float playerPitch = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f;
	float playerYaw = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
	double playerPosX = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * f;
	double playerPosY = (entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * f + 1.6200000000000001D) - entityplayer.yOffset;
	double playerPosZ = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * f;
	Vec3 vecPlayer = Vec3.createVectorHelper(playerPosX, playerPosY, playerPosZ);
	float cosYaw = MathHelper.cos(-playerYaw * 0.01745329F - 3.141593F);
	float sinYaw = MathHelper.sin(-playerYaw * 0.01745329F - 3.141593F);
	float cosPitch = -MathHelper.cos(-playerPitch * 0.01745329F);
	float sinPitch = MathHelper.sin(-playerPitch * 0.01745329F);
	float pointX = sinYaw * cosPitch;
	float pointY = sinPitch;
	float pointZ = cosYaw * cosPitch;
	Vec3 vecPoint = vecPlayer.addVector(pointX * reach, pointY * reach, pointZ * reach);
	MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do_do(vecPlayer, vecPoint, flag, !flag);
	return movingobjectposition;
}

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.