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

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 !

  • Author

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 !

Try this

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

 

What do you mean no accossiated item? You mean the ItemBlock just doesn't exist, or the item is unobtainable in vanilla

  • Author

Thanks for these infos, they're duly noted. I don't allow BlockContainers to be picked up, so I don't have any problems, but it's good to know if i ever need to know how to pick up flowerpots, thanks !

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/

  • Author

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;

}

  • Author

Yep, you're right.

Here is what I did:

player.inventory.setInventorySlotContents(player.inventory.currentItem, block.getPickBlock(new MovingObjectPosition(player), event.world, pos));

 

Thanks !

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.