Jump to content

Getting a block from coordinates


HexNation

Recommended Posts

3 minutes ago, bradylox said:

do you want the cords of the block if so just do F3 then hover over the block your gonna right click the itll show you the cords of that block. Or do u need the id of blocks.

Capture.PNG

I know the the cords of the block, its just from MC Forge, there use to be some world command that allowed you to grab a block with Coordinates and it 1.11.2 idk what it is/forgot

Link to comment
Share on other sites

Which version of MC are you modding for?  At the very least, 1.10 and above (and probably 1.9, as well), would require you do something like this:

Block blockClicked = world.getBlockState(new BlockPos(x, y, z)).getBlock();

EDIT: On top of that, I would think that any method in Item that would give you the block clicked would give you the Block, or at least a BlockPos, not xyz coordinates.

Edited by Malkierian
  • Like 1
Link to comment
Share on other sites

7 minutes ago, Malkierian said:

Which version of MC are you modding for?  At the very least, 1.10 and above (and probably 1.9, as well), would require you do something like this:


Block blockClicked = world.getBlockState(new BlockPos(x, y, z)).getBlock();

EDIT: On top of that, I would think that any method in Item that would give you the block clicked would give you the Block, or at least a BlockPos, not xyz coordinates.

It does and it worked

public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
		System.out.println(world.getBlockState(pos).getBlock());
		return EnumActionResult.PASS;
    }

But just another side question, do you know how to do it with say a dropped item on the ground?

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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