Jump to content

Recommended Posts

Posted

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));
		event.world.setBlockToAir(pos);
		player.addExperienceLevel(-1);

	}
}

 

Any help will be welcome !

Posted

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 !

Posted

Try this

player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(block, 1, block.getMetaFromState(world.getBlockState(pos))));

 

Posted

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

getPickBlock

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

 

http://www.howoldisminecraft1710.today/

Posted

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){

	@SuppressWarnings("rawtypes")
	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;

}

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.