Jump to content

Solved [1.8]Get blocks metadata (or equivalent)


Recommended Posts

Hey !

I'm trying to make it so when you right click on a block with an empty hand, it goes in your inventory. The problem is that when I right click on a blue flower, it gives me a red flower.

I know there are no more metadatas, but some properties. I would like to know how to get the color of the block I'm rightclicking on, and then convert it into an int so I can give it to my player. Here is my code:


public void clickEnderman(BlockPos pos, EntityPlayer player, Block block, PlayerInteractEvent event){
	if (isBlockEditable(block) == true && player.getCurrentEquippedItem() == null && (player.experienceLevel >= 1 || player.capabilities.isCreativeMode)){
		player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(block, 1));



Any help will be welcome !

Link to comment
Share on other sites

getPickBlock requires a moving object position, and it can only be accessed from an item. I want all this stuff to work when the player doesn't have an item.

Plus, I think it would be usefull to know how to get the damn colors from the block, I may need it some day.

Anyway, if you know how to get a moving object position without an Item, it would be usefull too !

Link to comment
Share on other sites

Doors aren't BlockContainers, and they don't have an associated ItemBlock. So you'd have to rethink your logic (Hint:


. Please use that, it is your only way to do it properly..

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.


1.12 -> 1.13 primer by williewillus.


1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.



Link to comment
Share on other sites

I'm aware of that, there's a whole list of blocks I don't want the player to pick up (such a buttons, levers, and everything you need to right click on):


public boolean isBlockEditable(Block block){

	Class[] forbidden = {BlockDoor.class, BlockButton.class, BlockContainer.class, BlockCrops.class, BlockFenceGate.class, BlockPortal.class, BlockLiquid.class, BlockFire.class, BlockLever.class, BlockRedstoneDiode.class, BlockTrapDoor.class, BlockPistonExtension.class, BlockPistonBase.class, BlockDragonEgg.class, BlockWorkbench.class, BlockAnvil.class};
	Boolean isblockeditable = true;

	for (int i=0; i<forbidden.length; i++){
		if (forbidden[i].isInstance(block) || block == Blocks.obsidian || block == Blocks.bedrock || block == Blocks.bed)
			isblockeditable = false;

	return isblockeditable;


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.

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.

  • Create New...

Important Information

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